Skip to content

Commit e29206f

Browse files
committed
Simplify uninstall code
1 parent cbc2447 commit e29206f

File tree

2 files changed

+25
-62
lines changed

2 files changed

+25
-62
lines changed

src/Forms/MainRemove.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Threading.Tasks;
25
using System.Windows.Forms;
36

47
using FlashpointInstaller.Common;
@@ -18,14 +21,30 @@ private void SourcePathBrowse2_Click(object sender, EventArgs e)
1821
RemoveButton.Enabled = true;
1922
}
2023

21-
private void RemoveButton_Click(object sender, EventArgs e)
24+
private async void RemoveButton_Click(object sender, EventArgs e)
2225
{
2326
if (FPM.VerifySourcePath(FPM.SourcePath2))
2427
{
2528
FPM.OperateMode = 3;
29+
TabControl.Enabled = false;
2630

27-
var operationWindow = new Operation();
28-
operationWindow.ShowDialog();
31+
await Task.Run(() => Directory.Delete(FPM.SourcePath2, true));
32+
33+
if (FPM.Main.RemoveShortcuts.Checked)
34+
{
35+
var shortcutPaths = new List<string>()
36+
{
37+
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), "Flashpoint.lnk"),
38+
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Flashpoint.lnk")
39+
};
40+
41+
foreach (string path in shortcutPaths) if (File.Exists(path)) File.Delete(path);
42+
}
43+
44+
Hide();
45+
46+
var finishWindow = new FinishOperation();
47+
finishWindow.ShowDialog();
2948
}
3049
}
3150
}

src/Forms/Operation.cs

Lines changed: 3 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ private async void Operation_Load(object sender, EventArgs e)
5454

5555
byteTotal = FPM.SizeTracker.ToDownload;
5656
}
57-
else if (FPM.OperateMode != 3)
57+
else
5858
{
5959
Text = "Modifying Flashpoint...";
6060
CancelButton.Visible = false;
@@ -93,15 +93,6 @@ private async void Operation_Load(object sender, EventArgs e)
9393

9494
byteTotal = removedComponents.Concat(addedComponents).Sum(item => item.Size);
9595
}
96-
else if (FPM.OperateMode == 3)
97-
{
98-
Text = "Removing Flashpoint...";
99-
CancelButton.Visible = false;
100-
101-
await Task.Run(RemoveFlashpoint);
102-
103-
FinishOperation();
104-
}
10596

10697
foreach (var component in removedComponents)
10798
{
@@ -154,6 +145,8 @@ await Task.Run(() =>
154145
});
155146
}
156147

148+
TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.NoProgress, FPM.Main.Handle);
149+
157150
FinishOperation();
158151
}
159152
}
@@ -310,36 +303,6 @@ private void RemoveComponents()
310303
FPM.DeleteFileAndDirectories(infoFile);
311304
}
312305

313-
private void RemoveFlashpoint()
314-
{
315-
string[] files = Directory.GetFiles(FPM.SourcePath2);
316-
317-
for (int i = 0; i < files.Length; i++)
318-
{
319-
double progress = (i + 1) / files.Length;
320-
string fileName = files[i].Substring(files[i].LastIndexOf(@"\"));
321-
322-
ProgressMeasure.Invoke((MethodInvoker)delegate
323-
{
324-
ProgressMeasure.Value = (int)((double)progress * ProgressMeasure.Maximum);
325-
});
326-
327-
ProgressLabel.Invoke((MethodInvoker)delegate
328-
{
329-
ProgressLabel.Text = $"[{(int)((double)progress * 100)}%] Removing \"{fileName}\"... {i + 1} of {files.Length} files";
330-
});
331-
332-
File.Delete(files[i]);
333-
}
334-
335-
ProgressLabel.Invoke((MethodInvoker)delegate
336-
{
337-
ProgressLabel.Text = $"[100%] Removing directories...";
338-
});
339-
340-
Directory.Delete(FPM.SourcePath2, true);
341-
}
342-
343306
private async void FinishOperation()
344307
{
345308
if (FPM.OperateMode == 0)
@@ -373,25 +336,6 @@ await Task.Run(() =>
373336
var finishWindow = new FinishOperation();
374337
finishWindow.ShowDialog();
375338
}
376-
else if (FPM.OperateMode == 3)
377-
{
378-
if (FPM.Main.RemoveShortcuts.Checked)
379-
{
380-
var shortcutPaths = new List<string>()
381-
{
382-
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), "Flashpoint.lnk"),
383-
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Flashpoint.lnk")
384-
};
385-
386-
foreach (string path in shortcutPaths) if (File.Exists(path)) File.Delete(path);
387-
}
388-
389-
Hide();
390-
FPM.Main.Hide();
391-
392-
var finishWindow = new FinishOperation();
393-
finishWindow.ShowDialog();
394-
}
395339

396340
Close();
397341
}

0 commit comments

Comments
 (0)