-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApp.xaml.cs
More file actions
140 lines (122 loc) · 5.41 KB
/
Copy pathApp.xaml.cs
File metadata and controls
140 lines (122 loc) · 5.41 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// This file is part of BOINC.
// https://boinc.berkeley.edu
// Copyright (C) 2026 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// BOINC is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
using System;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace boinc_buda_runner_wsl_installer
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
public static bool IsQuiet { get; private set; }
// Exit codes for quiet mode
public const int ExitOk = 0;
public const int ErrUnsupportedWindows = 10;
public const int ErrWindowsFeaturesRestartRequired = 11;
public const int ErrWindowsFeaturesEnableFailed = 12;
public const int ErrWslCheckOrInstallFailed = 20;
public const int ErrBoincRunning = 30;
public const int ErrBudaRunnerInstallFailed = 40;
public const int ErrUnexpected = 100;
protected override async void OnStartup(StartupEventArgs e)
{
DebugLogger.LogInfo("Application starting up", "App");
var args = e.Args ?? new string[0];
var hasQuiet = args.Any(a => string.Equals(a, "--quiet", StringComparison.OrdinalIgnoreCase) || string.Equals(a, "-q", StringComparison.OrdinalIgnoreCase));
var hasVeryQuiet = args.Any(a => string.Equals(a, "-qq", StringComparison.OrdinalIgnoreCase));
IsQuiet = hasQuiet || hasVeryQuiet;
if (hasQuiet || hasVeryQuiet)
{
// Configure console logging channels
// -q: info+debug to stdout, errors to stderr
// -qq: info to stdout (optional) but NO debug; we silence debug by disabling console debug
DebugLogger.ConfigureConsoleLogging(infoEnabled: true, debugEnabled: !hasVeryQuiet, errorEnabled: true);
// Do not show any windows
ShutdownMode = ShutdownMode.OnExplicitShutdown;
int exitCode = await RunHeadlessInstallAsync();
DebugLogger.LogInfo($"Headless install finished with exit code {exitCode}", "App");
DebugLogger.Flush();
Environment.Exit(exitCode);
return;
}
// Normal (non-quiet) mode: show main window
var mainWindow = new MainWindow();
mainWindow.Show();
}
private async Task<int> RunHeadlessInstallAsync()
{
try
{
var window = new MainWindow();
// 1) Windows update check (we only inform; never stop for self-update)
window.ChangeRowIconAndStatus(ID.ApplicationUpdate, "BlueInfoIcon", "Checking for installer updates...");
await Task.Delay(10);
await window.CheckApplicationUpdateAsync();
// 2) BOINC process must not run
var boincOk = await window.CheckBoincProcess();
if (!boincOk)
{
return ErrBoincRunning;
}
// 3) Windows version
window.ChangeRowIconAndStatus(ID.WindowsVersion, "BlueInfoIcon", "Checking Windows version...");
await Task.Delay(10);
var isSupported = window.CheckWindowsVersionCompatibility();
if (!isSupported)
{
DebugLogger.LogError("Unsupported Windows version", "Headless");
return ErrUnsupportedWindows;
}
// 4) Windows features
var featuresOk = await window.CheckWindowsFeatures();
if (!featuresOk)
{
// Determine if this was because of restart required or general failure by reading last status
// We map any failure here to Windows features error; consumers can check logs for details.
return ErrWindowsFeaturesEnableFailed;
}
// 5) WSL check and install/fix
var wslOk = await window.CheckWsl();
if (!wslOk)
{
return ErrWslCheckOrInstallFailed;
}
// 6) BUDA Runner check/install
var budaOk = await window.CheckBudaRunner();
if (!budaOk)
{
return ErrBudaRunnerInstallFailed;
}
return ExitOk;
}
catch (Exception ex)
{
DebugLogger.LogException(ex, "Unexpected error during headless installation", "Headless");
return ErrUnexpected;
}
}
protected override void OnExit(ExitEventArgs e)
{
DebugLogger.LogInfo("Application shutting down", "App");
DebugLogger.Flush();
base.OnExit(e);
}
}
}