-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCompilerWindow.axaml.cs
133 lines (129 loc) · 5.03 KB
/
CompilerWindow.axaml.cs
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
using System;
using System.Diagnostics;
using System.IO;
using System.Net.Http.Headers;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using Avalonia.Media;
using Avalonia.Platform.Storage;
using Avalonia.Threading;
namespace MoSpeedUI;
public partial class CompilerWindow : Window
{
private CancellationTokenSource _cancelT = new();
public CompilerWindow()
{
InitializeComponent();
this.Width = 800;
this.Height = 600;
//CompileOut.Height = ClientSize.Height - 100;
/*this.Resized += (_, e) =>
{
CompileOut.Height = e.ClientSize.Height / 2;
};*/
IStorageFile? fileout = Task.Run(SelectOutput).GetAwaiter().GetResult();
if (fileout == null)
{
ArgumentList.Text = Lang.Resources.CompileCancel;
ClsBtn.IsEnabled = true;
return;
}
ClsBtn.Content = Lang.Resources.Abort;
MainWindow.CompileConfig.OutputFile = fileout;
MainWindow.CompileConfig.ArgumentList = BuildArguments();
ArgumentList.Text = String.Format(Lang.Resources.UsingArguments, MainWindow.CompileConfig.ArgumentList);
Compile(_cancelT.Token);
MainWindow.CompileConfig.OutputFile = null;
ClsBtn.Content = Lang.Resources.Close;
}
private async void Compile(CancellationToken token)
{
bool isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
Process mospeed = new();
mospeed.StartInfo.WorkingDirectory = Shared.AppConfiguration.MoSpeedPath;
mospeed.StartInfo.FileName = Shared.AppConfiguration.JavaPath;
mospeed.StartInfo.UseShellExecute = false;
mospeed.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
if (isWindows)
{
mospeed.StartInfo.Arguments =
$"-cp basicv2.jar;dist/basicv2.jar com.sixtyfour.cbmnative.shell.MoSpeedCL {MainWindow.CompileConfig.ArgumentList}";
}
else
{
mospeed.StartInfo.Arguments =
$"-cp basicv2.jar:dist/basicv2.jar com.sixtyfour.cbmnative.shell.MoSpeedCL {MainWindow.CompileConfig.ArgumentList}";
}
mospeed.StartInfo.RedirectStandardOutput = true;
mospeed.EnableRaisingEvents = true;
mospeed.OutputDataReceived += (s, e) => AppendText(e.Data);
try
{
mospeed.Start();
mospeed.BeginOutputReadLine();
await mospeed.WaitForExitAsync(token);
ClsBtn.IsEnabled = true;
}
catch (TaskCanceledException)
{
return;
}
}
private void AppendText(string? text)
{
if (!string.IsNullOrEmpty(text))
{
Dispatcher.UIThread.Post(() =>
{
CompileOut.Text += text + Environment.NewLine;
CompileOut.CaretIndex = int.MaxValue;
});
}
}
private async Task<IStorageFile?> SelectOutput()
{
int count = 3;
IStorageFile? file = null;
while (file == null)
{
if (count <= 0)
{
break;
}
file = await this.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions()
{
Title = String.Format(Lang.Resources.SaveFilePickerTitle, MainWindow.CompileConfig.CurrentFile.Name,
count),
SuggestedFileName = $"++{MainWindow.CompileConfig.CurrentFile.Name}.prg",
DefaultExtension = "prg",
});
count--;
}
return file;
}
private string BuildArguments()
{
CompileConfig cc = MainWindow.CompileConfig;
return $"/target=\"{Uri.UnescapeDataString(cc.OutputFile?.Path.AbsolutePath)}\" /platform={cc.TargetPlatform?.Invoke()} " +
$"/memconfig={cc.Vc20Conf.Invoke()} /bigram={cc.C64Conf.ToString().ToLower()} /progstart={(string.IsNullOrWhiteSpace(cc.ProgramStartAdd) ? "2072" : cc.ProgramStartAdd)} " +
(string.IsNullOrWhiteSpace(cc.VariableStartAdd) ? "" : $" /varstart={cc.VariableStartAdd}") +
(string.IsNullOrWhiteSpace(cc.StringMemEndAdd) ? "" : $" /varend={cc.StringMemEndAdd}") +
(string.IsNullOrWhiteSpace(cc.RuntimeStartAdd) ? "" : $" /runtimestart={cc.RuntimeStartAdd}") +
(string.IsNullOrWhiteSpace(cc.MemHoles) ? "" : $" /memhole={cc.MemHoles}") +
$" /compactlevel={cc.CompactLevel} /tolower={cc.LowerSrc} /flipcase={cc.FlipSrcCase} /loopopt={cc.RemLoops} " +
$"/multipart={cc.SplitOutput}" + (string.IsNullOrWhiteSpace(cc.ExtendedArguments) ? "" : $" {cc.ExtendedArguments}") +
$" \"{Uri.UnescapeDataString(cc.CurrentFile.Path.AbsolutePath)}\"";
}
private void Button_OnClick(object? sender, RoutedEventArgs e)
{
_cancelT.Cancel();
this.Close();
}
}