Skip to content

Commit 586d677

Browse files
committed
2 parents 6bcdfb9 + fe161b6 commit 586d677

8 files changed

Lines changed: 60 additions & 21 deletions

File tree

FlashpointInstaller/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@
3232
// by using the '*' as shown below:
3333
// [assembly: AssemblyVersion("1.0.*")]
3434
[assembly: AssemblyVersion("1.0.0.0")]
35-
[assembly: AssemblyFileVersion("1.0-rc8")]
35+
[assembly: AssemblyFileVersion("1.0-rc10")]

FlashpointInstaller/src/Common.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ public static string GetFormattedBytes(long bytes)
376376
while (--i >= 0)
377377
{
378378
double unitSize = Math.Pow(1024, i);
379-
if (bytes >= unitSize) return (Math.Floor(bytes / unitSize * 10) / 10).ToString("N1") + units[i];
379+
if (bytes >= unitSize) return (Math.Round(bytes / unitSize * 10) / 10).ToString("N1") + units[i];
380380
}
381381

382382
return "0 bytes";

FlashpointInstaller/src/Forms/Operate.cs

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public partial class Operate : Form
2727
ZipArchive archive;
2828
IReader reader;
2929

30+
List<string> extractedFiles = new List<string>();
31+
3032
long byteProgress = 0;
3133
long byteTotal = 0;
3234

@@ -61,10 +63,19 @@ private async void Operation_Load(object sender, EventArgs e)
6163
{
6264
stream = new MemoryStream(await client.DownloadDataTaskAsync(new Uri(component.URL)));
6365
}
64-
catch (WebException ex) when (ex.Status == WebExceptionStatus.RequestCanceled)
66+
catch (WebException ex)
6567
{
66-
client.Dispose();
68+
if (ex.Status != WebExceptionStatus.RequestCanceled)
69+
{
70+
MessageBox.Show(
71+
$"The {workingComponent.Title} component failed to download.\n\n" +
72+
"If this issue persists, please let us know as soon as possible.",
73+
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error
74+
);
75+
}
76+
6777
cancelStatus = 2;
78+
CancelButton.PerformClick();
6879
return;
6980
}
7081
}
@@ -157,6 +168,8 @@ private void ExtractComponents()
157168
writer.WriteLine(string.Join(" ", header));
158169
}
159170

171+
extractedFiles.Add(infoFile);
172+
160173
if (workingComponent.Size == 0) return;
161174

162175
using (archive = ZipArchive.Open(stream))
@@ -178,6 +191,8 @@ private void ExtractComponents()
178191
ExtractFullPath = true, Overwrite = true, PreserveFileTime = true
179192
});
180193

194+
extractedFiles.Add(Path.Combine(destPath, reader.Entry.Key.Replace('/', '\\')));
195+
181196
using (TextWriter writer = File.AppendText(infoFile))
182197
{
183198
writer.WriteLine(Path.Combine(workingComponent.Path, reader.Entry.Key).Replace("/", @"\"));
@@ -253,7 +268,7 @@ await Task.Run(() =>
253268

254269
private async void CancelButton_Click(object sender, EventArgs e)
255270
{
256-
cancelStatus = 1;
271+
if (cancelStatus < 1) cancelStatus = 1;
257272

258273
CancelButton.Enabled = false;
259274
ProgressLabel.Invoke((MethodInvoker)delegate
@@ -267,12 +282,23 @@ await Task.Run(() =>
267282

268283
if (Directory.Exists(FPM.Main.DestinationPath.Text))
269284
{
270-
foreach (string file in Directory.EnumerateFiles(FPM.Main.DestinationPath.Text))
285+
foreach (string file in extractedFiles)
271286
{
272287
try { File.Delete(file); } catch { }
273-
}
274288

275-
try { Directory.Delete(FPM.Main.DestinationPath.Text, true); } catch { }
289+
string folder = Path.GetDirectoryName(file);
290+
291+
while (folder != Directory.GetParent(FPM.Main.DestinationPath.Text).ToString())
292+
{
293+
if (Directory.Exists(folder) && !Directory.EnumerateFiles(folder, "*", SearchOption.AllDirectories).Any())
294+
{
295+
try { Directory.Delete(folder, true); } catch { }
296+
}
297+
else break;
298+
299+
folder = Directory.GetParent(folder).ToString();
300+
}
301+
}
276302
}
277303
});
278304

FlashpointManager/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@
3232
// by using the '*' as shown below:
3333
// [assembly: AssemblyVersion("1.0.*")]
3434
[assembly: AssemblyVersion("1.0.0.0")]
35-
[assembly: AssemblyFileVersion("1.0-rc8")]
35+
[assembly: AssemblyFileVersion("1.0-rc10")]

FlashpointManager/src/Common.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,7 @@ public static void SyncManager()
377377
long sizeChange = component.Size - oldSize;
378378
totalSizeChange += sizeChange;
379379

380-
string displayedSize = GetFormattedBytes(sizeChange);
381-
if (displayedSize[0] != '-') displayedSize = "+" + displayedSize;
380+
string displayedSize = GetFormattedBytes(sizeChange, true);
382381

383382
var item = new ListViewItem();
384383
item.Text = component.Title;
@@ -397,7 +396,7 @@ public static void SyncManager()
397396
item.Text = component.Title;
398397
item.SubItems.Add("This component is deprecated and can be deleted.");
399398
item.SubItems.Add("");
400-
item.SubItems.Add(GetFormattedBytes(-component.Size));
399+
item.SubItems.Add(GetFormattedBytes(-component.Size, true));
401400

402401
Main.UpdateList.Items.Add(item);
403402
}
@@ -409,7 +408,7 @@ public static void SyncManager()
409408

410409
if (ComponentTracker.Outdated.Count > 0 || ComponentTracker.Deprecated.Count > 0)
411410
{
412-
Main.UpdateButton.Text += $" ({GetFormattedBytes(totalSizeChange)})";
411+
Main.UpdateButton.Text += $" ({GetFormattedBytes(totalSizeChange, true)})";
413412
Main.UpdateButton.Enabled = true;
414413
}
415414
else
@@ -607,18 +606,24 @@ void AddDependencies(string[] depends)
607606
}
608607

609608
// Formats bytes as a human-readable string
610-
public static string GetFormattedBytes(long bytes)
609+
public static string GetFormattedBytes(long bytes, bool plusSign = false)
611610
{
612611
string[] units = new[] { " bytes", "KB", "MB", "GB" };
613612
int i = units.Length;
614613

614+
string formattedBytes = "0 bytes";
615+
615616
while (--i >= 0)
616617
{
617618
double unitSize = Math.Pow(1024, i);
618-
if (Math.Abs(bytes) >= unitSize) return (Math.Floor(bytes / unitSize * 10) / 10).ToString("N1") + units[i];
619+
if (Math.Abs(bytes) >= unitSize)
620+
{
621+
formattedBytes = (Math.Round(bytes / unitSize * 10) / 10).ToString("N1") + units[i];
622+
break;
623+
}
619624
}
620625

621-
return "0 bytes";
626+
return (plusSign && !formattedBytes.StartsWith("-") ? "+" : "") + formattedBytes;
622627
}
623628

624629
// Function for errors unrelated to the component list

FlashpointManager/src/Forms/Main.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public void ComponentList_AfterCheck(object sender, TreeViewEventArgs e)
8383
? long.Parse(File.ReadLines(component.InfoFile).First().Split(' ')[1])
8484
: component.Size);
8585

86-
ChangeButton.Text = $"Apply changes ({FPM.GetFormattedBytes(FPM.ModifiedSize)})";
86+
ChangeButton.Text = $"Apply changes ({FPM.GetFormattedBytes(FPM.ModifiedSize, true)})";
8787
ChangeButton.Enabled = true;
8888
}
8989

FlashpointManager/src/Forms/Operate.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,18 @@ private async void Operation_Load(object sender, EventArgs e)
9696
{
9797
stream = new MemoryStream(await client.DownloadDataTaskAsync(new Uri(component.URL)));
9898
}
99-
catch (WebException ex) when (ex.Status == WebExceptionStatus.RequestCanceled)
99+
catch (WebException ex)
100100
{
101-
client.Dispose();
101+
if (ex.Status != WebExceptionStatus.RequestCanceled)
102+
{
103+
FPM.GenericError(
104+
$"The {workingComponent.Title} component failed to download.\n\n" +
105+
"If this issue persists, please let us know as soon as possible."
106+
);
107+
}
108+
102109
cancelStatus = 2;
110+
CancelButton.PerformClick();
103111
return;
104112
}
105113
}
@@ -325,7 +333,7 @@ void MoveDelete(string source, string dest)
325333

326334
private async void CancelButton_Click(object sender, EventArgs e)
327335
{
328-
cancelStatus = 1;
336+
if (cancelStatus < 1) cancelStatus = 1;
329337

330338
CancelButton.Enabled = false;
331339
ProgressLabel.Invoke((MethodInvoker)delegate

FlashpointManager/src/Forms/Settings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ private async void UninstallButton_Click(object sender, EventArgs e)
7676
TabControl.Enabled = false;
7777

7878
await Task.Run(() => {
79-
foreach (string file in Directory.EnumerateFileSystemEntries(FPM.SourcePath, "*", SearchOption.AllDirectories))
79+
foreach (string file in Directory.EnumerateFiles(FPM.SourcePath, "*", SearchOption.AllDirectories))
8080
{
8181
try { FPM.DeleteFileAndDirectories(file); } catch { }
8282
}

0 commit comments

Comments
 (0)