-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
58 lines (53 loc) · 1.85 KB
/
Program.cs
File metadata and controls
58 lines (53 loc) · 1.85 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
using System;
using System.Diagnostics;
using System.IO;
using System.Text.Json;
public class ExeConfiguration
{
public string EXEPath { get; set; }
}
class Program
{
static void Main()
{
string currentDir = AppDomain.CurrentDomain.BaseDirectory;
string configFilePath = Path.Combine(currentDir, "Configuration.json");
ExeConfiguration config;
if (!File.Exists(configFilePath))
{
// Create and save configuration
config = new ExeConfiguration { EXEPath = "" };
string json = JsonSerializer.Serialize(config, new JsonSerializerOptions { WriteIndented = true });
File.WriteAllText(configFilePath, json);
Console.WriteLine("Created Config file");
return;
}
else
{
try
{
string json = File.ReadAllText(configFilePath);
config = JsonSerializer.Deserialize<ExeConfiguration>(json);
}
catch (JsonException ex)
{
Console.WriteLine("Invalid JSON format in Configuration.json. Make sure there are only forward slashes in your path:");
Console.WriteLine(ex.Message);
return;
}
if (config == null||config.EXEPath=="")
{
Console.WriteLine("Failed to load configuration. Please check the Configuration.json file.");
return;
}
Console.WriteLine("Loaded EXEPath: " + config.EXEPath);
}
// Start the target process
Process firstProc = new();
firstProc.StartInfo.FileName = config.EXEPath;
firstProc.EnableRaisingEvents = true;
firstProc.StartInfo.WorkingDirectory = Path.GetDirectoryName(config.EXEPath);
firstProc.Start();
firstProc.WaitForExit();
}
}