-
Notifications
You must be signed in to change notification settings - Fork 2
/
GBModPrompt.xaml.cs
442 lines (379 loc) · 15.4 KB
/
GBModPrompt.xaml.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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Concursus.Classes;
using SevenZipExtractor;
namespace Concursus
{
/// <summary>
/// Interaction logic for GBModPrompt.xaml
/// </summary>
public partial class GBModPrompt : Window
{
static string DESCRIPTION_HTML = @"
<html>
<head>
<style>
* {
font-family: Arial, Helvetica, sans-serif;
}
</style>
</head>
<body>
[REPLACE]
</body>
</html>
";
public GamebananaMod mod;
public GBModPrompt()
{
new GBModPrompt(null, null).ShowDialog();
this.Close();
}
private void Log(string message)
{
try
{
File.AppendAllText("modmanager.log", $"{DateTime.Now}: {message}\n");
}
catch (Exception ex)
{
// Optional: Handle logging errors, maybe write to a different file or console
}
}
public GBModPrompt(string game_id = null, string mod_id = null)
{
Log("Constructor started");
this.WindowStartupLocation = WindowStartupLocation.CenterScreen;
Log("WindowStartupLocation set");
if (game_id == null && mod_id == null)
{
Log("game_id and mod_id are null, parsing command line arguments");
string[] args = Environment.GetCommandLineArgs();
Log($"Command line arguments count: {args.Length}");
if (args.Length != 2)
return;
string arg = args[1];
Log($"Argument extracted: {arg}");
if (arg.StartsWith(Utils.MM_PROTOCOL_LINK))
arg = arg.Substring((Utils.MM_PROTOCOL_LINK).Length);
Log($"Processed argument: {arg}");
string[] res = arg.Trim().Replace("\\", "/").Trim('/').Split('_');
Log($"Argument split into: {String.Join(", ", res)}");
if (res.Length != 2)
return;
game_id = res[0];
mod_id = res[1];
Log($"game_id: {game_id}, mod_id: {mod_id}");
}
mod = GamebananaMod.GetModInfoFromID(game_id, mod_id);
Log($"Mod fetched: {mod?.name ?? "null"}");
InitializeComponent();
Log("InitializeComponent called");
Themes.UpdateForm(Themes.CURRENT_THEME, this);
Log("Themes updated");
if (mod == null)
{
Log($"Failed getting mod with id {mod_id}");
MessageBox.Show($"Failed getting mod with id {mod_id}!", "Failed getting mod", MessageBoxButton.OK, MessageBoxImage.Error);
Environment.Exit(-1);
}
this.Title = $"Download {mod.name} for {mod.GameName}";
this.txtGame.Text = mod.GameName;
this.txtModName.Text = mod.name;
this.txtSubmitter.Text = mod.submitter;
this.txtVersion.Text = mod.version;
BitmapImage bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.UriSource = new Uri(mod.images[0], UriKind.Absolute);
bitmap.EndInit();
image.Source = bitmap;
string description = DESCRIPTION_HTML.Replace("[REPLACE]", mod.description);
broDescription.NavigateToString(description);
cboFiles.ItemsSource = mod.files;
cboFiles.SelectedIndex = 0;
}
private async void btnDownload_Click(object sender, RoutedEventArgs e)
{
Progress<string> progress = new Progress<string>(e => {
txtProgress.Text += $"{e}\n";
txtProgress.ScrollToEnd();
});
btnDownload.IsEnabled = false;
string dl_link = mod.files[cboFiles.SelectedValue.ToString()].download_link;
byte[] data = null;
await Task.Run(() =>
{
data = Utils.Download(dl_link, progress);
});
if (data == null)
{
MessageBox.Show($"Failed to download {dl_link}!", "Failed", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
string output_dir = mod.mod_dir_path;
txtProgress.Text += $"Reading archive...\n";
string parent = "";
bool found_data_dir = false;
bool foundCBBFile = false;
bool foundCBBCypher = false;
bool foundAudioFiles = false;
using (MemoryStream stream = new MemoryStream(data))
using (ArchiveFile archiveFile = new ArchiveFile(stream))
{
foreach (var entry in archiveFile.Entries)
{
// ...
string fileExtension = System.IO.Path.GetExtension(entry.FileName).ToLower();
if (fileExtension == ".mp3" || fileExtension == ".wav" || fileExtension == ".flac" || fileExtension == ".ogg" || fileExtension == ".xm")
{
foundAudioFiles = true;
// Prompt the user to choose between different options
MessageBoxResult result = MessageBox.Show($"Is this a BombRushRadio mod?", $"{fileExtension.ToUpper()} File Detected", MessageBoxButton.YesNo, MessageBoxImage.Question);
if (result == MessageBoxResult.Yes)
{
}
// Continue processing other entries
continue;
}
}
if (foundAudioFiles)
{
// Add specific actions for audio files
txtProgress.Text += $"Found an audio file! Handling it separately...\n";
parent = mod.GetValidFolderName();
output_dir = System.IO.Path.Combine(output_dir, mod.GetValidFolderName());
found_data_dir = true;
// Create the required directory structure inside the mod folder
string pluginsFolder = System.IO.Path.Combine(output_dir, "plugins");
string audiodata = System.IO.Path.Combine(pluginsFolder, "Bomb Rush Cyberfunk_Data");
string streamlikenetflix = System.IO.Path.Combine(audiodata, "StreamingAssets");
string modslikedniwetamp = System.IO.Path.Combine(streamlikenetflix, "Mods");
string BombRushRadio = System.IO.Path.Combine(modslikedniwetamp, "BombRushRadio");
string Songs1 = System.IO.Path.Combine(BombRushRadio, "Songs");
// Check if the directories exist, and create them if not
if (!Directory.Exists(pluginsFolder)) Directory.CreateDirectory(pluginsFolder);
if (!Directory.Exists(audiodata)) Directory.CreateDirectory(audiodata);
if (!Directory.Exists(streamlikenetflix)) Directory.CreateDirectory(streamlikenetflix);
if (!Directory.Exists(modslikedniwetamp)) Directory.CreateDirectory(modslikedniwetamp);
if (!Directory.Exists(BombRushRadio)) Directory.CreateDirectory(BombRushRadio);
if (!Directory.Exists(Songs1)) Directory.CreateDirectory(Songs1);
// Move audio files to the Songs folder
foreach (var fileEntry in archiveFile.Entries)
{
string entryFileName = fileEntry.FileName;
if (entryFileName.EndsWith(".mp3", StringComparison.OrdinalIgnoreCase) ||
entryFileName.EndsWith(".flac", StringComparison.OrdinalIgnoreCase) ||
entryFileName.EndsWith(".wav", StringComparison.OrdinalIgnoreCase) ||
entryFileName.EndsWith(".ogg", StringComparison.OrdinalIgnoreCase) ||
entryFileName.EndsWith(".xm", StringComparison.OrdinalIgnoreCase))
{
// Construct the destination path inside the Songs folder
string destinationPath = System.IO.Path.Combine(Songs1, System.IO.Path.GetFileName(entryFileName));
// Extract and move the file
using (FileStream fs = File.Create(destinationPath))
{
fileEntry.Extract(fs);
}
// Display a message
txtProgress.Text += $"Moved {entryFileName} to BombRushRadio's Songs folder.\n";
string dataFolder = System.IO.Path.Combine(output_dir, mod.GameFolderDataName);
if (!Directory.Exists(dataFolder)) Directory.CreateDirectory(dataFolder);
}
}
}
foreach (var entry in archiveFile.Entries)
{
List<string> split = entry.FileName.Split(new char[] { '\\', '/' }).ToList();
int idx = split.IndexOf(mod.GameFolderDataName);
if (entry.FileName.EndsWith(".cbb", StringComparison.OrdinalIgnoreCase))
{
// Prompt the user to choose between "no" and "no_cypher"
MessageBoxResult result = MessageBox.Show("Do you want the mod to go in 'no_cypher'?", "CBB File Detected", MessageBoxButton.YesNo, MessageBoxImage.Question);
if (result == MessageBoxResult.Yes)
{
// User chose "Yes," set foundCBBCypher to true
foundCBBCypher = true;
}
else
{
// User chose "No," set foundCBBFile to true
foundCBBFile = true;
}
// Continue
continue;
}
if (foundCBBFile)
{
// Add specific actions in here for cbb shit, can copy pasta for other files :adachi_true:
txtProgress.Text += $"Found a .cbb file! Handling it separately...\n";
parent = mod.GetValidFolderName();
output_dir = System.IO.Path.Combine(output_dir, mod.GetValidFolderName());
found_data_dir = true;
// Create the required directory structure inside the mod folder
string pluginsFolder = System.IO.Path.Combine(output_dir, "plugins");
string bepInExFolder = System.IO.Path.Combine(pluginsFolder, "BepInEx");
string configFolder = System.IO.Path.Combine(bepInExFolder, "config");
string crewBoomFolder = System.IO.Path.Combine(configFolder, "CrewBoom");
// Check if the directories exist, and create them if not
if (!Directory.Exists(pluginsFolder)) Directory.CreateDirectory(pluginsFolder);
if (!Directory.Exists(bepInExFolder)) Directory.CreateDirectory(bepInExFolder);
if (!Directory.Exists(configFolder)) Directory.CreateDirectory(configFolder);
if (!Directory.Exists(crewBoomFolder)) Directory.CreateDirectory(crewBoomFolder);
// Move .cbb and .json files to the CrewBoom folder
foreach (var fileEntry in archiveFile.Entries)
{
string entryFileName = fileEntry.FileName;
if (entryFileName.EndsWith(".cbb", StringComparison.OrdinalIgnoreCase) ||
entryFileName.EndsWith(".json", StringComparison.OrdinalIgnoreCase))
{
// Construct the destination path inside the CrewBoom folder
string destinationPath = System.IO.Path.Combine(crewBoomFolder, System.IO.Path.GetFileName(entryFileName));
if (entryFileName.EndsWith(".cbb", StringComparison.OrdinalIgnoreCase))
{
// For .cbb files, read the content into a MemoryStream and then write to the destination
using (MemoryStream memoryStream = new MemoryStream())
{
fileEntry.Extract(memoryStream);
File.WriteAllBytes(destinationPath, memoryStream.ToArray());
}
}
else
{
// For other files, extract and move as before
using (FileStream fs = File.Create(destinationPath))
{
fileEntry.Extract(fs);
}
}
// Crewboom message
txtProgress.Text += $"Moved {entryFileName} to CrewBoom folder.\n";
string dataFolder = System.IO.Path.Combine(output_dir, mod.GameFolderDataName);
if (!Directory.Exists(dataFolder)) Directory.CreateDirectory(dataFolder);
}
}
}
if (foundCBBCypher)
{
txtProgress.Text += $"Found a .cbb file! Handling it separately...\n";
parent = mod.GetValidFolderName();
output_dir = System.IO.Path.Combine(output_dir, parent);
found_data_dir = true;
// Create the required directory structure inside the mod folder
string pluginsFolder = System.IO.Path.Combine(output_dir, "plugins");
string bepInExFolder = System.IO.Path.Combine(pluginsFolder, "BepInEx");
string configFolder = System.IO.Path.Combine(bepInExFolder, "config");
string crewBoomFolder = System.IO.Path.Combine(configFolder, "CrewBoom");
string noCypherFolder = System.IO.Path.Combine(crewBoomFolder, "no_cypher");
// Check if the directories exist, and create them if not
if (!Directory.Exists(output_dir)) Directory.CreateDirectory(output_dir);
if (!Directory.Exists(pluginsFolder)) Directory.CreateDirectory(pluginsFolder);
if (!Directory.Exists(bepInExFolder)) Directory.CreateDirectory(bepInExFolder);
if (!Directory.Exists(configFolder)) Directory.CreateDirectory(configFolder);
if (!Directory.Exists(crewBoomFolder)) Directory.CreateDirectory(crewBoomFolder);
if (!Directory.Exists(noCypherFolder)) Directory.CreateDirectory(noCypherFolder);
// Move .cbb and .json files to the no_cypher folder
foreach (var fileEntry in archiveFile.Entries)
{
string entryFileName = fileEntry.FileName;
if (entryFileName.EndsWith(".cbb", StringComparison.OrdinalIgnoreCase) ||
entryFileName.EndsWith(".json", StringComparison.OrdinalIgnoreCase))
{
// Construct the destination path inside the CrewBoom folder no_cupher
string destinationPath = System.IO.Path.Combine(noCypherFolder, System.IO.Path.GetFileName(entryFileName));
if (entryFileName.EndsWith(".cbb", StringComparison.OrdinalIgnoreCase))
{
// For .cbb files, read the content into a MemoryStream and then write to the destination
using (MemoryStream memoryStream = new MemoryStream())
{
fileEntry.Extract(memoryStream);
File.WriteAllBytes(destinationPath, memoryStream.ToArray());
}
}
else
{
// For other files, extract and move as before
using (FileStream fs = File.Create(destinationPath))
{
fileEntry.Extract(fs);
}
}
// Crewboom message
txtProgress.Text += $"Moved {entryFileName} to CrewBoom's no_cypher folder.\n";
string dataFolder = System.IO.Path.Combine(output_dir, mod.GameFolderDataName);
if (!Directory.Exists(dataFolder)) Directory.CreateDirectory(dataFolder);
}
}
}
if (idx != -1)
{
if (idx == 0) // If the data folder is the parent folder in the archive, then make a new folder manually
{
txtProgress.Text += $"{mod.GameFolderDataName} does not have a parent! Creating new parent name...\n";
parent = mod.GetValidFolderName();
output_dir = System.IO.Path.Combine(output_dir, mod.GetValidFolderName());
found_data_dir = true;
break;
}
else if (idx == 1)
{
txtProgress.Text += $"{mod.GameFolderDataName} has a parent! Storing parent name...\n";
parent = split[idx - 1];
found_data_dir = true;
break;
}
else
{
MessageBox.Show("Archive has a invalid structure! Aborting the operation.", "Invalid Structure", MessageBoxButton.OK, MessageBoxImage.Error);
this.Close();
}
}
}
// Existing code for handling the case when mod.GameFolderDataName is not found
// Replace it with the following code
if (!found_data_dir && !foundCBBFile)
{
MessageBox.Show("Archive has an invalid structure! Aborting the operation.", "Invalid Structure", MessageBoxButton.OK, MessageBoxImage.Error);
this.Close();
}
archiveFile.Extract(output_dir);
}
string config_dir = System.IO.Path.Combine(mod.mod_dir_path, parent);
if (!File.Exists(System.IO.Path.Combine(config_dir, ModConfig.CONFIG_FILE)))
{
txtProgress.Text += $"Config not found! Generating new one based on mod data....\n";
mod.GetModConfig().SaveToPath(config_dir);
}
txtProgress.Text += $"Finished downloading {mod.name}! Closing the window in 5 seconds...\n";
await Task.Delay(TimeSpan.FromSeconds(5));
this.Close();
}
private void toggleImage_Click(object sender, RoutedEventArgs e)
{
if (toggleImage.IsChecked == true)
{
image.Visibility = Visibility.Collapsed;
}
else
{
image.Visibility = Visibility.Visible;
}
}
//public GBModPrompt(string test)
//{
// InitializeComponent();
//}
}
}