-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
140 lines (112 loc) · 4.72 KB
/
Program.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
134
135
136
137
138
139
140
using System;
using System.IO;
using System.Text;
namespace StartXemu
{
public class Program
{
// Author, tommojphillips. 06.04.2024
// Github, https://github.com/tommojphillips
private static StartXEMU config;
private static XSwitch switches;
private static void Main(string[] args)
{
init();
config = new StartXEMU();
try
{
parseArgs(args);
config.run(switches);
}
catch (Exception e)
{
Console.WriteLine("Error: " + e.Message);
Environment.ExitCode = 1;
}
cleanup();
}
private static void init()
{
Console.Title = "XEMU Console";
Console.CancelKeyPress += onCancelKeyPress;
}
private static void parseArgs(string[] args)
{
switches = new XSwitch();
bool hasSecondParam = false;
for (int i = 0; i < args.Length; i++)
{
string arg = args[i];
hasSecondParam = args.Length > i + 1 && !args[i + 1].StartsWith("-");
switch (arg)
{
case "-?":
printHelp();
Environment.Exit(0);
return;
case "-ls":
if (hasSecondParam)
{
switches.ls = true;
switches.lsSection = args[i + 1];
}
return;
case "-cmd":
switches.openPrompt = true;
if (hasSecondParam)
{
switches.cmd = args[i + 1];
i++;
}
break;
case "-qemu_cli":
switches.outputQEMU_cli = true;
break;
default:
Console.WriteLine($"Unknown switch: {arg}");
goto case "-?";
}
}
}
private static void printHelp()
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("XEMU Configuration Utility");
sb.AppendLine("# Overrides xemu settings prior to starting XEMU");
sb.AppendLine("# Settings are only updated if the associated environment variable is defined.");
sb.AppendLine("# Settings you want changed should be defined in the calling environment.");
sb.AppendLine($"\nUsage --> {Path.GetFileName(Environment.GetCommandLineArgs()[0])}");
sb.AppendLine("\nEnvironment variables:");
sb.AppendLine(" XEMU_DIR: - The directory where xemu is located");
sb.AppendLine(" XEMU_CFG: - The XEMU toml file to use");
sb.AppendLine(" XEMU_MCPX: - MCPX bin");
sb.AppendLine(" XEMU_BIOS: - BIOS bin");
sb.AppendLine(" XEMU_EEPROM: - eeprom bin");
sb.AppendLine(" XEMU_HDD: - hdd image; ( .qcow2, .img )");
sb.AppendLine(" XEMU_DVD: - dvd image; ( .iso )");
sb.AppendLine(" XEMU_MEM: - memory limit, 64 or 128");
sb.AppendLine(" XEMU_VIDEO: - video; ( hdtv, composite, vga, scart, svideo, rfu, none )");
sb.AppendLine(" XEMU_SIZE: - startup size; ( 640x480, 1280x720, etc )");
sb.AppendLine(" XEMU_POS: - position; ( CENTER=0, TOPL=1, TOPR=2, BOTL=3, BOTR=4 )");
sb.AppendLine(" XEMU_SKIP_ANI: - skip the boot animation, 0=false, 1=true");
sb.AppendLine("\nOptions:");
sb.AppendLine(" -? - Display this help message");
sb.AppendLine(" -ls - List all toml entries in the config file.");
sb.AppendLine(" -ls <section> - List all toml entries for a specific section");
sb.AppendLine(" -cmd <command> - Open a command prompt with the specified\n" +
" command while XEMU is running");
sb.AppendLine(" -qemu_cli - Output the QEMU command line to the console");
Console.WriteLine(sb.ToString());
}
// EVENT HANDLERS
private static void onCancelKeyPress(object sender, ConsoleCancelEventArgs e)
{
e.Cancel = true;
cleanup();
}
private static void cleanup()
{
Console.CancelKeyPress -= null;
}
}
}