-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMauiProgram.cs
More file actions
79 lines (65 loc) · 2.61 KB
/
MauiProgram.cs
File metadata and controls
79 lines (65 loc) · 2.61 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
using Microsoft.Extensions.Logging;
using Microsoft.Maui.Hosting;
using CommunityToolkit.Maui;
using System.IO;
namespace HexLoom
{
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.UseMauiCommunityToolkit()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});
string docsDir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\HexLoom";
if (!System.IO.Directory.Exists(docsDir))
System.IO.Directory.CreateDirectory(docsDir);
#if DEBUG
builder.Logging.AddDebug();
#endif
string[] args = Environment.GetCommandLineArgs();
if (args.Contains("--cmd"))
{
RunCommandLineMode(args);
Environment.Exit(0);
}
return builder.Build();
}
private static void RunCommandLineMode(string[] args)
{
Console.WriteLine("Running in CMD mode...");
List<string> argList = new List<string>(args);
String jsonPath = new String("");
bool hasJsonPath = false;
argList.ForEach(arg => {
if (arg.Contains(".json"))
jsonPath = arg;
});
if (jsonPath == null || jsonPath.Length == 0)
{
Console.WriteLine("Improper arguments. Exiting...");
Environment.Exit(0);
}
HexEditor.HexEditor hexEditor = new HexEditor.HexEditor();
Newtonsoft.Json.Linq.JObject project = Newtonsoft.Json.Linq.JObject.Parse(System.IO.File.ReadAllText(jsonPath));
ProjectSettings projectSettings = JsonHelpers.DeSerializeProjectSettings(project);
Byte[] binaryData = new Byte[0];
binaryData = System.IO.File.ReadAllBytes(projectSettings.InputFilePath);
if (binaryData == null)
return;
if (binaryData.Length == 0)
return;
hexEditor.SetBinaryData(binaryData);
hexEditor.SetBaseAddress(projectSettings.BaseAddress);
hexEditor._IsBigEndian = projectSettings.IsBigEndian;
EditorHelpers.ApplyFromJson(hexEditor, project);
System.IO.File.WriteAllBytes(projectSettings.OutputFilePath, binaryData);
}
}
}