Skip to content

Commit

Permalink
[MouseWithoutBorders] - fix references to Logger - microsoft#34126
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeclayton committed Sep 27, 2024
1 parent 1132f4e commit c35590d
Show file tree
Hide file tree
Showing 28 changed files with 488 additions and 451 deletions.
137 changes: 69 additions & 68 deletions src/modules/MouseWithoutBorders/App/Class/Common.Clipboard.cs

Large diffs are not rendered by default.

47 changes: 24 additions & 23 deletions src/modules/MouseWithoutBorders/App/Class/Common.DragDrop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
// 2023- Included in PowerToys.
// </history>
using MouseWithoutBorders.Class;
using MouseWithoutBorders.Core;

namespace MouseWithoutBorders
{
Expand Down Expand Up @@ -73,12 +74,12 @@ internal static void DragDropStep01(int wParam)
MouseDown = true;
DragMachine = desMachineID;
dropMachineID = ID.NONE;
LogDebug("DragDropStep01: MouseDown");
Logger.LogDebug("DragDropStep01: MouseDown");
}
else if (wParam == WM_LBUTTONUP)
{
MouseDown = false;
LogDebug("DragDropStep01: MouseUp");
Logger.LogDebug("DragDropStep01: MouseUp");
}

if (wParam == WM_RBUTTONUP && IsDropping)
Expand All @@ -92,7 +93,7 @@ internal static void DragDropStep02()
{
if (desMachineID == MachineID)
{
LogDebug("DragDropStep02: SendCheckExplorerDragDrop sent to myself");
Logger.LogDebug("DragDropStep02: SendCheckExplorerDragDrop sent to myself");
DoSomethingInUIThread(() =>
{
_ = NativeMethods.PostMessage(MainForm.Handle, NativeMethods.WM_CHECK_EXPLORER_DRAG_DROP, (IntPtr)0, (IntPtr)0);
Expand All @@ -101,7 +102,7 @@ internal static void DragDropStep02()
else
{
SendCheckExplorerDragDrop();
LogDebug("DragDropStep02: SendCheckExplorerDragDrop sent");
Logger.LogDebug("DragDropStep02: SendCheckExplorerDragDrop sent");
}
}

Expand All @@ -114,11 +115,11 @@ internal static void DragDropStep03(DATA package)

if (package.Des == MachineID || package.Des == ID.ALL)
{
LogDebug("DragDropStep03: ExplorerDragDrop Received.");
Logger.LogDebug("DragDropStep03: ExplorerDragDrop Received.");
dropMachineID = package.Src; // Drop machine is the machine that sent ExplorerDragDrop
if (MouseDown || IsDropping)
{
LogDebug("DragDropStep03: Mouse is down, check if dragging...sending WM_CHECK_EXPLORER_DRAG_DROP to myself...");
Logger.LogDebug("DragDropStep03: Mouse is down, check if dragging...sending WM_CHECK_EXPLORER_DRAG_DROP to myself...");
DoSomethingInUIThread(() =>
{
_ = NativeMethods.PostMessage(MainForm.Handle, NativeMethods.WM_CHECK_EXPLORER_DRAG_DROP, (IntPtr)0, (IntPtr)0);
Expand Down Expand Up @@ -150,12 +151,12 @@ internal static void DragDropStep04()
{
if (dragDropStep05ExCalledByIpc > 0)
{
LogDebug("DragDropStep04: DragDropStep05ExCalledByIpc.");
Logger.LogDebug("DragDropStep04: DragDropStep05ExCalledByIpc.");
break;
}

_ = NativeMethods.GetCursorPos(ref p);
LogDebug("DragDropStep04: Moving Mouse Without Borders Helper to (" + p.X.ToString(CultureInfo.CurrentCulture) + ", " + p.Y.ToString(CultureInfo.CurrentCulture) + ")");
Logger.LogDebug("DragDropStep04: Moving Mouse Without Borders Helper to (" + p.X.ToString(CultureInfo.CurrentCulture) + ", " + p.Y.ToString(CultureInfo.CurrentCulture) + ")");
_ = NativeMethods.SetWindowPos(h, NativeMethods.HWND_TOPMOST, p.X - 100 + i, p.Y - 100 + i, 200, 200, 0);
_ = NativeMethods.SendMessage(h, 0x000F, IntPtr.Zero, IntPtr.Zero); // WM_PAINT
Thread.Sleep(20);
Expand All @@ -166,20 +167,20 @@ internal static void DragDropStep04()
}
else
{
LogDebug("DragDropStep04: Mouse without Borders Helper not found!");
Logger.LogDebug("DragDropStep04: Mouse without Borders Helper not found!");
}
}
else
{
LogDebug("DragDropStep04: IsDropping == true, skip checking");
Logger.LogDebug("DragDropStep04: IsDropping == true, skip checking");
}

LogDebug("DragDropStep04: Got WM_CHECK_EXPLORER_DRAG_DROP, done with processing jump to DragDropStep05...");
Logger.LogDebug("DragDropStep04: Got WM_CHECK_EXPLORER_DRAG_DROP, done with processing jump to DragDropStep05...");
}

internal static void DragDropStep05Ex(string dragFileName)
{
LogDebug("DragDropStep05 called.");
Logger.LogDebug("DragDropStep05 called.");

_ = Interlocked.Exchange(ref dragDropStep05ExCalledByIpc, 1);

Expand All @@ -204,21 +205,21 @@ internal static void DragDropStep05Ex(string dragFileName)
}
DragDropStep06();
LogDebug("DragDropStep05: File dragging: " + dragFileName);
Logger.LogDebug("DragDropStep05: File dragging: " + dragFileName);
_ = NativeMethods.PostMessage(MainForm.Handle, NativeMethods.WM_HIDE_DD_HELPER, (IntPtr)1, (IntPtr)0);
}
else
{
LogDebug("DragDropStep05: File not found: [" + dragFileName + "]");
Logger.LogDebug("DragDropStep05: File not found: [" + dragFileName + "]");
_ = NativeMethods.PostMessage(MainForm.Handle, NativeMethods.WM_HIDE_DD_HELPER, (IntPtr)0, (IntPtr)0);
}
LogDebug("DragDropStep05: WM_HIDE_DDHelper sent");
Logger.LogDebug("DragDropStep05: WM_HIDE_DDHelper sent");
});
}
else
{
LogDebug("DragDropStep05: IsDropping == true, change drop machine...");
Logger.LogDebug("DragDropStep05: IsDropping == true, change drop machine...");
IsDropping = false;
MainFormVisible = true; // WM_HIDE_DRAG_DROP
SendDropBegin(); // To dropMachineID set in DragDropStep03
Expand All @@ -230,15 +231,15 @@ internal static void DragDropStep05Ex(string dragFileName)
internal static void DragDropStep06()
{
IsDragging = true;
LogDebug("DragDropStep06: SendClipboardBeatDragDrop");
Logger.LogDebug("DragDropStep06: SendClipboardBeatDragDrop");
SendClipboardBeatDragDrop();
SendDropBegin();
}

internal static void DragDropStep08(DATA package)
{
GetNameOfMachineWithClipboardData(package);
LogDebug("DragDropStep08: ClipboardDragDrop Received. machine with drag file was set");
Logger.LogDebug("DragDropStep08: ClipboardDragDrop Received. machine with drag file was set");
}

internal static void DragDropStep08_2(DATA package)
Expand All @@ -247,7 +248,7 @@ internal static void DragDropStep08_2(DATA package)
{
IsDropping = true;
dropMachineID = MachineID;
LogDebug("DragDropStep08_2: ClipboardDragDropOperation Received. IsDropping set");
Logger.LogDebug("DragDropStep08_2: ClipboardDragDropOperation Received. IsDropping set");
}
}

Expand Down Expand Up @@ -278,7 +279,7 @@ internal static void DragDropStep09(int wParam)

internal static void DragDropStep10()
{
LogDebug("DragDropStep10: Hide the form and get data...");
Logger.LogDebug("DragDropStep10: Hide the form and get data...");
IsDropping = false;
IsDragging = false;
LastIDWithClipboardData = ID.NONE;
Expand All @@ -294,7 +295,7 @@ internal static void DragDropStep10()

internal static void DragDropStep11()
{
LogDebug("DragDropStep11: Mouse drag coming back, canceling drag/drop");
Logger.LogDebug("DragDropStep11: Mouse drag coming back, canceling drag/drop");
SendClipboardBeatDragDropEnd();
IsDropping = false;
IsDragging = false;
Expand All @@ -306,7 +307,7 @@ internal static void DragDropStep11()

internal static void DragDropStep12()
{
LogDebug("DragDropStep12: ClipboardDragDropEnd received");
Logger.LogDebug("DragDropStep12: ClipboardDragDropEnd received");
IsDropping = false;
LastIDWithClipboardData = ID.NONE;

Expand Down Expand Up @@ -374,7 +375,7 @@ internal static void SendClipboardBeatDragDrop()

internal static void SendDropBegin()
{
LogDebug("SendDropBegin...");
Logger.LogDebug("SendDropBegin...");
SendPackage(dropMachineID, PackageType.ClipboardDragDropOperation);
}

Expand Down
10 changes: 7 additions & 3 deletions src/modules/MouseWithoutBorders/App/Class/Common.Encryption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@
using System.Security.Cryptography;
using System.Threading.Tasks;

using MouseWithoutBorders.Core;

namespace MouseWithoutBorders
{
internal partial class Common
{
#pragma warning disable SYSLIB0021
private static AesCryptoServiceProvider symAl;
#pragma warning restore SYSLIB0021
private static string myKey;
#pragma warning disable SA1307 // Accessible fields should begin with upper-case letter
internal static string myKey;
#pragma warning restore SA1307
private static uint magicNumber;
private static Random ran = new(); // Used for non encryption related functionality.
internal const int SymAlBlockSize = 16;
Expand Down Expand Up @@ -106,7 +110,7 @@ internal static void InitEncryption()
}
catch (Exception e)
{
Log(e);
Logger.Log(e);
}
}

Expand Down Expand Up @@ -189,7 +193,7 @@ internal static uint Get24BitHash(string st)
hashValue = hash.ComputeHash(hashValue);
}

Common.LogDebug(string.Format(CultureInfo.CurrentCulture, "magic: {0},{1},{2}", hashValue[0], hashValue[1], hashValue[^1]));
Logger.LogDebug(string.Format(CultureInfo.CurrentCulture, "magic: {0},{1},{2}", hashValue[0], hashValue[1], hashValue[^1]));
hash.Clear();
return (uint)((hashValue[0] << 23) + (hashValue[1] << 16) + (hashValue[^1] << 8) + hashValue[2]);
}
Expand Down
25 changes: 14 additions & 11 deletions src/modules/MouseWithoutBorders/App/Class/Common.Event.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// 2023- Included in PowerToys.
// </history>
using MouseWithoutBorders.Class;
using MouseWithoutBorders.Core;
using MouseWithoutBorders.Form;

namespace MouseWithoutBorders
Expand All @@ -26,8 +27,10 @@ internal partial class Common
{
private static readonly DATA KeybdPackage = new();
private static readonly DATA MousePackage = new();
private static ulong inputEventCount;
private static ulong invalidPackageCount;
#pragma warning disable SA1307 // Accessible fields should begin with upper-case names
internal static ulong inputEventCount;
internal static ulong invalidPackageCount;
#pragma warning restore SA1307
internal static int MOVE_MOUSE_RELATIVE = 100000;
internal static int XY_BY_PIXEL = 300000;

Expand Down Expand Up @@ -73,7 +76,7 @@ internal static void MouseEvent(MOUSEDATA e, int dx, int dy)
{
HasSwitchedMachineSinceLastCopy = true;

Common.LogDebug(string.Format(
Logger.LogDebug(string.Format(
CultureInfo.CurrentCulture,
"***** Host Machine: newDesMachineIdEx set = [{0}]. Mouse is now at ({1},{2})",
newDesMachineIdEx,
Expand Down Expand Up @@ -117,7 +120,7 @@ internal static void MouseEvent(MOUSEDATA e, int dx, int dy)

if (actualLastPos != Common.LastPos)
{
Common.LogDebug($"Mouse cursor has moved unexpectedly: Expected: {Common.LastPos}, actual: {actualLastPos}.");
Logger.LogDebug($"Mouse cursor has moved unexpectedly: Expected: {Common.LastPos}, actual: {actualLastPos}.");
Common.LastPos = actualLastPos;
}
}
Expand All @@ -138,7 +141,7 @@ internal static void MouseEvent(MOUSEDATA e, int dx, int dy)
}
catch (Exception ex)
{
Log(ex);
Logger.Log(ex);
}
}

Expand All @@ -149,11 +152,11 @@ private static bool IsSwitchingByMouseEnabled()

internal static void PrepareToSwitchToMachine(ID newDesMachineID, Point desMachineXY)
{
LogDebug($"PrepareToSwitchToMachine: newDesMachineID = {newDesMachineID}, desMachineXY = {desMachineXY}");
Logger.LogDebug($"PrepareToSwitchToMachine: newDesMachineID = {newDesMachineID}, desMachineXY = {desMachineXY}");

if (((GetTick() - lastJump < 100) && (GetTick() - lastJump > 0)) || desMachineID == ID.ALL)
{
LogDebug("PrepareToSwitchToMachine: lastJump");
Logger.LogDebug("PrepareToSwitchToMachine: lastJump");
return;
}

Expand All @@ -163,7 +166,7 @@ internal static void PrepareToSwitchToMachine(ID newDesMachineID, Point desMachi

if (!IsConnectedTo(newDesMachineID))
{// Connection lost, cancel switching
LogDebug("No active connection found for " + newDesMachineName);
Logger.LogDebug("No active connection found for " + newDesMachineName);

// ShowToolTip("No active connection found for [" + newDesMachineName + "]!", 500);
}
Expand Down Expand Up @@ -198,7 +201,7 @@ internal static void PrepareToSwitchToMachine(ID newDesMachineID, Point desMachi
// Change des machine
if (desMachineID != newDesMachineID)
{
LogDebug("MouseEvent: Switching to new machine:" + newDesMachineName);
Logger.LogDebug("MouseEvent: Switching to new machine:" + newDesMachineName);

// Ask current machine to hide the Mouse cursor
if (newDesMachineID != ID.ALL && desMachineID != MachineID)
Expand Down Expand Up @@ -246,7 +249,7 @@ internal static void KeybdEvent(KEYBDDATA e)
PaintCount = 0;
if (desMachineID != newDesMachineID)
{
LogDebug("KeybdEvent: Switching to new machine...");
Logger.LogDebug("KeybdEvent: Switching to new machine...");
DesMachineID = newDesMachineID;
}

Expand All @@ -265,7 +268,7 @@ internal static void KeybdEvent(KEYBDDATA e)
}
catch (Exception ex)
{
Log(ex);
Logger.Log(ex);
}
}
}
Expand Down
Loading

0 comments on commit c35590d

Please sign in to comment.