Skip to content

Commit e7ac543

Browse files
committed
Add more functionality and improve stability
1 parent 305047c commit e7ac543

7 files changed

Lines changed: 274 additions & 44 deletions

File tree

Finish.Designer.cs

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

Finish.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System.Diagnostics;
2+
3+
namespace FlashpointInstaller
4+
{
5+
public partial class Finish : Form
6+
{
7+
public Finish() => InitializeComponent();
8+
9+
private void Exit(object sender, EventArgs e)
10+
{
11+
if (RunOnClose.Checked)
12+
{
13+
Process.Start(Path.Combine(
14+
((Main)Application.OpenForms["Main"]).FolderText.Text,
15+
@"Flashpoint 11 Infinity\Launcher\Flashpoint.exe"
16+
));
17+
}
18+
19+
Environment.Exit(0);
20+
}
21+
}
22+
}

Finish.resx

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<root>
2+
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
3+
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
4+
<xsd:element name="root" msdata:IsDataSet="true">
5+
<xsd:complexType>
6+
<xsd:choice maxOccurs="unbounded">
7+
<xsd:element name="metadata">
8+
<xsd:complexType>
9+
<xsd:sequence>
10+
<xsd:element name="value" type="xsd:string" minOccurs="0" />
11+
</xsd:sequence>
12+
<xsd:attribute name="name" use="required" type="xsd:string" />
13+
<xsd:attribute name="type" type="xsd:string" />
14+
<xsd:attribute name="mimetype" type="xsd:string" />
15+
<xsd:attribute ref="xml:space" />
16+
</xsd:complexType>
17+
</xsd:element>
18+
<xsd:element name="assembly">
19+
<xsd:complexType>
20+
<xsd:attribute name="alias" type="xsd:string" />
21+
<xsd:attribute name="name" type="xsd:string" />
22+
</xsd:complexType>
23+
</xsd:element>
24+
<xsd:element name="data">
25+
<xsd:complexType>
26+
<xsd:sequence>
27+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
28+
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
29+
</xsd:sequence>
30+
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
31+
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
32+
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
33+
<xsd:attribute ref="xml:space" />
34+
</xsd:complexType>
35+
</xsd:element>
36+
<xsd:element name="resheader">
37+
<xsd:complexType>
38+
<xsd:sequence>
39+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
40+
</xsd:sequence>
41+
<xsd:attribute name="name" type="xsd:string" use="required" />
42+
</xsd:complexType>
43+
</xsd:element>
44+
</xsd:choice>
45+
</xsd:complexType>
46+
</xsd:element>
47+
</xsd:schema>
48+
<resheader name="resmimetype">
49+
<value>text/microsoft-resx</value>
50+
</resheader>
51+
<resheader name="version">
52+
<value>2.0</value>
53+
</resheader>
54+
<resheader name="reader">
55+
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
56+
</resheader>
57+
<resheader name="writer">
58+
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
59+
</resheader>
60+
</root>

FlashpointInstaller.csproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@
99
<ApplicationIcon>FlashpointIcon.ico</ApplicationIcon>
1010
</PropertyGroup>
1111

12+
<ItemGroup>
13+
<COMReference Include="IWshRuntimeLibrary">
14+
<WrapperTool>tlbimp</WrapperTool>
15+
<VersionMinor>0</VersionMinor>
16+
<VersionMajor>1</VersionMajor>
17+
<Guid>f935dc20-1cf0-11d0-adb9-00c04fd58a0b</Guid>
18+
<Lcid>0</Lcid>
19+
<Isolated>false</Isolated>
20+
<EmbedInteropTypes>true</EmbedInteropTypes>
21+
</COMReference>
22+
</ItemGroup>
23+
1224
<ItemGroup>
1325
<Content Include="FlashpointIcon.ico" />
1426
</ItemGroup>

Install.cs

Lines changed: 78 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,45 @@
11
using Downloader;
2-
using SharpCompress.Archives.SevenZip;
2+
using IWshRuntimeLibrary;
3+
using SharpCompress.Archives.Zip;
34
using SharpCompress.Common;
45
using SharpCompress.Readers;
6+
using File = System.IO.File;
57

68
namespace FlashpointInstaller
79
{
810
public partial class Install : Form
911
{
12+
Main mainForm = (Main)Application.OpenForms["Main"];
13+
1014
DownloadService downloader = new(new DownloadConfiguration());
1115

1216
Stream stream;
13-
SevenZipArchive archive;
17+
ZipArchive archive;
1418
IReader reader;
1519

16-
string lastEntry = "";
17-
long extractedSize = 0;
20+
bool finishedWriting = false;
1821

19-
public Install()
20-
{
21-
InitializeComponent();
22-
}
22+
public Install() => InitializeComponent();
2323

2424
private async void Install_Load(object sender, EventArgs e)
2525
{
2626
downloader.DownloadStarted += OnDownloadStarted;
2727
downloader.DownloadProgressChanged += OnDownloadProgressChanged;
2828

2929
stream = await downloader.DownloadFileTaskAsync("http://localhost/Flashpoint%2011%20Infinity.7z");
30-
31-
await Task.Run(() =>
30+
//stream = File.OpenRead(@"E:\Flashpoint 11 Infinity.zip");
31+
32+
if (!downloader.IsCancelled)
3233
{
33-
using (archive = SevenZipArchive.Open(stream))
34-
{
35-
using (reader = archive.ExtractAllEntries())
36-
{
37-
reader.EntryExtractionProgress += OnEntryExtractionProgressChanged;
38-
reader.WriteAllToDirectory(((Main)Application.OpenForms["Main"]).FolderText.Text, new ExtractionOptions { ExtractFullPath = true, Overwrite = true });
39-
}
40-
}
41-
});
34+
await Task.Run(ExtractTask);
35+
}
4236
}
4337

4438
private void OnDownloadStarted(object? sender, DownloadStartedEventArgs e)
4539
{
4640
Info.Invoke((MethodInvoker)delegate
4741
{
48-
Info.Text = $"Downloaded 0MB of {Math.Round((double)e.TotalBytesToReceive / 1000000)}MB";
42+
Info.Text = $"Downloaded 0MB of {e.TotalBytesToReceive / 1000000}MB";
4943
});
5044
}
5145

@@ -62,38 +56,85 @@ private void OnDownloadProgressChanged(object? sender, DownloadProgressChangedEv
6256
});
6357
}
6458

65-
private void OnEntryExtractionProgressChanged(object? sender, ReaderExtractionEventArgs<IEntry> e)
59+
private void ExtractTask()
6660
{
67-
if (e.Item.Key != lastEntry)
61+
using (archive = ZipArchive.Open(stream))
6862
{
69-
extractedSize += e.Item.Size;
70-
lastEntry = e.Item.Key;
71-
}
63+
using (reader = archive.ExtractAllEntries())
64+
{
65+
int extractedFiles = 0;
66+
int totalFiles = archive.Entries.Where(entry => !entry.IsDirectory).Count();
67+
68+
while (!reader.Cancelled && reader.MoveToNextEntry())
69+
{
70+
if (reader.Entry.IsDirectory)
71+
{
72+
continue;
73+
}
7274

73-
long extractedSizeExact = extractedSize - (e.Item.Size - e.ReaderProgress.BytesTransferred);
75+
reader.WriteEntryToDirectory(mainForm.FolderText.Text, new ExtractionOptions { ExtractFullPath = true, Overwrite = true });
7476

75-
Progress.Invoke((MethodInvoker)delegate
76-
{
77-
Progress.Value = (Progress.Maximum / 2) + ((int)((double)extractedSizeExact / archive.TotalUncompressSize * (Progress.Maximum / 2)));
78-
});
79-
80-
Info.Invoke((MethodInvoker)delegate
77+
extractedFiles++;
78+
79+
try
80+
{
81+
Progress.Invoke((MethodInvoker)delegate
82+
{
83+
Progress.Value = (Progress.Maximum / 2) + ((int)((double)extractedFiles / totalFiles * (Progress.Maximum / 2)));
84+
});
85+
86+
Info.Invoke((MethodInvoker)delegate
87+
{
88+
Info.Text = $"Extracted {extractedFiles} of {totalFiles} files";
89+
});
90+
}
91+
catch { }
92+
}
93+
94+
if (reader.Cancelled)
95+
{
96+
finishedWriting = true;
97+
}
98+
else
99+
{
100+
FinishInstallation();
101+
}
102+
}
103+
}
104+
}
105+
106+
private void FinishInstallation()
107+
{
108+
if (mainForm.ShortcutsDesktop.Checked)
81109
{
82-
Info.Text = $"Extracted {extractedSize / 1000000}MB of {archive.TotalUncompressSize / 1000000}MB";
83-
});
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");
114+
shortcut.Save();
115+
}
116+
117+
Finish FinishWindow = new();
118+
FinishWindow.ShowDialog();
84119
}
85120

86-
private void Cancel_Click(object sender, EventArgs e)
121+
private async void Cancel_Click(object sender, EventArgs e)
87122
{
123+
Cancel.Enabled = false;
124+
Info.Text = "Cancelling installation...";
125+
88126
if (downloader.IsBusy)
89127
{
90128
downloader.CancelAsync();
91129
}
92130
else if (reader != null)
93131
{
94132
reader.Cancel();
95-
archive.Dispose();
96-
stream.Dispose();
133+
134+
await Task.Run(() =>
135+
{
136+
while (!finishedWriting) { }
137+
});
97138
}
98139

99140
Close();

Main.Designer.cs

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

0 commit comments

Comments
 (0)