-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
67 lines (57 loc) · 2.5 KB
/
Copy pathmain.cpp
File metadata and controls
67 lines (57 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "MyForm.h"
#include "src/watchdog/RecoveryLoopFailsafe.h"
using namespace System;
using namespace System::Windows::Forms;
using namespace Windows_Hello_Fix_v2_0;
[STAThreadAttribute]
int main(array<String^>^ args)
{
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
MyForm form;
// Check for the background argument passed by Task Scheduler
bool runHidden = false;
for (int i = 0; i < args->Length; i++) {
if (args[i] == L"--background" || args[i] == L"/background" ||
args[i] == L"--disable-camera" || args[i] == L"/disable-camera" ||
args[i] == L"--enable-camera" || args[i] == L"/enable-camera" ||
args[i] == L"/restore-camera" || args[i] == L"/repair-camera") {
runHidden = true;
break;
}
}
if (runHidden) {
// Make the window completely invisible while keeping WndProc alive
form.Opacity = 0;
form.ShowInTaskbar = false;
form.WindowState = FormWindowState::Minimized;
}
// RecoveryLoopFailsafe: owned outside src/core (extreme core-preservation).
// Only for long-lived daemon - never for short-lived command workers.
bool isCommandWorker = false;
for (int i = 0; i < args->Length; i++) {
if (args[i]->Equals(L"--disable-camera", StringComparison::OrdinalIgnoreCase) ||
args[i]->Equals(L"/disable-camera", StringComparison::OrdinalIgnoreCase) ||
args[i]->Equals(L"--enable-camera", StringComparison::OrdinalIgnoreCase) ||
args[i]->Equals(L"/enable-camera", StringComparison::OrdinalIgnoreCase) ||
args[i]->Equals(L"/restore-camera", StringComparison::OrdinalIgnoreCase) ||
args[i]->Equals(L"/repair-camera", StringComparison::OrdinalIgnoreCase)) {
isCommandWorker = true;
break;
}
}
RecoveryLoopFailsafe^ recoveryLoop = nullptr;
if (!isCommandWorker) {
try {
recoveryLoop = gcnew RecoveryLoopFailsafe(%form);
form.Load += gcnew EventHandler(recoveryLoop, &RecoveryLoopFailsafe::OnOwnerLoad);
form.FormClosing += gcnew FormClosingEventHandler(recoveryLoop, &RecoveryLoopFailsafe::OnOwnerClosing);
} catch (...) {
recoveryLoop = nullptr;
}
}
Application::Run(%form);
// Ensure Disarm on exit if loop was armed (also handled by FormClosing).
try { if (recoveryLoop != nullptr) recoveryLoop->Disarm(); } catch (...) {}
return 0;
}