-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
87 lines (80 loc) · 2.74 KB
/
Program.cs
File metadata and controls
87 lines (80 loc) · 2.74 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
using MulderConfig.Actions;
using MulderConfig.Configuration;
using MulderConfig.Save;
using MulderConfig.Apply;
using MulderConfig.UI;
using MulderConfig;
namespace MulderConfig;
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
// Read and validate config
ConfigModel config;
try
{
config = ConfigProvider.GetConfig();
}
catch (Exception ex)
{
MessageBox.Show($"Error loading configuration:\n{ex.Message}");
return;
}
if (!ConfigValidator.IsValid(config))
{
MessageBox.Show("Error loading configuration:\nThe file 'MulderConfig.json' has invalid data.");
return;
}
// Initialize core components
var exeReplacer = new ExeReplacer(config);
var fileOperationManager = new FileOperationManager();
var modeDetector = new ModeDetector(config, args);
var saveLoader = new SaveLoader();
var saveSaver = new SaveSaver(saveLoader);
var steamAddonHandler = new SteamAddonHandler(config, args);
var applyManager = new ApplyManager(config, exeReplacer, fileOperationManager);
// Handle Steam Addons
var steamAddonId = steamAddonHandler.ResolveAddonId();
var title = steamAddonHandler.ResolveAddonTitle(steamAddonId) ?? config.Game.Title;
// Select current addon save
saveLoader.LoadAll();
var save = saveLoader.Load(title);
if (!SaveValidator.IsValid(config, save))
{
MessageBox.Show($"Invalid configuration for {title}.\nThe save file may be corrupted (delete MulderConfig.save.json).");
return;
}
// Run App
if (modeDetector.IsApplyMode())
{
applyManager.Apply(title, save);
}
else if (modeDetector.IsLaunchMode())
{
var launchManager = new LaunchManager(config, title, save);
launchManager.Launch();
}
else
{
// Initialize UI components
var formSelectionProvider = new FormSelectionProvider(config);
var formValidator = new FormValidator(config, formSelectionProvider);
var formBuilder = new FormBuilder(formValidator, formSelectionProvider);
// Normal UI mode
ApplicationConfiguration.Initialize();
Application.Run(new Form1(
title,
config,
applyManager,
formBuilder,
formValidator,
formSelectionProvider,
saveLoader,
saveSaver));
}
}
}