mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-15 03:07:56 +01:00
[MWB][CQ]Refactoring "Common" classes - Common.Log.cs (#35156)
* [MouseWithoutBorders] - split "Common.Log.cs" into "Logger.cs" * [MouseWithoutBorders] - fix references to Logger * [MouseWithoutBorders] - add MouseWithoutBorders.UnitTests * [MouseWithoutBorders] - fixing broken tests * [MouseWithoutBorders] - fixing spelling * [MouseWithoutBorders] - fixing spelling * [MouseWithoutBorders] - fixing resource filename casing * [MouseWithoutBorders] - fixing resource filename casing * [MouseWithoutBorders] - fixing resource filename casing * [MouseWithoutBorders] - fixing resource filename casing * [MouseWithoutBorders] - fixed compile error * [MouseWithoutBorders] - fixed failing test * [MouseWithoutBorders] - fixed failing build * [MouseWithoutBorders] - ignore flakey test
This commit is contained in:
1
.github/actions/spell-check/expect.txt
vendored
1
.github/actions/spell-check/expect.txt
vendored
@@ -1911,6 +1911,7 @@ XFile
|
||||
XIncrement
|
||||
XLoc
|
||||
XNamespace
|
||||
Xoshiro
|
||||
XPels
|
||||
XPixel
|
||||
xplorer
|
||||
|
||||
@@ -622,6 +622,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WorkspacesLauncher", "src\m
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WorkspacesWindowArranger", "src\modules\Workspaces\WorkspacesWindowArranger\WorkspacesWindowArranger.vcxproj", "{37D07516-4185-43A4-924F-3C7A5D95ECF6}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MouseWithoutBorders.UnitTests", "src\modules\MouseWithoutBorders\MouseWithoutBorders.UnitTests\MouseWithoutBorders.UnitTests.csproj", "{66614C26-314C-4B91-9071-76133422CFEF}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|ARM64 = Debug|ARM64
|
||||
@@ -2734,6 +2736,18 @@ Global
|
||||
{37D07516-4185-43A4-924F-3C7A5D95ECF6}.Release|x64.Build.0 = Release|x64
|
||||
{37D07516-4185-43A4-924F-3C7A5D95ECF6}.Release|x86.ActiveCfg = Release|x64
|
||||
{37D07516-4185-43A4-924F-3C7A5D95ECF6}.Release|x86.Build.0 = Release|x64
|
||||
{66614C26-314C-4B91-9071-76133422CFEF}.Debug|ARM64.ActiveCfg = Debug|ARM64
|
||||
{66614C26-314C-4B91-9071-76133422CFEF}.Debug|ARM64.Build.0 = Debug|ARM64
|
||||
{66614C26-314C-4B91-9071-76133422CFEF}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{66614C26-314C-4B91-9071-76133422CFEF}.Debug|x64.Build.0 = Debug|x64
|
||||
{66614C26-314C-4B91-9071-76133422CFEF}.Debug|x86.ActiveCfg = Debug|x64
|
||||
{66614C26-314C-4B91-9071-76133422CFEF}.Debug|x86.Build.0 = Debug|x64
|
||||
{66614C26-314C-4B91-9071-76133422CFEF}.Release|ARM64.ActiveCfg = Release|ARM64
|
||||
{66614C26-314C-4B91-9071-76133422CFEF}.Release|ARM64.Build.0 = Release|ARM64
|
||||
{66614C26-314C-4B91-9071-76133422CFEF}.Release|x64.ActiveCfg = Release|x64
|
||||
{66614C26-314C-4B91-9071-76133422CFEF}.Release|x64.Build.0 = Release|x64
|
||||
{66614C26-314C-4B91-9071-76133422CFEF}.Release|x86.ActiveCfg = Release|x64
|
||||
{66614C26-314C-4B91-9071-76133422CFEF}.Release|x86.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@@ -2962,6 +2976,7 @@ Global
|
||||
{367D7543-7DBA-4381-99F1-BF6142A996C4} = {A2221D7E-55E7-4BEA-90D1-4F162D670BBF}
|
||||
{2CAC093E-5FCF-4102-9C2C-AC7DD5D9EB96} = {A2221D7E-55E7-4BEA-90D1-4F162D670BBF}
|
||||
{37D07516-4185-43A4-924F-3C7A5D95ECF6} = {A2221D7E-55E7-4BEA-90D1-4F162D670BBF}
|
||||
{66614C26-314C-4B91-9071-76133422CFEF} = {B6C42F16-73EB-477E-8B0D-4E6CF6C20AAC}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {C3A2F9D1-7930-4EF4-A6FC-7EE0A99821D0}
|
||||
|
||||
@@ -28,6 +28,7 @@ using Microsoft.PowerToys.Telemetry;
|
||||
// 2023- Included in PowerToys.
|
||||
// </history>
|
||||
using MouseWithoutBorders.Class;
|
||||
using MouseWithoutBorders.Core;
|
||||
using MouseWithoutBorders.Exceptions;
|
||||
|
||||
using SystemClipboard = System.Windows.Forms.Clipboard;
|
||||
@@ -83,8 +84,8 @@ namespace MouseWithoutBorders
|
||||
|
||||
internal static bool CheckClipboardEx(ByteArrayOrString data, bool isFilePath)
|
||||
{
|
||||
LogDebug($"{nameof(CheckClipboardEx)}: ShareClipboard = {Setting.Values.ShareClipboard}, TransferFile = {Setting.Values.TransferFile}, data = {data}.");
|
||||
LogDebug($"{nameof(CheckClipboardEx)}: {nameof(Setting.Values.OneWayClipboardMode)} = {Setting.Values.OneWayClipboardMode}.");
|
||||
Logger.LogDebug($"{nameof(CheckClipboardEx)}: ShareClipboard = {Setting.Values.ShareClipboard}, TransferFile = {Setting.Values.TransferFile}, data = {data}.");
|
||||
Logger.LogDebug($"{nameof(CheckClipboardEx)}: {nameof(Setting.Values.OneWayClipboardMode)} = {Setting.Values.OneWayClipboardMode}.");
|
||||
|
||||
if (!Setting.Values.ShareClipboard)
|
||||
{
|
||||
@@ -98,7 +99,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
if (GetTick() - LastClipboardEventTime < 1000)
|
||||
{
|
||||
LogDebug("GetTick() - lastClipboardEventTime < 1000");
|
||||
Logger.LogDebug("GetTick() - lastClipboardEventTime < 1000");
|
||||
LastClipboardEventTime = GetTick();
|
||||
return false;
|
||||
}
|
||||
@@ -130,7 +131,7 @@ namespace MouseWithoutBorders
|
||||
{
|
||||
if (lastClipboardObject is string lastStringData && lastStringData.Equals(stringData, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
LogDebug("CheckClipboardEx: Same string data.");
|
||||
Logger.LogDebug("CheckClipboardEx: Same string data.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -139,11 +140,11 @@ namespace MouseWithoutBorders
|
||||
|
||||
if (isFilePath)
|
||||
{
|
||||
Common.LogDebug("Clipboard contains FileDropList");
|
||||
Logger.LogDebug("Clipboard contains FileDropList");
|
||||
|
||||
if (!Setting.Values.TransferFile)
|
||||
{
|
||||
Common.LogDebug("TransferFile option is unchecked.");
|
||||
Logger.LogDebug("TransferFile option is unchecked.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -155,7 +156,7 @@ namespace MouseWithoutBorders
|
||||
{
|
||||
if (File.Exists(filePath) && new FileInfo(filePath).Length <= MAX_CLIPBOARD_FILE_SIZE_CAN_BE_SENT)
|
||||
{
|
||||
LogDebug("Clipboard contains: " + filePath);
|
||||
Logger.LogDebug("Clipboard contains: " + filePath);
|
||||
LastDragDropFile = filePath;
|
||||
SendClipboardBeat();
|
||||
SetToggleIcon(new int[TOGGLE_ICONS_SIZE] { ICON_BIG_CLIPBOARD, -1, ICON_BIG_CLIPBOARD, -1 });
|
||||
@@ -164,7 +165,7 @@ namespace MouseWithoutBorders
|
||||
{
|
||||
if (Directory.Exists(filePath))
|
||||
{
|
||||
LogDebug("Clipboard contains a directory: " + filePath);
|
||||
Logger.LogDebug("Clipboard contains a directory: " + filePath);
|
||||
LastDragDropFile = filePath;
|
||||
SendClipboardBeat();
|
||||
}
|
||||
@@ -172,7 +173,7 @@ namespace MouseWithoutBorders
|
||||
{
|
||||
LastDragDropFile = filePath + " - File too big (greater than 100MB), please drag and drop the file instead!";
|
||||
SendClipboardBeat();
|
||||
Log("Clipboard: File too big: " + filePath);
|
||||
Logger.Log("Clipboard: File too big: " + filePath);
|
||||
}
|
||||
|
||||
SetToggleIcon(new int[TOGGLE_ICONS_SIZE] { ICON_ERROR, -1, ICON_ERROR, -1 });
|
||||
@@ -180,7 +181,7 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
else
|
||||
{
|
||||
Log("CheckClipboardEx: File not found: " + filePath);
|
||||
Logger.Log("CheckClipboardEx: File not found: " + filePath);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -194,7 +195,7 @@ namespace MouseWithoutBorders
|
||||
s.Write(texts, 0, texts.Length);
|
||||
}
|
||||
|
||||
Common.LogDebug("Plain/Zip = " + texts.Length.ToString(CultureInfo.CurrentCulture) + "/" +
|
||||
Logger.LogDebug("Plain/Zip = " + texts.Length.ToString(CultureInfo.CurrentCulture) + "/" +
|
||||
ms.Length.ToString(CultureInfo.CurrentCulture));
|
||||
|
||||
LastClipboardData = ms.GetBuffer();
|
||||
@@ -206,20 +207,20 @@ namespace MouseWithoutBorders
|
||||
{
|
||||
if (lastClipboardObject is byte[] lastByteData && Enumerable.SequenceEqual(lastByteData, byteData))
|
||||
{
|
||||
LogDebug("CheckClipboardEx: Same byte[] data.");
|
||||
Logger.LogDebug("CheckClipboardEx: Same byte[] data.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
HasSwitchedMachineSinceLastCopy = false;
|
||||
|
||||
Common.LogDebug("Clipboard contains image");
|
||||
Logger.LogDebug("Clipboard contains image");
|
||||
IsClipboardDataImage = true;
|
||||
LastClipboardData = byteData;
|
||||
}
|
||||
else
|
||||
{
|
||||
LogDebug("*** Clipboard contains something else!");
|
||||
Logger.LogDebug("*** Clipboard contains something else!");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -243,7 +244,7 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -334,7 +335,7 @@ namespace MouseWithoutBorders
|
||||
ProcessPackage(data, tcp);
|
||||
if (++unexpectedCount > 100)
|
||||
{
|
||||
Log("ReceiveClipboardDataUsingTCP: unexpectedCount > 100!");
|
||||
Logger.Log("ReceiveClipboardDataUsingTCP: unexpectedCount > 100!");
|
||||
done = true;
|
||||
}
|
||||
|
||||
@@ -363,7 +364,7 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log("ReceiveClipboardDataUsingTCP: " + e.Message);
|
||||
Logger.Log("ReceiveClipboardDataUsingTCP: " + e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -396,7 +397,7 @@ namespace MouseWithoutBorders
|
||||
{
|
||||
if (Sk == null)
|
||||
{
|
||||
Log("ConnectAndGetData: Sk == null!");
|
||||
Logger.Log("ConnectAndGetData: Sk == null!");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -404,7 +405,7 @@ namespace MouseWithoutBorders
|
||||
TcpClient clipboardTcpClient = null;
|
||||
string postAct = (string)postAction;
|
||||
|
||||
LogDebug("ConnectAndGetData.postAction: " + postAct);
|
||||
Logger.LogDebug("ConnectAndGetData.postAction: " + postAct);
|
||||
|
||||
ClipboardPostAction clipboardPostAct = postAct.Contains("mspaint,") ? ClipboardPostAction.Mspaint
|
||||
: postAct.Equals("desktop", StringComparison.OrdinalIgnoreCase) ? ClipboardPostAction.Desktop
|
||||
@@ -418,7 +419,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
if (!IsConnectedByAClientSocketTo(remoteMachine))
|
||||
{
|
||||
Log($"No potential inbound connection from {MachineName} to {remoteMachine}, ask for a push back instead.");
|
||||
Logger.Log($"No potential inbound connection from {MachineName} to {remoteMachine}, ask for a push back instead.");
|
||||
ID machineId = MachinePool.ResolveID(remoteMachine);
|
||||
|
||||
if (machineId != ID.NONE)
|
||||
@@ -436,7 +437,7 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
else
|
||||
{
|
||||
Log($"Unable to resolve {remoteMachine} to its long IP.");
|
||||
Logger.Log($"Unable to resolve {remoteMachine} to its long IP.");
|
||||
}
|
||||
|
||||
return;
|
||||
@@ -448,7 +449,7 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
catch (ThreadAbortException)
|
||||
{
|
||||
Common.Log("The current thread is being aborted (1).");
|
||||
Logger.Log("The current thread is being aborted (1).");
|
||||
if (clipboardTcpClient != null && clipboardTcpClient.Connected)
|
||||
{
|
||||
clipboardTcpClient.Client.Close();
|
||||
@@ -458,7 +459,7 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
Common.SetToggleIcon(new int[Common.TOGGLE_ICONS_SIZE]
|
||||
{
|
||||
Common.ICON_BIG_CLIPBOARD,
|
||||
@@ -513,7 +514,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
if ((rv = deStream.ReadEx(header, 0, header.Length)) < header.Length)
|
||||
{
|
||||
Common.Log("Reading header failed: " + rv.ToString(CultureInfo.CurrentCulture));
|
||||
Logger.Log("Reading header failed: " + rv.ToString(CultureInfo.CurrentCulture));
|
||||
Common.SetToggleIcon(new int[Common.TOGGLE_ICONS_SIZE]
|
||||
{
|
||||
Common.ICON_BIG_CLIPBOARD,
|
||||
@@ -523,12 +524,12 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
|
||||
fileName = Common.GetStringU(header).Replace("\0", string.Empty);
|
||||
Common.LogDebug("Header: " + fileName);
|
||||
Logger.LogDebug("Header: " + fileName);
|
||||
string[] headers = fileName.Split(Star);
|
||||
|
||||
if (headers.Length < 2 || !long.TryParse(headers[0], out long dataSize))
|
||||
{
|
||||
Common.Log(string.Format(
|
||||
Logger.Log(string.Format(
|
||||
CultureInfo.CurrentCulture,
|
||||
"Reading header failed: {0}:{1}",
|
||||
headers.Length,
|
||||
@@ -543,7 +544,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
fileName = headers[1];
|
||||
|
||||
Common.LogDebug(string.Format(
|
||||
Logger.LogDebug(string.Format(
|
||||
CultureInfo.CurrentCulture,
|
||||
"Receiving {0}:{1} from {2}...",
|
||||
Path.GetFileName(fileName),
|
||||
@@ -593,7 +594,7 @@ namespace MouseWithoutBorders
|
||||
m = new FileStream(tempFile, FileMode.Create);
|
||||
}
|
||||
|
||||
Common.Log("==> " + tempFile);
|
||||
Logger.Log("==> " + tempFile);
|
||||
}
|
||||
|
||||
ShowToolTip(
|
||||
@@ -643,7 +644,7 @@ namespace MouseWithoutBorders
|
||||
if (m != null && fileName != null)
|
||||
{
|
||||
m.Flush();
|
||||
Common.LogDebug(m.Length.ToString(CultureInfo.CurrentCulture) + " bytes received.");
|
||||
Logger.LogDebug(m.Length.ToString(CultureInfo.CurrentCulture) + " bytes received.");
|
||||
Common.LastClipboardEventTime = Common.GetTick();
|
||||
string toolTipText = null;
|
||||
string sizeText = m.Length >= 1024
|
||||
@@ -738,7 +739,7 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
catch (ThreadAbortException)
|
||||
{
|
||||
Common.Log("The current thread is being aborted (3).");
|
||||
Logger.Log("The current thread is being aborted (3).");
|
||||
s.Close();
|
||||
|
||||
if (m != null)
|
||||
@@ -754,11 +755,11 @@ namespace MouseWithoutBorders
|
||||
if (e is IOException)
|
||||
{
|
||||
string log = $"{nameof(ReceiveAndProcessClipboardData)}: Exception accessing the socket: {e.InnerException?.GetType()}/{e.Message}. (This is expected when the remote machine closes the connection during desktop switch or reconnection.)";
|
||||
Common.Log(log);
|
||||
Logger.Log(log);
|
||||
}
|
||||
else
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
|
||||
Common.SetToggleIcon(new int[Common.TOGGLE_ICONS_SIZE]
|
||||
@@ -805,15 +806,15 @@ namespace MouseWithoutBorders
|
||||
NetworkStream ns = new(s);
|
||||
enStream = Common.GetEncryptedStream(ns);
|
||||
Common.SendOrReceiveARandomDataBlockPerInitialIV(enStream);
|
||||
LogDebug($"{nameof(ShakeHand)}: Writing header package.");
|
||||
Logger.LogDebug($"{nameof(ShakeHand)}: Writing header package.");
|
||||
enStream.Write(package.Bytes, 0, PACKAGE_SIZE_EX);
|
||||
|
||||
LogDebug($"{nameof(ShakeHand)}: Sent: clientPush={clientPushData}, postAction={postAction}.");
|
||||
Logger.LogDebug($"{nameof(ShakeHand)}: Sent: clientPush={clientPushData}, postAction={postAction}.");
|
||||
|
||||
deStream = Common.GetDecryptedStream(ns);
|
||||
Common.SendOrReceiveARandomDataBlockPerInitialIV(deStream, false);
|
||||
|
||||
LogDebug($"{nameof(ShakeHand)}: Reading header package.");
|
||||
Logger.LogDebug($"{nameof(ShakeHand)}: Reading header package.");
|
||||
|
||||
int bytesReceived = deStream.ReadEx(buf, 0, Common.PACKAGE_SIZE_EX);
|
||||
package.Bytes = buf;
|
||||
@@ -826,41 +827,41 @@ namespace MouseWithoutBorders
|
||||
{
|
||||
name = remoteName = package.MachineName;
|
||||
|
||||
Common.LogDebug($"{nameof(ShakeHand)}: Connection from {name}:{package.Src}");
|
||||
Logger.LogDebug($"{nameof(ShakeHand)}: Connection from {name}:{package.Src}");
|
||||
|
||||
if (Common.MachinePool.ResolveID(name) == package.Src && Common.IsConnectedTo(package.Src))
|
||||
{
|
||||
clientPushData = package.Type == PackageType.ClipboardPush;
|
||||
postAction = package.PostAction;
|
||||
handShaken = true;
|
||||
LogDebug($"{nameof(ShakeHand)}: Received: clientPush={clientPushData}, postAction={postAction}.");
|
||||
Logger.LogDebug($"{nameof(ShakeHand)}: Received: clientPush={clientPushData}, postAction={postAction}.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Common.LogDebug($"{nameof(ShakeHand)}: No active connection to the machine: {name}.");
|
||||
Logger.LogDebug($"{nameof(ShakeHand)}: No active connection to the machine: {name}.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Common.LogDebug($"{nameof(ShakeHand)}: Unexpected package type: {package.Type}.");
|
||||
Logger.LogDebug($"{nameof(ShakeHand)}: Unexpected package type: {package.Type}.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Common.LogDebug($"{nameof(ShakeHand)}: BytesTransferred != PACKAGE_SIZE_EX: {bytesReceived}");
|
||||
Logger.LogDebug($"{nameof(ShakeHand)}: BytesTransferred != PACKAGE_SIZE_EX: {bytesReceived}");
|
||||
}
|
||||
|
||||
if (!handShaken)
|
||||
{
|
||||
string msg = $"Clipboard connection rejected: {name}:{remoteName}/{package.Src}\r\n\r\nMake sure you run the same version in all machines.";
|
||||
Common.Log(msg);
|
||||
Logger.Log(msg);
|
||||
Common.ShowToolTip(msg, 3000, ToolTipIcon.Warning);
|
||||
Common.SetToggleIcon(new int[Common.TOGGLE_ICONS_SIZE] { Common.ICON_BIG_CLIPBOARD, -1, -1, -1 });
|
||||
}
|
||||
}
|
||||
catch (ThreadAbortException)
|
||||
{
|
||||
Common.Log($"{nameof(ShakeHand)}: The current thread is being aborted.");
|
||||
Logger.Log($"{nameof(ShakeHand)}: The current thread is being aborted.");
|
||||
s.Close();
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -868,11 +869,11 @@ namespace MouseWithoutBorders
|
||||
if (e is IOException)
|
||||
{
|
||||
string log = $"{nameof(ShakeHand)}: Exception accessing the socket: {e.InnerException?.GetType()}/{e.Message}. (This is expected when the remote machine closes the connection during desktop switch or reconnection.)";
|
||||
Common.Log(log);
|
||||
Logger.Log(log);
|
||||
}
|
||||
else
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
|
||||
Common.SetToggleIcon(new int[Common.TOGGLE_ICONS_SIZE]
|
||||
@@ -906,7 +907,7 @@ namespace MouseWithoutBorders
|
||||
Common.DoSomethingInUIThread(() => Common.MainForm.ChangeIcon(Common.ICON_SMALL_CLIPBOARD));
|
||||
|
||||
System.Net.IPAddress ip = GetConnectedClientSocketIPAddressFor(remoteMachine);
|
||||
Common.LogDebug($"{nameof(ConnectToRemoteClipboardSocket)}Connecting to {remoteMachine}:{ip}:{sk.TcpPort}...");
|
||||
Logger.LogDebug($"{nameof(ConnectToRemoteClipboardSocket)}Connecting to {remoteMachine}:{ip}:{sk.TcpPort}...");
|
||||
|
||||
if (ip != null)
|
||||
{
|
||||
@@ -917,7 +918,7 @@ namespace MouseWithoutBorders
|
||||
clipboardTcpClient.Connect(remoteMachine, sk.TcpPort);
|
||||
}
|
||||
|
||||
Common.LogDebug($"Connected from {clipboardTcpClient.Client.LocalEndPoint}. Getting data...");
|
||||
Logger.LogDebug($"Connected from {clipboardTcpClient.Client.LocalEndPoint}. Getting data...");
|
||||
return clipboardTcpClient;
|
||||
}
|
||||
else
|
||||
@@ -930,7 +931,7 @@ namespace MouseWithoutBorders
|
||||
{
|
||||
if (data == null || data.Length <= 0)
|
||||
{
|
||||
Common.Log("data is null or empty!");
|
||||
Logger.Log("data is null or empty!");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -988,28 +989,28 @@ namespace MouseWithoutBorders
|
||||
|
||||
if (txt.StartsWith("RTF", StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
Common.LogDebug(((double)tmp.Length / 1024).ToString("0.00", CultureInfo.InvariantCulture) + "KB of RTF <-");
|
||||
Logger.LogDebug(((double)tmp.Length / 1024).ToString("0.00", CultureInfo.InvariantCulture) + "KB of RTF <-");
|
||||
data1.SetData(DataFormats.Rtf, tmp);
|
||||
}
|
||||
else if (txt.StartsWith("HTM", StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
Common.LogDebug(((double)tmp.Length / 1024).ToString("0.00", CultureInfo.InvariantCulture) + "KB of HTM <-");
|
||||
Logger.LogDebug(((double)tmp.Length / 1024).ToString("0.00", CultureInfo.InvariantCulture) + "KB of HTM <-");
|
||||
data1.SetData(DataFormats.Html, tmp);
|
||||
}
|
||||
else if (txt.StartsWith("TXT", StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
Common.LogDebug(((double)tmp.Length / 1024).ToString("0.00", CultureInfo.InvariantCulture) + "KB of TXT <-");
|
||||
Logger.LogDebug(((double)tmp.Length / 1024).ToString("0.00", CultureInfo.InvariantCulture) + "KB of TXT <-");
|
||||
data1.SetData(DataFormats.UnicodeText, tmp);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (textTypeCount == 0)
|
||||
{
|
||||
Common.LogDebug(((double)txt.Length / 1024).ToString("0.00", CultureInfo.InvariantCulture) + "KB of UNI <-");
|
||||
Logger.LogDebug(((double)txt.Length / 1024).ToString("0.00", CultureInfo.InvariantCulture) + "KB of UNI <-");
|
||||
data1.SetData(DataFormats.UnicodeText, txt);
|
||||
}
|
||||
|
||||
Common.Log("Invalid clipboard format received!");
|
||||
Logger.Log("Invalid clipboard format received!");
|
||||
}
|
||||
|
||||
textTypeCount++;
|
||||
@@ -1037,26 +1038,26 @@ namespace MouseWithoutBorders
|
||||
SystemClipboard.SetFileDropList(filePaths);
|
||||
return true;
|
||||
},
|
||||
(log) => Common.TelemetryLogTrace(
|
||||
(log) => Logger.TelemetryLogTrace(
|
||||
log,
|
||||
SeverityLevel.Information),
|
||||
() => Common.LastClipboardEventTime = Common.GetTick());
|
||||
}
|
||||
catch (ExternalException e)
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
catch (ThreadStateException e)
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
catch (ArgumentNullException e)
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
catch (ArgumentException e)
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1074,20 +1075,20 @@ namespace MouseWithoutBorders
|
||||
SystemClipboard.SetImage(image);
|
||||
return true;
|
||||
},
|
||||
(log) => Common.TelemetryLogTrace(log, SeverityLevel.Information),
|
||||
(log) => Logger.TelemetryLogTrace(log, SeverityLevel.Information),
|
||||
() => Common.LastClipboardEventTime = Common.GetTick());
|
||||
}
|
||||
catch (ExternalException e)
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
catch (ThreadStateException e)
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
catch (ArgumentNullException e)
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1105,20 +1106,20 @@ namespace MouseWithoutBorders
|
||||
SystemClipboard.SetText(text);
|
||||
return true;
|
||||
},
|
||||
(log) => Common.TelemetryLogTrace(log, SeverityLevel.Information),
|
||||
(log) => Logger.TelemetryLogTrace(log, SeverityLevel.Information),
|
||||
() => Common.LastClipboardEventTime = Common.GetTick());
|
||||
}
|
||||
catch (ExternalException e)
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
catch (ThreadStateException e)
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
catch (ArgumentNullException e)
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1134,15 +1135,15 @@ namespace MouseWithoutBorders
|
||||
catch (ExternalException e)
|
||||
{
|
||||
string dataFormats = string.Join(",", dataObject.GetFormats());
|
||||
Common.Log($"{e.Message}: {dataFormats}");
|
||||
Logger.Log($"{e.Message}: {dataFormats}");
|
||||
}
|
||||
catch (ThreadStateException e)
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
catch (ArgumentNullException e)
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ using Microsoft.PowerToys.Telemetry;
|
||||
// 2023- Included in PowerToys.
|
||||
// </history>
|
||||
using MouseWithoutBorders.Class;
|
||||
using MouseWithoutBorders.Core;
|
||||
|
||||
namespace MouseWithoutBorders
|
||||
{
|
||||
@@ -73,12 +74,12 @@ namespace MouseWithoutBorders
|
||||
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)
|
||||
@@ -92,7 +93,7 @@ namespace MouseWithoutBorders
|
||||
{
|
||||
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);
|
||||
@@ -101,7 +102,7 @@ namespace MouseWithoutBorders
|
||||
else
|
||||
{
|
||||
SendCheckExplorerDragDrop();
|
||||
LogDebug("DragDropStep02: SendCheckExplorerDragDrop sent");
|
||||
Logger.LogDebug("DragDropStep02: SendCheckExplorerDragDrop sent");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,11 +115,11 @@ namespace MouseWithoutBorders
|
||||
|
||||
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);
|
||||
@@ -150,12 +151,12 @@ namespace MouseWithoutBorders
|
||||
{
|
||||
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);
|
||||
@@ -166,20 +167,20 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
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);
|
||||
|
||||
@@ -204,21 +205,21 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
|
||||
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
|
||||
@@ -230,7 +231,7 @@ namespace MouseWithoutBorders
|
||||
internal static void DragDropStep06()
|
||||
{
|
||||
IsDragging = true;
|
||||
LogDebug("DragDropStep06: SendClipboardBeatDragDrop");
|
||||
Logger.LogDebug("DragDropStep06: SendClipboardBeatDragDrop");
|
||||
SendClipboardBeatDragDrop();
|
||||
SendDropBegin();
|
||||
}
|
||||
@@ -238,7 +239,7 @@ namespace MouseWithoutBorders
|
||||
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)
|
||||
@@ -247,7 +248,7 @@ namespace MouseWithoutBorders
|
||||
{
|
||||
IsDropping = true;
|
||||
dropMachineID = MachineID;
|
||||
LogDebug("DragDropStep08_2: ClipboardDragDropOperation Received. IsDropping set");
|
||||
Logger.LogDebug("DragDropStep08_2: ClipboardDragDropOperation Received. IsDropping set");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -278,7 +279,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
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;
|
||||
@@ -294,7 +295,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
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;
|
||||
@@ -306,7 +307,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
internal static void DragDropStep12()
|
||||
{
|
||||
LogDebug("DragDropStep12: ClipboardDragDropEnd received");
|
||||
Logger.LogDebug("DragDropStep12: ClipboardDragDropEnd received");
|
||||
IsDropping = false;
|
||||
LastIDWithClipboardData = ID.NONE;
|
||||
|
||||
@@ -374,7 +375,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
internal static void SendDropBegin()
|
||||
{
|
||||
LogDebug("SendDropBegin...");
|
||||
Logger.LogDebug("SendDropBegin...");
|
||||
SendPackage(dropMachineID, PackageType.ClipboardDragDropOperation);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,8 @@ using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using MouseWithoutBorders.Core;
|
||||
|
||||
namespace MouseWithoutBorders
|
||||
{
|
||||
internal partial class Common
|
||||
@@ -25,7 +27,9 @@ namespace MouseWithoutBorders
|
||||
#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;
|
||||
@@ -106,7 +110,7 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,7 +193,7 @@ namespace MouseWithoutBorders
|
||||
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]);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ using System.Threading.Tasks;
|
||||
// 2023- Included in PowerToys.
|
||||
// </history>
|
||||
using MouseWithoutBorders.Class;
|
||||
using MouseWithoutBorders.Core;
|
||||
using MouseWithoutBorders.Form;
|
||||
|
||||
namespace MouseWithoutBorders
|
||||
@@ -26,8 +27,10 @@ namespace MouseWithoutBorders
|
||||
{
|
||||
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;
|
||||
|
||||
@@ -73,7 +76,7 @@ namespace MouseWithoutBorders
|
||||
{
|
||||
HasSwitchedMachineSinceLastCopy = true;
|
||||
|
||||
Common.LogDebug(string.Format(
|
||||
Logger.LogDebug(string.Format(
|
||||
CultureInfo.CurrentCulture,
|
||||
"***** Host Machine: newDesMachineIdEx set = [{0}]. Mouse is now at ({1},{2})",
|
||||
newDesMachineIdEx,
|
||||
@@ -117,7 +120,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -138,7 +141,7 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log(ex);
|
||||
Logger.Log(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,11 +152,11 @@ namespace MouseWithoutBorders
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -163,7 +166,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
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);
|
||||
}
|
||||
@@ -198,7 +201,7 @@ namespace MouseWithoutBorders
|
||||
// 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)
|
||||
@@ -246,7 +249,7 @@ namespace MouseWithoutBorders
|
||||
PaintCount = 0;
|
||||
if (desMachineID != newDesMachineID)
|
||||
{
|
||||
LogDebug("KeybdEvent: Switching to new machine...");
|
||||
Logger.LogDebug("KeybdEvent: Switching to new machine...");
|
||||
DesMachineID = newDesMachineID;
|
||||
}
|
||||
|
||||
@@ -265,7 +268,7 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log(ex);
|
||||
Logger.Log(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ using System.Windows.Forms;
|
||||
// </history>
|
||||
using Microsoft.Win32;
|
||||
using MouseWithoutBorders.Class;
|
||||
|
||||
using MouseWithoutBorders.Core;
|
||||
using static System.Windows.Forms.Control;
|
||||
|
||||
namespace MouseWithoutBorders
|
||||
@@ -61,7 +61,7 @@ namespace MouseWithoutBorders
|
||||
Process p = Process.GetCurrentProcess();
|
||||
string procInfo = $"{p.PrivateMemorySize64 / 1024 / 1024}MB, {p.TotalProcessorTime}, {Environment.ProcessorCount}.";
|
||||
string threadStacks = $"{procInfo} {Thread.DumpThreadsStack()}";
|
||||
Common.TelemetryLogTrace(threadStacks, SeverityLevel.Error);
|
||||
Logger.TelemetryLogTrace(threadStacks, SeverityLevel.Error);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ namespace MouseWithoutBorders
|
||||
Common.SwitchLocation.Count--;
|
||||
|
||||
// When we want to move mouse by pixels, we add 300k to x and y (search for XY_BY_PIXEL for other related code).
|
||||
Common.LogDebug($"+++++ Moving mouse to {Common.SwitchLocation.X}, {Common.SwitchLocation.Y}");
|
||||
Logger.LogDebug($"+++++ Moving mouse to {Common.SwitchLocation.X}, {Common.SwitchLocation.Y}");
|
||||
|
||||
// MaxXY = 65535 so 100k is safe.
|
||||
if (Common.SwitchLocation.X > XY_BY_PIXEL - 100000 || Common.SwitchLocation.Y > XY_BY_PIXEL - 100000)
|
||||
@@ -119,16 +119,16 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
|
||||
signalHelperToExit = false;
|
||||
LogDebug("^^^Helper Thread exiting...^^^");
|
||||
Logger.LogDebug("^^^Helper Thread exiting...^^^");
|
||||
}
|
||||
|
||||
internal static void MainFormDotEx(bool bCheckTS)
|
||||
{
|
||||
LogDebug("***** MainFormDotEx:");
|
||||
Logger.LogDebug("***** MainFormDotEx:");
|
||||
|
||||
if (!Common.RunOnLogonDesktop && !Common.RunOnScrSaverDesktop)
|
||||
{
|
||||
@@ -178,7 +178,7 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -188,7 +188,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
internal static void MainForm3Pixels()
|
||||
{
|
||||
LogDebug("***** MainFormDotLarge:");
|
||||
Logger.LogDebug("***** MainFormDotLarge:");
|
||||
|
||||
DoSomethingInUIThread(
|
||||
() =>
|
||||
@@ -254,7 +254,7 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -277,7 +277,7 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log(e);
|
||||
Logger.Log(e);
|
||||
_ = Common.SendMessageToHelper(SharedConst.QUIT_CMD, IntPtr.Zero, IntPtr.Zero);
|
||||
}
|
||||
|
||||
@@ -291,7 +291,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
if (!Common.IpcChannelCreated)
|
||||
{
|
||||
TelemetryLogTrace($"{nameof(Common.IpcChannelCreated)} = {Common.IpcChannelCreated}. {GetStackTrace(new StackTrace())}", SeverityLevel.Warning);
|
||||
Logger.TelemetryLogTrace($"{nameof(Common.IpcChannelCreated)} = {Common.IpcChannelCreated}. {Logger.GetStackTrace(new StackTrace())}", SeverityLevel.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -317,12 +317,12 @@ namespace MouseWithoutBorders
|
||||
var processes = Process.GetProcessesByName(HelperProcessName);
|
||||
if (processes?.Length == 0)
|
||||
{
|
||||
Log("Unable to start helper process.");
|
||||
Logger.Log("Unable to start helper process.");
|
||||
Common.ShowToolTip("Error starting Mouse Without Borders Helper, clipboard sharing will not work!", 5000, ToolTipIcon.Error);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log("Helper process started.");
|
||||
Logger.Log("Helper process started.");
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -330,11 +330,11 @@ namespace MouseWithoutBorders
|
||||
var processes = Process.GetProcessesByName(HelperProcessName);
|
||||
if (processes?.Length > 0)
|
||||
{
|
||||
Log("Helper process found running.");
|
||||
Logger.Log("Helper process found running.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Log("Invalid helper process found running.");
|
||||
Logger.Log("Invalid helper process found running.");
|
||||
Common.ShowToolTip("Error finding Mouse Without Borders Helper, clipboard sharing will not work!", 5000, ToolTipIcon.Error);
|
||||
}
|
||||
}
|
||||
@@ -354,7 +354,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
if (log)
|
||||
{
|
||||
Common.LogDebug($"SendMessageToHelper: HelperWindow={h}, Return={rv}, msg={msg}, w={wparam.ToInt32()}, l={lparam.ToInt32()}, Post={!wait}");
|
||||
Logger.LogDebug($"SendMessageToHelper: HelperWindow={h}, Return={rv}, msg={msg}, w={wparam.ToInt32()}, l={lparam.ToInt32()}, Post={!wait}");
|
||||
}
|
||||
|
||||
return rv;
|
||||
@@ -424,7 +424,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
log += "Last 10 trace messages:\r\n";
|
||||
|
||||
log += string.Join(Environment.NewLine, LogCounter.Select(item => $"({item.Value}): {item.Key}").Take(10));
|
||||
log += string.Join(Environment.NewLine, Logger.LogCounter.Select(item => $"({item.Value}): {item.Key}").Take(10));
|
||||
|
||||
log += "\r\n=============================================================================================================================";
|
||||
|
||||
@@ -447,7 +447,7 @@ namespace MouseWithoutBorders
|
||||
Setting.Values.Username = Program.User;
|
||||
}
|
||||
|
||||
Common.LogDebug("[Username] = " + Setting.Values.Username);
|
||||
Logger.LogDebug("[Username] = " + Setting.Values.Username);
|
||||
}
|
||||
|
||||
return !string.IsNullOrEmpty(Setting.Values.Username);
|
||||
@@ -490,7 +490,7 @@ Please use the keyboard and Mouse from the SAW device.
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ using System.Threading;
|
||||
// </history>
|
||||
using Microsoft.Win32;
|
||||
using MouseWithoutBorders.Class;
|
||||
using MouseWithoutBorders.Core;
|
||||
using MouseWithoutBorders.Form;
|
||||
using Windows.UI.Input.Preview.Injection;
|
||||
|
||||
@@ -61,7 +62,7 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Common.Log(ex);
|
||||
Logger.Log(ex);
|
||||
Common.MachinePool.Clear();
|
||||
}
|
||||
}
|
||||
@@ -84,7 +85,7 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,13 +103,13 @@ namespace MouseWithoutBorders
|
||||
{
|
||||
Common.KeyCorrupted = true;
|
||||
Setting.Values.MyKey = Common.MyKey = Common.CreateRandomKey();
|
||||
Common.Log(e.Message);
|
||||
Logger.Log(e.Message);
|
||||
}
|
||||
catch (CryptographicException e)
|
||||
{
|
||||
Common.KeyCorrupted = true;
|
||||
Setting.Values.MyKey = Common.MyKey = Common.CreateRandomKey();
|
||||
Common.Log(e.Message);
|
||||
Logger.Log(e.Message);
|
||||
}
|
||||
|
||||
try
|
||||
@@ -123,7 +124,7 @@ namespace MouseWithoutBorders
|
||||
catch (EntryPointNotFoundException)
|
||||
{
|
||||
NativeMethods.InjectMouseInputAvailable = false;
|
||||
Common.Log($"{nameof(NativeMethods.InjectMouseInputAvailable)} = false");
|
||||
Logger.Log($"{nameof(NativeMethods.InjectMouseInputAvailable)} = false");
|
||||
}
|
||||
|
||||
bool dummy = Setting.Values.DrawMouseEx;
|
||||
@@ -149,7 +150,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
if (e.Mode is PowerModes.Resume or PowerModes.Suspend)
|
||||
{
|
||||
Common.TelemetryLogTrace($"{nameof(SystemEvents_PowerModeChanged)}: {e.Mode}", SeverityLevel.Information);
|
||||
Logger.TelemetryLogTrace($"{nameof(SystemEvents_PowerModeChanged)}: {e.Mode}", SeverityLevel.Information);
|
||||
LastResumeSuspendTime = DateTime.UtcNow;
|
||||
SwitchToMultipleMode(false, true);
|
||||
}
|
||||
@@ -206,7 +207,7 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,13 +231,13 @@ namespace MouseWithoutBorders
|
||||
VK.RCONTROL, VK.RMENU, VK.RWIN, VK.SHIFT, VK.MENU, VK.CONTROL,
|
||||
};
|
||||
|
||||
LogDebug("***** ReleaseAllKeys has been called! *****:");
|
||||
Logger.LogDebug("***** ReleaseAllKeys has been called! *****:");
|
||||
|
||||
foreach (VK vk in keys)
|
||||
{
|
||||
if ((NativeMethods.GetAsyncKeyState((IntPtr)vk) & 0x8000) != 0)
|
||||
{
|
||||
LogDebug(vk.ToString() + " is down, release it...");
|
||||
Logger.LogDebug(vk.ToString() + " is down, release it...");
|
||||
Hook?.ResetLastSwitchKeys(); // Sticky key can turn ALL PC mode on (CtrlCtrlCtrl)
|
||||
kd.wVk = (int)vk;
|
||||
InputSimulation.SendKey(kd);
|
||||
@@ -247,7 +248,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
private static void NetworkChange_NetworkAvailabilityChanged(object sender, NetworkAvailabilityEventArgs e)
|
||||
{
|
||||
LogDebug("NetworkAvailabilityEventArgs.IsAvailable: " + e.IsAvailable.ToString(CultureInfo.InvariantCulture));
|
||||
Logger.LogDebug("NetworkAvailabilityEventArgs.IsAvailable: " + e.IsAvailable.ToString(CultureInfo.InvariantCulture));
|
||||
Common.WndProcCounter++;
|
||||
ScheduleReopenSocketsDueToNetworkChanges(!e.IsAvailable);
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ using System.Security.Principal;
|
||||
// 2023- Included in PowerToys.
|
||||
// </history>
|
||||
using MouseWithoutBorders.Class;
|
||||
using MouseWithoutBorders.Core;
|
||||
|
||||
namespace MouseWithoutBorders
|
||||
{
|
||||
@@ -44,17 +45,17 @@ namespace MouseWithoutBorders
|
||||
{
|
||||
dwSessionId = (uint)Process.GetCurrentProcess().SessionId;
|
||||
uint rv = NativeMethods.WTSQueryUserToken(dwSessionId, ref hUserToken);
|
||||
LogDebug("WTSQueryUserToken returned " + rv.ToString(CultureInfo.CurrentCulture));
|
||||
Logger.LogDebug("WTSQueryUserToken returned " + rv.ToString(CultureInfo.CurrentCulture));
|
||||
|
||||
if (rv == 0)
|
||||
{
|
||||
LogDebug($"WTSQueryUserToken failed with: {Marshal.GetLastWin32Error()}.");
|
||||
Logger.LogDebug($"WTSQueryUserToken failed with: {Marshal.GetLastWin32Error()}.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!NativeMethods.DuplicateToken(hUserToken, (int)NativeMethods.SECURITY_IMPERSONATION_LEVEL.SecurityImpersonation, ref hUserTokenDup))
|
||||
{
|
||||
TelemetryLogTrace($"DuplicateToken Failed! {GetStackTrace(new StackTrace())}", SeverityLevel.Warning);
|
||||
Logger.TelemetryLogTrace($"DuplicateToken Failed! {Logger.GetStackTrace(new StackTrace())}", SeverityLevel.Warning);
|
||||
_ = NativeMethods.CloseHandle(hUserToken);
|
||||
_ = NativeMethods.CloseHandle(hUserTokenDup);
|
||||
return false;
|
||||
@@ -70,7 +71,7 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
else
|
||||
{
|
||||
Log("ImpersonateLoggedOnUser Failed!");
|
||||
Logger.Log("ImpersonateLoggedOnUser Failed!");
|
||||
_ = NativeMethods.CloseHandle(hUserToken);
|
||||
_ = NativeMethods.CloseHandle(hUserTokenDup);
|
||||
return false;
|
||||
@@ -78,7 +79,7 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -102,7 +103,7 @@ namespace MouseWithoutBorders
|
||||
int dwSessionId;
|
||||
IntPtr hUserToken = IntPtr.Zero, hUserTokenDup = IntPtr.Zero;
|
||||
|
||||
Common.LogDebug("CreateProcessInInputDesktopSession called, launching " + commandLineWithArg + " on " + desktop);
|
||||
Logger.LogDebug("CreateProcessInInputDesktopSession called, launching " + commandLineWithArg + " on " + desktop);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -122,7 +123,7 @@ namespace MouseWithoutBorders
|
||||
if (!NativeMethods.DuplicateTokenEx(hUserToken, NativeMethods.MAXIMUM_ALLOWED, ref sa, (int)NativeMethods.SECURITY_IMPERSONATION_LEVEL.SecurityIdentification, (int)NativeMethods.TOKEN_TYPE.TokenPrimary, ref hUserTokenDup))
|
||||
{
|
||||
lastError = Marshal.GetLastWin32Error();
|
||||
Common.Log(string.Format(CultureInfo.CurrentCulture, "DuplicateTokenEx error: {0} Token does not have the privilege.", lastError));
|
||||
Logger.Log(string.Format(CultureInfo.CurrentCulture, "DuplicateTokenEx error: {0} Token does not have the privilege.", lastError));
|
||||
_ = NativeMethods.CloseHandle(hUserToken);
|
||||
return 0;
|
||||
}
|
||||
@@ -138,7 +139,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
if (!rv)
|
||||
{
|
||||
Log("ConvertStringSidToSid failed");
|
||||
Logger.Log("ConvertStringSidToSid failed");
|
||||
_ = NativeMethods.CloseHandle(hUserToken);
|
||||
_ = NativeMethods.CloseHandle(hUserTokenDup);
|
||||
return 0;
|
||||
@@ -151,7 +152,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
if (!rv)
|
||||
{
|
||||
Log("SetTokenInformation failed");
|
||||
Logger.Log("SetTokenInformation failed");
|
||||
_ = NativeMethods.CloseHandle(hUserToken);
|
||||
_ = NativeMethods.CloseHandle(hUserTokenDup);
|
||||
return 0;
|
||||
@@ -185,7 +186,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
// GetLastError should be 0
|
||||
int iResultOfCreateProcessAsUser = Marshal.GetLastWin32Error();
|
||||
LogDebug("CreateProcessAsUser returned " + iResultOfCreateProcessAsUser.ToString(CultureInfo.CurrentCulture));
|
||||
Logger.LogDebug("CreateProcessAsUser returned " + iResultOfCreateProcessAsUser.ToString(CultureInfo.CurrentCulture));
|
||||
|
||||
// Close handles task
|
||||
_ = NativeMethods.CloseHandle(hUserToken);
|
||||
@@ -195,7 +196,7 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -223,19 +224,19 @@ namespace MouseWithoutBorders
|
||||
{
|
||||
if ((p = Process.GetProcessById(processId)) == null)
|
||||
{
|
||||
Log("Process exited!");
|
||||
Logger.Log("Process exited!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
Log("GetProcessById.ArgumentException");
|
||||
Logger.Log("GetProcessById.ArgumentException");
|
||||
break;
|
||||
}
|
||||
|
||||
if ((!p.HasExited && p.PrivateMemorySize64 > limitedMem) || (++sec > (wait / 1000)))
|
||||
{
|
||||
Log(string.Format(CultureInfo.CurrentCulture, "Process log (mem): {0}, {1}", sec, p.PrivateMemorySize64));
|
||||
Logger.Log(string.Format(CultureInfo.CurrentCulture, "Process log (mem): {0}, {1}", sec, p.PrivateMemorySize64));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -248,11 +249,11 @@ namespace MouseWithoutBorders
|
||||
|
||||
if ((p = Process.GetProcessById(processId)) == null)
|
||||
{
|
||||
Log("Process exited!");
|
||||
Logger.Log("Process exited!");
|
||||
}
|
||||
else if (NativeMethods.WaitForSingleObject(p.Handle, wait) != NativeMethods.WAIT_OBJECT_0 && killIfTimedOut)
|
||||
{
|
||||
Log("Process log (time).");
|
||||
Logger.Log("Process log (time).");
|
||||
TerminateProcessTree(p.Handle, (uint)processId, -1);
|
||||
return false;
|
||||
}
|
||||
@@ -287,12 +288,12 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
catch (InvalidOperationException e)
|
||||
{
|
||||
Log(e);
|
||||
Logger.Log(e);
|
||||
continue;
|
||||
}
|
||||
catch (Win32Exception e)
|
||||
{
|
||||
Log(e);
|
||||
Logger.Log(e);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ using System.Windows.Forms;
|
||||
// 2023- Included in PowerToys.
|
||||
// </history>
|
||||
using MouseWithoutBorders.Class;
|
||||
using MouseWithoutBorders.Core;
|
||||
using MouseWithoutBorders.Exceptions;
|
||||
|
||||
namespace MouseWithoutBorders
|
||||
@@ -81,7 +82,7 @@ namespace MouseWithoutBorders
|
||||
internal static string DumpThreadsStack()
|
||||
{
|
||||
string stack = "\r\nMANAGED THREADS: " + threads.Count.ToString(CultureInfo.InvariantCulture) + "\r\n";
|
||||
stack += Common.GetStackTrace(new StackTrace());
|
||||
stack += Logger.GetStackTrace(new StackTrace());
|
||||
return stack;
|
||||
}
|
||||
|
||||
@@ -115,385 +116,4 @@ namespace MouseWithoutBorders
|
||||
|
||||
internal System.Threading.ThreadState ThreadState => thread.ThreadState;
|
||||
}
|
||||
|
||||
internal partial class Common
|
||||
{
|
||||
private static readonly string[] AllLogs = new string[MAX_LOG];
|
||||
private static readonly object AllLogsLock = new();
|
||||
private static readonly ConcurrentDictionary<string, int> LogCounter = new();
|
||||
private static readonly int[] RepeatedLogIndexSelection = new[] { 1, 3, 10, 50, 100 };
|
||||
private const int MAX_LOG = 10000;
|
||||
private static int allLogsIndex;
|
||||
|
||||
private const int MaxLogExceptionPerHour = 1000;
|
||||
private static int lastHour;
|
||||
private static int exceptionCount;
|
||||
|
||||
internal static void TelemetryLogTrace(string log, SeverityLevel severityLevel, bool flush = false)
|
||||
{
|
||||
int logCount = LogCounter.AddOrUpdate(log, 1, (key, value) => value + 1);
|
||||
Common.Log(log);
|
||||
}
|
||||
|
||||
internal static void Log(Exception e)
|
||||
{
|
||||
if (e is not KnownException)
|
||||
{
|
||||
string exText = e.ToString();
|
||||
|
||||
Log($"!Exception!: {exText}");
|
||||
|
||||
if (DateTime.UtcNow.Hour != lastHour)
|
||||
{
|
||||
lastHour = DateTime.UtcNow.Hour;
|
||||
exceptionCount = 0;
|
||||
}
|
||||
|
||||
if (exceptionCount < MaxLogExceptionPerHour)
|
||||
{
|
||||
exceptionCount++;
|
||||
}
|
||||
else if (exceptionCount != short.MaxValue)
|
||||
{
|
||||
exceptionCount = short.MaxValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private const string HeaderSENT =
|
||||
"Be{0},Ke{1},Mo{2},He{3},Mx{4},Tx{5},Im{6},By{7},Cl{8},Dr{9},De{10},Ed{11},Ie{12},Ni{13}";
|
||||
|
||||
private const string HeaderRECEIVED =
|
||||
"Be{0},Ke{1},Mo{2},He{3},Mx{4},Tx{5},Im{6},By{7},Cl{8},Dr{9},De{10},Ed{11},In{12},Ni{13},Pc{14}/{15}";
|
||||
|
||||
internal static void LogDebug(string log, bool clearLog = false)
|
||||
{
|
||||
#if DEBUG
|
||||
Log(log, clearLog);
|
||||
#endif
|
||||
}
|
||||
|
||||
internal static void Log(string log, bool clearLog = false)
|
||||
{
|
||||
log = DateTime.Now.ToString("MM/dd HH:mm:ss.fff", CultureInfo.InvariantCulture) + $"({Thread.CurrentThread.ManagedThreadId})" + log;
|
||||
|
||||
ManagedCommon.Logger.LogInfo(log);
|
||||
lock (AllLogsLock)
|
||||
{
|
||||
if (clearLog)
|
||||
{
|
||||
allLogsIndex = 0;
|
||||
}
|
||||
|
||||
AllLogs[allLogsIndex] = log;
|
||||
allLogsIndex = (allLogsIndex + 1) % MAX_LOG;
|
||||
}
|
||||
}
|
||||
|
||||
internal static void LogDebug(string format, params object[] args)
|
||||
{
|
||||
#if DEBUG
|
||||
Log(format, args);
|
||||
#endif
|
||||
}
|
||||
|
||||
internal static void Log(string format, params object[] args)
|
||||
{
|
||||
Common.Log(string.Format(CultureInfo.InvariantCulture, format, args));
|
||||
}
|
||||
|
||||
private static PackageMonitor p1;
|
||||
private static PackageMonitor p2;
|
||||
|
||||
[Conditional("DEBUG")]
|
||||
internal static void LogAll()
|
||||
{
|
||||
string log;
|
||||
|
||||
if (!p1.Equals(PackageSent))
|
||||
{
|
||||
log = string.Format(
|
||||
CultureInfo.CurrentCulture,
|
||||
"SENT:" + HeaderSENT,
|
||||
PackageSent.Heartbeat,
|
||||
PackageSent.Keyboard,
|
||||
PackageSent.Mouse,
|
||||
PackageSent.Hello,
|
||||
PackageSent.Matrix,
|
||||
PackageSent.ClipboardText,
|
||||
PackageSent.ClipboardImage,
|
||||
PackageSent.ByeBye,
|
||||
PackageSent.Clipboard,
|
||||
PackageSent.ClipboardDragDrop,
|
||||
PackageSent.ClipboardDragDropEnd,
|
||||
PackageSent.ExplorerDragDrop,
|
||||
inputEventCount,
|
||||
PackageSent.Nil);
|
||||
Log(log);
|
||||
p1 = PackageSent; // Copy data
|
||||
}
|
||||
|
||||
if (!p2.Equals(PackageReceived))
|
||||
{
|
||||
log = string.Format(
|
||||
CultureInfo.CurrentCulture,
|
||||
"RECEIVED:" + HeaderRECEIVED,
|
||||
PackageReceived.Heartbeat,
|
||||
PackageReceived.Keyboard,
|
||||
PackageReceived.Mouse,
|
||||
PackageReceived.Hello,
|
||||
PackageReceived.Matrix,
|
||||
PackageReceived.ClipboardText,
|
||||
PackageReceived.ClipboardImage,
|
||||
PackageReceived.ByeBye,
|
||||
PackageReceived.Clipboard,
|
||||
PackageReceived.ClipboardDragDrop,
|
||||
PackageReceived.ClipboardDragDropEnd,
|
||||
PackageReceived.ExplorerDragDrop,
|
||||
invalidPackageCount,
|
||||
PackageReceived.Nil,
|
||||
processedPackageCount,
|
||||
skippedPackageCount);
|
||||
Log(log);
|
||||
p2 = PackageReceived;
|
||||
}
|
||||
}
|
||||
|
||||
internal static void GenerateLog()
|
||||
{
|
||||
int l = Setting.Values.DumpObjectsLevel;
|
||||
if (l is > 0 and < 10)
|
||||
{
|
||||
Common.DumpObjects(l);
|
||||
}
|
||||
}
|
||||
|
||||
private static List<ProcessThread> myThreads;
|
||||
|
||||
internal static void DumpObjects(int level)
|
||||
{
|
||||
try
|
||||
{
|
||||
string logFile = Path.Combine(Common.RunWithNoAdminRight ? Path.GetTempPath() : Path.GetDirectoryName(Application.ExecutablePath), "MagicMouse.log");
|
||||
|
||||
StringBuilder sb = new(1000000);
|
||||
string log;
|
||||
|
||||
myThreads = new List<ProcessThread>();
|
||||
|
||||
foreach (ProcessThread t in Process.GetCurrentProcess().Threads)
|
||||
{
|
||||
myThreads.Add(t);
|
||||
}
|
||||
|
||||
_ = PrivateDump(sb, AllLogs, "[Program logs]\r\n===============\r\n", 0, level, false);
|
||||
_ = PrivateDump(sb, new Common(), "[Other Logs]\r\n===============\r\n", 0, level, false);
|
||||
|
||||
log = string.Format(
|
||||
CultureInfo.CurrentCulture,
|
||||
"{0} {1}\r\n{2}\r\n\r\n{3}",
|
||||
Application.ProductName,
|
||||
Application.ProductVersion,
|
||||
"Private Mem: " + (Process.GetCurrentProcess().PrivateMemorySize64 / 1024).ToString(CultureInfo.CurrentCulture) + "KB",
|
||||
sb.ToString());
|
||||
|
||||
if (!string.IsNullOrEmpty(myKey))
|
||||
{
|
||||
log = log.Replace(MyKey, GetDebugInfo(MyKey));
|
||||
}
|
||||
|
||||
log += Thread.DumpThreadsStack();
|
||||
log += $"\r\nCurrent process session: {Process.GetCurrentProcess().SessionId}, active console session: {NativeMethods.WTSGetActiveConsoleSessionId()}.";
|
||||
|
||||
File.WriteAllText(logFile, log);
|
||||
|
||||
if (RunOnLogonDesktop || RunOnScrSaverDesktop)
|
||||
{
|
||||
_ = MessageBox.Show("Dump file created: " + logFile, Application.ProductName);
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowToolTip("Dump file created: " + logFile + " and placed in the Clipboard.", 10000);
|
||||
Clipboard.SetText(logFile);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_ = MessageBox.Show(e.Message + "\r\n" + e.StackTrace, Application.ProductName);
|
||||
}
|
||||
}
|
||||
|
||||
private static object GetFieldValue(object obj, string fieldName)
|
||||
{
|
||||
FieldInfo fi;
|
||||
Type t;
|
||||
|
||||
t = obj.GetType();
|
||||
fi = t.GetField(fieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
|
||||
return fi?.GetValue(obj);
|
||||
}
|
||||
|
||||
private static bool PrivateDump(StringBuilder sb, object obj, string objName, int level, int maxLevel, bool stop)
|
||||
{
|
||||
Type t;
|
||||
string padStr = string.Empty;
|
||||
string[] strArr;
|
||||
string objString;
|
||||
|
||||
if (obj == null || (maxLevel >= 0 && level >= maxLevel) || obj is Cursor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < level; i++)
|
||||
{
|
||||
padStr += i < level - 1 ? "-" : padStr += string.Empty;
|
||||
}
|
||||
|
||||
objString = obj.ToString();
|
||||
t = obj.GetType();
|
||||
strArr = new string[7];
|
||||
strArr[0] = padStr;
|
||||
strArr[1] = objName;
|
||||
|
||||
// strArr[2] = " ";
|
||||
// strArr[3] = t.FullName;
|
||||
strArr[4] = " = ";
|
||||
strArr[5] = objName.Equals("myKey", StringComparison.OrdinalIgnoreCase) ? GetDebugInfo(objString)
|
||||
: objName.Equals("lastClipboardObject", StringComparison.OrdinalIgnoreCase) ? string.Empty
|
||||
: objString.Replace("System.Windows.Forms.", string.Empty).Replace("System.Net.Sockets.", string.Empty).Replace("System.Security.Cryptography.", string.Empty).Replace("System.Threading.", string.Empty)
|
||||
.Replace("System.ComponentModel.", string.Empty).Replace("System.Runtime.", string.Empty).Replace("System.Drawing.", string.Empty).Replace("System.Object", "O").Replace("System.Diagnostics.", string.Empty)
|
||||
.Replace("System.Collections.", string.Empty).Replace("System.Drawing.", string.Empty).Replace("System.Int", string.Empty).Replace("System.EventHandler.", string.Empty);
|
||||
strArr[6] = "\r\n";
|
||||
_ = sb.Append(string.Concat(strArr).Replace(Common.BinaryName, "MM"));
|
||||
|
||||
if (stop || t.IsPrimitive)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
DumpType(padStr, sb, obj, level, t, maxLevel);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void DumpType(string initialStr, StringBuilder sb, object obj, int level, System.Type t, int maxLevel)
|
||||
{
|
||||
int i;
|
||||
bool stop;
|
||||
if (t == typeof(System.Delegate))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
FieldInfo[] fi;
|
||||
string type;
|
||||
|
||||
if (obj is MouseWithoutBorders.PackageType or string or AddressFamily or ID or IPAddress
|
||||
)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
type = obj.GetType().ToString();
|
||||
|
||||
if (type.EndsWith("type", StringComparison.CurrentCultureIgnoreCase) || type.Contains("Cryptography")
|
||||
|| type.EndsWith("AsyncEventBits", StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
stop = obj == null || obj is MouseWithoutBorders.DATA || obj.GetType().BaseType == typeof(ValueType)
|
||||
|| obj.GetType().Namespace.Contains("System.Windows");
|
||||
fi = t.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
|
||||
|
||||
foreach (FieldInfo f in fi)
|
||||
{
|
||||
if (f.GetValue(obj) != AllLogs)
|
||||
{
|
||||
_ = PrivateDump(sb, f.GetValue(obj), f.Name, level + 1, maxLevel, stop);
|
||||
}
|
||||
}
|
||||
|
||||
if (obj is Dictionary<string, List<IPAddress>>)
|
||||
{
|
||||
Dictionary<string, List<IPAddress>> d = obj as Dictionary<string, List<IPAddress>>;
|
||||
|
||||
foreach (string k in d.Keys)
|
||||
{
|
||||
if (d.TryGetValue(k, out List<IPAddress> l))
|
||||
{
|
||||
foreach (IPAddress ip in l)
|
||||
{
|
||||
_ = PrivateDump(sb, ip, "[" + k + "]", level + 1, maxLevel, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (obj is System.Array)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (obj is MachineInf[])
|
||||
{
|
||||
MachineInf[] os = (MachineInf[])obj;
|
||||
|
||||
for (i = 0; i < os.GetLength(0); i++)
|
||||
{
|
||||
_ = PrivateDump(sb, os[i], "[" + i + "]", level + 1, maxLevel, false);
|
||||
}
|
||||
}
|
||||
else if (obj is int[] || obj is uint[])
|
||||
{
|
||||
int[] os = (int[])obj;
|
||||
|
||||
for (i = 0; i < os.GetLength(0); i++)
|
||||
{
|
||||
_ = PrivateDump(sb, os[i], "[" + i + "]", level + 1, maxLevel, false);
|
||||
}
|
||||
}
|
||||
else if (obj is short[] || obj is ushort[])
|
||||
{
|
||||
short[] os = (short[])obj;
|
||||
|
||||
for (i = 0; i < os.GetLength(0); i++)
|
||||
{
|
||||
_ = PrivateDump(sb, os[i], "[" + i + "]", level + 1, maxLevel, false);
|
||||
}
|
||||
}
|
||||
else if (obj is TcpClient[] || obj is IPAddress[] || obj is TcpSk[] || obj is string[]
|
||||
|| obj is TcpServer[]
|
||||
|| obj is ProcessThread[] || obj is Thread[])
|
||||
{
|
||||
object[] os = (object[])obj;
|
||||
|
||||
for (i = 0; i < os.GetLength(0); i++)
|
||||
{
|
||||
_ = PrivateDump(sb, os[i], "[" + i + "]", level + 1, maxLevel, false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_ = PrivateDump(sb, obj.GetType().ToString() + ": N/A", obj.GetType().ToString(), level + 1, maxLevel, false);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static string GetStackTrace(StackTrace st)
|
||||
{
|
||||
string rv = string.Empty;
|
||||
|
||||
for (int i = 0; i < st.FrameCount; i++)
|
||||
{
|
||||
StackFrame sf = st.GetFrame(i);
|
||||
rv += sf.GetMethod() + " <= ";
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ using Microsoft.PowerToys.Telemetry;
|
||||
// 2023- Included in PowerToys.
|
||||
// </history>
|
||||
using MouseWithoutBorders.Class;
|
||||
using MouseWithoutBorders.Core;
|
||||
|
||||
namespace MouseWithoutBorders
|
||||
{
|
||||
@@ -390,7 +391,7 @@ namespace MouseWithoutBorders
|
||||
// THIS LOGIC IS THE SAME FOR Move*(int x, int y) METHODS.
|
||||
if (newDesMachineIdEx != desMachineID)
|
||||
{
|
||||
LogDebug("Move Right");
|
||||
Logger.LogDebug("Move Right");
|
||||
|
||||
if (!Setting.Values.MoveMouseRelatively)
|
||||
{
|
||||
@@ -529,7 +530,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
if (newDesMachineIdEx != desMachineID)
|
||||
{
|
||||
LogDebug("Move Left");
|
||||
Logger.LogDebug("Move Left");
|
||||
|
||||
return !Setting.Values.MoveMouseRelatively
|
||||
? newDesMachineIdEx == MachineID
|
||||
@@ -598,7 +599,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
if (newDesMachineIdEx != desMachineID)
|
||||
{
|
||||
LogDebug("Move Up");
|
||||
Logger.LogDebug("Move Up");
|
||||
|
||||
return !Setting.Values.MoveMouseRelatively
|
||||
? newDesMachineIdEx == MachineID
|
||||
@@ -668,7 +669,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
if (newDesMachineIdEx != desMachineID)
|
||||
{
|
||||
LogDebug("Move Down");
|
||||
Logger.LogDebug("Move Down");
|
||||
|
||||
return !Setting.Values.MoveMouseRelatively
|
||||
? newDesMachineIdEx == MachineID
|
||||
@@ -696,7 +697,7 @@ namespace MouseWithoutBorders
|
||||
rv = true;
|
||||
}
|
||||
|
||||
LogDebug("<><><><><>>><><><<><><><><><><><><><><>><><><><><><><><><><><" + inf.Name);
|
||||
Logger.LogDebug("<><><><><>>><><><<><><><><><><><><><><>><><><><><><><><><><><" + inf.Name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -740,7 +741,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
if (machineInfo.Name.Equals(DesMachineName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
LogDebug("AddToMachinePool: Des ID updated: " + DesMachineID.ToString() + "/" + package.Src.ToString());
|
||||
Logger.LogDebug("AddToMachinePool: Des ID updated: " + DesMachineID.ToString() + "/" + package.Src.ToString());
|
||||
newDesMachineID = desMachineID = package.Src;
|
||||
}
|
||||
|
||||
@@ -754,7 +755,7 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
else
|
||||
{
|
||||
LogDebug("AddToMachinePool: could not add a new machine: " + name);
|
||||
Logger.LogDebug("AddToMachinePool: could not add a new machine: " + name);
|
||||
return "The 5th machine";
|
||||
}
|
||||
}
|
||||
@@ -781,14 +782,14 @@ namespace MouseWithoutBorders
|
||||
Common.ReopenSockets(true);
|
||||
Common.SendMachineMatrix();
|
||||
|
||||
LogDebug("Machine added: " + name + "/" + package.Src.ToString());
|
||||
Logger.LogDebug("Machine added: " + name + "/" + package.Src.ToString());
|
||||
UpdateClientSockets("AddToMachinePool");
|
||||
return name;
|
||||
}
|
||||
|
||||
internal static void UpdateClientSockets(string logHeader)
|
||||
{
|
||||
LogDebug("UpdateClientSockets: " + logHeader);
|
||||
Logger.LogDebug("UpdateClientSockets: " + logHeader);
|
||||
Sk?.UpdateTCPClients();
|
||||
}
|
||||
|
||||
@@ -802,13 +803,13 @@ namespace MouseWithoutBorders
|
||||
|
||||
internal static void ShowSetupForm(bool reopenSockets = false)
|
||||
{
|
||||
Common.LogDebug("========== BEGIN THE SETUP EXPERIENCE ==========", true);
|
||||
Logger.LogDebug("========== BEGIN THE SETUP EXPERIENCE ==========", true);
|
||||
Setting.Values.MyKey = Common.MyKey = Common.CreateRandomKey();
|
||||
Common.GeneratedKey = true;
|
||||
|
||||
if (Process.GetCurrentProcess().SessionId != NativeMethods.WTSGetActiveConsoleSessionId())
|
||||
{
|
||||
Common.Log("Not physical console session.");
|
||||
Logger.Log("Not physical console session.");
|
||||
_ = MessageBox.Show(
|
||||
"Please run the program in the physical console session.\r\nThe program does not work in a remote desktop or virtual machine session.",
|
||||
Application.ProductName,
|
||||
@@ -948,7 +949,7 @@ namespace MouseWithoutBorders
|
||||
{
|
||||
bool twoRow = !Setting.Values.MatrixOneRow;
|
||||
string[] connectedMachines = twoRow ? MachineMatrix : MachineMatrix.Select(m => IsConnectedTo(IdFromName(m)) ? m : string.Empty).ToArray();
|
||||
LogDebug($"Matrix: {string.Join(",", MachineMatrix)}, Connected: {string.Join(",", connectedMachines)}");
|
||||
Logger.LogDebug($"Matrix: {string.Join(",", MachineMatrix)}, Connected: {string.Join(",", connectedMachines)}");
|
||||
|
||||
return connectedMachines;
|
||||
}
|
||||
@@ -981,7 +982,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
SkSend(package, null, false);
|
||||
|
||||
LogDebug($"matrixIncludedMachine sent: [{i + 1}]:[{MachineMatrix[i]}]");
|
||||
Logger.LogDebug($"matrixIncludedMachine sent: [{i + 1}]:[{MachineMatrix[i]}]");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -992,7 +993,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
if (i is > 0 and <= MAX_MACHINE)
|
||||
{
|
||||
LogDebug($"matrixIncludedMachine: [{i}]:[{matrixIncludedMachine}]");
|
||||
Logger.LogDebug($"matrixIncludedMachine: [{i}]:[{matrixIncludedMachine}]");
|
||||
|
||||
MachineMatrix[i - 1] = matrixIncludedMachine;
|
||||
|
||||
@@ -1011,7 +1012,7 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
else
|
||||
{
|
||||
LogDebug("Invalid machine Matrix package!");
|
||||
Logger.LogDebug("Invalid machine Matrix package!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1080,7 +1081,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
if (!created)
|
||||
{
|
||||
TelemetryLogTrace($"Second instance found: {eventName}.", SeverityLevel.Warning, true);
|
||||
Logger.TelemetryLogTrace($"Second instance found: {eventName}.", SeverityLevel.Warning, true);
|
||||
CurrentProcess.KillProcess(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ using System.Windows.Forms;
|
||||
// 2023- Included in PowerToys.
|
||||
// </history>
|
||||
using MouseWithoutBorders.Class;
|
||||
using MouseWithoutBorders.Core;
|
||||
|
||||
[module: SuppressMessage("Microsoft.Reliability", "CA2002:DoNotLockOnObjectsWithWeakIdentity", Scope = "member", Target = "MouseWithoutBorders.Common.#PreProcess(MouseWithoutBorders.DATA)", Justification = "Dotnet port with style preservation")]
|
||||
|
||||
@@ -30,8 +31,10 @@ namespace MouseWithoutBorders
|
||||
private static readonly uint QUEUE_SIZE = 50;
|
||||
private static readonly int[] RecentProcessedPackageIDs = new int[QUEUE_SIZE];
|
||||
private static int recentProcessedPackageIndex;
|
||||
private static long processedPackageCount;
|
||||
private static long skippedPackageCount;
|
||||
#pragma warning disable SA1307 // Accessible fields should begin with upper-case letter
|
||||
internal static long processedPackageCount;
|
||||
internal static long skippedPackageCount;
|
||||
#pragma warning restore SA1307
|
||||
|
||||
internal static long JustGotAKey { get; set; }
|
||||
|
||||
@@ -45,12 +48,12 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
|
||||
Common.InvalidPackageCount++;
|
||||
Common.Log("Invalid packages received!");
|
||||
Logger.Log("Invalid packages received!");
|
||||
return false;
|
||||
}
|
||||
else if (package.Type == 0)
|
||||
{
|
||||
Common.Log("Got an unknown package!");
|
||||
Logger.Log("Got an unknown package!");
|
||||
return false;
|
||||
}
|
||||
else if (package.Type is not PackageType.ClipboardText and not PackageType.ClipboardImage
|
||||
@@ -157,7 +160,7 @@ namespace MouseWithoutBorders
|
||||
{
|
||||
HasSwitchedMachineSinceLastCopy = true;
|
||||
|
||||
Common.LogDebug(string.Format(
|
||||
Logger.LogDebug(string.Format(
|
||||
CultureInfo.CurrentCulture,
|
||||
"***** Controlled Machine: newDesMachineIdEx set = [{0}]. Mouse is now at ({1},{2})",
|
||||
newDesMachineIdEx,
|
||||
@@ -191,7 +194,7 @@ namespace MouseWithoutBorders
|
||||
break;
|
||||
|
||||
case PackageType.NextMachine:
|
||||
LogDebug("PackageType.NextMachine received!");
|
||||
Logger.LogDebug("PackageType.NextMachine received!");
|
||||
|
||||
if (IsSwitchingByMouseEnabled())
|
||||
{
|
||||
@@ -334,7 +337,7 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -395,7 +398,7 @@ namespace MouseWithoutBorders
|
||||
else
|
||||
{
|
||||
// We should never get to this point!
|
||||
Common.Log("Invalid package received!");
|
||||
Logger.Log("Invalid package received!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -421,7 +424,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
private static void SignalBigClipboardData()
|
||||
{
|
||||
LogDebug("SignalBigClipboardData");
|
||||
Logger.LogDebug("SignalBigClipboardData");
|
||||
SetToggleIcon(new int[TOGGLE_ICONS_SIZE] { ICON_BIG_CLIPBOARD, -1, ICON_BIG_CLIPBOARD, -1 });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ using System.Windows.Forms;
|
||||
// 2023- Included in PowerToys.
|
||||
// </history>
|
||||
using MouseWithoutBorders.Class;
|
||||
using MouseWithoutBorders.Core;
|
||||
|
||||
[module: SuppressMessage("Microsoft.Globalization", "CA1300:SpecifyMessageBoxOptions", Scope = "member", Target = "MouseWithoutBorders.Common.#StartMouseWithoutBordersService()", Justification = "Dotnet port with style preservation")]
|
||||
|
||||
@@ -39,7 +40,7 @@ namespace MouseWithoutBorders
|
||||
return;
|
||||
}
|
||||
|
||||
Log($"{nameof(StartMouseWithoutBordersService)}: {GetStackTrace(new StackTrace())}.");
|
||||
Logger.Log($"{nameof(StartMouseWithoutBordersService)}: {Logger.GetStackTrace(new StackTrace())}.");
|
||||
|
||||
Task task = Task.Run(() =>
|
||||
{
|
||||
@@ -49,13 +50,13 @@ namespace MouseWithoutBorders
|
||||
{
|
||||
if (DateTime.UtcNow - lastStartServiceTime < TimeSpan.FromSeconds(5))
|
||||
{
|
||||
Log($"{nameof(StartMouseWithoutBordersService)}: Aborted.");
|
||||
Logger.Log($"{nameof(StartMouseWithoutBordersService)}: Aborted.");
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (Process pp in ps)
|
||||
{
|
||||
Common.Log(string.Format(CultureInfo.InvariantCulture, "Killing process MouseWithoutBordersSvc {0}.", pp.Id));
|
||||
Logger.Log(string.Format(CultureInfo.InvariantCulture, "Killing process MouseWithoutBordersSvc {0}.", pp.Id));
|
||||
pp.KillProcess();
|
||||
}
|
||||
}
|
||||
@@ -65,7 +66,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
try
|
||||
{
|
||||
Log("Starting " + service.ServiceName);
|
||||
Logger.Log("Starting " + service.ServiceName);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
@@ -104,7 +105,7 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log(e);
|
||||
Logger.Log(e);
|
||||
|
||||
// ERROR_SERVICE_ALREADY_RUNNING
|
||||
if (!(shownErrMessage || ((e?.InnerException as Win32Exception)?.NativeErrorCode == 1056)))
|
||||
@@ -153,7 +154,7 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Common.Log($"{nameof(StartServiceAndSendLogoffSignal)}: {e.Message}");
|
||||
Logger.Log($"{nameof(StartServiceAndSendLogoffSignal)}: {e.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ using System.Diagnostics;
|
||||
|
||||
using ManagedCommon;
|
||||
|
||||
using Logger = MouseWithoutBorders.Core.Logger;
|
||||
|
||||
namespace MouseWithoutBorders
|
||||
{
|
||||
internal class ShutdownWithPowerToys
|
||||
@@ -22,7 +24,7 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ using System.Windows.Forms;
|
||||
// 2023- Included in PowerToys.
|
||||
// </history>
|
||||
using MouseWithoutBorders.Class;
|
||||
using MouseWithoutBorders.Core;
|
||||
|
||||
namespace MouseWithoutBorders
|
||||
{
|
||||
@@ -52,19 +53,19 @@ namespace MouseWithoutBorders
|
||||
{
|
||||
// For logging only
|
||||
_ = NativeMethods.GetDpiForMonitor(hMonitor, 0, out uint dpiX, out uint dpiY);
|
||||
Log(string.Format(CultureInfo.CurrentCulture, "MONITOR: ({0}, {1}, {2}, {3}). DPI: ({4}, {5})", mi.rcMonitor.Left, mi.rcMonitor.Top, mi.rcMonitor.Right, mi.rcMonitor.Bottom, dpiX, dpiY));
|
||||
Logger.Log(string.Format(CultureInfo.CurrentCulture, "MONITOR: ({0}, {1}, {2}, {3}). DPI: ({4}, {5})", mi.rcMonitor.Left, mi.rcMonitor.Top, mi.rcMonitor.Right, mi.rcMonitor.Bottom, dpiX, dpiY));
|
||||
}
|
||||
catch (DllNotFoundException)
|
||||
{
|
||||
Common.Log("GetDpiForMonitor is unsupported in Windows 7 and lower.");
|
||||
Logger.Log("GetDpiForMonitor is unsupported in Windows 7 and lower.");
|
||||
}
|
||||
catch (EntryPointNotFoundException)
|
||||
{
|
||||
Common.Log("GetDpiForMonitor is unsupported in Windows 7 and lower.");
|
||||
Logger.Log("GetDpiForMonitor is unsupported in Windows 7 and lower.");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
|
||||
if (mi.rcMonitor.Left == 0 && mi.rcMonitor.Top == 0 && mi.rcMonitor.Right != 0 && mi.rcMonitor.Bottom != 0)
|
||||
@@ -116,7 +117,7 @@ namespace MouseWithoutBorders
|
||||
{
|
||||
try
|
||||
{
|
||||
Common.LogDebug("==================== GetScreenConfig started");
|
||||
Logger.LogDebug("==================== GetScreenConfig started");
|
||||
newDesktopBounds = new MyRectangle();
|
||||
newPrimaryScreenBounds = new MyRectangle();
|
||||
newDesktopBounds.Left = newPrimaryScreenBounds.Left = Screen.PrimaryScreen.Bounds.Left;
|
||||
@@ -124,7 +125,7 @@ namespace MouseWithoutBorders
|
||||
newDesktopBounds.Right = newPrimaryScreenBounds.Right = Screen.PrimaryScreen.Bounds.Right;
|
||||
newDesktopBounds.Bottom = newPrimaryScreenBounds.Bottom = Screen.PrimaryScreen.Bounds.Bottom;
|
||||
|
||||
Common.Log(string.Format(
|
||||
Logger.Log(string.Format(
|
||||
CultureInfo.CurrentCulture,
|
||||
"logon = {0} PrimaryScreenBounds = {1},{2},{3},{4} desktopBounds = {5},{6},{7},{8}",
|
||||
Common.RunOnLogonDesktop,
|
||||
@@ -162,7 +163,7 @@ namespace MouseWithoutBorders
|
||||
Interlocked.Exchange(ref desktopBounds, newDesktopBounds);
|
||||
Interlocked.Exchange(ref primaryScreenBounds, newPrimaryScreenBounds);
|
||||
|
||||
Common.Log(string.Format(
|
||||
Logger.Log(string.Format(
|
||||
CultureInfo.CurrentCulture,
|
||||
"logon = {0} PrimaryScreenBounds = {1},{2},{3},{4} desktopBounds = {5},{6},{7},{8}",
|
||||
Common.RunOnLogonDesktop,
|
||||
@@ -175,11 +176,11 @@ namespace MouseWithoutBorders
|
||||
Common.DesktopBounds.Right,
|
||||
Common.DesktopBounds.Bottom));
|
||||
|
||||
Common.Log("==================== GetScreenConfig ended");
|
||||
Logger.Log("==================== GetScreenConfig ended");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -265,7 +266,7 @@ namespace MouseWithoutBorders
|
||||
{
|
||||
if (!Common.RunWithNoAdminRight)
|
||||
{
|
||||
LogDebug("*** Starting on active Desktop: " + desktopToRunMouseWithoutBordersOn);
|
||||
Logger.LogDebug("*** Starting on active Desktop: " + desktopToRunMouseWithoutBordersOn);
|
||||
StartMouseWithoutBordersService(desktopToRunMouseWithoutBordersOn);
|
||||
}
|
||||
}
|
||||
@@ -282,19 +283,19 @@ namespace MouseWithoutBorders
|
||||
while (NativeMethods.WTSGetActiveConsoleSessionId() == 0xFFFFFFFF && waitCount > 0)
|
||||
{
|
||||
waitCount--;
|
||||
LogDebug("The session is detached/attached.");
|
||||
Logger.LogDebug("The session is detached/attached.");
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
|
||||
string myDesktop = GetMyDesktop();
|
||||
activeDesktop = GetInputDesktop();
|
||||
|
||||
LogDebug("*** Active Desktop = " + activeDesktop);
|
||||
LogDebug("*** My Desktop = " + myDesktop);
|
||||
Logger.LogDebug("*** Active Desktop = " + activeDesktop);
|
||||
Logger.LogDebug("*** My Desktop = " + myDesktop);
|
||||
|
||||
if (myDesktop.Equals(activeDesktop, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
LogDebug("*** Active Desktop == My Desktop (TS session)");
|
||||
Logger.LogDebug("*** Active Desktop == My Desktop (TS session)");
|
||||
}
|
||||
|
||||
if (!activeDesktop.Equals("winlogon", StringComparison.OrdinalIgnoreCase) &&
|
||||
@@ -307,25 +308,25 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Common.Log($"{nameof(CheckForDesktopSwitchEvent)}: {e}");
|
||||
Logger.Log($"{nameof(CheckForDesktopSwitchEvent)}: {e}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!myDesktop.Equals(activeDesktop, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
Log("*** Active Desktop <> My Desktop");
|
||||
Logger.Log("*** Active Desktop <> My Desktop");
|
||||
}
|
||||
|
||||
uint sid = NativeMethods.WTSGetActiveConsoleSessionId();
|
||||
|
||||
if (Process.GetProcessesByName(Common.BinaryName).Any(p => (uint)p.SessionId == sid))
|
||||
{
|
||||
Log("Found MouseWithoutBorders on the active session!");
|
||||
Logger.Log("Found MouseWithoutBorders on the active session!");
|
||||
}
|
||||
else
|
||||
{
|
||||
Log("MouseWithoutBorders not found on the active session!");
|
||||
Logger.Log("MouseWithoutBorders not found on the active session!");
|
||||
StartMMService(null);
|
||||
}
|
||||
}
|
||||
@@ -333,7 +334,7 @@ namespace MouseWithoutBorders
|
||||
if (!myDesktop.Equals("winlogon", StringComparison.OrdinalIgnoreCase) &&
|
||||
!myDesktop.Equals("default", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
LogDebug("*** Desktop inactive, exiting: " + myDesktop);
|
||||
Logger.LogDebug("*** Desktop inactive, exiting: " + myDesktop);
|
||||
Setting.Values.LastX = JUST_GOT_BACK_FROM_SCREEN_SAVER;
|
||||
if (cleanupIfExit)
|
||||
{
|
||||
@@ -346,7 +347,7 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ using Microsoft.PowerToys.Settings.UI.Library;
|
||||
// 2023- Included in PowerToys.
|
||||
// </history>
|
||||
using MouseWithoutBorders.Class;
|
||||
using MouseWithoutBorders.Core;
|
||||
using MouseWithoutBorders.Exceptions;
|
||||
|
||||
// Log is enough
|
||||
@@ -78,7 +79,7 @@ namespace MouseWithoutBorders
|
||||
{
|
||||
internal partial class Common
|
||||
{
|
||||
private Common()
|
||||
internal Common()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -259,7 +260,7 @@ namespace MouseWithoutBorders
|
||||
{
|
||||
if (SocketMutex != null)
|
||||
{
|
||||
LogDebug("SOCKET MUTEX BEGIN RELEASE.");
|
||||
Logger.LogDebug("SOCKET MUTEX BEGIN RELEASE.");
|
||||
|
||||
try
|
||||
{
|
||||
@@ -269,14 +270,14 @@ namespace MouseWithoutBorders
|
||||
catch (ApplicationException e)
|
||||
{
|
||||
// The current thread does not own the mutex, the thread acquired it will own it.
|
||||
TelemetryLogTrace($"{nameof(ReleaseSocketMutex)}: {e.Message}. {Thread.CurrentThread.ManagedThreadId}/{UIThreadID}.", SeverityLevel.Warning);
|
||||
Logger.TelemetryLogTrace($"{nameof(ReleaseSocketMutex)}: {e.Message}. {Thread.CurrentThread.ManagedThreadId}/{UIThreadID}.", SeverityLevel.Warning);
|
||||
}
|
||||
|
||||
LogDebug("SOCKET MUTEX RELEASED.");
|
||||
Logger.LogDebug("SOCKET MUTEX RELEASED.");
|
||||
}
|
||||
else
|
||||
{
|
||||
LogDebug("SOCKET MUTEX NULL.");
|
||||
Logger.LogDebug("SOCKET MUTEX NULL.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -284,7 +285,7 @@ namespace MouseWithoutBorders
|
||||
{
|
||||
if (SocketMutex != null)
|
||||
{
|
||||
LogDebug("SOCKET MUTEX BEGIN WAIT.");
|
||||
Logger.LogDebug("SOCKET MUTEX BEGIN WAIT.");
|
||||
int waitTimeout = 60000; // TcpListener.Stop may take very long to complete for some reason.
|
||||
|
||||
int socketMutexBalance = int.MinValue;
|
||||
@@ -302,14 +303,14 @@ namespace MouseWithoutBorders
|
||||
if (!acquireMutex)
|
||||
{
|
||||
Process[] ps = Process.GetProcessesByName(Common.BinaryName);
|
||||
TelemetryLogTrace($"Balance: {socketMutexBalance}, Active: {IsMyDesktopActive()}, Sid/Console: {Process.GetCurrentProcess().SessionId}/{NativeMethods.WTSGetActiveConsoleSessionId()}, Desktop/Input: {GetMyDesktop()}/{GetInputDesktop()}, count: {ps?.Length}.", SeverityLevel.Warning);
|
||||
Logger.TelemetryLogTrace($"Balance: {socketMutexBalance}, Active: {IsMyDesktopActive()}, Sid/Console: {Process.GetCurrentProcess().SessionId}/{NativeMethods.WTSGetActiveConsoleSessionId()}, Desktop/Input: {GetMyDesktop()}/{GetInputDesktop()}, count: {ps?.Length}.", SeverityLevel.Warning);
|
||||
}
|
||||
|
||||
LogDebug("SOCKET MUTEX ENDED.");
|
||||
Logger.LogDebug("SOCKET MUTEX ENDED.");
|
||||
}
|
||||
else
|
||||
{
|
||||
LogDebug("SOCKET MUTEX NULL.");
|
||||
Logger.LogDebug("SOCKET MUTEX NULL.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -318,7 +319,7 @@ namespace MouseWithoutBorders
|
||||
internal static bool ExecuteAndTrace(string actionName, Action action, TimeSpan timeout, bool restart = false)
|
||||
{
|
||||
bool rv = true;
|
||||
LogDebug(actionName);
|
||||
Logger.LogDebug(actionName);
|
||||
bool done = false;
|
||||
|
||||
BlockingUI = true;
|
||||
@@ -343,12 +344,12 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
}
|
||||
|
||||
TelemetryLogTrace($"[{actionName}] took more than {(long)timeout.TotalSeconds}, restarting the process.", SeverityLevel.Warning, true);
|
||||
Logger.TelemetryLogTrace($"[{actionName}] took more than {(long)timeout.TotalSeconds}, restarting the process.", SeverityLevel.Warning, true);
|
||||
|
||||
string desktop = Common.GetMyDesktop();
|
||||
oneInstanceCheck?.Close();
|
||||
_ = Process.Start(Application.ExecutablePath, desktop);
|
||||
LogDebug($"Started on desktop {desktop}");
|
||||
Logger.LogDebug($"Started on desktop {desktop}");
|
||||
|
||||
Process.GetCurrentProcess().KillProcess(true);
|
||||
},
|
||||
@@ -379,7 +380,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
if (!restart)
|
||||
{
|
||||
TelemetryLogTrace($"[{actionName}] took more than {(long)timeout.TotalSeconds}: {(long)timer.Elapsed.TotalSeconds}.", SeverityLevel.Warning);
|
||||
Logger.TelemetryLogTrace($"[{actionName}] took more than {(long)timeout.TotalSeconds}: {(long)timer.Elapsed.TotalSeconds}.", SeverityLevel.Warning);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -445,7 +446,7 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -457,7 +458,7 @@ namespace MouseWithoutBorders
|
||||
catch (Exception e)
|
||||
{
|
||||
done = true;
|
||||
Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
|
||||
while (blocking && !done)
|
||||
@@ -508,11 +509,11 @@ namespace MouseWithoutBorders
|
||||
|
||||
internal static void SendNextMachine(ID hostMachine, ID nextMachine, Point requestedXY)
|
||||
{
|
||||
LogDebug($"SendNextMachine: Host machine: {hostMachine}, Next machine: {nextMachine}, Requested XY: {requestedXY}");
|
||||
Logger.LogDebug($"SendNextMachine: Host machine: {hostMachine}, Next machine: {nextMachine}, Requested XY: {requestedXY}");
|
||||
|
||||
if (GetTick() - lastSendNextMachine < 100)
|
||||
{
|
||||
LogDebug("Machine switching in progress."); // "Move Mouse relatively" mode, slow machine/network, quick/busy hand.
|
||||
Logger.LogDebug("Machine switching in progress."); // "Move Mouse relatively" mode, slow machine/network, quick/busy hand.
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -529,7 +530,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
SkSend(package, null, false);
|
||||
|
||||
LogDebug("SendNextMachine done.");
|
||||
Logger.LogDebug("SendNextMachine done.");
|
||||
}
|
||||
|
||||
private static ulong lastInputEventCount;
|
||||
@@ -603,7 +604,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
private static void SendByeBye()
|
||||
{
|
||||
LogDebug($"{nameof(SendByeBye)}");
|
||||
Logger.LogDebug($"{nameof(SendByeBye)}");
|
||||
SendPackage(ID.ALL, PackageType.ByeBye);
|
||||
}
|
||||
|
||||
@@ -629,7 +630,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
internal static void SetToggleIcon(int[] toggleIcons)
|
||||
{
|
||||
Common.LogDebug($"{nameof(SetToggleIcon)}: {toggleIcons?.FirstOrDefault()}");
|
||||
Logger.LogDebug($"{nameof(SetToggleIcon)}: {toggleIcons?.FirstOrDefault()}");
|
||||
Common.toggleIcons = toggleIcons;
|
||||
toggleIconsIndex = 0;
|
||||
}
|
||||
@@ -651,7 +652,7 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log(e);
|
||||
Logger.Log(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -666,7 +667,7 @@ namespace MouseWithoutBorders
|
||||
InputSimulation.SendKey(new KEYBDDATA() { wVk = (int)VK.SNAPSHOT });
|
||||
InputSimulation.SendKey(new KEYBDDATA() { dwFlags = (int)Common.LLKHF.UP, wVk = (int)VK.SNAPSHOT });
|
||||
|
||||
Common.LogDebug("PrepareScreenCapture: SNAPSHOT simulated.");
|
||||
Logger.LogDebug("PrepareScreenCapture: SNAPSHOT simulated.");
|
||||
|
||||
_ = NativeMethods.MoveWindow(
|
||||
(IntPtr)NativeMethods.FindWindow(null, Common.HELPER_FORM_TEXT),
|
||||
@@ -680,7 +681,7 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
else
|
||||
{
|
||||
Common.Log("PrepareScreenCapture: Validation failed.");
|
||||
Logger.Log("PrepareScreenCapture: Validation failed.");
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -761,7 +762,7 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
else
|
||||
{
|
||||
Log(tip);
|
||||
Logger.Log(tip);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -934,7 +935,7 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log(e);
|
||||
Logger.Log(e);
|
||||
t.BackingSocket = null; // To be removed at CloseAnUnusedSocket()
|
||||
updateClientSockets = true;
|
||||
}
|
||||
@@ -945,7 +946,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
if (!connected && data.Des != ID.ALL)
|
||||
{
|
||||
LogDebug("********** No active connection found for the remote machine! **********" + data.Des.ToString());
|
||||
Logger.LogDebug("********** No active connection found for the remote machine! **********" + data.Des.ToString());
|
||||
|
||||
if (data.Des == ID.NONE || RemoveDeadMachines(data.Des))
|
||||
{
|
||||
@@ -965,7 +966,7 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
@@ -1006,7 +1007,7 @@ namespace MouseWithoutBorders
|
||||
{
|
||||
if ((t.Status != SocketStatus.Connected && t.BirthTime < GetTick() - SocketStuff.CONNECT_TIMEOUT) || t.BackingSocket == null)
|
||||
{
|
||||
LogDebug("CloseAnUnusedSocket: " + t.MachineName + ":" + t.MachineId + "|" + t.Status.ToString());
|
||||
Logger.LogDebug("CloseAnUnusedSocket: " + t.MachineName + ":" + t.MachineId + "|" + t.Status.ToString());
|
||||
tobeRemoved = t;
|
||||
|
||||
if (t.BackingSocket != null)
|
||||
@@ -1017,7 +1018,7 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1048,7 +1049,7 @@ namespace MouseWithoutBorders
|
||||
{
|
||||
if (t.Status == SocketStatus.Connected)
|
||||
{
|
||||
LogDebug("AtLeastOneSocketConnected returning true: " + t.MachineName);
|
||||
Logger.LogDebug("AtLeastOneSocketConnected returning true: " + t.MachineName);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1056,7 +1057,7 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
}
|
||||
|
||||
LogDebug("AtLeastOneSocketConnected returning false.");
|
||||
Logger.LogDebug("AtLeastOneSocketConnected returning false.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1074,7 +1075,7 @@ namespace MouseWithoutBorders
|
||||
{
|
||||
if (!t.IsClient && t.Status == SocketStatus.Connected)
|
||||
{
|
||||
LogDebug("AtLeastOneServerSocketConnected returning true: " + t.MachineName);
|
||||
Logger.LogDebug("AtLeastOneServerSocketConnected returning true: " + t.MachineName);
|
||||
return t.BackingSocket;
|
||||
}
|
||||
}
|
||||
@@ -1082,7 +1083,7 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
}
|
||||
|
||||
LogDebug("AtLeastOneServerSocketConnected returning false.");
|
||||
Logger.LogDebug("AtLeastOneServerSocketConnected returning false.");
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1119,7 +1120,7 @@ namespace MouseWithoutBorders
|
||||
{
|
||||
if (TestSend(t))
|
||||
{
|
||||
LogDebug($"{nameof(AtLeastOneSocketEstablished)} returning true: {t.MachineName}");
|
||||
Logger.LogDebug($"{nameof(AtLeastOneSocketEstablished)} returning true: {t.MachineName}");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1128,7 +1129,7 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
}
|
||||
|
||||
LogDebug($"{nameof(AtLeastOneSocketEstablished)} returning false.");
|
||||
Logger.LogDebug($"{nameof(AtLeastOneSocketEstablished)} returning false.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1209,7 +1210,7 @@ namespace MouseWithoutBorders
|
||||
if (machineCt < 2 && Common.Settings != null && (Common.Settings.GetCurrentPage() is SetupPage1 || Common.Settings.GetCurrentPage() is SetupPage2b))
|
||||
{
|
||||
Common.MachineMatrix = new string[Common.MAX_MACHINE] { Common.MachineName.Trim(), desMachine, string.Empty, string.Empty };
|
||||
Common.LogDebug("UpdateSetupMachineMatrix: " + string.Join(",", Common.MachineMatrix));
|
||||
Logger.LogDebug("UpdateSetupMachineMatrix: " + string.Join(",", Common.MachineMatrix));
|
||||
|
||||
Common.DoSomethingInUIThread(
|
||||
() =>
|
||||
@@ -1240,7 +1241,7 @@ namespace MouseWithoutBorders
|
||||
catch (Exception e)
|
||||
{
|
||||
Sk = null;
|
||||
Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
|
||||
if (Sk != null)
|
||||
@@ -1325,7 +1326,7 @@ namespace MouseWithoutBorders
|
||||
});
|
||||
}
|
||||
|
||||
LogDebug("GetMyStorageDir: " + st);
|
||||
Logger.LogDebug("GetMyStorageDir: " + st);
|
||||
|
||||
// Delete old files.
|
||||
foreach (FileInfo fi in new DirectoryInfo(st).GetFiles())
|
||||
@@ -1340,7 +1341,7 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log(e);
|
||||
Logger.Log(e);
|
||||
|
||||
if (string.IsNullOrEmpty(st) || !st.Contains(Common.BinaryName))
|
||||
{
|
||||
@@ -1358,11 +1359,11 @@ namespace MouseWithoutBorders
|
||||
try
|
||||
{
|
||||
machine_Name = Dns.GetHostName();
|
||||
LogDebug("GetHostName = " + machine_Name);
|
||||
Logger.LogDebug("GetHostName = " + machine_Name);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log(e);
|
||||
Logger.Log(e);
|
||||
|
||||
if (string.IsNullOrEmpty(machine_Name))
|
||||
{
|
||||
@@ -1377,7 +1378,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
Common.MachineName = machine_Name.Trim();
|
||||
|
||||
LogDebug($"========== {nameof(GetMachineName)} ended!");
|
||||
Logger.LogDebug($"========== {nameof(GetMachineName)} ended!");
|
||||
}
|
||||
|
||||
private static string GetNetworkName(NetworkInterface networkInterface)
|
||||
@@ -1405,7 +1406,7 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
catch (ObjectDisposedException e)
|
||||
{
|
||||
Log($"{nameof(GetRemoteStringIP)}: The socket could have been disposed by other threads, error: {e.Message}");
|
||||
Logger.Log($"{nameof(GetRemoteStringIP)}: The socket could have been disposed by other threads, error: {e.Message}");
|
||||
|
||||
if (throwException)
|
||||
{
|
||||
@@ -1416,7 +1417,7 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
catch (SocketException e)
|
||||
{
|
||||
Log($"{nameof(GetRemoteStringIP)}: {e.Message}");
|
||||
Logger.Log($"{nameof(GetRemoteStringIP)}: {e.Message}");
|
||||
|
||||
if (throwException)
|
||||
{
|
||||
@@ -1466,7 +1467,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
internal static void MoveMouseToCenter()
|
||||
{
|
||||
LogDebug("+++++ MoveMouseToCenter");
|
||||
Logger.LogDebug("+++++ MoveMouseToCenter");
|
||||
InputSimulation.MoveMouse(
|
||||
Common.PrimaryScreenBounds.Left + ((Common.PrimaryScreenBounds.Right - Common.PrimaryScreenBounds.Left) / 2),
|
||||
Common.PrimaryScreenBounds.Top + ((Common.PrimaryScreenBounds.Bottom - Common.PrimaryScreenBounds.Top) / 2));
|
||||
@@ -1482,7 +1483,7 @@ namespace MouseWithoutBorders
|
||||
{
|
||||
_ = NativeMethods.SetCursorPos(Common.LastPos.X, Common.LastPos.Y);
|
||||
_ = NativeMethods.GetCursorPos(ref Common.lastPos);
|
||||
LogDebug($"+++++ HideMouseCursor, byHideMouseMessage = {byHideMouseMessage}");
|
||||
Logger.LogDebug($"+++++ HideMouseCursor, byHideMouseMessage = {byHideMouseMessage}");
|
||||
}
|
||||
|
||||
CustomCursor.ShowFakeMouseCursor(int.MinValue, int.MinValue);
|
||||
@@ -1493,7 +1494,7 @@ namespace MouseWithoutBorders
|
||||
int length = NativeMethods.GetWindowTextLength(hWnd);
|
||||
StringBuilder sb = new(length + 1);
|
||||
int rv = NativeMethods.GetWindowText(hWnd, sb, sb.Capacity);
|
||||
LogDebug("GetWindowText returned " + rv.ToString(CultureInfo.CurrentCulture));
|
||||
Logger.LogDebug("GetWindowText returned " + rv.ToString(CultureInfo.CurrentCulture));
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
@@ -1536,14 +1537,14 @@ namespace MouseWithoutBorders
|
||||
|
||||
if (read != toRead)
|
||||
{
|
||||
Common.LogDebug("Stream has no more data after reading {0} bytes.", read);
|
||||
Logger.LogDebug("Stream has no more data after reading {0} bytes.", read);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
string log = $"{nameof(SendOrReceiveARandomDataBlockPerInitialIV)}: Exception {(send ? "writing" : "reading")} to the socket stream: {e.InnerException?.GetType()}/{e.Message}. (This is expected when the remote machine closes the connection during desktop switch or reconnection.)";
|
||||
Common.Log(log);
|
||||
Logger.Log(log);
|
||||
|
||||
if (e.InnerException is not (SocketException or ObjectDisposedException))
|
||||
{
|
||||
|
||||
@@ -16,6 +16,8 @@ using System.Drawing.Imaging;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using MouseWithoutBorders.Core;
|
||||
|
||||
// Disable the warning to preserve original code
|
||||
#pragma warning disable CA1716
|
||||
namespace MouseWithoutBorders.Class
|
||||
@@ -107,12 +109,12 @@ namespace MouseWithoutBorders.Class
|
||||
}
|
||||
catch (NullReferenceException)
|
||||
{
|
||||
Common.Log($"{nameof(Common.MouseCursorForm)} has been set to null by another thread.");
|
||||
Logger.Log($"{nameof(Common.MouseCursorForm)} has been set to null by another thread.");
|
||||
Common.MouseCursorForm = new FrmMouseCursor();
|
||||
}
|
||||
catch (ObjectDisposedException)
|
||||
{
|
||||
Common.Log($"{nameof(Common.MouseCursorForm)} has been disposed.");
|
||||
Logger.Log($"{nameof(Common.MouseCursorForm)} has been disposed.");
|
||||
Common.MouseCursorForm = new FrmMouseCursor();
|
||||
}
|
||||
},
|
||||
@@ -134,11 +136,11 @@ namespace MouseWithoutBorders.Class
|
||||
}
|
||||
catch (NullReferenceException)
|
||||
{
|
||||
Common.Log($"{nameof(Common.MouseCursorForm)} has already been set to null by another thread!");
|
||||
Logger.Log($"{nameof(Common.MouseCursorForm)} has already been set to null by another thread!");
|
||||
}
|
||||
catch (ObjectDisposedException)
|
||||
{
|
||||
Common.Log($"{nameof(Common.MouseCursorForm)} has already been disposed!");
|
||||
Logger.Log($"{nameof(Common.MouseCursorForm)} has already been disposed!");
|
||||
}
|
||||
|
||||
Common.MouseCursorForm = null;
|
||||
|
||||
@@ -6,6 +6,8 @@ using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
using MouseWithoutBorders.Core;
|
||||
|
||||
// Disable the warning to preserve original code
|
||||
#pragma warning disable CA1716
|
||||
namespace MouseWithoutBorders.Class
|
||||
@@ -42,7 +44,7 @@ namespace MouseWithoutBorders.Class
|
||||
catch (Win32Exception e)
|
||||
{
|
||||
string log = $"The process {processName} (PID={processId}) could not be terminated, error: {e.Message}";
|
||||
Common.TelemetryLogTrace(log, SeverityLevel.Error);
|
||||
Logger.TelemetryLogTrace(log, SeverityLevel.Error);
|
||||
Common.ShowToolTip(log, 5000);
|
||||
|
||||
if (!keepTrying)
|
||||
|
||||
@@ -23,8 +23,9 @@ using StreamJsonRpc;
|
||||
|
||||
#if !MM_HELPER
|
||||
using MouseWithoutBorders.Class;
|
||||
|
||||
using MouseWithoutBorders.Core;
|
||||
#endif
|
||||
|
||||
using SystemClipboard = System.Windows.Forms.Clipboard;
|
||||
|
||||
namespace MouseWithoutBorders
|
||||
@@ -127,7 +128,7 @@ namespace MouseWithoutBorders
|
||||
{
|
||||
public void SendLog(string log)
|
||||
{
|
||||
Common.LogDebug("FROM HELPER: " + log);
|
||||
Logger.LogDebug("FROM HELPER: " + log);
|
||||
|
||||
if (!string.IsNullOrEmpty(log))
|
||||
{
|
||||
@@ -143,7 +144,7 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
else if (log.StartsWith("Trace:", StringComparison.InvariantCulture))
|
||||
{
|
||||
Common.TelemetryLogTrace(log, SeverityLevel.Information);
|
||||
Logger.TelemetryLogTrace(log, SeverityLevel.Information);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -197,7 +198,7 @@ WellKnownSidType.AuthenticatedUserSid, null);
|
||||
#if MM_HELPER
|
||||
_ = e;
|
||||
#else
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
#endif
|
||||
}
|
||||
},
|
||||
@@ -247,7 +248,7 @@ WellKnownSidType.AuthenticatedUserSid, null);
|
||||
{
|
||||
Common.IpcChannelCreated = false;
|
||||
Common.ShowToolTip("Error setting up clipboard sharing, clipboard sharing will not work!", 5000, ToolTipIcon.Error);
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
}
|
||||
#else
|
||||
@@ -263,7 +264,7 @@ WellKnownSidType.AuthenticatedUserSid, null);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogEvent(e.Message, EventLogEntryType.Error);
|
||||
EventLogger.LogEvent(e.Message, EventLogEntryType.Error);
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -272,7 +273,7 @@ WellKnownSidType.AuthenticatedUserSid, null);
|
||||
|
||||
}
|
||||
|
||||
internal static class Logger
|
||||
internal static class EventLogger
|
||||
{
|
||||
#if MM_HELPER
|
||||
private const string EventSourceName = "MouseWithoutBordersHelper";
|
||||
|
||||
@@ -19,6 +19,7 @@ using System.Runtime.InteropServices;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
using MouseWithoutBorders.Core;
|
||||
|
||||
[module: SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Scope = "member", Target = "MouseWithoutBorders.InputHook.#MouseHookProc(System.Int32,System.Int32,System.IntPtr)", Justification = "Dotnet port with style preservation")]
|
||||
[module: SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity", Scope = "member", Target = "MouseWithoutBorders.InputHook.#ProcessKeyEx(System.Int32,System.Int32)", Justification = "Dotnet port with style preservation")]
|
||||
@@ -117,7 +118,7 @@ namespace MouseWithoutBorders.Class
|
||||
if (hMouseHook == 0)
|
||||
{
|
||||
le = Marshal.GetLastWin32Error();
|
||||
Common.Log("Error installing Mouse hook: " + le.ToString(CultureInfo.CurrentCulture));
|
||||
Logger.Log("Error installing Mouse hook: " + le.ToString(CultureInfo.CurrentCulture));
|
||||
er = true;
|
||||
Stop();
|
||||
}
|
||||
@@ -133,7 +134,7 @@ namespace MouseWithoutBorders.Class
|
||||
if (hKeyboardHook == 0)
|
||||
{
|
||||
le = Marshal.GetLastWin32Error();
|
||||
Common.Log("Error installing keyboard hook: " + le.ToString(CultureInfo.CurrentCulture));
|
||||
Logger.Log("Error installing keyboard hook: " + le.ToString(CultureInfo.CurrentCulture));
|
||||
er = true;
|
||||
Stop();
|
||||
}
|
||||
@@ -166,7 +167,7 @@ namespace MouseWithoutBorders.Class
|
||||
int errorCode = Marshal.GetLastWin32Error();
|
||||
|
||||
// throw new Win32Exception(errorCode);
|
||||
Common.Log("Exception uninstalling Mouse hook, error code: " + errorCode.ToString(CultureInfo.CurrentCulture));
|
||||
Logger.Log("Exception uninstalling Mouse hook, error code: " + errorCode.ToString(CultureInfo.CurrentCulture));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,7 +180,7 @@ namespace MouseWithoutBorders.Class
|
||||
int errorCode = Marshal.GetLastWin32Error();
|
||||
|
||||
// throw new Win32Exception(errorCode);
|
||||
Common.Log("Exception uninstalling keyboard hook, error code: " + errorCode.ToString(CultureInfo.CurrentCulture));
|
||||
Logger.Log("Exception uninstalling keyboard hook, error code: " + errorCode.ToString(CultureInfo.CurrentCulture));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -234,7 +235,7 @@ namespace MouseWithoutBorders.Class
|
||||
{
|
||||
if (wParam == Common.WM_LBUTTONUP && SkipMouseUpCount > 0)
|
||||
{
|
||||
Common.LogDebug($"{nameof(SkipMouseUpCount)}: {SkipMouseUpCount}.");
|
||||
Logger.LogDebug($"{nameof(SkipMouseUpCount)}: {SkipMouseUpCount}.");
|
||||
SkipMouseUpCount--;
|
||||
rv = NativeMethods.CallNextHookEx(hMouseHook, nCode, wParam, lParam);
|
||||
return rv;
|
||||
@@ -326,7 +327,7 @@ namespace MouseWithoutBorders.Class
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
rv = NativeMethods.CallNextHookEx(hMouseHook, nCode, wParam, lParam);
|
||||
}
|
||||
|
||||
@@ -455,7 +456,7 @@ namespace MouseWithoutBorders.Class
|
||||
break;
|
||||
|
||||
default:
|
||||
Common.LogDebug("X");
|
||||
Logger.LogDebug("X");
|
||||
return ProcessHotKeys(vkCode, hookCallbackKeybdData);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ using System.ServiceProcess;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
using MouseWithoutBorders.Core;
|
||||
using Windows.UI.Input.Preview.Injection;
|
||||
|
||||
using static MouseWithoutBorders.Class.NativeMethods;
|
||||
@@ -152,7 +153,7 @@ namespace MouseWithoutBorders.Class
|
||||
}
|
||||
|
||||
log += "*"; // ((Keys)kd.wVk).ToString(CultureInfo.InvariantCulture);
|
||||
Common.LogDebug(log);
|
||||
Logger.LogDebug(log);
|
||||
}
|
||||
|
||||
// Md.X, Md.Y is from 0 to 65535
|
||||
@@ -174,7 +175,7 @@ namespace MouseWithoutBorders.Class
|
||||
|
||||
if (md.dwFlags != Common.WM_MOUSEMOVE)
|
||||
{
|
||||
Common.LogDebug($"InputSimulation.SendMouse: x = {md.X}, y = {md.Y}, WheelDelta = {md.WheelDelta}, dwFlags = {md.dwFlags}.");
|
||||
Logger.LogDebug($"InputSimulation.SendMouse: x = {md.X}, y = {md.Y}, WheelDelta = {md.WheelDelta}, dwFlags = {md.dwFlags}.");
|
||||
}
|
||||
|
||||
switch (md.dwFlags)
|
||||
@@ -242,7 +243,7 @@ namespace MouseWithoutBorders.Class
|
||||
mouse_input.mi.dx = (int)dx;
|
||||
mouse_input.mi.dy = (int)dy;
|
||||
|
||||
Common.LogDebug($"InputSimulation.MoveMouseEx: x = {x}, y = {y}.");
|
||||
Logger.LogDebug($"InputSimulation.MoveMouseEx: x = {x}, y = {y}.");
|
||||
|
||||
mouse_input.mi.dwFlags |= (int)(NativeMethods.MOUSEEVENTF.MOVE | NativeMethods.MOUSEEVENTF.ABSOLUTE);
|
||||
|
||||
@@ -264,7 +265,7 @@ namespace MouseWithoutBorders.Class
|
||||
mouse_input.mi.mouseData = 0;
|
||||
mouse_input.mi.dwFlags = (int)(NativeMethods.MOUSEEVENTF.MOVE | NativeMethods.MOUSEEVENTF.ABSOLUTE);
|
||||
|
||||
Common.LogDebug($"InputSimulation.MoveMouse: x = {x}, y = {y}.");
|
||||
Logger.LogDebug($"InputSimulation.MoveMouse: x = {x}, y = {y}.");
|
||||
|
||||
Common.DoSomethingInTheInputSimulationThread(() =>
|
||||
{
|
||||
@@ -285,7 +286,7 @@ namespace MouseWithoutBorders.Class
|
||||
mouse_input.mi.mouseData = 0;
|
||||
mouse_input.mi.dwFlags = (int)NativeMethods.MOUSEEVENTF.MOVE;
|
||||
|
||||
Common.LogDebug($"InputSimulation.MoveMouseRelative: x = {dx}, y = {dy}.");
|
||||
Logger.LogDebug($"InputSimulation.MoveMouseRelative: x = {dx}, y = {dy}.");
|
||||
|
||||
Common.DoSomethingInTheInputSimulationThread(() =>
|
||||
{
|
||||
@@ -309,7 +310,7 @@ namespace MouseWithoutBorders.Class
|
||||
|
||||
InputHook.SkipMouseUpCount++;
|
||||
_ = SendInputEx(input);
|
||||
Common.LogDebug("MouseUp() called");
|
||||
Logger.LogDebug("MouseUp() called");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -338,7 +339,7 @@ namespace MouseWithoutBorders.Class
|
||||
input.mi.dwFlags = (int)NativeMethods.MOUSEEVENTF.LEFTUP;
|
||||
_ = SendInputEx(input);
|
||||
|
||||
Common.LogDebug("MouseClick() called");
|
||||
Logger.LogDebug("MouseClick() called");
|
||||
Thread.Sleep(200);
|
||||
}
|
||||
finally
|
||||
@@ -450,7 +451,7 @@ namespace MouseWithoutBorders.Class
|
||||
eatKey = true;
|
||||
Common.ReleaseAllKeys();
|
||||
uint rv = NativeMethods.LockWorkStation();
|
||||
Common.LogDebug("LockWorkStation returned " + rv.ToString(CultureInfo.CurrentCulture));
|
||||
Logger.LogDebug("LockWorkStation returned " + rv.ToString(CultureInfo.CurrentCulture));
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
@@ -34,6 +34,8 @@ using Microsoft.PowerToys.Telemetry;
|
||||
using Newtonsoft.Json;
|
||||
using StreamJsonRpc;
|
||||
|
||||
using Logger = MouseWithoutBorders.Core.Logger;
|
||||
|
||||
[module: SuppressMessage("Microsoft.MSInternal", "CA904:DeclareTypesInMicrosoftOrSystemNamespace", Scope = "namespace", Target = "MouseWithoutBorders", Justification = "Dotnet port with style preservation")]
|
||||
[module: SuppressMessage("Microsoft.Design", "CA1014:MarkAssembliesWithClsCompliant", Justification = "Dotnet port with style preservation")]
|
||||
[module: SuppressMessage("Microsoft.Globalization", "CA1304:SpecifyCultureInfo", Scope = "member", Target = "MouseWithoutBorders.Program.#Main()", MessageId = "System.String.ToLower", Justification = "Dotnet port with style preservation")]
|
||||
@@ -53,11 +55,11 @@ namespace MouseWithoutBorders.Class
|
||||
private static void Main()
|
||||
{
|
||||
ManagedCommon.Logger.InitializeLogger("\\MouseWithoutBorders\\Logs");
|
||||
Common.Log(Application.ProductName + " Started!");
|
||||
Logger.Log(Application.ProductName + " Started!");
|
||||
|
||||
if (PowerToys.GPOWrapper.GPOWrapper.GetConfiguredMouseWithoutBordersEnabledValue() == PowerToys.GPOWrapper.GpoRuleConfigured.Disabled)
|
||||
{
|
||||
Common.Log("Tried to start with a GPO policy setting the utility to always be disabled. Please contact your systems administrator.");
|
||||
Logger.Log("Tried to start with a GPO policy setting the utility to always be disabled. Please contact your systems administrator.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -81,9 +83,9 @@ namespace MouseWithoutBorders.Class
|
||||
}
|
||||
|
||||
User = WindowsIdentity.GetCurrent().Name;
|
||||
Common.LogDebug("*** Started as " + User);
|
||||
Logger.LogDebug("*** Started as " + User);
|
||||
|
||||
Common.Log(Environment.CommandLine);
|
||||
Logger.Log(Environment.CommandLine);
|
||||
|
||||
bool serviceMode = firstArg == ServiceModeArg;
|
||||
|
||||
@@ -99,8 +101,8 @@ namespace MouseWithoutBorders.Class
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Common.Log("Couldn't start the service. Will try to continue as not a service.");
|
||||
Common.Log(ex);
|
||||
Logger.Log("Couldn't start the service. Will try to continue as not a service.");
|
||||
Logger.Log(ex);
|
||||
ShowServiceModeErrorTooltip = true;
|
||||
serviceMode = false;
|
||||
Setting.Values.UseService = false;
|
||||
@@ -121,7 +123,7 @@ namespace MouseWithoutBorders.Class
|
||||
{
|
||||
if (Common.CheckSecondInstance(Common.RunWithNoAdminRight))
|
||||
{
|
||||
Common.Log("*** Second instance, exiting...");
|
||||
Logger.Log("*** Second instance, exiting...");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -130,16 +132,16 @@ namespace MouseWithoutBorders.Class
|
||||
if (firstArg.Equals("winlogon", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
// Executed by service, running on logon desktop
|
||||
Common.Log("*** Running on " + firstArg + " desktop");
|
||||
Logger.Log("*** Running on " + firstArg + " desktop");
|
||||
Common.RunOnLogonDesktop = true;
|
||||
}
|
||||
else if (args[1].Trim().Equals("default", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
Common.Log("*** Running on " + firstArg + " desktop");
|
||||
Logger.Log("*** Running on " + firstArg + " desktop");
|
||||
}
|
||||
else if (args[1].Equals(myDesktop, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
Common.Log("*** Running on " + myDesktop);
|
||||
Logger.Log("*** Running on " + myDesktop);
|
||||
if (myDesktop.Equals("Screen-saver", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
Common.RunOnScrSaverDesktop = true;
|
||||
@@ -151,7 +153,7 @@ namespace MouseWithoutBorders.Class
|
||||
{
|
||||
if (Common.CheckSecondInstance(true))
|
||||
{
|
||||
Common.Log("*** Second instance, exiting...");
|
||||
Logger.Log("*** Second instance, exiting...");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -165,10 +167,10 @@ namespace MouseWithoutBorders.Class
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
|
||||
Common.Log(Environment.OSVersion.ToString());
|
||||
Logger.Log(Environment.OSVersion.ToString());
|
||||
|
||||
// Environment.OSVersion is unreliable from 6.2 and up, so just forcefully call the APIs and log the exception unsupported by Windows:
|
||||
int setProcessDpiAwarenessResult = -1;
|
||||
@@ -176,31 +178,31 @@ namespace MouseWithoutBorders.Class
|
||||
try
|
||||
{
|
||||
setProcessDpiAwarenessResult = NativeMethods.SetProcessDpiAwareness(2);
|
||||
Common.Log(string.Format(CultureInfo.InvariantCulture, "SetProcessDpiAwareness: {0}.", setProcessDpiAwarenessResult));
|
||||
Logger.Log(string.Format(CultureInfo.InvariantCulture, "SetProcessDpiAwareness: {0}.", setProcessDpiAwarenessResult));
|
||||
}
|
||||
catch (DllNotFoundException)
|
||||
{
|
||||
Common.Log("SetProcessDpiAwareness is unsupported in Windows 7 and lower.");
|
||||
Logger.Log("SetProcessDpiAwareness is unsupported in Windows 7 and lower.");
|
||||
}
|
||||
catch (EntryPointNotFoundException)
|
||||
{
|
||||
Common.Log("SetProcessDpiAwareness is unsupported in Windows 7 and lower.");
|
||||
Logger.Log("SetProcessDpiAwareness is unsupported in Windows 7 and lower.");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (setProcessDpiAwarenessResult != 0)
|
||||
{
|
||||
Common.Log(string.Format(CultureInfo.InvariantCulture, "SetProcessDPIAware: {0}.", NativeMethods.SetProcessDPIAware()));
|
||||
Logger.Log(string.Format(CultureInfo.InvariantCulture, "SetProcessDPIAware: {0}.", NativeMethods.SetProcessDPIAware()));
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
|
||||
System.Threading.Thread mainUIThread = Thread.CurrentThread;
|
||||
@@ -226,7 +228,7 @@ namespace MouseWithoutBorders.Class
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -397,14 +399,14 @@ namespace MouseWithoutBorders.Class
|
||||
{
|
||||
if (pp.Id != me.Id)
|
||||
{
|
||||
Common.Log(string.Format(CultureInfo.InvariantCulture, "Killing process {0}.", pp.Id));
|
||||
Logger.Log(string.Format(CultureInfo.InvariantCulture, "Killing process {0}.", pp.Id));
|
||||
pp.KillProcess();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
|
||||
Common.StartMouseWithoutBordersService();
|
||||
|
||||
@@ -29,6 +29,7 @@ using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
||||
// 2023- Included in PowerToys.
|
||||
// </history>
|
||||
using Microsoft.Win32;
|
||||
using MouseWithoutBorders.Core;
|
||||
using Settings.UI.Library.Attributes;
|
||||
|
||||
[module: SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Scope = "member", Target = "MouseWithoutBorders.Properties.Setting.Values.#LoadIntSetting(System.String,System.Int32)", Justification = "Dotnet port with style preservation")]
|
||||
@@ -133,7 +134,7 @@ namespace MouseWithoutBorders.Class
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
Logger.LogEvent($"Failed to read settings: {ex.Message}", System.Diagnostics.EventLogEntryType.Error);
|
||||
EventLogger.LogEvent($"Failed to read settings: {ex.Message}", System.Diagnostics.EventLogEntryType.Error);
|
||||
}
|
||||
|
||||
PauseInstantSaving = false;
|
||||
@@ -168,7 +169,7 @@ namespace MouseWithoutBorders.Class
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
Logger.LogEvent($"Failed to write settings: {ex.Message}", System.Diagnostics.EventLogEntryType.Error);
|
||||
EventLogger.LogEvent($"Failed to write settings: {ex.Message}", System.Diagnostics.EventLogEntryType.Error);
|
||||
}
|
||||
|
||||
if (saved)
|
||||
@@ -198,7 +199,7 @@ namespace MouseWithoutBorders.Class
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogEvent($"Failed to update settings: {ex.Message}", System.Diagnostics.EventLogEntryType.Error);
|
||||
EventLogger.LogEvent($"Failed to update settings: {ex.Message}", System.Diagnostics.EventLogEntryType.Error);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -442,7 +443,7 @@ namespace MouseWithoutBorders.Class
|
||||
{
|
||||
if (_properties.SecurityKey.Value.Length != 0)
|
||||
{
|
||||
Common.LogDebug("GETSECKEY: Key was already loaded/set: " + _properties.SecurityKey.Value);
|
||||
Logger.LogDebug("GETSECKEY: Key was already loaded/set: " + _properties.SecurityKey.Value);
|
||||
return _properties.SecurityKey.Value;
|
||||
}
|
||||
else
|
||||
|
||||
@@ -17,6 +17,7 @@ using System.Security.Cryptography;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using MouseWithoutBorders.Core;
|
||||
|
||||
// <summary>
|
||||
// Socket code.
|
||||
@@ -174,12 +175,12 @@ namespace MouseWithoutBorders.Class
|
||||
|
||||
internal SocketStuff(int port, bool byUser)
|
||||
{
|
||||
Common.LogDebug("SocketStuff started.");
|
||||
Logger.LogDebug("SocketStuff started.");
|
||||
|
||||
bASE_PORT = port;
|
||||
Common.Ran = new Random();
|
||||
|
||||
Common.LogDebug("Validating session...");
|
||||
Logger.LogDebug("Validating session...");
|
||||
|
||||
if (Common.CurrentProcess.SessionId != NativeMethods.WTSGetActiveConsoleSessionId())
|
||||
{
|
||||
@@ -198,12 +199,12 @@ namespace MouseWithoutBorders.Class
|
||||
}
|
||||
|
||||
Common.MMSleep(1);
|
||||
Common.Log("Not physical console session.");
|
||||
Logger.Log("Not physical console session.");
|
||||
|
||||
throw new NotPhysicalConsoleException("Not physical console session.");
|
||||
}
|
||||
|
||||
Common.LogDebug("Creating socket list and mutex...");
|
||||
Logger.LogDebug("Creating socket list and mutex...");
|
||||
|
||||
try
|
||||
{
|
||||
@@ -235,7 +236,7 @@ namespace MouseWithoutBorders.Class
|
||||
}
|
||||
catch (AbandonedMutexException e)
|
||||
{
|
||||
Common.TelemetryLogTrace($"{nameof(SocketStuff)}: {e.Message}", SeverityLevel.Warning);
|
||||
Logger.TelemetryLogTrace($"{nameof(SocketStuff)}: {e.Message}", SeverityLevel.Warning);
|
||||
}
|
||||
|
||||
Common.GetScreenConfig();
|
||||
@@ -280,7 +281,7 @@ namespace MouseWithoutBorders.Class
|
||||
Common.GetMachineName(); // IPs might have been changed
|
||||
Common.UpdateMachineTimeAndID();
|
||||
|
||||
Common.LogDebug("Creating sockets...");
|
||||
Logger.LogDebug("Creating sockets...");
|
||||
|
||||
openSocketErr = CreateSocket();
|
||||
|
||||
@@ -303,7 +304,7 @@ namespace MouseWithoutBorders.Class
|
||||
// It is reasonable to give a try on restarting MwB processes in other sessions.
|
||||
if (restartCount++ < 5 && Common.IsMyDesktopActive() && !Common.RunOnLogonDesktop && !Common.RunOnScrSaverDesktop)
|
||||
{
|
||||
Common.TelemetryLogTrace("Restarting the service dues to WSAEADDRINUSE.", SeverityLevel.Warning);
|
||||
Logger.TelemetryLogTrace("Restarting the service dues to WSAEADDRINUSE.", SeverityLevel.Warning);
|
||||
Program.StartService();
|
||||
Common.PleaseReopenSocket = Common.REOPEN_WHEN_WSAECONNRESET;
|
||||
}
|
||||
@@ -367,11 +368,11 @@ namespace MouseWithoutBorders.Class
|
||||
"Closing sockets",
|
||||
() =>
|
||||
{
|
||||
Common.LogDebug($"Closing socket [{skMessageServer?.Name}].");
|
||||
Logger.LogDebug($"Closing socket [{skMessageServer?.Name}].");
|
||||
skMessageServer?.Close(); // The original ones, not the socket instances produced by the accept() method.
|
||||
skMessageServer = null;
|
||||
|
||||
Common.LogDebug($"Closing socket [{skClipboardServer?.Name}].");
|
||||
Logger.LogDebug($"Closing socket [{skClipboardServer?.Name}].");
|
||||
skClipboardServer?.Close();
|
||||
skClipboardServer = null;
|
||||
try
|
||||
@@ -383,7 +384,7 @@ namespace MouseWithoutBorders.Class
|
||||
|
||||
if (TcpSockets != null)
|
||||
{
|
||||
Common.LogDebug("********** Closing Sockets: " + TcpSockets.Count.ToString(CultureInfo.InvariantCulture));
|
||||
Logger.LogDebug("********** Closing Sockets: " + TcpSockets.Count.ToString(CultureInfo.InvariantCulture));
|
||||
|
||||
List<TcpSk> notClosedSockets = new();
|
||||
|
||||
@@ -412,16 +413,16 @@ namespace MouseWithoutBorders.Class
|
||||
catch (SocketException e)
|
||||
{
|
||||
string log = $"Socket.Close error: {e.GetType()}/{e.Message}. This is expected when the socket is already closed by remote host.";
|
||||
Common.Log(log);
|
||||
Logger.Log(log);
|
||||
}
|
||||
catch (ObjectDisposedException e)
|
||||
{
|
||||
string log = $"Socket.Close error: {e.GetType()}/{e.Message}. This is expected when the socket is already disposed.";
|
||||
Common.Log(log);
|
||||
Logger.Log(log);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
|
||||
// If there was an error closing the socket:
|
||||
@@ -435,12 +436,12 @@ namespace MouseWithoutBorders.Class
|
||||
TcpSockets = notClosedSockets;
|
||||
}
|
||||
|
||||
Common.LogDebug("********** Sockets Closed: " + c.ToString(CultureInfo.CurrentCulture));
|
||||
Logger.LogDebug("********** Sockets Closed: " + c.ToString(CultureInfo.CurrentCulture));
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
},
|
||||
TimeSpan.FromSeconds(3),
|
||||
@@ -448,7 +449,7 @@ namespace MouseWithoutBorders.Class
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -463,7 +464,7 @@ namespace MouseWithoutBorders.Class
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -477,16 +478,16 @@ namespace MouseWithoutBorders.Class
|
||||
}
|
||||
catch (SocketException e)
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
return e;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
return e;
|
||||
}
|
||||
|
||||
Common.LogDebug("==================================================");
|
||||
Logger.LogDebug("==================================================");
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -497,7 +498,7 @@ namespace MouseWithoutBorders.Class
|
||||
if (tcp.BackingSocket == null || !tcp.BackingSocket.Connected || encryptedStream == null)
|
||||
{
|
||||
string log = $"{nameof(TcpSendData)}: The socket is no longer connected, it could have been closed by the remote host.";
|
||||
Common.Log(log);
|
||||
Logger.Log(log);
|
||||
throw new ExpectedSocketException(log);
|
||||
}
|
||||
|
||||
@@ -516,7 +517,7 @@ namespace MouseWithoutBorders.Class
|
||||
catch (IOException e)
|
||||
{
|
||||
string log = $"{nameof(TcpSendData)}: Exception writing to the socket: {tcp.MachineName}: {e.InnerException?.GetType()}/{e.Message}. (This is expected when the remote machine closes the connection during desktop switch or reconnection.)";
|
||||
Common.Log(log);
|
||||
Logger.Log(log);
|
||||
|
||||
throw e.InnerException is SocketException se ? new ExpectedSocketException(se) : new ExpectedSocketException(log);
|
||||
}
|
||||
@@ -533,7 +534,7 @@ namespace MouseWithoutBorders.Class
|
||||
|
||||
if (magic != (Common.MagicNumber & 0xFFFF0000))
|
||||
{
|
||||
Common.Log("Magic number invalid!");
|
||||
Logger.Log("Magic number invalid!");
|
||||
buf[0] = (byte)PackageType.Invalid;
|
||||
}
|
||||
|
||||
@@ -544,7 +545,7 @@ namespace MouseWithoutBorders.Class
|
||||
|
||||
if (buf[1] != checksum)
|
||||
{
|
||||
Common.Log("Checksum invalid!");
|
||||
Logger.Log("Checksum invalid!");
|
||||
buf[0] = (byte)PackageType.Invalid;
|
||||
}
|
||||
|
||||
@@ -559,7 +560,7 @@ namespace MouseWithoutBorders.Class
|
||||
if (tcp.BackingSocket == null || !tcp.BackingSocket.Connected || decryptedStream == null)
|
||||
{
|
||||
string log = $"{nameof(TcpReceiveData)}: The socket is no longer connected, it could have been closed by the remote host.";
|
||||
Common.Log(log);
|
||||
Logger.Log(log);
|
||||
throw new ExpectedSocketException(log);
|
||||
}
|
||||
|
||||
@@ -597,7 +598,7 @@ namespace MouseWithoutBorders.Class
|
||||
catch (IOException e)
|
||||
{
|
||||
string log = $"{nameof(TcpReceiveData)}: Exception reading from the socket: {tcp.MachineName}: {e.InnerException?.GetType()}/{e.Message}. (This is expected when the remote machine closes the connection during desktop switch or reconnection.)";
|
||||
Common.Log(log);
|
||||
Logger.Log(log);
|
||||
|
||||
throw e.InnerException is SocketException se ? new ExpectedSocketException(se) : new ExpectedSocketException(log);
|
||||
}
|
||||
@@ -668,7 +669,7 @@ namespace MouseWithoutBorders.Class
|
||||
int rv = TcpSendData(tcp, dataAsBytes);
|
||||
if (rv < dataAsBytes.Length)
|
||||
{
|
||||
Common.Log("TcpSend error! Length of sent data is unexpected.");
|
||||
Logger.Log("TcpSend error! Length of sent data is unexpected.");
|
||||
UpdateTcpSockets(tcp, SocketStatus.SendError);
|
||||
throw new SocketException((int)SocketStatus.SendError);
|
||||
}
|
||||
@@ -683,7 +684,7 @@ namespace MouseWithoutBorders.Class
|
||||
TcpListener server = param as TcpListener;
|
||||
do
|
||||
{
|
||||
Common.LogDebug("TCPServerThread: Waiting for request...");
|
||||
Logger.LogDebug("TCPServerThread: Waiting for request...");
|
||||
Socket s = server.AcceptSocket();
|
||||
|
||||
_ = Task.Run(() =>
|
||||
@@ -694,7 +695,7 @@ namespace MouseWithoutBorders.Class
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -703,22 +704,22 @@ namespace MouseWithoutBorders.Class
|
||||
catch (InvalidOperationException e)
|
||||
{
|
||||
string log = $"TCPServerThread.AcceptSocket: The server socket could have been closed. {e.Message}";
|
||||
Common.Log(log);
|
||||
Logger.Log(log);
|
||||
}
|
||||
catch (SocketException e)
|
||||
{
|
||||
if (e.ErrorCode == (int)SocketError.Interrupted)
|
||||
{
|
||||
Common.Log("TCPServerThread.AcceptSocket: A blocking socket call was canceled.");
|
||||
Logger.Log("TCPServerThread.AcceptSocket: A blocking socket call was canceled.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -734,7 +735,7 @@ namespace MouseWithoutBorders.Class
|
||||
}
|
||||
catch (SocketException e)
|
||||
{
|
||||
Common.Log($"{nameof(GetMachineNameFromSocket)}: {e.Message}");
|
||||
Logger.Log($"{nameof(GetMachineNameFromSocket)}: {e.Message}");
|
||||
return stringIP;
|
||||
}
|
||||
|
||||
@@ -745,7 +746,7 @@ namespace MouseWithoutBorders.Class
|
||||
|
||||
if (dotPos > 0)
|
||||
{
|
||||
Common.LogDebug("Removing domain part from the full machine name: {0}.", name);
|
||||
Logger.LogDebug("Removing domain part from the full machine name: {0}.", name);
|
||||
name = name[..dotPos];
|
||||
}
|
||||
}
|
||||
@@ -756,7 +757,7 @@ namespace MouseWithoutBorders.Class
|
||||
private void AddSocket(Socket s)
|
||||
{
|
||||
string machineName = GetMachineNameFromSocket(s);
|
||||
Common.Log($"New connection from client: [{machineName}].");
|
||||
Logger.Log($"New connection from client: [{machineName}].");
|
||||
TcpSk tcp = AddTcpSocket(false, s, SocketStatus.Connecting, machineName);
|
||||
StartNewTcpServer(tcp, machineName);
|
||||
}
|
||||
@@ -772,7 +773,7 @@ namespace MouseWithoutBorders.Class
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -789,13 +790,13 @@ namespace MouseWithoutBorders.Class
|
||||
return;
|
||||
}
|
||||
|
||||
Common.LogDebug("!!!!! UpdateTCPClients !!!!!");
|
||||
Logger.LogDebug("!!!!! UpdateTCPClients !!!!!");
|
||||
|
||||
try
|
||||
{
|
||||
if (Common.MachineMatrix != null)
|
||||
{
|
||||
Common.LogDebug("MachineMatrix = " + string.Join(", ", Common.MachineMatrix));
|
||||
Logger.LogDebug("MachineMatrix = " + string.Join(", ", Common.MachineMatrix));
|
||||
|
||||
foreach (string st in Common.MachineMatrix)
|
||||
{
|
||||
@@ -809,7 +810,7 @@ namespace MouseWithoutBorders.Class
|
||||
|
||||
if (found)
|
||||
{
|
||||
Common.LogDebug(machineName + " is already connected! ^^^^^^^^^^^^^^^^^^^^^");
|
||||
Logger.LogDebug(machineName + " is already connected! ^^^^^^^^^^^^^^^^^^^^^");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -820,7 +821,7 @@ namespace MouseWithoutBorders.Class
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -883,7 +884,7 @@ namespace MouseWithoutBorders.Class
|
||||
Socket dummySocket = new(AddressFamily.Unspecified, SocketType.Stream, ProtocolType.Tcp);
|
||||
TcpSk dummyTcp = AddTcpSocket(true, dummySocket, SocketStatus.Resolving, machineName);
|
||||
|
||||
Common.LogDebug("Connecting to: " + machineName);
|
||||
Logger.LogDebug("Connecting to: " + machineName);
|
||||
|
||||
if (!string.IsNullOrEmpty(Setting.Values.Name2IP))
|
||||
{
|
||||
@@ -911,7 +912,7 @@ namespace MouseWithoutBorders.Class
|
||||
{
|
||||
useName2IP = true;
|
||||
|
||||
Common.LogDebug("Using both user-defined Name-to-IP mappings and DNS result for " + machineName);
|
||||
Logger.LogDebug("Using both user-defined Name-to-IP mappings and DNS result for " + machineName);
|
||||
|
||||
Common.ShowToolTip("Using both user-defined Name-to-IP mappings and DNS result for " + machineName, 3000, ToolTipIcon.Info, false);
|
||||
|
||||
@@ -941,7 +942,7 @@ namespace MouseWithoutBorders.Class
|
||||
|
||||
Common.ShowToolTip(e.Message + ": " + machineName, 10000, ToolTipIcon.Warning, Setting.Values.ShowClipNetStatus);
|
||||
|
||||
Common.Log($"{nameof(StartNewTcpClient)}.{nameof(Dns.GetHostEntry)}: {e.Message}");
|
||||
Logger.Log($"{nameof(StartNewTcpClient)}.{nameof(Dns.GetHostEntry)}: {e.Message}");
|
||||
}
|
||||
|
||||
UpdateTcpSockets(dummyTcp, SocketStatus.NA);
|
||||
@@ -967,7 +968,7 @@ namespace MouseWithoutBorders.Class
|
||||
}
|
||||
}
|
||||
|
||||
Common.LogDebug(machineName + ipLog);
|
||||
Logger.LogDebug(machineName + ipLog);
|
||||
}
|
||||
|
||||
if (validAddresses.Count > 0)
|
||||
@@ -983,7 +984,7 @@ namespace MouseWithoutBorders.Class
|
||||
{
|
||||
if (IsBadIP(machineName, ip))
|
||||
{
|
||||
Common.Log($"Skip bad IP address: {ip}");
|
||||
Logger.Log($"Skip bad IP address: {ip}");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -998,18 +999,18 @@ namespace MouseWithoutBorders.Class
|
||||
}
|
||||
else
|
||||
{
|
||||
Common.Log($"DNS information of machine not matched: {machineName} => {ip} => {hn}.");
|
||||
Logger.Log($"DNS information of machine not matched: {machineName} => {ip} => {hn}.");
|
||||
AddBadIP(machineName, ip);
|
||||
}
|
||||
}
|
||||
catch (SocketException se)
|
||||
{
|
||||
Common.Log($"{nameof(StartNewTcpClient)}: DNS information of machine not matched: {machineName} => {ip} => {se.Message}.");
|
||||
Logger.Log($"{nameof(StartNewTcpClient)}: DNS information of machine not matched: {machineName} => {ip} => {se.Message}.");
|
||||
AddBadIP(machineName, ip);
|
||||
}
|
||||
catch (ArgumentException ae)
|
||||
{
|
||||
Common.Log($"{nameof(StartNewTcpClient)}: DNS information of machine not matched: {machineName} => {ip} => {ae.Message}.");
|
||||
Logger.Log($"{nameof(StartNewTcpClient)}: DNS information of machine not matched: {machineName} => {ip} => {ae.Message}.");
|
||||
AddBadIP(machineName, ip);
|
||||
}
|
||||
}
|
||||
@@ -1030,7 +1031,7 @@ namespace MouseWithoutBorders.Class
|
||||
}
|
||||
else
|
||||
{
|
||||
Common.Log("Cannot resolve IPv4 Addresses of machine: " + machineName);
|
||||
Logger.Log("Cannot resolve IPv4 Addresses of machine: " + machineName);
|
||||
|
||||
if (!useName2IP)
|
||||
{
|
||||
@@ -1058,7 +1059,7 @@ namespace MouseWithoutBorders.Class
|
||||
|
||||
if (!remoteIPv4Addresses.Any())
|
||||
{
|
||||
Common.Log($"No IPv4 resolved from the remote machine: {machineName}.");
|
||||
Logger.Log($"No IPv4 resolved from the remote machine: {machineName}.");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1066,7 +1067,7 @@ namespace MouseWithoutBorders.Class
|
||||
|
||||
if (localIPv4Addresses.Count == 0)
|
||||
{
|
||||
Common.Log($"No IPv4 resolved from the local machine: {Common.MachineName}");
|
||||
Logger.Log($"No IPv4 resolved from the local machine: {Common.MachineName}");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1085,7 +1086,7 @@ namespace MouseWithoutBorders.Class
|
||||
}
|
||||
}
|
||||
|
||||
Common.Log($"Skip machine not in the same network: {machineName}.");
|
||||
Logger.Log($"Skip machine not in the same network: {machineName}.");
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -1105,7 +1106,7 @@ namespace MouseWithoutBorders.Class
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
return Enumerable.Empty<IPAddress>();
|
||||
}
|
||||
}
|
||||
@@ -1123,13 +1124,13 @@ namespace MouseWithoutBorders.Class
|
||||
|
||||
if (Common.IsConnectedByAClientSocketTo(machineName))
|
||||
{
|
||||
Common.LogDebug(machineName + " is already connected by another client socket.");
|
||||
Logger.LogDebug(machineName + " is already connected by another client socket.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (Common.IsConnectingByAClientSocketTo(machineName, ip))
|
||||
{
|
||||
Common.LogDebug($"{machineName}:{ip} is already being connected by another client socket.");
|
||||
Logger.LogDebug($"{machineName}:{ip} is already being connected by another client socket.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1138,7 +1139,7 @@ namespace MouseWithoutBorders.Class
|
||||
// Update the other server socket's machine name based on this corresponding client socket.
|
||||
UpdateTcpSockets(tcp, SocketStatus.Connecting);
|
||||
|
||||
Common.LogDebug(string.Format(CultureInfo.CurrentCulture, "=====> Connecting to: {0}:{1}", machineName, ip.ToString()));
|
||||
Logger.LogDebug(string.Format(CultureInfo.CurrentCulture, "=====> Connecting to: {0}:{1}", machineName, ip.ToString()));
|
||||
|
||||
long timeoutLeft;
|
||||
|
||||
@@ -1151,7 +1152,7 @@ namespace MouseWithoutBorders.Class
|
||||
catch (ObjectDisposedException)
|
||||
{
|
||||
// When user reconnects.
|
||||
Common.LogDebug($"tcpClient.Connect: The socket has already been disposed: {machineName}:{ip}");
|
||||
Logger.LogDebug($"tcpClient.Connect: The socket has already been disposed: {machineName}:{ip}");
|
||||
return;
|
||||
}
|
||||
catch (SocketException e)
|
||||
@@ -1160,13 +1161,13 @@ namespace MouseWithoutBorders.Class
|
||||
|
||||
if (timeoutLeft > 0)
|
||||
{
|
||||
Common.LogDebug($"tcpClient.Connect: {timeoutLeft}: {e.Message}");
|
||||
Logger.LogDebug($"tcpClient.Connect: {timeoutLeft}: {e.Message}");
|
||||
Thread.Sleep(1000);
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
Common.Log($"tcpClient.Connect: Unable to connect after a timeout: {machineName}:{ip} : {e.Message}");
|
||||
Logger.Log($"tcpClient.Connect: Unable to connect after a timeout: {machineName}:{ip} : {e.Message}");
|
||||
|
||||
string message = $"Connection timed out: {machineName}:{ip}";
|
||||
|
||||
@@ -1181,14 +1182,14 @@ namespace MouseWithoutBorders.Class
|
||||
}
|
||||
while (true);
|
||||
|
||||
Common.LogDebug($"=====> Connected: {tcpClient.Client.LocalEndPoint} => {machineName}: {ip}");
|
||||
Logger.LogDebug($"=====> Connected: {tcpClient.Client.LocalEndPoint} => {machineName}: {ip}");
|
||||
|
||||
// Sending/Receiving packages
|
||||
MainTCPRoutine(tcp, machineName, true);
|
||||
}
|
||||
catch (ObjectDisposedException e)
|
||||
{
|
||||
Common.Log($"{nameof(StartNewTcpClientThread)}: The socket could have been closed/disposed due to machine switch: {e.Message}");
|
||||
Logger.Log($"{nameof(StartNewTcpClientThread)}: The socket could have been closed/disposed due to machine switch: {e.Message}");
|
||||
}
|
||||
catch (SocketException e)
|
||||
{
|
||||
@@ -1201,12 +1202,12 @@ namespace MouseWithoutBorders.Class
|
||||
}
|
||||
else
|
||||
{
|
||||
Common.TelemetryLogTrace($"{nameof(StartNewTcpClientThread)}: Error: {e.Message} on the IP Address: {localIP}", SeverityLevel.Error);
|
||||
Logger.TelemetryLogTrace($"{nameof(StartNewTcpClientThread)}: Error: {e.Message} on the IP Address: {localIP}", SeverityLevel.Error);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1230,7 +1231,7 @@ namespace MouseWithoutBorders.Class
|
||||
if (e is ExpectedSocketException se && se.ShouldReconnect)
|
||||
{
|
||||
Common.PleaseReopenSocket = Common.REOPEN_WHEN_WSAECONNRESET;
|
||||
Common.Log($"MainTCPRoutine: {nameof(FlagReopenSocketIfNeeded)}");
|
||||
Logger.Log($"MainTCPRoutine: {nameof(FlagReopenSocketIfNeeded)}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1254,7 +1255,7 @@ namespace MouseWithoutBorders.Class
|
||||
|
||||
if (currentSocket == null)
|
||||
{
|
||||
Common.LogDebug($"{nameof(MainTCPRoutine)}: The socket could have been closed/disposed by other threads.");
|
||||
Logger.LogDebug($"{nameof(MainTCPRoutine)}: The socket could have been closed/disposed by other threads.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1283,21 +1284,21 @@ namespace MouseWithoutBorders.Class
|
||||
strIP = Common.GetRemoteStringIP(currentSocket, true);
|
||||
remoteMachine = string.IsNullOrEmpty(machineName) ? GetMachineNameFromSocket(currentSocket) : machineName;
|
||||
|
||||
Common.LogDebug($"MainTCPRoutine: Remote machineName/IP = {remoteMachine}/{strIP}");
|
||||
Logger.LogDebug($"MainTCPRoutine: Remote machineName/IP = {remoteMachine}/{strIP}");
|
||||
}
|
||||
catch (ObjectDisposedException e)
|
||||
{
|
||||
Common.PleaseReopenSocket = Common.REOPEN_WHEN_WSAECONNRESET;
|
||||
UpdateTcpSockets(currentTcp, SocketStatus.ForceClosed);
|
||||
currentSocket.Close();
|
||||
Common.Log($"{nameof(MainTCPRoutine)}: The socket could have been closed/disposed by other threads: {e.Message}");
|
||||
Logger.Log($"{nameof(MainTCPRoutine)}: The socket could have been closed/disposed by other threads: {e.Message}");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
UpdateTcpSockets(currentTcp, SocketStatus.ForceClosed);
|
||||
FlagReopenSocketIfNeeded(e);
|
||||
currentSocket.Close();
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
|
||||
int errCount = 0;
|
||||
@@ -1314,7 +1315,7 @@ namespace MouseWithoutBorders.Class
|
||||
errCount++;
|
||||
|
||||
string log = $"{nameof(MainTCPRoutine)}.TcpReceive error, invalid package from {remoteMachine}: {receivedCount}";
|
||||
Common.Log(log);
|
||||
Logger.Log(log);
|
||||
|
||||
if (receivedCount > 0)
|
||||
{
|
||||
@@ -1369,7 +1370,7 @@ namespace MouseWithoutBorders.Class
|
||||
if (++packageCount >= 10)
|
||||
{
|
||||
// Common.ShowToolTip("Invalid Security Key from " + remoteMachine, 5000);
|
||||
Common.Log("More than 10 invalid packages received!");
|
||||
Logger.Log("More than 10 invalid packages received!");
|
||||
|
||||
package.Type = PackageType.Invalid;
|
||||
|
||||
@@ -1393,7 +1394,7 @@ namespace MouseWithoutBorders.Class
|
||||
|
||||
if (!remoteMachine.Equals(claimedMachineName, StringComparison.Ordinal))
|
||||
{
|
||||
Common.LogDebug($"DNS.RemoteMachineName({remoteMachine}) <> Claimed.MachineName({claimedMachineName}), using the claimed machine name.");
|
||||
Logger.LogDebug($"DNS.RemoteMachineName({remoteMachine}) <> Claimed.MachineName({claimedMachineName}), using the claimed machine name.");
|
||||
remoteMachine = claimedMachineName;
|
||||
currentTcp.MachineName = remoteMachine;
|
||||
}
|
||||
@@ -1401,7 +1402,7 @@ namespace MouseWithoutBorders.Class
|
||||
// Double check to avoid a redundant client socket.
|
||||
if (isClient && Common.IsConnectedByAClientSocketTo(remoteMachine))
|
||||
{
|
||||
Common.LogDebug("=====> Duplicate connected client socket for: " + remoteMachine + ":" + strIP + " is being removed.");
|
||||
Logger.LogDebug("=====> Duplicate connected client socket for: " + remoteMachine + ":" + strIP + " is being removed.");
|
||||
UpdateTcpSockets(currentTcp, SocketStatus.ForceClosed);
|
||||
currentSocket.Close();
|
||||
return;
|
||||
@@ -1409,7 +1410,7 @@ namespace MouseWithoutBorders.Class
|
||||
|
||||
if (remoteMachine.Equals(Common.MachineName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
Common.LogDebug("Connected to/from local socket: " + strIP + (isClient ? "-Client" : "-Server"));
|
||||
Logger.LogDebug("Connected to/from local socket: " + strIP + (isClient ? "-Client" : "-Server"));
|
||||
UpdateTcpSockets(currentTcp, SocketStatus.NA);
|
||||
Common.MMSleep(1);
|
||||
currentSocket.Close();
|
||||
@@ -1421,7 +1422,7 @@ namespace MouseWithoutBorders.Class
|
||||
currentTcp.MachineId = (uint)remoteID;
|
||||
currentTcp.Status = SocketStatus.Connected;
|
||||
UpdateTcpSockets(currentTcp, SocketStatus.Connected);
|
||||
Common.LogDebug("))))))))))))))) Machine got trusted: " + remoteMachine + ":" + strIP + ", Is client: " + isClient);
|
||||
Logger.LogDebug("))))))))))))))) Machine got trusted: " + remoteMachine + ":" + strIP + ", Is client: " + isClient);
|
||||
|
||||
if (Math.Abs(Common.GetTick() - Common.LastReconnectByHotKeyTime) < 5000)
|
||||
{
|
||||
@@ -1432,11 +1433,11 @@ namespace MouseWithoutBorders.Class
|
||||
|
||||
if (Common.MachinePool.TryFindMachineByName(remoteMachine, out MachineInf machineInfo))
|
||||
{
|
||||
Common.LogDebug("Machine updated: " + remoteMachine + "/" + remoteID.ToString());
|
||||
Logger.LogDebug("Machine updated: " + remoteMachine + "/" + remoteID.ToString());
|
||||
|
||||
if (machineInfo.Name.Equals(Common.DesMachineName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
Common.LogDebug("Des ID updated: " + Common.DesMachineID.ToString() +
|
||||
Logger.LogDebug("Des ID updated: " + Common.DesMachineID.ToString() +
|
||||
"/" + remoteID.ToString());
|
||||
Common.NewDesMachineID = Common.DesMachineID = remoteID;
|
||||
}
|
||||
@@ -1446,7 +1447,7 @@ namespace MouseWithoutBorders.Class
|
||||
}
|
||||
else
|
||||
{
|
||||
Common.LogDebug("New machine connected: {0}.", remoteMachine);
|
||||
Logger.LogDebug("New machine connected: {0}.", remoteMachine);
|
||||
|
||||
if (!Common.RunOnLogonDesktop && !Common.RunOnScrSaverDesktop)
|
||||
{
|
||||
@@ -1461,7 +1462,7 @@ namespace MouseWithoutBorders.Class
|
||||
}
|
||||
else
|
||||
{
|
||||
Common.LogDebug("Invalid ACK from " + remoteMachine);
|
||||
Logger.LogDebug("Invalid ACK from " + remoteMachine);
|
||||
UpdateTcpSockets(currentTcp, SocketStatus.InvalidKey);
|
||||
|
||||
string remoteEP = currentSocket.RemoteEndPoint.ToString();
|
||||
@@ -1500,7 +1501,7 @@ namespace MouseWithoutBorders.Class
|
||||
}
|
||||
else
|
||||
{
|
||||
Common.Log(string.Format(
|
||||
Logger.Log(string.Format(
|
||||
CultureInfo.CurrentCulture,
|
||||
"Unexpected package, size = {0}, type = {1}",
|
||||
receivedCount,
|
||||
@@ -1514,12 +1515,12 @@ namespace MouseWithoutBorders.Class
|
||||
if (lastRemoteMachineID != (long)remoteID)
|
||||
{
|
||||
_ = Interlocked.Exchange(ref lastRemoteMachineID, (long)remoteID);
|
||||
Common.LogDebug($"MainTCPRoutine: Remote machine = {strIP}/{lastRemoteMachineID}");
|
||||
Logger.LogDebug($"MainTCPRoutine: Remote machine = {strIP}/{lastRemoteMachineID}");
|
||||
}
|
||||
|
||||
if (package.Type == PackageType.HandshakeAck)
|
||||
{
|
||||
Common.LogDebug("Skipping the rest of the Handshake packages.");
|
||||
Logger.LogDebug("Skipping the rest of the Handshake packages.");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1533,7 +1534,7 @@ namespace MouseWithoutBorders.Class
|
||||
UpdateTcpSockets(currentTcp, SocketStatus.Error);
|
||||
FlagReopenSocketIfNeeded(e);
|
||||
currentSocket.Close();
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1550,7 +1551,7 @@ namespace MouseWithoutBorders.Class
|
||||
|
||||
do
|
||||
{
|
||||
Common.LogDebug("SendClipboardData: Waiting for request...");
|
||||
Logger.LogDebug("SendClipboardData: Waiting for request...");
|
||||
Socket s = null;
|
||||
|
||||
try
|
||||
@@ -1559,25 +1560,25 @@ namespace MouseWithoutBorders.Class
|
||||
}
|
||||
catch (InvalidOperationException e)
|
||||
{
|
||||
Common.Log($"The clipboard socket could have been closed. {e.Message}");
|
||||
Logger.Log($"The clipboard socket could have been closed. {e.Message}");
|
||||
break;
|
||||
}
|
||||
catch (SocketException e)
|
||||
{
|
||||
if (e.ErrorCode == (int)SocketError.Interrupted)
|
||||
{
|
||||
Common.Log("server.AcceptSocket: A blocking socket call was canceled.");
|
||||
Logger.Log("server.AcceptSocket: A blocking socket call was canceled.");
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1595,7 +1596,7 @@ namespace MouseWithoutBorders.Class
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1607,7 +1608,7 @@ namespace MouseWithoutBorders.Class
|
||||
try
|
||||
{
|
||||
string remoteEndPoint = s.RemoteEndPoint.ToString();
|
||||
Common.LogDebug("SendClipboardData: Request accepted: " + s.LocalEndPoint.ToString() + "/" + remoteEndPoint);
|
||||
Logger.LogDebug("SendClipboardData: Request accepted: " + s.LocalEndPoint.ToString() + "/" + remoteEndPoint);
|
||||
Common.IsDropping = false;
|
||||
Common.IsDragging = false;
|
||||
Common.DragMachine = (ID)1;
|
||||
@@ -1623,7 +1624,7 @@ namespace MouseWithoutBorders.Class
|
||||
}
|
||||
else
|
||||
{
|
||||
Common.LogDebug($"{nameof(SendOrReceiveClipboardData)}: Clipboard connection accepted: " + remoteEndPoint);
|
||||
Logger.LogDebug($"{nameof(SendOrReceiveClipboardData)}: Clipboard connection accepted: " + remoteEndPoint);
|
||||
Common.SetToggleIcon(new int[Common.TOGGLE_ICONS_SIZE] { Common.ICON_SMALL_CLIPBOARD, -1, -1, -1 });
|
||||
}
|
||||
|
||||
@@ -1638,7 +1639,7 @@ namespace MouseWithoutBorders.Class
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1699,17 +1700,17 @@ namespace MouseWithoutBorders.Class
|
||||
catch (IOException e)
|
||||
{
|
||||
string log = $"{nameof(SendClipboardData)}: Exception accessing the socket: {e.InnerException?.GetType()}/{e.Message}. (This is expected when the remote machine closes the connection during desktop switch or reconnection.)";
|
||||
Common.Log(log);
|
||||
Logger.Log(log);
|
||||
}
|
||||
catch (SocketException e)
|
||||
{
|
||||
string log = $"{nameof(SendClipboardData)}: {e.GetType()}/{e.Message}. This is expected when the connection is closed by the remote host.";
|
||||
Common.Log(log);
|
||||
Logger.Log(log);
|
||||
}
|
||||
catch (ObjectDisposedException e)
|
||||
{
|
||||
string log = $"{nameof(SendClipboardData)}: {e.GetType()}/{e.Message}. This is expected when the socket is disposed by a machine switch for ex..";
|
||||
Common.Log(log);
|
||||
Logger.Log(log);
|
||||
}
|
||||
}
|
||||
else if (!Common.IsClipboardDataImage && Common.LastClipboardData != null)
|
||||
@@ -1725,7 +1726,7 @@ namespace MouseWithoutBorders.Class
|
||||
{
|
||||
ecStream.Write(header, 0, header.Length);
|
||||
_ = SendData(s, ecStream, data);
|
||||
Common.LogDebug("Text sent: " + data.Length.ToString(CultureInfo.CurrentCulture));
|
||||
Logger.LogDebug("Text sent: " + data.Length.ToString(CultureInfo.CurrentCulture));
|
||||
}
|
||||
|
||||
s.Close(CLOSE_TIMEOUT);
|
||||
@@ -1733,17 +1734,17 @@ namespace MouseWithoutBorders.Class
|
||||
catch (IOException e)
|
||||
{
|
||||
string log = $"{nameof(SendClipboardData)}: Exception accessing the socket: {e.InnerException?.GetType()}/{e.Message}. (This is expected when the remote machine closes the connection during desktop switch or reconnection.)";
|
||||
Common.Log(log);
|
||||
Logger.Log(log);
|
||||
}
|
||||
catch (SocketException e)
|
||||
{
|
||||
string log = $"{nameof(SendClipboardData)}: {e.GetType()}/{e.Message}. This is expected when the connection is closed by the remote host.";
|
||||
Common.Log(log);
|
||||
Logger.Log(log);
|
||||
}
|
||||
catch (ObjectDisposedException e)
|
||||
{
|
||||
string log = $"{nameof(SendClipboardData)}: {e.GetType()}/{e.Message}. This is expected when the socket is disposed by a machine switch for ex..";
|
||||
Common.Log(log);
|
||||
Logger.Log(log);
|
||||
}
|
||||
}
|
||||
else if (Common.LastClipboardData != null && Common.LastClipboardData.Length > 0)
|
||||
@@ -1756,28 +1757,28 @@ namespace MouseWithoutBorders.Class
|
||||
{
|
||||
ecStream.Write(header, 0, header.Length);
|
||||
_ = SendData(s, ecStream, data);
|
||||
Common.LogDebug("Image sent: " + data.Length.ToString(CultureInfo.CurrentCulture));
|
||||
Logger.LogDebug("Image sent: " + data.Length.ToString(CultureInfo.CurrentCulture));
|
||||
s.Close(CLOSE_TIMEOUT);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
string log = $"{nameof(SendClipboardData)}: Exception accessing the socket: {e.InnerException?.GetType()}/{e.Message}. (This is expected when the remote machine closes the connection during desktop switch or reconnection.)";
|
||||
Common.Log(log);
|
||||
Logger.Log(log);
|
||||
}
|
||||
catch (SocketException e)
|
||||
{
|
||||
string log = $"{nameof(SendClipboardData)}: {e.GetType()}/{e.Message}. This is expected when the connection is closed by the remote host.";
|
||||
Common.Log(log);
|
||||
Logger.Log(log);
|
||||
}
|
||||
catch (ObjectDisposedException e)
|
||||
{
|
||||
string log = $"{nameof(SendClipboardData)}: {e.GetType()}/{e.Message}. This is expected when the socket is disposed by a machine switch for ex..";
|
||||
Common.Log(log);
|
||||
Logger.Log(log);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Common.Log("No data available in clipboard or LastDragDropFile!");
|
||||
Logger.Log("No data available in clipboard or LastDragDropFile!");
|
||||
s.Close();
|
||||
}
|
||||
}
|
||||
@@ -1809,7 +1810,7 @@ namespace MouseWithoutBorders.Class
|
||||
|
||||
ecStream.Flush();
|
||||
|
||||
Common.LogDebug("File sent: " + fileName);
|
||||
Logger.LogDebug("File sent: " + fileName);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -1819,11 +1820,11 @@ namespace MouseWithoutBorders.Class
|
||||
if (e is IOException)
|
||||
{
|
||||
string log = $"{nameof(SendFileEx)}: Exception accessing the socket: {e.InnerException?.GetType()}/{e.Message}. (This is expected when the remote machine closes the connection during desktop switch or reconnection.)";
|
||||
Common.Log(log);
|
||||
Logger.Log(log);
|
||||
}
|
||||
else
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
|
||||
Common.ShowToolTip(e.Message, 1000, ToolTipIcon.Warning, Setting.Values.ShowClipNetStatus);
|
||||
@@ -1879,7 +1880,7 @@ namespace MouseWithoutBorders.Class
|
||||
}
|
||||
|
||||
ecStream.Flush();
|
||||
Common.LogDebug("Data sent: " + data.Length.ToString(CultureInfo.InvariantCulture));
|
||||
Logger.LogDebug("Data sent: " + data.Length.ToString(CultureInfo.InvariantCulture));
|
||||
r = true;
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -1887,11 +1888,11 @@ namespace MouseWithoutBorders.Class
|
||||
if (e is IOException)
|
||||
{
|
||||
string log = $"{nameof(SendData)}: Exception accessing the socket: {e.InnerException?.GetType()}/{e.Message}. (This is expected when the remote machine closes the connection during desktop switch or reconnection.)";
|
||||
Common.Log(log);
|
||||
Logger.Log(log);
|
||||
}
|
||||
else
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
|
||||
Common.ShowToolTip(e.Message, 1000, ToolTipIcon.Warning, Setting.Values.ShowClipNetStatus);
|
||||
@@ -1960,7 +1961,7 @@ namespace MouseWithoutBorders.Class
|
||||
Common.UpdateMachineTimeAndID();
|
||||
Common.PleaseReopenSocket = Common.REOPEN_WHEN_HOTKEY;
|
||||
|
||||
Common.TelemetryLogTrace("MachineID conflict.", SeverityLevel.Information);
|
||||
Logger.TelemetryLogTrace("MachineID conflict.", SeverityLevel.Information);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1971,7 +1972,7 @@ namespace MouseWithoutBorders.Class
|
||||
foreach (TcpSk t in tobeRemovedSockets)
|
||||
{
|
||||
t.Status = SocketStatus.ForceClosed;
|
||||
Common.LogDebug($"Closing duplicated socket {t.MachineName}: {t.Address}");
|
||||
Logger.LogDebug($"Closing duplicated socket {t.MachineName}: {t.Address}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2001,12 +2002,12 @@ namespace MouseWithoutBorders.Class
|
||||
catch (SocketException e)
|
||||
{
|
||||
string log = $"{nameof(UpdateTcpSockets)}: {e.GetType()}/{e.Message}. This is expected when the connection is closed by the remote host.";
|
||||
Common.Log(log);
|
||||
Logger.Log(log);
|
||||
}
|
||||
catch (ObjectDisposedException e)
|
||||
{
|
||||
string log = $"{nameof(UpdateTcpSockets)}: {e.GetType()}/{e.Message}. This is expected when the socket is disposed by a machine switch for ex..";
|
||||
Common.Log(log);
|
||||
Logger.Log(log);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2048,7 +2049,7 @@ namespace MouseWithoutBorders.Class
|
||||
}
|
||||
else
|
||||
{
|
||||
Common.Log("UpdateTcpSockets.Exception: Socket not found!");
|
||||
Logger.Log("UpdateTcpSockets.Exception: Socket not found!");
|
||||
}
|
||||
|
||||
foreach (TcpSk t in toBeRemoved)
|
||||
@@ -2060,7 +2061,7 @@ namespace MouseWithoutBorders.Class
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,8 @@ using System.Net.Sockets;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using MouseWithoutBorders.Core;
|
||||
|
||||
// <summary>
|
||||
// TCP Server implementation.
|
||||
// </summary>
|
||||
@@ -33,7 +35,7 @@ namespace MouseWithoutBorders.Class
|
||||
|
||||
internal TcpServer(int port, ParameterizedThreadStart job)
|
||||
{
|
||||
Common.Log($"TCP listening on port: {port}");
|
||||
Logger.Log($"TCP listening on port: {port}");
|
||||
Name = port.ToString(CultureInfo.CurrentCulture);
|
||||
server = TcpListener.Create(port);
|
||||
StartServer(job);
|
||||
@@ -79,7 +81,7 @@ namespace MouseWithoutBorders.Class
|
||||
}
|
||||
else
|
||||
{
|
||||
Common.TelemetryLogTrace($"Error listening on: {server.LocalEndpoint}: {e.ErrorCode}/{e.Message}", SeverityLevel.Error);
|
||||
Logger.TelemetryLogTrace($"Error listening on: {server.LocalEndpoint}: {e.ErrorCode}/{e.Message}", SeverityLevel.Error);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
@@ -99,7 +101,7 @@ namespace MouseWithoutBorders.Class
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
447
src/modules/MouseWithoutBorders/App/Core/Logger.cs
Normal file
447
src/modules/MouseWithoutBorders/App/Core/Logger.cs
Normal file
@@ -0,0 +1,447 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
// <summary>
|
||||
// Logging.
|
||||
// </summary>
|
||||
// <history>
|
||||
// 2008 created by Truong Do (ductdo).
|
||||
// 2009-... modified by Truong Do (TruongDo).
|
||||
// 2023- Included in PowerToys.
|
||||
// </history>
|
||||
using MouseWithoutBorders.Class;
|
||||
using MouseWithoutBorders.Exceptions;
|
||||
|
||||
namespace MouseWithoutBorders.Core;
|
||||
|
||||
internal static class Logger
|
||||
{
|
||||
internal static readonly string[] AllLogs = new string[MAX_LOG];
|
||||
private static readonly object AllLogsLock = new();
|
||||
internal static readonly ConcurrentDictionary<string, int> LogCounter = new();
|
||||
private const int MAX_LOG = 10000;
|
||||
private static int allLogsIndex;
|
||||
|
||||
private const int MaxLogExceptionPerHour = 1000;
|
||||
private static int lastHour;
|
||||
private static int exceptionCount;
|
||||
|
||||
internal static void TelemetryLogTrace(string log, SeverityLevel severityLevel, bool flush = false)
|
||||
{
|
||||
int logCount = LogCounter.AddOrUpdate(log, 1, (key, value) => value + 1);
|
||||
Logger.Log(log);
|
||||
}
|
||||
|
||||
internal static void Log(Exception e)
|
||||
{
|
||||
if (e is not KnownException)
|
||||
{
|
||||
string exText = e.ToString();
|
||||
|
||||
Log($"!Exception!: {exText}");
|
||||
|
||||
if (DateTime.UtcNow.Hour != lastHour)
|
||||
{
|
||||
lastHour = DateTime.UtcNow.Hour;
|
||||
exceptionCount = 0;
|
||||
}
|
||||
|
||||
if (exceptionCount < MaxLogExceptionPerHour)
|
||||
{
|
||||
exceptionCount++;
|
||||
}
|
||||
else if (exceptionCount != short.MaxValue)
|
||||
{
|
||||
exceptionCount = short.MaxValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private const string HeaderSENT =
|
||||
"Be{0},Ke{1},Mo{2},He{3},Mx{4},Tx{5},Im{6},By{7},Cl{8},Dr{9},De{10},Ed{11},Ie{12},Ni{13}";
|
||||
|
||||
private const string HeaderRECEIVED =
|
||||
"Be{0},Ke{1},Mo{2},He{3},Mx{4},Tx{5},Im{6},By{7},Cl{8},Dr{9},De{10},Ed{11},In{12},Ni{13},Pc{14}/{15}";
|
||||
|
||||
internal static void LogDebug(string log, bool clearLog = false)
|
||||
{
|
||||
#if DEBUG
|
||||
Log(log, clearLog);
|
||||
#endif
|
||||
}
|
||||
|
||||
internal static void Log(string log, bool clearLog = false)
|
||||
{
|
||||
log = DateTime.Now.ToString("MM/dd HH:mm:ss.fff", CultureInfo.InvariantCulture) + $"({Thread.CurrentThread.ManagedThreadId})" + log;
|
||||
|
||||
ManagedCommon.Logger.LogInfo(log);
|
||||
lock (AllLogsLock)
|
||||
{
|
||||
if (clearLog)
|
||||
{
|
||||
allLogsIndex = 0;
|
||||
}
|
||||
|
||||
AllLogs[allLogsIndex] = log;
|
||||
allLogsIndex = (allLogsIndex + 1) % MAX_LOG;
|
||||
}
|
||||
}
|
||||
|
||||
internal static void LogDebug(string format, params object[] args)
|
||||
{
|
||||
#if DEBUG
|
||||
Logger.Log(format, args);
|
||||
#endif
|
||||
}
|
||||
|
||||
private static void Log(string format, params object[] args)
|
||||
{
|
||||
Logger.Log(string.Format(CultureInfo.InvariantCulture, format, args));
|
||||
}
|
||||
|
||||
private static PackageMonitor lastPackageSent;
|
||||
private static PackageMonitor lastPackageReceived;
|
||||
|
||||
[Conditional("DEBUG")]
|
||||
internal static void LogAll()
|
||||
{
|
||||
string log;
|
||||
|
||||
if (!lastPackageSent.Equals(Common.PackageSent))
|
||||
{
|
||||
log = string.Format(
|
||||
CultureInfo.CurrentCulture,
|
||||
"SENT:" + HeaderSENT,
|
||||
Common.PackageSent.Heartbeat,
|
||||
Common.PackageSent.Keyboard,
|
||||
Common.PackageSent.Mouse,
|
||||
Common.PackageSent.Hello,
|
||||
Common.PackageSent.Matrix,
|
||||
Common.PackageSent.ClipboardText,
|
||||
Common.PackageSent.ClipboardImage,
|
||||
Common.PackageSent.ByeBye,
|
||||
Common.PackageSent.Clipboard,
|
||||
Common.PackageSent.ClipboardDragDrop,
|
||||
Common.PackageSent.ClipboardDragDropEnd,
|
||||
Common.PackageSent.ExplorerDragDrop,
|
||||
Common.inputEventCount,
|
||||
Common.PackageSent.Nil);
|
||||
Log(log);
|
||||
lastPackageSent = Common.PackageSent; // Copy data
|
||||
}
|
||||
|
||||
if (!lastPackageReceived.Equals(Common.PackageReceived))
|
||||
{
|
||||
log = string.Format(
|
||||
CultureInfo.CurrentCulture,
|
||||
"RECEIVED:" + HeaderRECEIVED,
|
||||
Common.PackageReceived.Heartbeat,
|
||||
Common.PackageReceived.Keyboard,
|
||||
Common.PackageReceived.Mouse,
|
||||
Common.PackageReceived.Hello,
|
||||
Common.PackageReceived.Matrix,
|
||||
Common.PackageReceived.ClipboardText,
|
||||
Common.PackageReceived.ClipboardImage,
|
||||
Common.PackageReceived.ByeBye,
|
||||
Common.PackageReceived.Clipboard,
|
||||
Common.PackageReceived.ClipboardDragDrop,
|
||||
Common.PackageReceived.ClipboardDragDropEnd,
|
||||
Common.PackageReceived.ExplorerDragDrop,
|
||||
Common.invalidPackageCount,
|
||||
Common.PackageReceived.Nil,
|
||||
Common.processedPackageCount,
|
||||
Common.skippedPackageCount);
|
||||
Log(log);
|
||||
lastPackageReceived = Common.PackageReceived;
|
||||
}
|
||||
}
|
||||
|
||||
internal static void GenerateLog()
|
||||
{
|
||||
int l = Setting.Values.DumpObjectsLevel;
|
||||
if (l is > 0 and < 10)
|
||||
{
|
||||
Logger.DumpObjects(l);
|
||||
}
|
||||
}
|
||||
|
||||
private static List<ProcessThread> myThreads;
|
||||
|
||||
internal static void DumpObjects(int level)
|
||||
{
|
||||
try
|
||||
{
|
||||
string logFile = Path.Combine(Common.RunWithNoAdminRight ? Path.GetTempPath() : Path.GetDirectoryName(Application.ExecutablePath), "MagicMouse.log");
|
||||
|
||||
StringBuilder sb = new(1000000);
|
||||
string log;
|
||||
|
||||
myThreads = new List<ProcessThread>();
|
||||
|
||||
foreach (ProcessThread t in Process.GetCurrentProcess().Threads)
|
||||
{
|
||||
myThreads.Add(t);
|
||||
}
|
||||
|
||||
_ = Logger.PrivateDump(sb, AllLogs, "[Program logs]\r\n===============\r\n", 0, level, false);
|
||||
_ = Logger.PrivateDump(sb, new Common(), "[Other Logs]\r\n===============\r\n", 0, level, false);
|
||||
sb.AppendLine("[Logger]\r\n===============");
|
||||
Logger.DumpType(sb, typeof(Logger), 0, level);
|
||||
|
||||
log = string.Format(
|
||||
CultureInfo.CurrentCulture,
|
||||
"{0} {1}\r\n{2}\r\n\r\n{3}",
|
||||
Application.ProductName,
|
||||
Application.ProductVersion,
|
||||
"Private Mem: " + (Process.GetCurrentProcess().PrivateMemorySize64 / 1024).ToString(CultureInfo.CurrentCulture) + "KB",
|
||||
sb.ToString());
|
||||
|
||||
if (!string.IsNullOrEmpty(Common.myKey))
|
||||
{
|
||||
log = log.Replace(Common.MyKey, Common.GetDebugInfo(Common.MyKey));
|
||||
}
|
||||
|
||||
log += Thread.DumpThreadsStack();
|
||||
log += $"\r\nCurrent process session: {Process.GetCurrentProcess().SessionId}, active console session: {NativeMethods.WTSGetActiveConsoleSessionId()}.";
|
||||
|
||||
File.WriteAllText(logFile, log);
|
||||
|
||||
if (Common.RunOnLogonDesktop || Common.RunOnScrSaverDesktop)
|
||||
{
|
||||
_ = MessageBox.Show("Dump file created: " + logFile, Application.ProductName);
|
||||
}
|
||||
else
|
||||
{
|
||||
Common.ShowToolTip("Dump file created: " + logFile + " and placed in the Clipboard.", 10000);
|
||||
Clipboard.SetText(logFile);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_ = MessageBox.Show(e.Message + "\r\n" + e.StackTrace, Application.ProductName);
|
||||
}
|
||||
}
|
||||
|
||||
internal static bool PrivateDump(StringBuilder sb, object obj, string objName, int level, int maxLevel, bool stop)
|
||||
{
|
||||
Type t;
|
||||
string padStr = string.Empty;
|
||||
string[] strArr;
|
||||
string objString;
|
||||
|
||||
if (obj == null || (maxLevel >= 0 && level >= maxLevel) || obj is Cursor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < level; i++)
|
||||
{
|
||||
padStr += i < level - 1 ? "-" : padStr += string.Empty;
|
||||
}
|
||||
|
||||
objString = obj.ToString();
|
||||
t = obj.GetType();
|
||||
strArr = new string[7];
|
||||
strArr[0] = padStr;
|
||||
strArr[1] = objName;
|
||||
|
||||
// strArr[2] = " ";
|
||||
// strArr[3] = t.FullName;
|
||||
strArr[4] = " = ";
|
||||
strArr[5] = objName.Equals("myKey", StringComparison.OrdinalIgnoreCase)
|
||||
? Common.GetDebugInfo(objString)
|
||||
: objName.Equals("lastClipboardObject", StringComparison.OrdinalIgnoreCase)
|
||||
? string.Empty
|
||||
: objString
|
||||
.Replace("System.Windows.Forms.", string.Empty)
|
||||
.Replace("System.Net.Sockets.", string.Empty)
|
||||
.Replace("System.Security.Cryptography.", string.Empty)
|
||||
.Replace("System.Threading.", string.Empty)
|
||||
.Replace("System.ComponentModel.", string.Empty)
|
||||
.Replace("System.Runtime.", string.Empty)
|
||||
.Replace("System.Drawing.", string.Empty)
|
||||
.Replace("System.Object", "O")
|
||||
.Replace("System.Diagnostics.", string.Empty)
|
||||
.Replace("System.Collections.", string.Empty)
|
||||
.Replace("System.Drawing.", string.Empty)
|
||||
.Replace("System.Int", string.Empty)
|
||||
.Replace("System.EventHandler.", string.Empty);
|
||||
strArr[6] = "\r\n";
|
||||
_ = sb.Append(string.Concat(strArr).Replace(Common.BinaryName, "MM"));
|
||||
|
||||
if (stop || t.IsPrimitive)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Logger.DumpObject(sb, obj, level, t, maxLevel);
|
||||
return true;
|
||||
}
|
||||
|
||||
internal static void DumpObject(StringBuilder sb, object obj, int level, Type t, int maxLevel)
|
||||
{
|
||||
int i;
|
||||
bool stop;
|
||||
if (t == typeof(Delegate))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
FieldInfo[] fi;
|
||||
string type;
|
||||
|
||||
if (obj is PackageType or string or AddressFamily or ID or IPAddress)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
type = obj.GetType().ToString();
|
||||
|
||||
if (type.EndsWith("type", StringComparison.CurrentCultureIgnoreCase) || type.Contains("Cryptography")
|
||||
|| type.EndsWith("AsyncEventBits", StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
stop = obj == null || obj is DATA || obj.GetType().BaseType == typeof(ValueType)
|
||||
|| obj.GetType().Namespace.Contains("System.Windows");
|
||||
fi = t.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
|
||||
|
||||
foreach (FieldInfo f in fi)
|
||||
{
|
||||
if (f.GetValue(obj) != AllLogs)
|
||||
{
|
||||
_ = PrivateDump(sb, f.GetValue(obj), f.Name, level + 1, maxLevel, stop);
|
||||
}
|
||||
}
|
||||
|
||||
if (obj is Dictionary<string, List<IPAddress>>)
|
||||
{
|
||||
Dictionary<string, List<IPAddress>> d = obj as Dictionary<string, List<IPAddress>>;
|
||||
|
||||
foreach (string k in d.Keys)
|
||||
{
|
||||
if (d.TryGetValue(k, out List<IPAddress> l))
|
||||
{
|
||||
foreach (IPAddress ip in l)
|
||||
{
|
||||
_ = PrivateDump(sb, ip, "[" + k + "]", level + 1, maxLevel, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (obj is Array)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (obj is MachineInf[])
|
||||
{
|
||||
MachineInf[] os = (MachineInf[])obj;
|
||||
|
||||
for (i = 0; i < os.GetLength(0); i++)
|
||||
{
|
||||
_ = PrivateDump(sb, os[i], "[" + i + "]", level + 1, maxLevel, false);
|
||||
}
|
||||
}
|
||||
else if (obj is int[] || obj is uint[])
|
||||
{
|
||||
int[] os = (int[])obj;
|
||||
|
||||
for (i = 0; i < os.GetLength(0); i++)
|
||||
{
|
||||
_ = PrivateDump(sb, os[i], "[" + i + "]", level + 1, maxLevel, false);
|
||||
}
|
||||
}
|
||||
else if (obj is short[] || obj is ushort[])
|
||||
{
|
||||
short[] os = (short[])obj;
|
||||
|
||||
for (i = 0; i < os.GetLength(0); i++)
|
||||
{
|
||||
_ = PrivateDump(sb, os[i], "[" + i + "]", level + 1, maxLevel, false);
|
||||
}
|
||||
}
|
||||
else if (obj is TcpClient[] || obj is IPAddress[] || obj is TcpSk[] || obj is string[]
|
||||
|| obj is TcpServer[]
|
||||
|| obj is ProcessThread[] || obj is Thread[])
|
||||
{
|
||||
object[] os = (object[])obj;
|
||||
|
||||
for (i = 0; i < os.GetLength(0); i++)
|
||||
{
|
||||
_ = PrivateDump(sb, os[i], "[" + i + "]", level + 1, maxLevel, false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_ = PrivateDump(sb, obj.GetType().ToString() + ": N/A", obj.GetType().ToString(), level + 1, maxLevel, false);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static void DumpType(StringBuilder sb, Type typeToDump, int level, int maxLevel)
|
||||
{
|
||||
if ((typeToDump == typeof(Delegate))
|
||||
|| (typeToDump == typeof(PackageType))
|
||||
|| (typeToDump == typeof(string))
|
||||
|| (typeToDump == typeof(AddressFamily))
|
||||
|| (typeToDump == typeof(ID))
|
||||
|| (typeToDump == typeof(IPAddress)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var typeFullName = typeToDump.ToString();
|
||||
if (typeFullName.EndsWith("type", StringComparison.CurrentCultureIgnoreCase)
|
||||
|| typeFullName.Contains("Cryptography")
|
||||
|| typeFullName.EndsWith("AsyncEventBits", StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var stop = (typeToDump == null)
|
||||
|| (typeToDump == typeof(DATA))
|
||||
|| (typeToDump.BaseType == typeof(ValueType))
|
||||
|| typeToDump.Namespace.Contains("System.Windows");
|
||||
|
||||
var fieldInfos = typeToDump.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
|
||||
foreach (var fieldInfo in fieldInfos)
|
||||
{
|
||||
if (fieldInfo.GetValue(null) != AllLogs)
|
||||
{
|
||||
_ = Logger.PrivateDump(sb, fieldInfo.GetValue(null), fieldInfo.Name, level + 1, maxLevel, stop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static string GetStackTrace(StackTrace st)
|
||||
{
|
||||
string rv = string.Empty;
|
||||
|
||||
for (int i = 0; i < st.FrameCount; i++)
|
||||
{
|
||||
StackFrame sf = st.GetFrame(i);
|
||||
rv += sf.GetMethod() + " <= ";
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using MouseWithoutBorders.Core;
|
||||
using MouseWithoutBorders.Form.Settings;
|
||||
|
||||
namespace MouseWithoutBorders
|
||||
@@ -23,9 +23,9 @@ namespace MouseWithoutBorders
|
||||
toolTipManual.ToolTipTitle = Application.ProductName;
|
||||
Text = Application.ProductName;
|
||||
|
||||
Common.LogDebug("FIRST RUN, SHOWING THE FIRST SETUP PAGE.");
|
||||
Logger.LogDebug("FIRST RUN, SHOWING THE FIRST SETUP PAGE.");
|
||||
|
||||
Common.LogDebug($"{nameof(Common.RunWithNoAdminRight)} = {Common.RunWithNoAdminRight}");
|
||||
Logger.LogDebug($"{nameof(Common.RunWithNoAdminRight)} = {Common.RunWithNoAdminRight}");
|
||||
|
||||
if (Common.RunWithNoAdminRight)
|
||||
{
|
||||
@@ -43,7 +43,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
if (_currentPage != null)
|
||||
{
|
||||
Common.LogDebug(_currentPage.Name + " closing.");
|
||||
Logger.LogDebug(_currentPage.Name + " closing.");
|
||||
_currentPage.OnPageClosing();
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
if (page != null)
|
||||
{
|
||||
Common.LogDebug("GOING TO NEXT PAGE: " + page.Name);
|
||||
Logger.LogDebug("GOING TO NEXT PAGE: " + page.Name);
|
||||
page.BackColor = Color.Transparent;
|
||||
page.NextPage += PageNextPage;
|
||||
page.Location = contentPanel.Location;
|
||||
|
||||
@@ -7,6 +7,7 @@ using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using MouseWithoutBorders.Class;
|
||||
using MouseWithoutBorders.Core;
|
||||
using MouseWithoutBorders.Properties;
|
||||
|
||||
namespace MouseWithoutBorders
|
||||
@@ -42,7 +43,7 @@ namespace MouseWithoutBorders
|
||||
private void ShowStatus(string status)
|
||||
{
|
||||
labelStatus.Text = status;
|
||||
Common.Log(status);
|
||||
Logger.Log(status);
|
||||
}
|
||||
|
||||
public override void OnPageClosing()
|
||||
|
||||
@@ -16,6 +16,7 @@ using System.Windows.Forms;
|
||||
// 2023- Included in PowerToys.
|
||||
// </history>
|
||||
using MouseWithoutBorders.Class;
|
||||
using MouseWithoutBorders.Core;
|
||||
|
||||
[module: SuppressMessage("Microsoft.Globalization", "CA1300:SpecifyMessageBoxOptions", Scope = "member", Target = "MouseWithoutBorders.frmInputCallback.#InstallKeyboardAndMouseHook()", Justification = "Dotnet port with style preservation")]
|
||||
|
||||
@@ -65,7 +66,7 @@ namespace MouseWithoutBorders
|
||||
Common.Hook.MouseEvent += new InputHook.MouseEvHandler(Common.MouseEvent);
|
||||
Common.Hook.KeyboardEvent += new InputHook.KeybdEvHandler(Common.KeybdEvent);
|
||||
|
||||
Common.Log("(((((Keyboard/Mouse hooks installed/reinstalled!)))))");
|
||||
Logger.Log("(((((Keyboard/Mouse hooks installed/reinstalled!)))))");
|
||||
/* The hook is called in the context of the thread that installed it.
|
||||
* The call is made by sending a message to the thread that installed the hook.
|
||||
* Therefore, the thread that installed the hook must have a message loop!!!
|
||||
|
||||
@@ -21,7 +21,7 @@ using Microsoft.PowerToys.Telemetry;
|
||||
// 2023- Included in PowerToys.
|
||||
// </history>
|
||||
using MouseWithoutBorders.Class;
|
||||
|
||||
using MouseWithoutBorders.Core;
|
||||
using Timer = System.Windows.Forms.Timer;
|
||||
|
||||
[module: SuppressMessage("Microsoft.Globalization", "CA1300:SpecifyMessageBoxOptions", Scope = "member", Target = "MouseWithoutBorders.frmMatrix.#buttonOK_Click(System.Object,System.EventArgs)", Justification = "Dotnet port with style preservation")]
|
||||
@@ -151,7 +151,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
if (Common.MachineMatrix != null && Common.MachineMatrix.Length == Common.MAX_MACHINE)
|
||||
{
|
||||
Common.LogDebug("LoadMachines: Machine Matrix: " + Setting.Values.MachineMatrixString);
|
||||
Logger.LogDebug("LoadMachines: Machine Matrix: " + Setting.Values.MachineMatrixString);
|
||||
|
||||
for (int i = 0; i < Common.MAX_MACHINE; i++)
|
||||
{
|
||||
@@ -329,8 +329,8 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
catch (Exception ee)
|
||||
{
|
||||
Common.Log(ee);
|
||||
Common.Log(rv.ToString(CultureInfo.CurrentCulture));
|
||||
Logger.Log(ee);
|
||||
Logger.Log(rv.ToString(CultureInfo.CurrentCulture));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ using Microsoft.PowerToys.Telemetry;
|
||||
// 2023- Included in PowerToys.
|
||||
// </history>
|
||||
using MouseWithoutBorders.Class;
|
||||
using MouseWithoutBorders.Core;
|
||||
using MouseWithoutBorders.Properties;
|
||||
|
||||
using Timer = System.Windows.Forms.Timer;
|
||||
@@ -81,7 +82,7 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,7 +233,7 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -273,7 +274,7 @@ namespace MouseWithoutBorders
|
||||
{
|
||||
BackColor = Color.White;
|
||||
Opacity = 0.15;
|
||||
Common.Log(ex);
|
||||
Logger.Log(ex);
|
||||
}
|
||||
|
||||
helperTimer = new System.Windows.Forms.Timer();
|
||||
@@ -355,7 +356,7 @@ namespace MouseWithoutBorders
|
||||
if (!Common.RunOnLogonDesktop && !Common.RunOnScrSaverDesktop && !Common.GetUserName())
|
||||
{
|
||||
// While Windows 8 is hybrid-shutting down, user name would be empty (as returned from the .Net API), we should not do anything in this case.
|
||||
Common.LogDebug("No active user.");
|
||||
Logger.LogDebug("No active user.");
|
||||
Thread.Sleep(1000);
|
||||
busy = false;
|
||||
return;
|
||||
@@ -432,7 +433,7 @@ namespace MouseWithoutBorders
|
||||
if (!Common.AtLeastOneSocketEstablished())
|
||||
{
|
||||
Common.GetMachineName();
|
||||
Common.LogDebug("Common.pleaseReopenSocket: " + Common.PleaseReopenSocket.ToString(CultureInfo.InvariantCulture));
|
||||
Logger.LogDebug("Common.pleaseReopenSocket: " + Common.PleaseReopenSocket.ToString(CultureInfo.InvariantCulture));
|
||||
Common.ReopenSockets(false);
|
||||
Common.NewDesMachineID = Common.DesMachineID = Common.MachineID;
|
||||
}
|
||||
@@ -545,7 +546,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
if (count % 20 == 0)
|
||||
{
|
||||
Common.LogAll();
|
||||
Logger.LogAll();
|
||||
|
||||
// Need to review this code on why it is needed (moved from MoveToMyNeighbourIfNeeded(...))
|
||||
for (int i = 0; i < Common.MachineMatrix.Length; i++)
|
||||
@@ -579,14 +580,14 @@ namespace MouseWithoutBorders
|
||||
|
||||
if (!Common.RunOnLogonDesktop && !Common.RunOnScrSaverDesktop && Common.IsMyDesktopActive() && (rv = Common.SendMessageToHelper(0x400, IntPtr.Zero, IntPtr.Zero)) <= 0)
|
||||
{
|
||||
Common.TelemetryLogTrace($"{Common.HELPER_FORM_TEXT} not found: {rv}", SeverityLevel.Warning);
|
||||
Logger.TelemetryLogTrace($"{Common.HELPER_FORM_TEXT} not found: {rv}", SeverityLevel.Warning);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Common.Log(ex);
|
||||
Logger.Log(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -678,7 +679,7 @@ namespace MouseWithoutBorders
|
||||
p.Dispose();
|
||||
#endif
|
||||
|
||||
Common.LogDebug($"Changing icon to {iconCode}.");
|
||||
Logger.LogDebug($"Changing icon to {iconCode}.");
|
||||
|
||||
if (NotifyIcon.Icon != null)
|
||||
{
|
||||
@@ -690,13 +691,13 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
}
|
||||
|
||||
internal void MenuAllPC_Click(object sender, EventArgs e)
|
||||
{
|
||||
Common.LogDebug("menuAllPC_Click");
|
||||
Logger.LogDebug("menuAllPC_Click");
|
||||
Common.SwitchToMultipleMode(MenuAllPC.Checked, true);
|
||||
CurIcon = MenuAllPC.Checked ? Common.ICON_ALL : Common.ICON_ONE;
|
||||
ChangeIcon(CurIcon);
|
||||
@@ -801,7 +802,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
if (h.ToInt32() > 0)
|
||||
{
|
||||
Common.LogDebug("Hide Mouse Without Borders Helper.");
|
||||
Logger.LogDebug("Hide Mouse Without Borders Helper.");
|
||||
|
||||
// Common.ShowWindow(h, 1);
|
||||
_ = NativeMethods.ShowWindow(h, 0);
|
||||
@@ -813,7 +814,7 @@ namespace MouseWithoutBorders
|
||||
break;
|
||||
|
||||
case NativeMethods.WM_CHECK_EXPLORER_DRAG_DROP:
|
||||
Common.LogDebug("Got WM_CHECK_EXPLORER_DRAG_DROP!");
|
||||
Logger.LogDebug("Got WM_CHECK_EXPLORER_DRAG_DROP!");
|
||||
Common.DragDropStep04();
|
||||
break;
|
||||
|
||||
@@ -825,7 +826,7 @@ namespace MouseWithoutBorders
|
||||
break;
|
||||
|
||||
case WM_QUERYENDSESSION:
|
||||
Common.LogDebug("WM_QUERYENDSESSION...");
|
||||
Logger.LogDebug("WM_QUERYENDSESSION...");
|
||||
Common.StartServiceAndSendLogoffSignal();
|
||||
break;
|
||||
|
||||
@@ -993,7 +994,7 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Common.Log(e);
|
||||
Logger.Log(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1210,7 +1211,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
private void MenuGenDumpFile_Click(object sender, EventArgs e)
|
||||
{
|
||||
Common.GenerateLog();
|
||||
Logger.GenerateLog();
|
||||
}
|
||||
|
||||
private void MainMenu_Opening(object sender, CancelEventArgs e)
|
||||
|
||||
@@ -100,7 +100,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
if (Process.GetCurrentProcess().SessionId != NativeMethods.WTSGetActiveConsoleSessionId())
|
||||
{
|
||||
Logger.LogEvent(Application.ProductName + " cannot be used in a remote desktop or virtual machine session.");
|
||||
EventLogger.LogEvent(Application.ProductName + " cannot be used in a remote desktop or virtual machine session.");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -135,7 +135,7 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogEvent("FormHelper_DragEnter: " + ex.Message, EventLogEntryType.Error);
|
||||
EventLogger.LogEvent("FormHelper_DragEnter: " + ex.Message, EventLogEntryType.Error);
|
||||
QuitDueToCommunicationError();
|
||||
}
|
||||
}
|
||||
@@ -164,11 +164,11 @@ namespace MouseWithoutBorders
|
||||
{
|
||||
try
|
||||
{
|
||||
Logger.LogEvent(log, EventLogEntryType.Warning);
|
||||
EventLogger.LogEvent(log, EventLogEntryType.Warning);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogEvent(log + " ==> SendLog Exception: " + e.Message, EventLogEntryType.Warning);
|
||||
EventLogger.LogEvent(log + " ==> SendLog Exception: " + e.Message, EventLogEntryType.Warning);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -343,7 +343,7 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogEvent("WM_DRAWCLIPBOARD: " + ex.Message, EventLogEntryType.Error);
|
||||
EventLogger.LogEvent("WM_DRAWCLIPBOARD: " + ex.Message, EventLogEntryType.Error);
|
||||
QuitDueToCommunicationError();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("MouseWithoutBorders.UnitTests")]
|
||||
@@ -0,0 +1,404 @@
|
||||
[Program logs]
|
||||
===============
|
||||
= System.String[]
|
||||
[Other Logs]
|
||||
===============
|
||||
= MouseWithoutBorders.Common
|
||||
lastClipboardEventTime = 0
|
||||
clipboardCopiedTime = 0
|
||||
Comma = System.Char[]
|
||||
--System.Char[] = System.Char[]: N/A
|
||||
Star = System.Char[]
|
||||
--System.Char[] = System.Char[]: N/A
|
||||
NullSeparator = System.Char[]
|
||||
--System.Char[] = System.Char[]: N/A
|
||||
<LastIDWithClipboardData>k__BackingField = NONE
|
||||
<NextClipboardViewer>k__BackingField = 0
|
||||
<IsClipboardDataImage>k__BackingField = False
|
||||
lastClipboardObject =
|
||||
<HasSwitchedMachineSinceLastCopy>k__BackingField = False
|
||||
ClipboardThreadOldLock = O
|
||||
screenWidth = 0
|
||||
screenHeight = 0
|
||||
lastX = 0
|
||||
lastY = 0
|
||||
mainFormVisible = True
|
||||
runOnLogonDesktop = False
|
||||
runOnScrSaverDesktop = False
|
||||
toggleIconsIndex = 0
|
||||
EvSwitch = EventWaitHandle
|
||||
lastPos = {X=0,Y=0}
|
||||
--x = 0
|
||||
--y = 0
|
||||
--Empty = {X=0,Y=0}
|
||||
switchCount = 0
|
||||
lastReconnectByHotKeyTime = 0
|
||||
tcpPort = 0
|
||||
secondOpenSocketTry = False
|
||||
binaryName = MM
|
||||
<PaintCount>k__BackingField = 0
|
||||
<RunWithNoAdminRight>k__BackingField = False
|
||||
<Is64bitOS>k__BackingField = False
|
||||
socketMutexBalance = 0
|
||||
<BlockingUI>k__BackingField = False
|
||||
<UIThreadID>k__BackingField = 0
|
||||
<InputCallbackThreadID>k__BackingField = 0
|
||||
InputSimulationLock = O
|
||||
lastSendNextMachine = 0
|
||||
lastInputEventCount = 0
|
||||
lastRealInputEventCount = 0
|
||||
minSendTime = 9223372036854775807
|
||||
avgSendTime = 0
|
||||
maxSendTime = 0
|
||||
totalSendCount = 0
|
||||
totalSendTime = 0
|
||||
isDragging = False
|
||||
dragDropStep05ExCalledByIpc = 0
|
||||
isDropping = False
|
||||
dragMachine = NONE
|
||||
<MouseDown>k__BackingField = False
|
||||
magicNumber = 0
|
||||
ran = System.Random
|
||||
--_impl = System.Random+XoshiroImpl
|
||||
----_s0 = ????????????
|
||||
----_s1 = ????????????
|
||||
----_s2 = ????????????
|
||||
----_s3 = ????????????
|
||||
--<Shared>k__BackingField = System.Random+ThreadSafeRandom
|
||||
InitialIV = ????????????
|
||||
<GeneratedKey>k__BackingField = False
|
||||
<KeyCorrupted>k__BackingField = False
|
||||
LegalKeyDictionary = Concurrent.ConcurrentDictionary`2[System.String,System.Byte[]]
|
||||
--_tables = Concurrent.ConcurrentDictionary`2+Tables[System.String,System.Byte[]]
|
||||
----_comparer = Generic.NonRandomizedStringEqualityComparer+OrdinalIgnoreCaseComparer
|
||||
----_buckets = Concurrent.ConcurrentDictionary`2+VolatileNode[System.String,System.Byte[]][]
|
||||
------System.Collections.Concurrent.ConcurrentDictionary`2+VolatileNode[System.String,System.Byte[]][] = Concurrent.ConcurrentDictionary`2+VolatileNode[System.String,System.Byte[]][]: N/A
|
||||
----_fastModBucketsMultiplier = 498560650640798693
|
||||
----_locks = O[]
|
||||
------System.Object[] = O[]: N/A
|
||||
----_countPerLock = 32[]
|
||||
------[0] = 0
|
||||
------[1] = 0
|
||||
------[2] = 0
|
||||
------[3] = 0
|
||||
------[4] = 0
|
||||
------[5] = 0
|
||||
------[6] = 0
|
||||
------[7] = 0
|
||||
------[8] = 0
|
||||
------[9] = 0
|
||||
------[10] = 0
|
||||
------[11] = 0
|
||||
------[12] = 0
|
||||
------[13] = 0
|
||||
------[14] = 0
|
||||
------[15] = 0
|
||||
--_budget = 2
|
||||
--_growLockArray = True
|
||||
--_comparerIsDefaultForClasses = False
|
||||
KeybdPackage = MouseWithoutBorders.DATA
|
||||
--Type = 0
|
||||
--Id = 0
|
||||
--Src = NONE
|
||||
--Des = NONE
|
||||
--DateTime = 0
|
||||
--Kd = MouseWithoutBorders.KEYBDDATA
|
||||
--Md = MouseWithoutBorders.MOUSEDATA
|
||||
--Machine1 = NONE
|
||||
--Machine2 = NONE
|
||||
--Machine3 = NONE
|
||||
--Machine4 = NONE
|
||||
--PostAction = Other
|
||||
--machineNameP1 = 0
|
||||
--machineNameP2 = 0
|
||||
--machineNameP3 = 0
|
||||
--machineNameP4 = 0
|
||||
MousePackage = MouseWithoutBorders.DATA
|
||||
--Type = 0
|
||||
--Id = 0
|
||||
--Src = NONE
|
||||
--Des = NONE
|
||||
--DateTime = 0
|
||||
--Kd = MouseWithoutBorders.KEYBDDATA
|
||||
--Md = MouseWithoutBorders.MOUSEDATA
|
||||
--Machine1 = NONE
|
||||
--Machine2 = NONE
|
||||
--Machine3 = NONE
|
||||
--Machine4 = NONE
|
||||
--PostAction = Other
|
||||
--machineNameP1 = 0
|
||||
--machineNameP2 = 0
|
||||
--machineNameP3 = 0
|
||||
--machineNameP4 = 0
|
||||
inputEventCount = 0
|
||||
invalidPackageCount = 0
|
||||
MOVE_MOUSE_RELATIVE = 100000
|
||||
XY_BY_PIXEL = 300000
|
||||
<RealInputEventCount>k__BackingField = 0
|
||||
actualLastPos = {X=0,Y=0}
|
||||
--x = 0
|
||||
--y = 0
|
||||
--Empty = {X=0,Y=0}
|
||||
myLastX = 0
|
||||
myLastY = 0
|
||||
signalHelperToExit = False
|
||||
signalWatchDogToExit = False
|
||||
WndProcCounter = 0
|
||||
initDone = False
|
||||
REOPEN_WHEN_WSAECONNRESET = -10054
|
||||
REOPEN_WHEN_HOTKEY = -10055
|
||||
PleaseReopenSocket = 0
|
||||
ReopenSocketDueToReadError = False
|
||||
<LastResumeSuspendTime>k__BackingField = ????????????
|
||||
--_dateData = ????????????
|
||||
--MinValue = 01/01/0001 00:00:00
|
||||
--MaxValue = 31/12/9999 23:59:59
|
||||
--UnixEpoch = 01/01/1970 00:00:00
|
||||
lastReleaseAllKeysCall = 0
|
||||
McMatrixLock = O
|
||||
desMachineID = NONE
|
||||
DesMachineName =
|
||||
newDesMachineID = NONE
|
||||
newDesMachineIdEx = NONE
|
||||
dropMachineID = NONE
|
||||
lastJump = ????????????
|
||||
desktopBounds = MouseWithoutBorders.MyRectangle
|
||||
--Left = 0
|
||||
--Top = 0
|
||||
--Right = 0
|
||||
--Bottom = 0
|
||||
primaryScreenBounds = MouseWithoutBorders.MyRectangle
|
||||
--Left = 0
|
||||
--Top = 0
|
||||
--Right = 0
|
||||
--Bottom = 0
|
||||
SwitchLocation = MouseWithoutBorders.Class.MouseLocation
|
||||
--<X>k__BackingField = 0
|
||||
--<Y>k__BackingField = 0
|
||||
--<Count>k__BackingField = 0
|
||||
PackageSent = MouseWithoutBorders.PackageMonitor
|
||||
--Keyboard = 0
|
||||
--Mouse = 0
|
||||
--Heartbeat = 0
|
||||
--ByeBye = 0
|
||||
--Hello = 0
|
||||
--Matrix = 0
|
||||
--ClipboardText = 0
|
||||
--ClipboardImage = 0
|
||||
--Clipboard = 0
|
||||
--ClipboardDragDrop = 0
|
||||
--ClipboardDragDropEnd = 0
|
||||
--ClipboardAsk = 0
|
||||
--ExplorerDragDrop = 0
|
||||
--Nil = 0
|
||||
PackageReceived = MouseWithoutBorders.PackageMonitor
|
||||
--Keyboard = 0
|
||||
--Mouse = 0
|
||||
--Heartbeat = 0
|
||||
--ByeBye = 0
|
||||
--Hello = 0
|
||||
--Matrix = 0
|
||||
--ClipboardText = 0
|
||||
--ClipboardImage = 0
|
||||
--Clipboard = 0
|
||||
--ClipboardDragDrop = 0
|
||||
--ClipboardDragDropEnd = 0
|
||||
--ClipboardAsk = 0
|
||||
--ExplorerDragDrop = 0
|
||||
--Nil = 0
|
||||
PackageID = 0
|
||||
QUEUE_SIZE = 50
|
||||
RecentProcessedPackageIDs = 32[]
|
||||
--[0] = 0
|
||||
--[1] = 0
|
||||
--[2] = 0
|
||||
--[3] = 0
|
||||
--[4] = 0
|
||||
--[5] = 0
|
||||
--[6] = 0
|
||||
--[7] = 0
|
||||
--[8] = 0
|
||||
--[9] = 0
|
||||
--[10] = 0
|
||||
--[11] = 0
|
||||
--[12] = 0
|
||||
--[13] = 0
|
||||
--[14] = 0
|
||||
--[15] = 0
|
||||
--[16] = 0
|
||||
--[17] = 0
|
||||
--[18] = 0
|
||||
--[19] = 0
|
||||
--[20] = 0
|
||||
--[21] = 0
|
||||
--[22] = 0
|
||||
--[23] = 0
|
||||
--[24] = 0
|
||||
--[25] = 0
|
||||
--[26] = 0
|
||||
--[27] = 0
|
||||
--[28] = 0
|
||||
--[29] = 0
|
||||
--[30] = 0
|
||||
--[31] = 0
|
||||
--[32] = 0
|
||||
--[33] = 0
|
||||
--[34] = 0
|
||||
--[35] = 0
|
||||
--[36] = 0
|
||||
--[37] = 0
|
||||
--[38] = 0
|
||||
--[39] = 0
|
||||
--[40] = 0
|
||||
--[41] = 0
|
||||
--[42] = 0
|
||||
--[43] = 0
|
||||
--[44] = 0
|
||||
--[45] = 0
|
||||
--[46] = 0
|
||||
--[47] = 0
|
||||
--[48] = 0
|
||||
--[49] = 0
|
||||
recentProcessedPackageIndex = 0
|
||||
processedPackageCount = 0
|
||||
skippedPackageCount = 0
|
||||
<JustGotAKey>k__BackingField = 0
|
||||
lastXY = {X=0,Y=0}
|
||||
--x = 0
|
||||
--y = 0
|
||||
--Empty = {X=0,Y=0}
|
||||
shownErrMessage = False
|
||||
lastStartServiceTime = ????????????
|
||||
--_dateData = ????????????
|
||||
--MinValue = 01/01/0001 00:00:00
|
||||
--MaxValue = 31/12/9999 23:59:59
|
||||
--UnixEpoch = 01/01/1970 00:00:00
|
||||
SensitivePoints = Generic.List`1[Point]
|
||||
--_items = Point[]
|
||||
----System.Drawing.Point[] = Point[]: N/A
|
||||
--_size = 0
|
||||
--_version = 0
|
||||
--s_emptyArray = Point[]
|
||||
----System.Drawing.Point[] = Point[]: N/A
|
||||
p = {X=0,Y=0}
|
||||
--x = 0
|
||||
--y = 0
|
||||
--Empty = {X=0,Y=0}
|
||||
<IpcChannelCreated>k__BackingField = False
|
||||
BIG_CLIPBOARD_DATA_TIMEOUT = 30000
|
||||
MAX_CLIPBOARD_DATA_SIZE_CAN_BE_SENT_INSTANTLY_TCP = 1048576
|
||||
MAX_CLIPBOARD_FILE_SIZE_CAN_BE_SENT = 104857600
|
||||
TEXT_HEADER_SIZE = 12
|
||||
DATA_SIZE = 48
|
||||
TEXT_TYPE_SEP = {4CFF57F7-BEDD-43d5-AE8F-27A61E886F2F}
|
||||
TOGGLE_ICONS_SIZE = 4
|
||||
ICON_ONE = 0
|
||||
ICON_ALL = 1
|
||||
ICON_SMALL_CLIPBOARD = 2
|
||||
ICON_BIG_CLIPBOARD = 3
|
||||
ICON_ERROR = 4
|
||||
JUST_GOT_BACK_FROM_SCREEN_SAVER = 9999
|
||||
NETWORK_STREAM_BUF_SIZE = 1048576
|
||||
SymAlBlockSize = 16
|
||||
PW_LENGTH = 16
|
||||
HELPER_FORM_TEXT = Mouse without Borders Helper
|
||||
HelperProcessName = PowerToys.MouseWithoutBordersHelper
|
||||
MAX_MACHINE = 4
|
||||
MAX_SOCKET = 8
|
||||
HEARTBEAT_TIMEOUT = 1500000
|
||||
SKIP_PIXELS = 1
|
||||
JUMP_PIXELS = 2
|
||||
PACKAGE_SIZE = 32
|
||||
PACKAGE_SIZE_EX = 64
|
||||
WP_PACKAGE_SIZE = 6
|
||||
KEYEVENTF_KEYDOWN = 1
|
||||
KEYEVENTF_KEYUP = 2
|
||||
WH_MOUSE = 7
|
||||
WH_KEYBOARD = 2
|
||||
WH_MOUSE_LL = 14
|
||||
WH_KEYBOARD_LL = 13
|
||||
WM_MOUSEMOVE = 512
|
||||
WM_LBUTTONDOWN = 513
|
||||
WM_RBUTTONDOWN = 516
|
||||
WM_MBUTTONDOWN = 519
|
||||
WM_XBUTTONDOWN = 523
|
||||
WM_LBUTTONUP = 514
|
||||
WM_RBUTTONUP = 517
|
||||
WM_MBUTTONUP = 520
|
||||
WM_XBUTTONUP = 524
|
||||
WM_LBUTTONDBLCLK = 515
|
||||
WM_RBUTTONDBLCLK = 518
|
||||
WM_MBUTTONDBLCLK = 521
|
||||
WM_MOUSEWHEEL = 522
|
||||
WM_KEYDOWN = 256
|
||||
WM_KEYUP = 257
|
||||
WM_SYSKEYDOWN = 260
|
||||
WM_SYSKEYUP = 261
|
||||
[Logger Logs]
|
||||
===============
|
||||
AllLogsLock = O
|
||||
LogCounter = Concurrent.ConcurrentDictionary`2[System.String,32]
|
||||
--_tables = Concurrent.ConcurrentDictionary`2+Tables[System.String,32]
|
||||
----_comparer = Generic.NonRandomizedStringEqualityComparer+OrdinalComparer
|
||||
----_buckets = Concurrent.ConcurrentDictionary`2+VolatileNode[System.String,32][]
|
||||
------System.Collections.Concurrent.ConcurrentDictionary`2+VolatileNode[System.String,System.Int32][] = Concurrent.ConcurrentDictionary`2+VolatileNode[System.String,32][]: N/A
|
||||
----_fastModBucketsMultiplier = 498560650640798693
|
||||
----_locks = O[]
|
||||
------System.Object[] = O[]: N/A
|
||||
----_countPerLock = 32[]
|
||||
------[0] = 0
|
||||
------[1] = 0
|
||||
------[2] = 0
|
||||
------[3] = 0
|
||||
------[4] = 0
|
||||
------[5] = 0
|
||||
------[6] = 0
|
||||
------[7] = 0
|
||||
------[8] = 0
|
||||
------[9] = 0
|
||||
------[10] = 0
|
||||
------[11] = 0
|
||||
------[12] = 0
|
||||
------[13] = 0
|
||||
------[14] = 0
|
||||
------[15] = 0
|
||||
--_budget = 2
|
||||
--_growLockArray = True
|
||||
--_comparerIsDefaultForClasses = False
|
||||
allLogsIndex = 0
|
||||
lastHour = 0
|
||||
exceptionCount = 0
|
||||
lastPackageSent = MouseWithoutBorders.PackageMonitor
|
||||
--Keyboard = 0
|
||||
--Mouse = 0
|
||||
--Heartbeat = 0
|
||||
--ByeBye = 0
|
||||
--Hello = 0
|
||||
--Matrix = 0
|
||||
--ClipboardText = 0
|
||||
--ClipboardImage = 0
|
||||
--Clipboard = 0
|
||||
--ClipboardDragDrop = 0
|
||||
--ClipboardDragDropEnd = 0
|
||||
--ClipboardAsk = 0
|
||||
--ExplorerDragDrop = 0
|
||||
--Nil = 0
|
||||
lastPackageReceived = MouseWithoutBorders.PackageMonitor
|
||||
--Keyboard = 0
|
||||
--Mouse = 0
|
||||
--Heartbeat = 0
|
||||
--ByeBye = 0
|
||||
--Hello = 0
|
||||
--Matrix = 0
|
||||
--ClipboardText = 0
|
||||
--ClipboardImage = 0
|
||||
--Clipboard = 0
|
||||
--ClipboardDragDrop = 0
|
||||
--ClipboardDragDropEnd = 0
|
||||
--ClipboardAsk = 0
|
||||
--ExplorerDragDrop = 0
|
||||
--Nil = 0
|
||||
MAX_LOG = 10000
|
||||
MaxLogExceptionPerHour = 1000
|
||||
HeaderSENT = Be{0},Ke{1},Mo{2},He{3},Mx{4},Tx{5},Im{6},By{7},Cl{8},Dr{9},De{10},Ed{11},Ie{12},Ni{13}
|
||||
HeaderRECEIVED = Be{0},Ke{1},Mo{2},He{3},Mx{4},Tx{5},Im{6},By{7},Cl{8},Dr{9},De{10},Ed{11},In{12},Ni{13},Pc{14}/{15}
|
||||
@@ -0,0 +1,405 @@
|
||||
[Other Logs]
|
||||
===============
|
||||
= MouseWithoutBorders.Common
|
||||
lastClipboardEventTime = 0
|
||||
clipboardCopiedTime = 0
|
||||
Comma = System.Char[]
|
||||
--System.Char[] = System.Char[]: N/A
|
||||
Star = System.Char[]
|
||||
--System.Char[] = System.Char[]: N/A
|
||||
NullSeparator = System.Char[]
|
||||
--System.Char[] = System.Char[]: N/A
|
||||
<LastIDWithClipboardData>k__BackingField = NONE
|
||||
<NextClipboardViewer>k__BackingField = 0
|
||||
<IsClipboardDataImage>k__BackingField = False
|
||||
lastClipboardObject =
|
||||
<HasSwitchedMachineSinceLastCopy>k__BackingField = False
|
||||
ClipboardThreadOldLock = O
|
||||
screenWidth = 0
|
||||
screenHeight = 0
|
||||
lastX = 0
|
||||
lastY = 0
|
||||
mainFormVisible = True
|
||||
runOnLogonDesktop = False
|
||||
runOnScrSaverDesktop = False
|
||||
toggleIconsIndex = 0
|
||||
EvSwitch = EventWaitHandle
|
||||
lastPos = {X=0,Y=0}
|
||||
--x = 0
|
||||
--y = 0
|
||||
--Empty = {X=0,Y=0}
|
||||
switchCount = 0
|
||||
lastReconnectByHotKeyTime = 0
|
||||
tcpPort = 0
|
||||
secondOpenSocketTry = False
|
||||
binaryName = MM
|
||||
<PaintCount>k__BackingField = 0
|
||||
<RunWithNoAdminRight>k__BackingField = False
|
||||
<Is64bitOS>k__BackingField = False
|
||||
socketMutexBalance = 0
|
||||
<BlockingUI>k__BackingField = False
|
||||
<UIThreadID>k__BackingField = 0
|
||||
<InputCallbackThreadID>k__BackingField = 0
|
||||
InputSimulationLock = O
|
||||
lastSendNextMachine = 0
|
||||
lastInputEventCount = 0
|
||||
lastRealInputEventCount = 0
|
||||
minSendTime = 9223372036854775807
|
||||
avgSendTime = 0
|
||||
maxSendTime = 0
|
||||
totalSendCount = 0
|
||||
totalSendTime = 0
|
||||
isDragging = False
|
||||
dragDropStep05ExCalledByIpc = 0
|
||||
isDropping = False
|
||||
dragMachine = NONE
|
||||
<MouseDown>k__BackingField = False
|
||||
magicNumber = 0
|
||||
ran = System.Random
|
||||
--_impl = System.Random+XoshiroImpl
|
||||
----_s0 = 7284351989338469498
|
||||
----_s1 = 15479097190878625043
|
||||
----_s2 = 10963166711904013490
|
||||
----_s3 = 8600427501468926680
|
||||
--<Shared>k__BackingField = System.Random+ThreadSafeRandom
|
||||
InitialIV = 99999999999999999999
|
||||
<GeneratedKey>k__BackingField = False
|
||||
<KeyCorrupted>k__BackingField = False
|
||||
LegalKeyDictionary = Concurrent.ConcurrentDictionary`2[System.String,System.Byte[]]
|
||||
--_tables = Concurrent.ConcurrentDictionary`2+Tables[System.String,System.Byte[]]
|
||||
----_comparer = Generic.NonRandomizedStringEqualityComparer+OrdinalIgnoreCaseComparer
|
||||
----_buckets = Concurrent.ConcurrentDictionary`2+VolatileNode[System.String,System.Byte[]][]
|
||||
------System.Collections.Concurrent.ConcurrentDictionary`2+VolatileNode[System.String,System.Byte[]][] = Concurrent.ConcurrentDictionary`2+VolatileNode[System.String,System.Byte[]][]: N/A
|
||||
----_fastModBucketsMultiplier = 498560650640798693
|
||||
----_locks = O[]
|
||||
------System.Object[] = O[]: N/A
|
||||
----_countPerLock = 32[]
|
||||
------[0] = 0
|
||||
------[1] = 0
|
||||
------[2] = 0
|
||||
------[3] = 0
|
||||
------[4] = 0
|
||||
------[5] = 0
|
||||
------[6] = 0
|
||||
------[7] = 0
|
||||
------[8] = 0
|
||||
------[9] = 0
|
||||
------[10] = 0
|
||||
------[11] = 0
|
||||
------[12] = 0
|
||||
------[13] = 0
|
||||
------[14] = 0
|
||||
------[15] = 0
|
||||
--_budget = 2
|
||||
--_growLockArray = True
|
||||
--_comparerIsDefaultForClasses = False
|
||||
KeybdPackage = MouseWithoutBorders.DATA
|
||||
--Type = 0
|
||||
--Id = 0
|
||||
--Src = NONE
|
||||
--Des = NONE
|
||||
--DateTime = 0
|
||||
--Kd = MouseWithoutBorders.KEYBDDATA
|
||||
--Md = MouseWithoutBorders.MOUSEDATA
|
||||
--Machine1 = NONE
|
||||
--Machine2 = NONE
|
||||
--Machine3 = NONE
|
||||
--Machine4 = NONE
|
||||
--PostAction = Other
|
||||
--machineNameP1 = 0
|
||||
--machineNameP2 = 0
|
||||
--machineNameP3 = 0
|
||||
--machineNameP4 = 0
|
||||
MousePackage = MouseWithoutBorders.DATA
|
||||
--Type = 0
|
||||
--Id = 0
|
||||
--Src = NONE
|
||||
--Des = NONE
|
||||
--DateTime = 0
|
||||
--Kd = MouseWithoutBorders.KEYBDDATA
|
||||
--Md = MouseWithoutBorders.MOUSEDATA
|
||||
--Machine1 = NONE
|
||||
--Machine2 = NONE
|
||||
--Machine3 = NONE
|
||||
--Machine4 = NONE
|
||||
--PostAction = Other
|
||||
--machineNameP1 = 0
|
||||
--machineNameP2 = 0
|
||||
--machineNameP3 = 0
|
||||
--machineNameP4 = 0
|
||||
inputEventCount = 0
|
||||
invalidPackageCount = 0
|
||||
MOVE_MOUSE_RELATIVE = 100000
|
||||
XY_BY_PIXEL = 300000
|
||||
<RealInputEventCount>k__BackingField = 0
|
||||
actualLastPos = {X=0,Y=0}
|
||||
--x = 0
|
||||
--y = 0
|
||||
--Empty = {X=0,Y=0}
|
||||
myLastX = 0
|
||||
myLastY = 0
|
||||
signalHelperToExit = False
|
||||
signalWatchDogToExit = False
|
||||
WndProcCounter = 0
|
||||
initDone = False
|
||||
REOPEN_WHEN_WSAECONNRESET = -10054
|
||||
REOPEN_WHEN_HOTKEY = -10055
|
||||
PleaseReopenSocket = 0
|
||||
ReopenSocketDueToReadError = False
|
||||
<LastResumeSuspendTime>k__BackingField = 26/09/2024 20:35:51
|
||||
--_dateData = 5250315815941007823
|
||||
--MinValue = 01/01/0001 00:00:00
|
||||
--MaxValue = 31/12/9999 23:59:59
|
||||
--UnixEpoch = 01/01/1970 00:00:00
|
||||
lastReleaseAllKeysCall = 0
|
||||
AllLogsLock = O
|
||||
LogCounter = Concurrent.ConcurrentDictionary`2[System.String,32]
|
||||
--_tables = Concurrent.ConcurrentDictionary`2+Tables[System.String,32]
|
||||
----_comparer = Generic.NonRandomizedStringEqualityComparer+OrdinalComparer
|
||||
----_buckets = Concurrent.ConcurrentDictionary`2+VolatileNode[System.String,32][]
|
||||
------System.Collections.Concurrent.ConcurrentDictionary`2+VolatileNode[System.String,System.Int32][] = Concurrent.ConcurrentDictionary`2+VolatileNode[System.String,32][]: N/A
|
||||
----_fastModBucketsMultiplier = 498560650640798693
|
||||
----_locks = O[]
|
||||
------System.Object[] = O[]: N/A
|
||||
----_countPerLock = 32[]
|
||||
------[0] = 0
|
||||
------[1] = 0
|
||||
------[2] = 0
|
||||
------[3] = 0
|
||||
------[4] = 0
|
||||
------[5] = 0
|
||||
------[6] = 0
|
||||
------[7] = 0
|
||||
------[8] = 0
|
||||
------[9] = 0
|
||||
------[10] = 0
|
||||
------[11] = 0
|
||||
------[12] = 0
|
||||
------[13] = 0
|
||||
------[14] = 0
|
||||
------[15] = 0
|
||||
--_budget = 2
|
||||
--_growLockArray = True
|
||||
--_comparerIsDefaultForClasses = False
|
||||
RepeatedLogIndexSelection = 32[]
|
||||
--[0] = 1
|
||||
--[1] = 3
|
||||
--[2] = 10
|
||||
--[3] = 50
|
||||
--[4] = 100
|
||||
allLogsIndex = 0
|
||||
lastHour = 0
|
||||
exceptionCount = 0
|
||||
p1 = MouseWithoutBorders.PackageMonitor
|
||||
--Keyboard = 0
|
||||
--Mouse = 0
|
||||
--Heartbeat = 0
|
||||
--ByeBye = 0
|
||||
--Hello = 0
|
||||
--Matrix = 0
|
||||
--ClipboardText = 0
|
||||
--ClipboardImage = 0
|
||||
--Clipboard = 0
|
||||
--ClipboardDragDrop = 0
|
||||
--ClipboardDragDropEnd = 0
|
||||
--ClipboardAsk = 0
|
||||
--ExplorerDragDrop = 0
|
||||
--Nil = 0
|
||||
p2 = MouseWithoutBorders.PackageMonitor
|
||||
--Keyboard = 0
|
||||
--Mouse = 0
|
||||
--Heartbeat = 0
|
||||
--ByeBye = 0
|
||||
--Hello = 0
|
||||
--Matrix = 0
|
||||
--ClipboardText = 0
|
||||
--ClipboardImage = 0
|
||||
--Clipboard = 0
|
||||
--ClipboardDragDrop = 0
|
||||
--ClipboardDragDropEnd = 0
|
||||
--ClipboardAsk = 0
|
||||
--ExplorerDragDrop = 0
|
||||
--Nil = 0
|
||||
McMatrixLock = O
|
||||
desMachineID = NONE
|
||||
DesMachineName =
|
||||
newDesMachineID = NONE
|
||||
newDesMachineIdEx = NONE
|
||||
dropMachineID = NONE
|
||||
lastJump = 63862983351362
|
||||
desktopBounds = MouseWithoutBorders.MyRectangle
|
||||
--Left = 0
|
||||
--Top = 0
|
||||
--Right = 0
|
||||
--Bottom = 0
|
||||
primaryScreenBounds = MouseWithoutBorders.MyRectangle
|
||||
--Left = 0
|
||||
--Top = 0
|
||||
--Right = 0
|
||||
--Bottom = 0
|
||||
SwitchLocation = MouseWithoutBorders.Class.MouseLocation
|
||||
--<X>k__BackingField = 0
|
||||
--<Y>k__BackingField = 0
|
||||
--<Count>k__BackingField = 0
|
||||
PackageSent = MouseWithoutBorders.PackageMonitor
|
||||
--Keyboard = 0
|
||||
--Mouse = 0
|
||||
--Heartbeat = 0
|
||||
--ByeBye = 0
|
||||
--Hello = 0
|
||||
--Matrix = 0
|
||||
--ClipboardText = 0
|
||||
--ClipboardImage = 0
|
||||
--Clipboard = 0
|
||||
--ClipboardDragDrop = 0
|
||||
--ClipboardDragDropEnd = 0
|
||||
--ClipboardAsk = 0
|
||||
--ExplorerDragDrop = 0
|
||||
--Nil = 0
|
||||
PackageReceived = MouseWithoutBorders.PackageMonitor
|
||||
--Keyboard = 0
|
||||
--Mouse = 0
|
||||
--Heartbeat = 0
|
||||
--ByeBye = 0
|
||||
--Hello = 0
|
||||
--Matrix = 0
|
||||
--ClipboardText = 0
|
||||
--ClipboardImage = 0
|
||||
--Clipboard = 0
|
||||
--ClipboardDragDrop = 0
|
||||
--ClipboardDragDropEnd = 0
|
||||
--ClipboardAsk = 0
|
||||
--ExplorerDragDrop = 0
|
||||
--Nil = 0
|
||||
PackageID = 0
|
||||
QUEUE_SIZE = 50
|
||||
RecentProcessedPackageIDs = 32[]
|
||||
--[0] = 0
|
||||
--[1] = 0
|
||||
--[2] = 0
|
||||
--[3] = 0
|
||||
--[4] = 0
|
||||
--[5] = 0
|
||||
--[6] = 0
|
||||
--[7] = 0
|
||||
--[8] = 0
|
||||
--[9] = 0
|
||||
--[10] = 0
|
||||
--[11] = 0
|
||||
--[12] = 0
|
||||
--[13] = 0
|
||||
--[14] = 0
|
||||
--[15] = 0
|
||||
--[16] = 0
|
||||
--[17] = 0
|
||||
--[18] = 0
|
||||
--[19] = 0
|
||||
--[20] = 0
|
||||
--[21] = 0
|
||||
--[22] = 0
|
||||
--[23] = 0
|
||||
--[24] = 0
|
||||
--[25] = 0
|
||||
--[26] = 0
|
||||
--[27] = 0
|
||||
--[28] = 0
|
||||
--[29] = 0
|
||||
--[30] = 0
|
||||
--[31] = 0
|
||||
--[32] = 0
|
||||
--[33] = 0
|
||||
--[34] = 0
|
||||
--[35] = 0
|
||||
--[36] = 0
|
||||
--[37] = 0
|
||||
--[38] = 0
|
||||
--[39] = 0
|
||||
--[40] = 0
|
||||
--[41] = 0
|
||||
--[42] = 0
|
||||
--[43] = 0
|
||||
--[44] = 0
|
||||
--[45] = 0
|
||||
--[46] = 0
|
||||
--[47] = 0
|
||||
--[48] = 0
|
||||
--[49] = 0
|
||||
recentProcessedPackageIndex = 0
|
||||
processedPackageCount = 0
|
||||
skippedPackageCount = 0
|
||||
<JustGotAKey>k__BackingField = 0
|
||||
lastXY = {X=0,Y=0}
|
||||
--x = 0
|
||||
--y = 0
|
||||
--Empty = {X=0,Y=0}
|
||||
shownErrMessage = False
|
||||
lastStartServiceTime = 26/09/2024 20:35:51
|
||||
--_dateData = 5250315815941010854
|
||||
--MinValue = 01/01/0001 00:00:00
|
||||
--MaxValue = 31/12/9999 23:59:59
|
||||
--UnixEpoch = 01/01/1970 00:00:00
|
||||
SensitivePoints = Generic.List`1[Point]
|
||||
--_items = Point[]
|
||||
----System.Drawing.Point[] = Point[]: N/A
|
||||
--_size = 0
|
||||
--_version = 0
|
||||
--s_emptyArray = Point[]
|
||||
----System.Drawing.Point[] = Point[]: N/A
|
||||
p = {X=0,Y=0}
|
||||
--x = 0
|
||||
--y = 0
|
||||
--Empty = {X=0,Y=0}
|
||||
<IpcChannelCreated>k__BackingField = False
|
||||
BIG_CLIPBOARD_DATA_TIMEOUT = 30000
|
||||
MAX_CLIPBOARD_DATA_SIZE_CAN_BE_SENT_INSTANTLY_TCP = 1048576
|
||||
MAX_CLIPBOARD_FILE_SIZE_CAN_BE_SENT = 104857600
|
||||
TEXT_HEADER_SIZE = 12
|
||||
DATA_SIZE = 48
|
||||
TEXT_TYPE_SEP = {4CFF57F7-BEDD-43d5-AE8F-27A61E886F2F}
|
||||
TOGGLE_ICONS_SIZE = 4
|
||||
ICON_ONE = 0
|
||||
ICON_ALL = 1
|
||||
ICON_SMALL_CLIPBOARD = 2
|
||||
ICON_BIG_CLIPBOARD = 3
|
||||
ICON_ERROR = 4
|
||||
JUST_GOT_BACK_FROM_SCREEN_SAVER = 9999
|
||||
NETWORK_STREAM_BUF_SIZE = 1048576
|
||||
SymAlBlockSize = 16
|
||||
PW_LENGTH = 16
|
||||
HELPER_FORM_TEXT = Mouse without Borders Helper
|
||||
HelperProcessName = PowerToys.MouseWithoutBordersHelper
|
||||
MAX_LOG = 10000
|
||||
MaxLogExceptionPerHour = 1000
|
||||
HeaderSENT = Be{0},Ke{1},Mo{2},He{3},Mx{4},Tx{5},Im{6},By{7},Cl{8},Dr{9},De{10},Ed{11},Ie{12},Ni{13}
|
||||
HeaderRECEIVED = Be{0},Ke{1},Mo{2},He{3},Mx{4},Tx{5},Im{6},By{7},Cl{8},Dr{9},De{10},Ed{11},In{12},Ni{13},Pc{14}/{15}
|
||||
MAX_MACHINE = 4
|
||||
MAX_SOCKET = 8
|
||||
HEARTBEAT_TIMEOUT = 1500000
|
||||
SKIP_PIXELS = 1
|
||||
JUMP_PIXELS = 2
|
||||
PACKAGE_SIZE = 32
|
||||
PACKAGE_SIZE_EX = 64
|
||||
WP_PACKAGE_SIZE = 6
|
||||
KEYEVENTF_KEYDOWN = 1
|
||||
KEYEVENTF_KEYUP = 2
|
||||
WH_MOUSE = 7
|
||||
WH_KEYBOARD = 2
|
||||
WH_MOUSE_LL = 14
|
||||
WH_KEYBOARD_LL = 13
|
||||
WM_MOUSEMOVE = 512
|
||||
WM_LBUTTONDOWN = 513
|
||||
WM_RBUTTONDOWN = 516
|
||||
WM_MBUTTONDOWN = 519
|
||||
WM_XBUTTONDOWN = 523
|
||||
WM_LBUTTONUP = 514
|
||||
WM_RBUTTONUP = 517
|
||||
WM_MBUTTONUP = 520
|
||||
WM_XBUTTONUP = 524
|
||||
WM_LBUTTONDBLCLK = 515
|
||||
WM_RBUTTONDBLCLK = 518
|
||||
WM_MBUTTONDBLCLK = 521
|
||||
WM_MOUSEWHEEL = 522
|
||||
WM_KEYDOWN = 256
|
||||
WM_KEYUP = 257
|
||||
WM_SYSKEYDOWN = 260
|
||||
WM_SYSKEYUP = 261
|
||||
@@ -0,0 +1,161 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Collections.Concurrent;
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using MouseWithoutBorders.Core;
|
||||
|
||||
namespace MouseWithoutBorders.UnitTests.Core;
|
||||
|
||||
public static class LoggerTests
|
||||
{
|
||||
[TestClass]
|
||||
public sealed class PrivateDumpTests
|
||||
{
|
||||
/*
|
||||
[TestMethod]
|
||||
public void PrivateDumpShouldGenerateExpectedOutput()
|
||||
{
|
||||
// this was used to create the contents of "Logger.PrivateDump.original.txt"
|
||||
// when the "Core.Logger" class was "Common" in "Common.Log.cs"
|
||||
|
||||
// PrivateDump throws an ArgumentNullException if this is null
|
||||
Common.BinaryName = "MyBinary.dll";
|
||||
|
||||
// magic number from Settings.cs
|
||||
var dumpObjectsLevel = 6;
|
||||
|
||||
// copied from DumpObjects in Common.Log.cs
|
||||
var sb = new StringBuilder(1000000);
|
||||
var result = Common.PrivateDump(sb, new Common(), "[Other Logs]\r\n===============\r\n", 0, dumpObjectsLevel, false);
|
||||
var output = sb.ToString();
|
||||
}
|
||||
*/
|
||||
|
||||
[TestMethod]
|
||||
[Ignore(
|
||||
"This test relies on internal details of the dotnet platform and is sensitive to " +
|
||||
"the specific version of dotnet being used. As a result it's likely to fail if the " +
|
||||
"\"expected\" result was generated with a different version to the version used to " +
|
||||
"run the test, so we're going to ignore it in the CI build process.")]
|
||||
public void PrivateDumpShouldGenerateExpectedOutput()
|
||||
{
|
||||
static string NormalizeLog(string log)
|
||||
{
|
||||
var lines = log.Split("\r\n");
|
||||
|
||||
// some parts of the PrivateDump output are impossible to reproduce -
|
||||
// e.g. random numbers, system timestamps, thread ids, etc, so we'll mask them
|
||||
var maskPrefixes = new string[]
|
||||
{
|
||||
"----_s0 = ",
|
||||
"----_s1 = ",
|
||||
"----_s2 = ",
|
||||
"----_s3 = ",
|
||||
"<LastResumeSuspendTime>k__BackingField = ",
|
||||
"--_dateData = ",
|
||||
"lastJump = ",
|
||||
"lastStartServiceTime = ",
|
||||
"InitialIV = ",
|
||||
};
|
||||
for (var i = 0; i < lines.Length; i++)
|
||||
{
|
||||
foreach (var maskPrefix in maskPrefixes)
|
||||
{
|
||||
if (lines[i].StartsWith(maskPrefix, StringComparison.InvariantCulture))
|
||||
{
|
||||
// replace the trailing text with "?" characters
|
||||
lines[i] = string.Concat(
|
||||
lines[i].AsSpan(0, maskPrefix.Length),
|
||||
new string('?', 12));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// hide some of the internals of concurrent dictionary lock tables
|
||||
// as the size can vary across machines
|
||||
var removeLines = new string[]
|
||||
{
|
||||
"------[8] = 0",
|
||||
"------[9] = 0",
|
||||
"------[10] = 0",
|
||||
"------[11] = 0",
|
||||
"------[12] = 0",
|
||||
"------[13] = 0",
|
||||
"------[14] = 0",
|
||||
"------[15] = 0",
|
||||
};
|
||||
lines = lines.Where(line => !removeLines.Contains(line)).ToArray();
|
||||
|
||||
return string.Join("\r\n", lines);
|
||||
}
|
||||
|
||||
// PrivateDump throws an ArgumentNullException if this is null
|
||||
Common.BinaryName = "MyBinary.dll";
|
||||
|
||||
// default magic number from Settings.cs
|
||||
var settingsDumpObjectsLevel = 6;
|
||||
|
||||
// get the expected test result from an embedded resource
|
||||
var assembly = Assembly.GetExecutingAssembly();
|
||||
var resourceName = $"{typeof(LoggerTests).Namespace}.Logger.PrivateDump.expected.txt";
|
||||
using var stream = assembly.GetManifestResourceStream(resourceName)
|
||||
?? throw new InvalidOperationException();
|
||||
using var streamReader = new StreamReader(stream);
|
||||
var expected = streamReader.ReadToEnd();
|
||||
|
||||
// copied from DumpObjects in Common.Log.cs
|
||||
var sb = new StringBuilder(1000000);
|
||||
_ = Logger.PrivateDump(sb, Logger.AllLogs, "[Program logs]\r\n===============\r\n", 0, settingsDumpObjectsLevel, false);
|
||||
_ = Logger.PrivateDump(sb, new Common(), "[Other Logs]\r\n===============\r\n", 0, settingsDumpObjectsLevel, false);
|
||||
sb.AppendLine("[Logger Logs]\r\n===============");
|
||||
Logger.DumpType(sb, typeof(Logger), 0, settingsDumpObjectsLevel);
|
||||
var actual = sb.ToString();
|
||||
|
||||
expected = NormalizeLog(expected);
|
||||
actual = NormalizeLog(actual);
|
||||
|
||||
// Azure DevOps truncates debug output which makes it hard to see where
|
||||
// the expected and actual differ, so we need to write a custom error message
|
||||
// so we can just focus on the differences between expected and actual
|
||||
var expectedLines = expected.Split("\r\n");
|
||||
var actualLines = actual.Split("\r\n");
|
||||
for (var i = 0; i < Math.Min(expectedLines.Length, actualLines.Length); i++)
|
||||
{
|
||||
if (actualLines[i] != expectedLines[i])
|
||||
{
|
||||
var message = new StringBuilder();
|
||||
message.AppendLine(CultureInfo.InvariantCulture, $"{nameof(actual)} and {nameof(expected)} differ at line {i}:");
|
||||
|
||||
message.AppendLine();
|
||||
message.AppendLine($"{nameof(actual)}:");
|
||||
for (var j = i; j < Math.Min(i + 5, actualLines.Length); j++)
|
||||
{
|
||||
message.AppendLine(CultureInfo.InvariantCulture, $"[{j}]: {actualLines[j]}:");
|
||||
}
|
||||
|
||||
message.AppendLine();
|
||||
message.AppendLine($"{nameof(expected)}:");
|
||||
for (var j = i; j < Math.Min(i + 5, expectedLines.Length); j++)
|
||||
{
|
||||
message.AppendLine(CultureInfo.InvariantCulture, $"[{j}]: {expectedLines[j]}:");
|
||||
}
|
||||
|
||||
var x = new ConcurrentDictionary<string, string>(-1, 16);
|
||||
|
||||
Assert.Fail(message.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
// finally, throw an exception if the two don't match
|
||||
// just in case the above doesn't spot a difference
|
||||
// (e.g. different number of lines in the output)
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<!-- Look at Directory.Build.props in root for common stuff as well -->
|
||||
<Import Project="..\..\..\Common.Dotnet.CsWinRT.props" />
|
||||
<Import Project="..\..\..\Common.SelfContained.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<OutputType>Library</OutputType>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="Core\Logger.PrivateDump.expected.txt" />
|
||||
<None Remove="Core\Logger.PrivateDump.original.txt" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Core\Logger.PrivateDump.expected.txt" />
|
||||
<EmbeddedResource Include="Core\Logger.PrivateDump.original.txt" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MSTest" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\App\MouseWithoutBorders.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user