/// <summary> /// Form Shown Event Handler /// </summary> /// <param name="sender">Sender</param> /// <param name="e">EventArgs</param> private void Form1_Shown(object sender, EventArgs e) { string[] arguments = Environment.GetCommandLineArgs(); int protectPid = -1; if (arguments.Length == 3 && arguments[1] == "protect") { protectPid = (int.TryParse(arguments[2], out int result)) ? result : -1; } if (protectPid == -1) { #if DEBUG LoadDebugWindow(); #endif //LoadToTraybar(); qrCodeGenerator = new QRGenerator(); qrCodeGenerator.SetData(AndroidServer.GetLocalIPAddress(), 9624); LoadKeyGeneration(); LoadAndroidServer(); LoadJavascriptServer(); int protectorPID = -1; if (arguments.Length == 3 && arguments[1] == "lock") { protectorPID = (int.TryParse(arguments[2], out int result)) ? result : -1; if (!WindowsLocking.CanLock()) { protectorPID = -1; } } systemLocking = new WindowsLocking(qrCodeGenerator, androidServer, protectorPID); if (protectorPID != -1) { androidServer.SendLockSignal(); } if (arguments.Length == 2 && arguments[2] == "forcelock" && WindowsLocking.CanLock()) { androidServer.SendLockSignal(); } } else { Hide(); ProcessLocker locker = new ProcessLocker(); locker.StartProtectProcess(protectPid, $"lock {System.Diagnostics.Process.GetCurrentProcess().Id}"); } }
/// <summary> /// Constructor /// </summary> /// <param name="qrCodeGenerator">QR Code Generator</param> /// <param name="server">Android Server Instance</param> /// <param name="previousLockerID">Previously protected PID</param> public WindowsLocking(QRGenerator qrCodeGenerator, AndroidServer server, int previousLockerID) { qrGenerator = qrCodeGenerator; locker = new ProcessLocker(); previousProtectionPID = previousLockerID; server.LockStateChanged += new Action <AndroidServer.LockState>((state) => { if (state == AndroidServer.LockState.Failed) { Form1.WriteLine("Lock or Unlock Failed"); } else if (state == AndroidServer.LockState.Locked) { Form1.WriteLine("Locking System"); LockSystem(); } else { Form1.WriteLine("Unlocking system"); UnlockSystem(); } }); }