-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.cs
700 lines (610 loc) · 28.7 KB
/
Form1.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
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DBDPakInstallerGUI2
{
public partial class dbdPakInstaller : Form
{
private TextBox paksTextBox;
private TextBox pakFileTextBox;
private TextBox paksTextBoxDisplay;
private TextBox pakFileTextBoxDisplay;
private Logger logger;
private string paksFolderPath;
private string modsListFilePath;
private List<string> selectedFilePaths = new List<string>();
public dbdPakInstaller()
{
InitializeComponent();
LoadSelectedFilePaths();
//Textbox field instancess
paksTextBox = new TextBox();
pakFileTextBox = new TextBox();
//display TextBoxes
paksTextBoxDisplay = new TextBox();
paksTextBoxDisplay.ReadOnly = true;
pakFileTextBoxDisplay = new TextBox();
pakFileTextBoxDisplay.ReadOnly = true;
// Get the application directory path
string appDirectory = AppDomain.CurrentDomain.BaseDirectory;
// Initialize logger with the log file path in the application directory
string logFilePath = Path.Combine(appDirectory, "logs.txt");
logger = new Logger(logFilePath);
logger.Log("Application started.");
// Set the paksFolderPath to the PaksFolderPath.txt file in the application directory
paksFolderPath = Path.Combine(appDirectory, "PaksFolderPath.txt");
// set the modlist path to modList.txt in the app directory
modsListFilePath = Path.Combine(appDirectory, "modsList.txt");
// Load the initial mod name from the text file
}
private void Form1_Load(object sender, EventArgs e)
{
LoadSelectedFilePaths();
modsList.Items.AddRange(selectedFilePaths.Select(Path.GetFileName).ToArray());
// Load the previously saved mod name from the modName.txt file
string appDirectory = AppDomain.CurrentDomain.BaseDirectory;
string modNameFilePath = Path.Combine(appDirectory, "modName.txt");
if (File.Exists(modNameFilePath))
{
string modName = File.ReadAllText(modNameFilePath);
this.modName.Text = modName;
}
}
private void modName_TextChanged(object sender, EventArgs e)
{
string appDirectory = AppDomain.CurrentDomain.BaseDirectory;
string modNameFilePath = Path.Combine(appDirectory, "modName.txt");
// Save the current text from the modName TextBox to the modName.txt file
File.WriteAllText(modNameFilePath, modName.Text);
}
private void selectPaksFolder_Click(object sender, EventArgs e)
{
logger.Log("Selecting Paks folder.");
using (var folderBrowserDialog = new FolderBrowserDialog())
{
string paksFolder = string.Empty;
// Check if the PaksFolderPath.txt file exists and contains a valid path
if (File.Exists(paksFolderPath))
{
paksFolder = File.ReadAllText(paksFolderPath).Trim();
if (Directory.Exists(paksFolder))
{
logger.Log($"Paks folder found at: {paksFolder}");
DialogResult result = MessageBox.Show($"Paks folder is already found at: {paksFolder}\nDo you want to select a different folder?", "Paks Folder Found", MessageBoxButtons.YesNo);
if (result == DialogResult.No)
{
paksTextBox.Text = paksFolder;
paksTextBoxDisplay.Text = paksFolder;
return;
}
}
}
if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
{
paksFolder = folderBrowserDialog.SelectedPath;
logger.Log($"Paks folder selected: {paksFolder}");
paksTextBox.Text = paksFolder;
paksTextBoxDisplay.Text = paksFolder;
// Save the selected Paks folder path to PaksFolderPath.txt
File.WriteAllText(paksFolderPath, paksFolder);
}
}
}
private void selectPakBakFile_Click(object sender, EventArgs e)
{
logger.Log("Selecting PAK or BAK file.");
string paksFolder = string.Empty;
// Check if the PaksFolderPath.txt file exists and contains a valid path
if (File.Exists(paksFolderPath))
{
paksFolder = File.ReadAllText(paksFolderPath).Trim();
if (Directory.Exists(paksFolder))
{
logger.Log($"Paks folder found at: {paksFolder}");
paksTextBox.Text = paksFolder;
paksTextBoxDisplay.Text = paksFolder;
}
}
if (string.IsNullOrEmpty(paksFolder))
{
// Prompt the user to select the Paks folder
using (var folderBrowserDialog = new FolderBrowserDialog())
{
if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
{
paksFolder = folderBrowserDialog.SelectedPath;
logger.Log($"Paks folder selected: {paksFolder}");
paksTextBox.Text = paksFolder;
paksTextBoxDisplay.Text = paksFolder;
// Save the selected Paks folder path to PaksFolderPath.txt
File.WriteAllText(paksFolderPath, paksFolder);
}
else
{
logger.Log("No Paks folder selected.");
MessageBox.Show("No Paks folder selected. Operation canceled.");
return;
}
}
}
using (var openFileDialog = new OpenFileDialog())
{
openFileDialog.Filter = "PAK files (*.pak)|*.pak|BAK files (*.bak)|*.bak";
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
string chosenPakFileName = openFileDialog.FileName;
logger.Log($"PAK or BAK file selected: {chosenPakFileName}");
pakFileTextBox.Text = chosenPakFileName;
pakFileTextBoxDisplay.Text = chosenPakFileName; // Update display TextBox
//selectedFilePaths.Clear(); // Clear the selected file paths list
selectedFilePaths.AddRange(openFileDialog.FileNames); // Add the selected file paths to the list
//modsList.Items.Clear(); // Clear the modsList
modsList.Items.AddRange(openFileDialog.FileNames.Select(Path.GetFileName).ToArray()); // Add the selected file names to the modsList
// Write the selected file names to modsList.txt
try
{
File.AppendAllLines(modsListFilePath, openFileDialog.FileNames.Select(Path.GetFileName));
logger.Log("Selected file names saved to modsList.txt");
}
catch (Exception ex)
{
logger.Log($"Error occurred while saving selected file names to modsList.txt: {ex.Message}");
}
logger.Log($"PAK or BAK files selected: {string.Join(", ", openFileDialog.FileNames)}");
// Check whether the Paks folder is valid
if (!string.IsNullOrEmpty(paksFolder) && Directory.Exists(paksFolder))
{
// Determine the platform based on the selected file name
bool isEpicGamesFile = chosenPakFileName.Contains("EGS");
bool isSteamFile = chosenPakFileName.Contains("WindowsNoEditor");
// Determine the base file name based on the selected file
string baseFileName = isEpicGamesFile ? "pakchunk348-EGS" : "pakchunk348-WindowsNoEditor";
// Update copies accordingly
UpdateCopies(paksFolder, chosenPakFileName, baseFileName);
// Create copies accordingly
if (isEpicGamesFile)
{
// Create copies of both "pakchunk348-EGS.pak"
CreatePakSigCopies(paksFolder, "pakchunk348-EGS.sig");
}
else if (isSteamFile)
{
// Create a copy of "pakchunk348-WindowsNoEditor.pak" for Steam
CreatePakSigCopies(paksFolder, "pakchunk348-WindowsNoEditor.sig");
}
}
else
{
logger.Log("Invalid Paks folder selected.");
MessageBox.Show("Please select a valid Paks folder before selecting the PAK/BAK file.");
}
}
}
}
private void EpicGames_CheckedChanged(object sender, EventArgs e)
{
if (EpicGames.Checked)
{
RenameFileToEGS();
}
}
private void Steam_CheckedChanged(object sender, EventArgs e)
{
if (Steam.Checked)
{
RenameFileToWindowsNoEditor();
}
}
private void RenameFileToEGS()
{
string chosenPakFileName = pakFileTextBox.Text;
if (!string.IsNullOrEmpty(chosenPakFileName))
{
// Check if the file contains "WindowsNoEditor"
if (chosenPakFileName.Contains("WindowsNoEditor"))
{
string newFileName = chosenPakFileName.Replace("WindowsNoEditor", "EGS");
RenameFile(chosenPakFileName, newFileName);
UpdateModsList(newFileName); // Update the ListBox and modsList.txt
// Update the pakFileTextBox with the new filename
pakFileTextBox.Text = newFileName;
}
else
{
MessageBox.Show("File does not contain 'WindowsNoEditor'. No action taken.");
}
}
}
private void RenameFileToWindowsNoEditor()
{
string chosenPakFileName = pakFileTextBox.Text;
if (!string.IsNullOrEmpty(chosenPakFileName))
{
// Check if the file contains "EGS"
if (chosenPakFileName.Contains("EGS"))
{
string newFileName = chosenPakFileName.Replace("EGS", "WindowsNoEditor");
RenameFile(chosenPakFileName, newFileName);
UpdateModsList(newFileName); // Update the ListBox and modsList.txt
// Update the pakFileTextBox with the new filename
pakFileTextBox.Text = newFileName;
}
else
{
MessageBox.Show("File does not contain 'EGS'. No action taken.");
}
}
}
private void RenameFile(string oldFileName, string newFileName)
{
string paksFolder = paksTextBox.Text;
string oldFilePath = Path.Combine(paksFolder, oldFileName);
string newFilePath = Path.Combine(paksFolder, newFileName);
if (File.Exists(oldFilePath))
{
try
{
File.Move(oldFilePath, newFilePath);
logger.Log($"File renamed: {oldFileName} -> {newFileName}");
MessageBox.Show($"File renamed: {oldFileName} -> {newFileName}");
}
catch (IOException ex)
{
logger.Log($"Error occurred while renaming file: {ex.Message}");
MessageBox.Show($"Error occurred while renaming file: {ex.Message}");
}
}
else
{
logger.Log($"File not found: {oldFileName}");
MessageBox.Show($"File not found: {oldFileName}");
}
}
private void UpdateModsList(string newFileName)
{
string oldFileName = Path.GetFileName(pakFileTextBox.Text);
string newFileNameOnly = Path.GetFileName(newFileName);
// Update ListBox
int indexToUpdate = modsList.Items.IndexOf(oldFileName);
if (indexToUpdate != -1)
{
modsList.Items[indexToUpdate] = newFileNameOnly;
}
// Update modsList.txt
try
{
string appDirectory = AppDomain.CurrentDomain.BaseDirectory;
string modsListFilePath = Path.Combine(appDirectory, "modsList.txt");
if (File.Exists(modsListFilePath))
{
string[] fileNames = File.ReadAllLines(modsListFilePath);
for (int i = 0; i < fileNames.Length; i++)
{
// Update the file name in the modsList.txt file
if (fileNames[i] == oldFileName)
{
fileNames[i] = newFileNameOnly;
break;
}
}
File.WriteAllLines(modsListFilePath, fileNames);
}
}
catch (Exception ex)
{
MessageBox.Show($"Error occurred while updating modsList.txt: {ex.Message}");
}
}
private void EXECUTE_Click(object sender, EventArgs e)
{
logger.Log("Executing operation.");
string paksFolder = paksTextBox.Text;
string chosenPakFileName = pakFileTextBox.Text;
// Check if either "Epic Games" or "Steam" option is checked
if (!EpicGames.Checked && !Steam.Checked)
{
logger.Log("Platform not chosen.");
MessageBox.Show("Please choose your platform first before executing.");
return;
}
if (string.IsNullOrEmpty(paksFolder) || string.IsNullOrEmpty(chosenPakFileName))
{
logger.Log("Paks folder or PAK/BAK file not selected.");
MessageBox.Show("Please select the Paks folder and PAK/BAK file.");
return;
}
string chosenPakFile = Path.Combine(paksFolder, chosenPakFileName);
if (!File.Exists(chosenPakFile) || (!chosenPakFileName.EndsWith(".pak") && !chosenPakFileName.EndsWith(".bak")))
{
logger.Log("Invalid file name or file not found.");
MessageBox.Show("Error: invalid file name or file not found.");
return;
}
logger.Log("Operation started.");
CopyPakOrBakFile(chosenPakFile, paksFolder);
RenameCopies(paksFolder, chosenPakFileName);
logger.Log("Operation completed successfully!");
MessageBox.Show("Operation completed successfully! HAPPY MODDING!");
}
private void PakBypass_Click(object sender, EventArgs e)
{
RunPakBypassProgram();
}
private void Uninstall_Click(object sender, EventArgs e)
{
// Read the Paks folder path from PaksFolderPath.txt
string appDirectory = AppDomain.CurrentDomain.BaseDirectory;
string paksFolderPathFile = Path.Combine(appDirectory, "PaksFolderPath.txt");
string paksFolderPath = File.Exists(paksFolderPathFile) ? File.ReadAllText(paksFolderPathFile).Trim() : "";
if (modsList.SelectedIndex != -1)
{
// Get the selected item's index
int selectedIndex = modsList.SelectedIndex;
// Get the corresponding file name from the modsList
string selectedFileName = modsList.Items[selectedIndex].ToString();
// Remove the selected file from the Paks folder
string pakFilePath = Path.Combine(paksFolderPath, selectedFileName);
string sigFilePath = Path.Combine(paksFolderPath, $"{Path.GetFileNameWithoutExtension(selectedFileName)}.sig");
string kekFilePath = Path.Combine(paksFolderPath, $"{Path.GetFileNameWithoutExtension(selectedFileName)}.kek");
// Ask for confirmation before uninstalling
DialogResult result = MessageBox.Show($"Are you sure you want to uninstall {selectedFileName}?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
try
{
// Delete the PAK/BAK file and its copies
File.Delete(pakFilePath);
File.Delete(sigFilePath);
File.Delete(kekFilePath);
logger.Log($"Files removed: {selectedFileName}, {Path.GetFileName(sigFilePath)}, {Path.GetFileName(kekFilePath)}");
MessageBox.Show($"Files removed: {selectedFileName}, {Path.GetFileName(sigFilePath)}, {Path.GetFileName(kekFilePath)}");
// Remove the item from the modsList and selectedFilePaths lists
modsList.Items.RemoveAt(selectedIndex);
selectedFilePaths.RemoveAt(selectedIndex);
// Save the updated selected file paths back to modsList.txt
SaveSelectedFilePaths();
}
catch (IOException ex)
{
logger.Log($"Error occurred while removing files: {ex.Message}");
MessageBox.Show($"Error occurred while removing files: {ex.Message}");
}
}
}
else
{
MessageBox.Show("Please select a file to uninstall.");
}
}
private void CopyPakOrBakFile(string sourceFile, string destinationFolder)
{
logger.Log($"Copying {Path.GetFileName(sourceFile)} to {destinationFolder}");
string destinationFile = Path.Combine(destinationFolder, Path.GetFileName(sourceFile));
try
{
File.Copy(sourceFile, destinationFile, true); // Overwrite if the file already exists
logger.Log($"{Path.GetFileName(sourceFile)} copied successfully.");
}
catch (IOException ex)
{
logger.Log($"Error occurred while copying {Path.GetFileName(sourceFile)} to Paks folder: {ex.Message}");
MessageBox.Show($"Error occurred while copying {Path.GetFileName(sourceFile)} to Paks folder: {ex.Message}");
}
}
private void UpdateCopies(string paksFolder, string fileName, string baseFileName) // Updating the copies of pakchunk348-EGS.sig
{
logger.Log($"Updating copies of {baseFileName}.sig.");
try
{
// Update the copies based on the base file name
File.WriteAllText(Path.Combine(paksFolder, $"{baseFileName} - Copy.sig"), Path.GetFileNameWithoutExtension(fileName));
File.WriteAllText(Path.Combine(paksFolder, $"{baseFileName} - Copy (2).sig"), Path.GetFileNameWithoutExtension(fileName));
logger.Log("Copies updated successfully.");
}
catch (IOException ex)
{
logger.Log($"Error occurred while updating copies of {baseFileName}.sig: {ex.Message}");
MessageBox.Show($"Error occurred while updating copies of {baseFileName}.sig: {ex.Message}");
}
}
private void RenameCopies(string paksFolder, string fileName)
{
logger.Log("Renaming copies.");
// Determine the base file name based on the selected file
string baseFileName = fileName.Contains("EGS") ? "pakchunk348-EGS" : "pakchunk348-WindowsNoEditor";
string renamedFile1 = Path.Combine(paksFolder, $"{baseFileName} - Copy.sig");
string renamedFile2 = Path.Combine(paksFolder, $"{baseFileName} - Copy (2).sig");
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);
string newName1 = Path.Combine(paksFolder, $"{fileNameWithoutExtension}.sig");
string newName2 = Path.Combine(paksFolder, $"{fileNameWithoutExtension}.kek");
try
{
// Rename copies based on the platform
File.Move(renamedFile1, newName1);
File.Move(renamedFile2, newName2);
logger.Log("Files renamed successfully.");
}
catch (IOException ex)
{
logger.Log($"Error occurred while renaming files: {ex.Message}");
MessageBox.Show($"Error occurred while renaming files: {ex.Message}");
}
}
private void CreatePakSigCopies(string paksFolder, string baseFileName)
{
string pakSigFile = Path.Combine(paksFolder, $"{baseFileName}.sig");
if (File.Exists(pakSigFile))
{
// Make copies of the "pakchunk348-EGS.sig" or "pakchunk348-WindowsNoEditor.sig" file
try
{
logger.Log($"Creating copies of {baseFileName}.sig.");
File.Copy(pakSigFile, Path.Combine(paksFolder, $"{baseFileName} - Copy.sig"), true);
File.Copy(pakSigFile, Path.Combine(paksFolder, $"{baseFileName} - Copy (2).sig"), true);
logger.Log("Copies created successfully.");
}
catch (IOException ex)
{
logger.Log($"Error occurred while copying files: {ex.Message}");
MessageBox.Show($"Error occurred while copying files: {ex.Message}");
}
}
}
private string ExtractPakBypassExecutable()
{
string exeDirectory = Path.GetDirectoryName(Application.ExecutablePath);
string tempFolderPath = Path.Combine(exeDirectory, "Temp");
// Create a temporary folder if it doesn't exist
Directory.CreateDirectory(tempFolderPath);
// Path to the extracted PakBypass.exe
string extractedFilePath = Path.Combine(tempFolderPath, "PakBypass.exe");
// Check if PakBypass.exe already exists in the temporary folder
if (!File.Exists(extractedFilePath))
{
// Extract PakBypass.exe from the embedded resource to the temporary folder
using (Stream resourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("DBDPakInstallerGUI2.PakBypass.PakBypass.exe"))
{
if (resourceStream != null)
{
using (FileStream fileStream = new FileStream(extractedFilePath, FileMode.Create))
{
resourceStream.CopyTo(fileStream);
}
}
else
{
// Resource stream is null, indicating that the resource was not found
logger.Log("PakBypass.exe resource not found.");
MessageBox.Show("PakBypass.exe resource not found. Please ensure it is properly embedded.");
}
}
}
return extractedFilePath;
}
private string FindPakBypassExecutable()
{
string extractedFilePath = ExtractPakBypassExecutable();
if (!string.IsNullOrEmpty(extractedFilePath) && File.Exists(extractedFilePath))
{
return extractedFilePath;
}
// PakBypass.exe not found or failed to extract, return an empty string
return string.Empty;
}
private void RunPakBypassProgram()
{
string pakBypassProgramPath = FindPakBypassExecutable();
if (!string.IsNullOrEmpty(pakBypassProgramPath))
{
try
{
ProcessStartInfo startInfo = new ProcessStartInfo(pakBypassProgramPath);
Process.Start(startInfo);
}
catch (Exception ex)
{
logger.Log($"Error occurred while running the Pak Bypass program: {ex.Message}");
MessageBox.Show($"Error occurred while running the Pak Bypass program: {ex.Message}");
}
}
else
{
logger.Log("Pak Bypass executable not found.");
MessageBox.Show("The Pak Bypass executable was not found in the expected location.");
}
}
private void LoadSelectedFilePaths()
{
string appDirectory = AppDomain.CurrentDomain.BaseDirectory;
modsListFilePath = Path.Combine(appDirectory, "modsList.txt");
// Check if the modsList.txt file exists
if (File.Exists(modsListFilePath))
{
try
{
// Read the file names from modsList.txt
var fileNames = File.ReadAllLines(modsListFilePath);
// Add the file names to the selectedFilePaths list
selectedFilePaths.AddRange(fileNames.Except(selectedFilePaths));
}
catch (Exception ex)
{
logger.Log($"Error occurred while loading selected file names from modsList.txt: {ex.Message}");
}
}
}
private void SaveSelectedFilePaths()
{
string appDirectory = AppDomain.CurrentDomain.BaseDirectory;
string modsListFilePath = Path.Combine(appDirectory, "modsList.txt");
if (selectedFilePaths.Count > 0)
{
try
{
File.WriteAllLines(modsListFilePath, selectedFilePaths);
logger.Log("Selected file paths saved to modsList.txt");
}
catch (Exception ex)
{
logger.Log($"Error occurred while saving selected file paths: {ex.Message}");
}
}
else
{
logger.Log("No selected file paths to save.");
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
try
{
SaveSelectedFilePaths();
}
catch (Exception ex)
{
logger.Log($"Error occurred while saving selected file paths: {ex.Message}");
}
}
public class Logger
{
private string logFilePath;
public Logger(string logFilePath)
{
this.logFilePath = logFilePath;
}
public void Log(string message)
{
try
{
using (StreamWriter writer = new StreamWriter(logFilePath, true))
{
writer.WriteLine($"{DateTime.Now.ToString()} - {message}");
}
}
catch (Exception ex)
{
Console.WriteLine($"Error occurred while logging: {ex.Message}");
}
}
}
private void modsList_SelectedIndexChanged(object sender, EventArgs e)
{
if (modsList.SelectedIndex != -1)
{
// Get the selected item's index
int selectedIndex = modsList.SelectedIndex;
// Get the corresponding file path from the selectedFilePaths list
string selectedFilePath = selectedFilePaths[selectedIndex];
}
}
}
}