-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainForm.cs
221 lines (162 loc) · 7.16 KB
/
MainForm.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
using System.ComponentModel;
using System.Diagnostics;
using System.Reflection;
using System.Security.Principal;
namespace GH3MLGUI;
public partial class MainForm : Form
{
public static void OpenDirectory(string path) => Process.Start("explorer.exe", path);
public Dictionary<string, (string path, ModSettings settings)> ModList { get; private set; } = new Dictionary<string, (string path, ModSettings settings)>();
public void RefreshModList()
{
if (!Directory.Exists(Program.GH3MLModDirectory))
Directory.CreateDirectory(Program.GH3MLModDirectory);
// TODO: SAVE UNCHECKED MOD MOVEMENT
ModList.Clear();
modCheckedListBox.Items.Clear();
modCheckedListBox.Tag = Array.Empty<string>();
var directories = Directory.GetDirectories(Program.GH3MLModDirectory);
foreach (var dir in directories)
{
var modInfoPath = Path.Combine(dir, "modinfo.json");
if (!Program.CheckPathExists(modInfoPath))
continue;
var settings = ModSettings.Read(modInfoPath);
ModList.Add(settings.Name, (modInfoPath, settings));
}
// TODO: reorder some stuff?
modCheckedListBox.Tag = new string[ModList.Count];
string[]? modCheckedListNames = modCheckedListBox.Tag as string[];
int indexer = 0;
foreach (var kv in ModList)
{
modCheckedListBox.Items.Add(kv.Value.settings.DisplayName);
modCheckedListNames![indexer++] = kv.Key;
}
foreach (var enabledMod in Program.Settings.EnabledMods)
{
var index = Array.IndexOf(modCheckedListNames!, enabledMod);
if (index != -1)
modCheckedListBox.SetItemChecked(index, true);
}
}
public MainForm()
{
InitializeComponent();
}
private void MainForm_Load(object sender, EventArgs e)
{
versionToolStripLabel.Text = $"GUI v{Program.VersionString}";
if (Path.Exists(Path.Combine(Program.GuitarHero3GameDirectory, "gh3ml.dll")))
{
installLoaderToolStripButton.Text = "Uninstall Loader";
installLoaderToolStripButton.Tag = true;
}
else
{
installLoaderToolStripButton.Text = "Install Loader";
installLoaderToolStripButton.Tag = false;
}
var dirToDisplay = Program.GuitarHero3GameDirectory;
if (dirToDisplay.StartsWith(Environment.GetEnvironmentVariable("ProgramFiles(x86)")!))
dirToDisplay = "%ProgramFiles(x86)%\\Aspyr\\Guitar Hero III\\";
gamePathLinkLabel.Text = $"Game Path: {dirToDisplay}";
dirToDisplay = Program.GuitarHero3SaveDirectory;
if (dirToDisplay.StartsWith(Environment.GetEnvironmentVariable("LocalAppData")!))
dirToDisplay = "%LocalAppData%\\Aspyr\\Guitar Hero III\\";
savePathLinkLabel.Text = $"Save Path: {dirToDisplay}";
modCheckedListBox.Tag = Array.Empty<string>();
RefreshModList();
}
#region Toolstrip
private void installLoaderToolStripButton_Click(object sender, EventArgs e)
{
if (sender is not ToolStripButton control)
return;
if ((bool)(control?.Tag ?? false))
{
Program.UninstallLoader(Program.GuitarHero3GameDirectory);
installLoaderToolStripButton.Text = "Install Loader";
installLoaderToolStripButton.Tag = false;
}
else
{
Program.InstallLoader(Program.GuitarHero3GameDirectory);
installLoaderToolStripButton.Text = "Uninstall Loader";
installLoaderToolStripButton.Tag = true;
}
}
private void saveToolStripButton_Click(object sender, EventArgs e)
{
Program.Settings.EnabledMods = Array.Empty<string>();
List<string> enabledMods = new();
for (var i = 0; i < modCheckedListBox.Items.Count; i++)
{
if (modCheckedListBox.GetItemChecked(i))
enabledMods.Add(((string[])modCheckedListBox.Tag!)[i]);
}
Program.Settings.EnabledMods = enabledMods.ToArray();
GH3MLSettings.Write(Program.Settings);
}
private void settingsToolStripButton_Click(object sender, EventArgs e)
{
using SettingsForm form = new SettingsForm();
form.OpenGH3Console = Program.Settings.OpenGH3Console;
form.AllowQScriptPrintf = Program.Settings.AllowQScriptPrintf;
form.ModLogType = Program.Settings.ModLogType;
form.WindowStyle = Program.Settings.WindowStyle;
if (form.ShowDialog() == DialogResult.OK)
{
Program.Settings.OpenGH3Console = form.OpenGH3Console;
Program.Settings.AllowQScriptPrintf = form.AllowQScriptPrintf;
Program.Settings.ModLogType = form.ModLogType;
Program.Settings.WindowStyle = form.WindowStyle;
GH3MLSettings.Write(Program.Settings);
}
}
private void aboutToolStripButton_Click(object sender, EventArgs e)
{
using AboutForm form = new();
form.ShowDialog();
}
#endregion
#region Mod Context Menu
private void pluginContextMenuStrip_Opening(object sender, CancelEventArgs e)
{
var index = modCheckedListBox.IndexFromPoint(modCheckedListBox.PointToClient(MousePosition));
if (index != -1)
modCheckedListBox.SelectedIndex = index;
moveModUpToolStripMenuItem.Enabled = index != -1 && modCheckedListBox.Items.Count > 1 && index > 0;
moveModDownToolStripMenuItem.Enabled = index != -1 && modCheckedListBox.Items.Count > 1 && index < modCheckedListBox.Items.Count - 1;
}
private void refreshToolStripMenuItem_Click(object sender, EventArgs e)
{
RefreshModList();
}
private void MoveModIndex(int index, int sign)
{
var itemA = modCheckedListBox.Items[modCheckedListBox.SelectedIndex];
var itemB = modCheckedListBox.Items[modCheckedListBox.SelectedIndex + Math.Sign(sign)];
modCheckedListBox.Items[modCheckedListBox.SelectedIndex] = itemB;
modCheckedListBox.Items[modCheckedListBox.SelectedIndex + Math.Sign(sign)] = itemA;
}
private void moveModUpToolStripMenuItem_Click(object sender, EventArgs e) => MoveModIndex(modCheckedListBox.SelectedIndex, -1);
private void moveModDownToolStripMenuItem_Click(object sender, EventArgs e) => MoveModIndex(modCheckedListBox.SelectedIndex, 1);
#endregion
#region Link Labels
private void gamePathLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) => OpenDirectory(Program.GuitarHero3GameDirectory);
private void savePathLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) => OpenDirectory(Program.GuitarHero3SaveDirectory);
#endregion
private void launchGH3Button_Click(object sender, EventArgs e)
{
ProcessStartInfo gh3Info = new();
gh3Info.FileName = Path.Combine(Program.GuitarHero3GameDirectory, "gh3.exe");
gh3Info.UseShellExecute = true;
Process.Start(gh3Info);
Application.Exit();
}
private void checkForLoaderUpdatesToolStripButton_Click(object sender, EventArgs e)
{
MessageBox.Show("TODO: THIS");
}
}