Skip to content

Commit e93c310

Browse files
committed
More improvements
1 parent e7ac543 commit e93c310

5 files changed

Lines changed: 74 additions & 108 deletions

File tree

Finish.Designer.cs

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Finish.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@ private void Exit(object sender, EventArgs e)
1010
{
1111
if (RunOnClose.Checked)
1212
{
13-
Process.Start(Path.Combine(
14-
((Main)Application.OpenForms["Main"]).FolderText.Text,
15-
@"Flashpoint 11 Infinity\Launcher\Flashpoint.exe"
16-
));
13+
Process flashpointProcess = new();
14+
flashpointProcess.StartInfo.UseShellExecute = true;
15+
flashpointProcess.StartInfo.FileName = "Flashpoint.exe";
16+
flashpointProcess.StartInfo.WorkingDirectory = Path.Combine(
17+
((Main)Application.OpenForms["Main"]).FolderTextBox.Text,
18+
@"Flashpoint 11 Infinity\Launcher"
19+
);
20+
flashpointProcess.Start();
1721
}
1822

1923
Environment.Exit(0);

Install.cs

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using SharpCompress.Archives.Zip;
44
using SharpCompress.Common;
55
using SharpCompress.Readers;
6-
using File = System.IO.File;
76

87
namespace FlashpointInstaller
98
{
@@ -23,26 +22,17 @@ public partial class Install : Form
2322

2423
private async void Install_Load(object sender, EventArgs e)
2524
{
26-
downloader.DownloadStarted += OnDownloadStarted;
2725
downloader.DownloadProgressChanged += OnDownloadProgressChanged;
2826

29-
stream = await downloader.DownloadFileTaskAsync("http://localhost/Flashpoint%2011%20Infinity.7z");
30-
//stream = File.OpenRead(@"E:\Flashpoint 11 Infinity.zip");
27+
stream = await downloader.DownloadFileTaskAsync("https://bluepload.unstable.life/selif/flashpointdummy.zip");
28+
//stream = System.IO.File.OpenRead(@"E:\Flashpoint 11 Infinity.zip");
3129

3230
if (!downloader.IsCancelled)
3331
{
3432
await Task.Run(ExtractTask);
3533
}
3634
}
3735

38-
private void OnDownloadStarted(object? sender, DownloadStartedEventArgs e)
39-
{
40-
Info.Invoke((MethodInvoker)delegate
41-
{
42-
Info.Text = $"Downloaded 0MB of {e.TotalBytesToReceive / 1000000}MB";
43-
});
44-
}
45-
4636
private void OnDownloadProgressChanged(object? sender, DownloadProgressChangedEventArgs e)
4737
{
4838
Progress.Invoke((MethodInvoker)delegate
@@ -52,7 +42,7 @@ private void OnDownloadProgressChanged(object? sender, DownloadProgressChangedEv
5242

5343
Info.Invoke((MethodInvoker)delegate
5444
{
55-
Info.Text = $"Downloaded {e.ReceivedBytesSize / 1000000}MB of {e.TotalBytesToReceive / 1000000}MB";
45+
Info.Text = $"1/2: Downloading archive - {e.ReceivedBytesSize / 1000000}MB of {e.TotalBytesToReceive / 1000000}MB";
5646
});
5747
}
5848

@@ -62,8 +52,8 @@ private void ExtractTask()
6252
{
6353
using (reader = archive.ExtractAllEntries())
6454
{
65-
int extractedFiles = 0;
66-
int totalFiles = archive.Entries.Where(entry => !entry.IsDirectory).Count();
55+
long extractedSize = 0;
56+
long totalSize = archive.TotalUncompressSize;
6757

6858
while (!reader.Cancelled && reader.MoveToNextEntry())
6959
{
@@ -72,20 +62,20 @@ private void ExtractTask()
7262
continue;
7363
}
7464

75-
reader.WriteEntryToDirectory(mainForm.FolderText.Text, new ExtractionOptions { ExtractFullPath = true, Overwrite = true });
65+
reader.WriteEntryToDirectory(mainForm.FolderTextBox.Text, new ExtractionOptions { ExtractFullPath = true, Overwrite = true });
7666

77-
extractedFiles++;
67+
extractedSize += reader.Entry.Size;
7868

7969
try
8070
{
8171
Progress.Invoke((MethodInvoker)delegate
8272
{
83-
Progress.Value = (Progress.Maximum / 2) + ((int)((double)extractedFiles / totalFiles * (Progress.Maximum / 2)));
73+
Progress.Value = (Progress.Maximum / 2) + (int)((double)extractedSize / totalSize * (Progress.Maximum / 2));
8474
});
8575

8676
Info.Invoke((MethodInvoker)delegate
8777
{
88-
Info.Text = $"Extracted {extractedFiles} of {totalFiles} files";
78+
Info.Text = $"2/2: Extracting files - {extractedSize / 1000000}MB of {totalSize / 1000000}MB";
8979
});
9080
}
9181
catch { }
@@ -105,23 +95,31 @@ private void ExtractTask()
10595

10696
private void FinishInstallation()
10797
{
108-
if (mainForm.ShortcutsDesktop.Checked)
98+
if (mainForm.Shortcut.Checked)
10999
{
110-
string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
111-
112-
IWshShortcut shortcut = new WshShell().CreateShortcut(Path.Combine(desktopPath, "Flashpoint Infinity.lnk"));
113-
shortcut.TargetPath = Path.Combine(mainForm.FolderText.Text, @"Flashpoint 11 Infinity\Launcher\Flashpoint.exe");
100+
IWshShortcut shortcut = new WshShell().CreateShortcut(Path.Combine(
101+
Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
102+
"Flashpoint Infinity.lnk"
103+
));
104+
shortcut.TargetPath = Path.Combine(mainForm.FolderTextBox.Text, @"Flashpoint 11 Infinity\Launcher\Flashpoint.exe");
105+
shortcut.WorkingDirectory = Path.Combine(mainForm.FolderTextBox.Text, @"Flashpoint 11 Infinity\Launcher");
106+
shortcut.Description = "Shortcut to Flashpoint Infinity";
114107
shortcut.Save();
115108
}
116109

117-
Finish FinishWindow = new();
118-
FinishWindow.ShowDialog();
110+
Invoke((MethodInvoker)delegate
111+
{
112+
Hide();
113+
mainForm.Hide();
114+
115+
Finish FinishWindow = new();
116+
FinishWindow.ShowDialog();
117+
});
119118
}
120119

121120
private async void Cancel_Click(object sender, EventArgs e)
122121
{
123122
Cancel.Enabled = false;
124-
Info.Text = "Cancelling installation...";
125123

126124
if (downloader.IsBusy)
127125
{
@@ -133,7 +131,14 @@ private async void Cancel_Click(object sender, EventArgs e)
133131

134132
await Task.Run(() =>
135133
{
134+
Info.Invoke((MethodInvoker)delegate
135+
{
136+
Info.Text = $"Cancelling installation...";
137+
});
138+
136139
while (!finishedWriting) { }
140+
141+
Directory.Delete(Path.Combine(mainForm.FolderTextBox.Text, "Flashpoint 11 Infinity"), true);
137142
});
138143
}
139144

Main.Designer.cs

Lines changed: 26 additions & 70 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Main.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ public partial class Main : Form
99

1010
private void Main_Load(object sender, EventArgs e)
1111
{
12-
FolderText.AutoSize = false;
13-
FolderText.Height = 21;
12+
FolderTextBox.AutoSize = false;
13+
FolderTextBox.Height = 21;
1414

15-
FolderText.Text = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
15+
FolderTextBox.Text = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
1616
}
1717

1818
private void Link_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
@@ -51,7 +51,7 @@ private bool SetPath(string path, bool updateText)
5151
{
5252
if (updateText)
5353
{
54-
FolderText.Text = path;
54+
FolderTextBox.Text = path;
5555
}
5656
return true;
5757
}
@@ -65,7 +65,7 @@ private bool SetPath(string path, bool updateText)
6565

6666
private void Install_Click(object sender, EventArgs e)
6767
{
68-
if (!SetPath(FolderText.Text, false))
68+
if (!SetPath(FolderTextBox.Text, false))
6969
{
7070
return;
7171
}

0 commit comments

Comments
 (0)