-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
82 lines (74 loc) · 2.73 KB
/
Program.cs
File metadata and controls
82 lines (74 loc) · 2.73 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.Threading.Tasks;
using System.Windows.Forms;
using MalwareDefense.Core;
using MalwareDefense.UI;
namespace MalwareDefense
{
static class Program
{
[STAThread]
static async Task Main()
{
Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// Check for administrator privileges
if (!IsRunningAsAdministrator())
{
MessageBox.Show(
"This application requires administrator privileges to function properly.\n\n" +
"Please restart the application as administrator.",
"Administrator Required",
MessageBoxButtons.OK,
MessageBoxIcon.Warning
);
return;
}
// Initialize engine and UI directly (no splash screen)
var engine = new MalwareDefenseEngine();
var controlPanel = new MainControlPanel(engine);
var alertSystem = new AlertSystem(controlPanel);
engine.SetAlertSystem(alertSystem);
// Show control panel immediately
controlPanel.Show();
Application.DoEvents();
try
{
// Start engine in background
_ = Task.Run(async () =>
{
try
{
await engine.StartAsync();
}
catch (Exception ex)
{
controlPanel.Invoke(new Action(() =>
{
MessageBox.Show(
$"Engine startup error: {ex.Message}\n\nSome features may not work properly.",
"Warning",
MessageBoxButtons.OK,
MessageBoxIcon.Warning
);
}));
}
});
// Run application with control panel as main form
Application.Run(controlPanel);
}
finally
{
engine.Dispose();
alertSystem.Dispose();
}
}
private static bool IsRunningAsAdministrator()
{
var identity = System.Security.Principal.WindowsIdentity.GetCurrent();
var principal = new System.Security.Principal.WindowsPrincipal(identity);
return principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator);
}
}
}