-
Notifications
You must be signed in to change notification settings - Fork 1
/
MainWindow.cs
610 lines (441 loc) · 30.3 KB
/
MainWindow.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
using Microsoft.Win32;
using System.Diagnostics;
using System.Security.Policy;
using System.Text.RegularExpressions;
using static System.Windows.Forms.LinkLabel;
namespace Blade_and_Sorcery_Update_Skipper
{
public partial class MainWindow : Form
{
public MainWindow()
{
InitializeComponent();
}
// Function that loads the main window and sets up environment
private void MainWindow_Load(object sender, EventArgs e)
{
// Set ActiveControl to button to open SteamDB
// Reference: https://stackoverflow.com/questions/6597196/how-do-i-put-focus-on-a-textbox-when-a-form-loads
ActiveControl = LatestManifestIDOpenSteamDBButton;
// Call helper method getSteamInstallationLocation to read Steam install location
string steamLocation = getSteamInstallationLocation();
// If return value stored in steamLocation is null, Steam is not installed
if (steamLocation == null)
{
// Show error message
// Reference: https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.messagebox.show?view=windowsdesktop-7.0#system-windows-forms-messagebox-show(system-windows-forms-iwin32window-system-string-system-string-system-windows-forms-messageboxbuttons-system-windows-forms-messageboxicon)
MessageBox.Show(this,
"A valid Steam installation was not detected. Steam must be installed through the standard Windows installation method in order to use this tool.",
"ERROR: Steam not installed",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
// Exit application
// Reference: https://stackoverflow.com/questions/17222156/end-program-after-messagebox-is-closed
Application.Exit();
}
// Call helper method getBladeAndSorceryInstallationLocation(), passing steamLocation, to read
// Blade and Sorcery install location
string bladeAndSorceryLocation = getBladeAndSorceryInstallationLocation(steamLocation);
// If return value stored in bladeAndSorceryLocation is null, Blade and Sorcery is not installed
if (bladeAndSorceryLocation == null)
{
// Show warning message
// Reference: https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.messagebox.show?view=windowsdesktop-7.0#system-windows-forms-messagebox-show(system-windows-forms-iwin32window-system-string-system-string-system-windows-forms-messageboxbuttons-system-windows-forms-messageboxicon)
MessageBox.Show(this,
"A valid Steam installation of Blade and Sorcery was not detected automatically. You may continue using this tool at your own risk, but the application may not run correctly.",
"WARNING: Blade and Sorcery not detected",
MessageBoxButtons.OK,
MessageBoxIcon.Warning);
// Otherwise, set the GameLocationTextBox text to the stored location
}
else
{
GameLocationTextBox.Text = bladeAndSorceryLocation;
}
// Set the BackupLocationTextBox text to default location of C:\Users\[CURRENT_USER]\Documents\Blade and Sorcery Update Skipper\
// Reference: https://stackoverflow.com/questions/30872229/how-can-i-get-the-location-of-a-users-documents-directory
BackupLocationTextBox.Text = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
}
// Function that gets and returns the Steam installation location
// Reference: https://stackoverflow.com/questions/34090258/find-steam-games-folder
private string getSteamInstallationLocation()
{
// Set base registry search values
string registryBase = "HKEY_LOCAL_MACHINE\\SOFTWARE\\";
// Get location of Steam installation
// Reference: https://stackoverflow.com/questions/9092160/check-if-a-folder-exist-in-a-directory-and-create-them-using-c-sharp
// Reference: https://learn.microsoft.com/en-us/dotnet/api/microsoft.win32.registry.getvalue?view=net-7.0
// If C:\Program Files (x86) exists, host machine is 64-bit
if (System.IO.Directory.Exists(@"C:\Program Files (x86)"))
{
// Read and return registry value at HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Valve\Steam\InstallPath
return (string)Microsoft.Win32.Registry.GetValue(registryBase + "Wow6432Node\\Valve\\Steam", "InstallPath", (string)null);
// Else, host machine is 32-bit
}
else
{
// Read and return registry value at HKEY_LOCAL_MACHINE\SOFTWARE\Valve\Steam\InstallPath
return (string)Microsoft.Win32.Registry.GetValue(registryBase + "Valve\\Steam", "InstallPath", (string)null);
}
}
// Function that gets and returns the Blade and Sorcery installation location
private string getBladeAndSorceryInstallationLocation(string steamLocation)
{
// Count the number of opening and closing brackets to make sure libraryfolders.vdf is valid
// Reference: https://www.codeproject.com/Questions/750004/How-to-count-the-occurrences-of-a-particular-word
string entireFileText = File.ReadAllText(steamLocation + "\\steamapps\\libraryfolders.vdf");
int numOpeningBrackets = Regex.Matches(entireFileText, @"{").Count;
int numClosingBrackets = Regex.Matches(entireFileText, @"}").Count;
// If number of opening and closing brackets are not equal, exit application (prevents infinite loop)
if (numOpeningBrackets != numClosingBrackets)
{
// Show error message
// Reference: https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.messagebox.show?view=windowsdesktop-7.0#system-windows-forms-messagebox-show(system-windows-forms-iwin32window-system-string-system-string-system-windows-forms-messageboxbuttons-system-windows-forms-messageboxicon)
MessageBox.Show(this,
"File at \"" + steamLocation + "\\steamapps\\libraryfolders.vdf\" is malformed. Please verify that Steam was installed correctly.",
"ERROR: Malformed library file",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
// Exit application
// Reference: https://stackoverflow.com/questions/17222156/end-program-after-messagebox-is-closed
Application.Exit();
}
// Open libraryfolders.vdf file within Steam installation directory and parse
// Reference: https://stackoverflow.com/questions/3709104/how-do-you-read-a-file-which-is-in-use
using (FileStream libraryFolders = File.Open(steamLocation + "\\steamapps\\libraryfolders.vdf", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
using (StreamReader reader = new StreamReader(libraryFolders))
{
// Variable to store the current path where the Blade and Sorcery app
// ID might be found
string currentPath = null;
// Variable to store whether Blade and Sorcery's installation location
// has been found
bool found = false;
// Read through file until EOF
while (!reader.EndOfStream)
{
// Store the current line being read
string currentLine = reader.ReadLine();
// If the current line in the file is the path
if (currentLine.Trim().Contains("\"path\""))
{
// Extract current library folder path
// Reference: https://stackoverflow.com/questions/6219454/efficient-way-to-remove-all-whitespace-from-string
// Reference: https://www.c-sharpcorner.com/blogs/remove-last-character-from-string-in-c-sharp1
currentPath = Regex.Replace(currentLine.Trim(), @"\s+", " ").Substring(7);
currentPath = Regex.Replace(currentPath, @"\\+", "\\");
currentPath = Regex.Replace(currentPath, "\"", "");
}
// If the current line in the file is the beginning of the apps array
if (currentLine.Trim().Contains("\"apps\""))
{
// Loop forever (loop will be broken by closing bracket)
while (true)
{
// Read the next line in the file
currentLine = reader.ReadLine();
// If the current line is a closing bracket, we've reached the end of the apps array
if (currentLine.Trim() == "}")
{
break;
}
// If the current line is not an opening bracket (closing brackets handled already), check
// for the correct app ID
if (currentLine.Trim() != "{")
{
// If the current line contains the correct app ID, we've found the installation
// location
if (currentLine.Trim().Contains("\"629730\""))
{
found = true;
break;
}
}
}
}
// If the correct app ID has been found, break the reader loop early
if (found)
{
break;
}
}
// If the correct app ID has been found, return the path to the app's steamapps location
if (found)
{
return currentPath + "\\steamapps\\common\\Blade & Sorcery";
}
else
{
return (string)null;
}
}
}
}
// Function that opens project repository URL on LinkLabel click
private void DownloadLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
// Store URL
string URL = "https://github.com/sulliops/BladeAndSorceryUpdateSkipper";
// Open URL in browser
// Reference: https://csharpforums.net/threads/net6-open-hyperlink-start-browser-with-url.7735/#post-28218
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo() { FileName = URL, UseShellExecute = true });
}
// Function that opens a FolderBrowserDialog and allows the user to manually select a game installation location
private void GameLocationBrowseButton_Click(object sender, EventArgs e)
{
// Create a new FolderBrowserDialog and set the text value of GameLocationTextBox to the dialog result
// Reference: https://stackoverflow.com/questions/11624298/how-do-i-use-openfiledialog-to-select-a-folder
using (FolderBrowserDialog browser = new FolderBrowserDialog())
{
DialogResult result = browser.ShowDialog();
if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(browser.SelectedPath))
{
GameLocationTextBox.Text = browser.SelectedPath;
}
}
}
// Function that opens the SteamDB page for Blade and Sorcery
private void LatestManifestIDOpenSteamDBButton_Click(object sender, EventArgs e)
{
// Store URL
string URL = "https://steamdb.info/app/629730/depots/?branch=public#depots";
// Open URL in browser
// Reference: https://csharpforums.net/threads/net6-open-hyperlink-start-browser-with-url.7735/#post-28218
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo() { FileName = URL, UseShellExecute = true });
}
// Function that opens a FolderBrowserDialog and allows the user to manually select an appmanifest backup location
private void BackupLocationBrowseButton_Click(object sender, EventArgs e)
{
// Create a new FolderBrowserDialog and set the text value of GameLocationTextBox to the dialog result
// Reference: https://stackoverflow.com/questions/11624298/how-do-i-use-openfiledialog-to-select-a-folder
using (FolderBrowserDialog browser = new FolderBrowserDialog())
{
DialogResult result = browser.ShowDialog();
if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(browser.SelectedPath))
{
BackupLocationTextBox.Text = browser.SelectedPath;
}
}
}
// Function that checks runtime conditions and applies changes to appmanifest
private void ApplyChangesButton_Click(object sender, EventArgs e)
{
// Make sure that a Blade and Sorcery installation location has been provided
if (string.IsNullOrWhiteSpace(GameLocationTextBox.Text))
{
// Show error message
// Reference: https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.messagebox.show?view=windowsdesktop-7.0#system-windows-forms-messagebox-show(system-windows-forms-iwin32window-system-string-system-string-system-windows-forms-messageboxbuttons-system-windows-forms-messageboxicon)
MessageBox.Show(this,
"A Blade and Sorcery installation location was not provided. Please select the correct installation location and try again.",
"ERROR: Missing installation location",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
// Return function early
return;
}
// Store the location of the parent steamapps folder path
string steamAppsParentPath = GameLocationTextBox.Text.Trim();
// If the path still contains "\common\Blade & Sorcery" at the end, remove it
// Reference: https://stackoverflow.com/questions/4101539/c-sharp-removing-substring-from-end-of-string
if (steamAppsParentPath.EndsWith("\\common\\Blade & Sorcery"))
{
steamAppsParentPath = steamAppsParentPath.Remove(steamAppsParentPath.Length - ("\\common\\Blade & Sorcery").Length);
}
// Store the full path to the app manifest file
string appManifestPath = steamAppsParentPath + "\\appmanifest_629730.acf";
// Make sure that a valid Blade and Sorcery app manifest file exists, show error if not
// Reference: https://learn.microsoft.com/en-us/dotnet/api/system.io.file.exists?view=net-7.0
if (!System.IO.File.Exists(appManifestPath))
{
// Show error message
// Reference: https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.messagebox.show?view=windowsdesktop-7.0#system-windows-forms-messagebox-show(system-windows-forms-iwin32window-system-string-system-string-system-windows-forms-messageboxbuttons-system-windows-forms-messageboxicon)
MessageBox.Show(this,
"The appmanifest file at \"" + appManifestPath + "\" does not exist. Please select the correct installation location and try again.",
"ERROR: Missing appmanifest file",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
// Return function early
return;
}
// Make sure that a manifest ID has been provided
if (string.IsNullOrWhiteSpace(LatestManifestIDTextBox.Text))
{
// Show error message
// Reference: https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.messagebox.show?view=windowsdesktop-7.0#system-windows-forms-messagebox-show(system-windows-forms-iwin32window-system-string-system-string-system-windows-forms-messageboxbuttons-system-windows-forms-messageboxicon)
MessageBox.Show(this,
"A manifest ID was not provided. Please copy/paste the latest manifest ID from SteamDB and try again.",
"ERROR: Missing manifest ID",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
// Return function early
return;
}
// Create a variable to store the converted manifest ID
long manifestID;
// Try to convert the manifest ID from a string to an integer
// Reference: https://stackoverflow.com/questions/1019793/how-can-i-convert-string-to-int
// Reference: https://learn.microsoft.com/en-us/dotnet/api/system.int64.parse?view=net-7.0
try
{
manifestID = Int64.Parse(LatestManifestIDTextBox.Text.Trim());
// If conversion fails
}
catch
{
// Show error message
// Reference: https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.messagebox.show?view=windowsdesktop-7.0#system-windows-forms-messagebox-show(system-windows-forms-iwin32window-system-string-system-string-system-windows-forms-messageboxbuttons-system-windows-forms-messageboxicon)
MessageBox.Show(this,
"The manifest ID provided contains non-integer characters. Please copy/paste the latest manifest ID from SteamDB and try again.",
"ERROR: Malformed manifest ID",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
// Return function early
return;
}
// Make sure a valid manifest ID was provided, if not show error
// Reference: https://stackoverflow.com/questions/10845820/check-the-length-of-integer-variable
if (!(manifestID.ToString().Length >= 16 && manifestID.ToString().Length <= 19))
{
// Show error message
// Reference: https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.messagebox.show?view=windowsdesktop-7.0#system-windows-forms-messagebox-show(system-windows-forms-iwin32window-system-string-system-string-system-windows-forms-messageboxbuttons-system-windows-forms-messageboxicon)
MessageBox.Show(this,
"The manifest ID provided is too short. Please copy/paste the latest manifest ID from SteamDB and try again.",
"ERROR: Malformed manifest ID",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
// Return function early
return;
}
// Make sure that an appmanifest backup location was provided
if (string.IsNullOrWhiteSpace(BackupLocationTextBox.Text))
{
// Show error message
// Reference: https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.messagebox.show?view=windowsdesktop-7.0#system-windows-forms-messagebox-show(system-windows-forms-iwin32window-system-string-system-string-system-windows-forms-messageboxbuttons-system-windows-forms-messageboxicon)
MessageBox.Show(this,
"An appmanifest backup location was not provided. Please select a backup location and try again.",
"ERROR: Missing backup location",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
// Return function early
return;
}
// Store the appmanifest backup location
string backupLocationPath = BackupLocationTextBox.Text.Trim() + "\\Blade and Sorcery Update Skipper";
// Determine if a sub-folder for appmanifest backups already exists, and create one if not
// Reference: https://stackoverflow.com/questions/9065598/if-a-folder-does-not-exist-create-it
System.IO.Directory.CreateDirectory(backupLocationPath);
// Copy the existing appmanifest to the backup location, appending a timestamp to the file name
// Reference: https://learn.microsoft.com/en-us/dotnet/api/system.io.file.copy?view=net-7.0
// Reference: https://stackoverflow.com/questions/17632584/how-to-get-the-unix-timestamp-in-c-sharp
File.Copy(appManifestPath, backupLocationPath + "\\appmanifest_629730_" + ((uint)DateTimeOffset.Now.ToUnixTimeSeconds()).ToString() + ".acf");
// Show warning message before continuing and store result of click
// Reference: https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.messagebox.show?view=windowsdesktop-7.0#system-windows-forms-messagebox-show(system-windows-forms-iwin32window-system-string-system-string-system-windows-forms-messageboxbuttons-system-windows-forms-messageboxicon)
DialogResult proceedResult = MessageBox.Show(this,
"Using this tool may break your Blade and Sorcery installation, your Steam installation, or worse. The developer of this tool is not responsible for damages caused by incorrect parameters. Click \"OK\" to proceed, or \"Cancel\" to abort the operation.",
"WARNING: Confirm action",
MessageBoxButtons.OKCancel,
MessageBoxIcon.Warning);
// If result of dialog box button click is "Cancel", return early
// Reference: https://www.codeproject.com/Questions/68682/How-to-know-the-user-Click-OK-on-MessageBox
if (proceedResult == DialogResult.Cancel) {
return;
}
// Check if Steam is currently running
// Reference: https://stackoverflow.com/questions/18015193/how-to-check-if-application-is-running
if (System.Diagnostics.Process.GetProcessesByName("steam").Length > 0)
{
// Show warning message and store result of click
// Reference: https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.messagebox.show?view=windowsdesktop-7.0#system-windows-forms-messagebox-show(system-windows-forms-iwin32window-system-string-system-string-system-windows-forms-messageboxbuttons-system-windows-forms-messageboxicon)
DialogResult steamKillResult = MessageBox.Show(this,
"Steam appears to be running, and this tool cannot proceed until Steam is exited. Click \"OK\" to attempt to exit Steam, or click \"Cancel\" to abort the operation.",
"WARNING: Steam still running",
MessageBoxButtons.OKCancel,
MessageBoxIcon.Warning);
// If result of dialog box button click is "OK"
// Reference: https://www.codeproject.com/Questions/68682/How-to-know-the-user-Click-OK-on-MessageBox
if (steamKillResult == DialogResult.OK)
{
// Kill Steam process
// Reference: https://stackoverflow.com/questions/3345363/kill-some-processes-by-exe-file-name
foreach (System.Diagnostics.Process process in System.Diagnostics.Process.GetProcessesByName("steam"))
{
process.Kill();
}
}
else
{
return;
}
}
// Count the number of opening and closing brackets to make sure appmanifest is valid
// Reference: https://www.codeproject.com/Questions/750004/How-to-count-the-occurrences-of-a-particular-word
string entireFileText = File.ReadAllText(appManifestPath);
int numOpeningBrackets = Regex.Matches(entireFileText, @"{").Count;
int numClosingBrackets = Regex.Matches(entireFileText, @"}").Count;
// If number of opening and closing brackets are not equal
if (numOpeningBrackets != numClosingBrackets)
{
// Show error message
// Reference: https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.messagebox.show?view=windowsdesktop-7.0#system-windows-forms-messagebox-show(system-windows-forms-iwin32window-system-string-system-string-system-windows-forms-messageboxbuttons-system-windows-forms-messageboxicon)
MessageBox.Show(this,
"File at \"" + appManifestPath + "\" is malformed. Please verify the game integrity through Steam, or uninstall and reinstall Blade and Sorcery and try again.",
"ERROR: Malformed appmanifest file",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
// Return function early
return;
}
// Replace all instances of the Windows-style new line sequence "\r\n" with the Unix-style '\n' character
// Reference: https://learn.microsoft.com/en-us/dotnet/api/system.string.replacelineendings?view=net-7.0
entireFileText = entireFileText.ReplaceLineEndings("\n");
// Split existing file contents by new line
// Reference: https://www.techiedelight.com/split-string-on-newlines-csharp/
string[] lines = Regex.Split(entireFileText, "\n");
// Loop through each line to be written
for (int line = 0; line < lines.Length; line++)
{
// If the line contains the StateFlags entry, replace it with a new entry
if (lines[line].Contains("\"StateFlags\"")) {
// Extra spaces here to match existing file structure
lines[line] = " \"StateFlags\" \"4\"";
}
// If the line contains the LastUpdated entry, replace it with a new entry
if (lines[line].Contains("\"LastUpdated\"")) {
// Extra spaces here to match existing file structure
// Reference: https://stackoverflow.com/questions/17632584/how-to-get-the-unix-timestamp-in-c-sharp
lines[line] = " \"LastUpdated\" \"" + ((uint)DateTimeOffset.Now.ToUnixTimeSeconds()).ToString() + "\"";
}
// If the line contains the AutoUpdateBehavior entry, replace it with a new entry
if (lines[line].Contains("\"AutoUpdateBehavior\"")) {
// Extra spaces here to match existing file structure
lines[line] = " \"AutoUpdateBehavior\" \"1\"";
}
// If the line contains the ScheduledAutoUpdate entry, replace it with a new entry
if (lines[line].Contains("\"ScheduledAutoUpdate\"")) {
// Extra spaces here to match existing file structure
lines[line] = " \"ScheduledAutoUpdate\" \"0\"";
}
// If the line contains the manifest entry, replace it with a new entry
if (lines[line].Contains("\"manifest\""))
{
// Extra spaces here to match existing file structure
lines[line] = " \"manifest\" \"" + manifestID.ToString() + "\"";
}
}
// Write lines array to appmanifest file
// Reference: https://stackoverflow.com/questions/7569904/easiest-way-to-read-from-and-write-to-files
File.WriteAllLines(appManifestPath, lines);
// Show success message
// Reference: https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.messagebox.show?view=windowsdesktop-7.0#system-windows-forms-messagebox-show(system-windows-forms-iwin32window-system-string-system-string-system-windows-forms-messageboxbuttons-system-windows-forms-messageboxicon)
MessageBox.Show(this,
"The changes were applied successfully.",
"SUCCESS: Operation completed",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
// Exit application
// Reference: https://stackoverflow.com/questions/17222156/end-program-after-messagebox-is-closed
Application.Exit();
}
}
}