-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuildOutputWindow.xaml.cs
More file actions
161 lines (144 loc) · 6.1 KB
/
BuildOutputWindow.xaml.cs
File metadata and controls
161 lines (144 loc) · 6.1 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
using System;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using System.Windows;
namespace Sm64DecompLevelViewer
{
public partial class BuildOutputWindow : Window
{
private readonly string _projectRoot;
private readonly string _emulatorPath;
private bool _isBuildSuccessful = false;
public BuildOutputWindow(string projectRoot, string emulatorPath)
{
InitializeComponent();
_projectRoot = projectRoot;
_emulatorPath = emulatorPath;
Loaded += async (s, e) => await StartBuildAsync();
}
private async Task StartBuildAsync()
{
StatusText.Text = "Building...";
LogTextBox.AppendText($"> Building project in: {_projectRoot}\n");
try
{
// Run wsl make -j8 COMPARE=0
var startInfo = new ProcessStartInfo
{
FileName = "wsl",
Arguments = $"make -j8 COMPARE=0",
WorkingDirectory = _projectRoot,
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true
};
using (var process = new Process { StartInfo = startInfo })
{
process.OutputDataReceived += (s, e) => AppendLog(e.Data);
process.ErrorDataReceived += (s, e) => AppendLog(e.Data);
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
await Task.Run(() => process.WaitForExit());
_isBuildSuccessful = process.ExitCode == 0;
if (_isBuildSuccessful)
{
// Check if ROM exists even if make succeeded
if (RomExists())
{
MainStatusBar.Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(40, 167, 69)); // Green
StatusText.Text = "Build Succeeded!";
LogTextBox.AppendText("\n> BUILD SUCCESSFUL!\n");
if (!string.IsNullOrEmpty(_emulatorPath) && File.Exists(_emulatorPath))
{
LogTextBox.AppendText($"> Launching emulator: {Path.GetFileName(_emulatorPath)}\n");
LaunchEmulator();
}
else
{
LogTextBox.AppendText("> No emulator path configured or emulator not found. Build only.\n");
}
}
else
{
_isBuildSuccessful = false;
MainStatusBar.Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(220, 53, 69)); // Red
StatusText.Text = "Build Error: ROM Not Found";
LogTextBox.AppendText("\n> ERROR: make reported success, but no ROM file was found in build/.\n");
}
}
else
{
MainStatusBar.Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(220, 53, 69)); // Red
StatusText.Text = "Build Failed";
LogTextBox.AppendText($"\n> BUILD FAILED with exit code {process.ExitCode}\n");
}
}
}
catch (Exception ex)
{
MainStatusBar.Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(220, 53, 69)); // Red
LogTextBox.AppendText($"\n> FATAL ERROR: {ex.Message}\n");
StatusText.Text = "Execution Error";
}
}
private bool RomExists()
{
string[] potentialRoms = {
Path.Combine(_projectRoot, "build", "us", "sm64.us.z64"),
Path.Combine(_projectRoot, "build", "jp", "sm64.jp.z64"),
Path.Combine(_projectRoot, "build", "eu", "sm64.eu.z64")
};
foreach (var p in potentialRoms)
{
if (File.Exists(p)) return true;
}
return false;
}
private void AppendLog(string? data)
{
if (data == null) return;
Dispatcher.Invoke(() =>
{
LogTextBox.AppendText(data + "\n");
LogScrollViewer.ScrollToEnd();
});
}
private void LaunchEmulator()
{
try
{
// Find the built ROM. Usually build/us/sm64.us.z64
// We should check common locations
string[] potentialRoms = {
Path.Combine(_projectRoot, "build", "us", "sm64.us.z64"),
Path.Combine(_projectRoot, "build", "jp", "sm64.jp.z64"),
Path.Combine(_projectRoot, "build", "eu", "sm64.eu.z64")
};
string? romPath = null;
foreach (var p in potentialRoms)
{
if (File.Exists(p))
{
romPath = p;
break;
}
}
if (romPath != null)
{
Process.Start(_emulatorPath, $"\"{romPath}\"");
}
else
{
Dispatcher.Invoke(() => LogTextBox.AppendText("> ERROR: Built ROM not found in build/ subfolders.\n"));
}
}
catch (Exception ex)
{
Dispatcher.Invoke(() => LogTextBox.AppendText($"> ERROR launching emulator: {ex.Message}\n"));
}
}
}
}