Skip to content

Commit d10865b

Browse files
committed
Rename to "Flashpoint Manager", continue implementing component functionality
1 parent 5c3d9b5 commit d10865b

9 files changed

Lines changed: 297 additions & 139 deletions

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
bin/
33
obj/
44
packages/
5-
FlashpointInstaller.csproj.user
5+
FlashpointManager.csproj.user
66
FodyWeavers.xsd
77
FodyWeavers.xml

Finish.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.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 17
44
VisualStudioVersion = 17.2.32616.157
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlashpointInstaller", "FlashpointInstaller.csproj", "{3A52CEC9-3EEC-4ED4-8E21-51635A08AC38}"
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlashpointManager", "FlashpointManager.csproj", "{3A52CEC9-3EEC-4ED4-8E21-51635A08AC38}"
77
EndProject
88
Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution

Install.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Install.cs

Lines changed: 87 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.IO;
34
using System.Threading.Tasks;
45
using System.Windows.Forms;
@@ -9,18 +10,26 @@
910
using SharpCompress.Common;
1011
using SharpCompress.Readers;
1112

13+
using File = System.IO.File;
14+
1215
namespace FlashpointInstaller
1316
{
1417
public partial class Install : Form
1518
{
1619
Main mainForm = (Main)Application.OpenForms["Main"];
1720

21+
List<Dictionary<string, string>> componentInfo = new List<Dictionary<string, string>>();
22+
Dictionary<string, string> workingComponent;
23+
1824
DownloadService downloader = new DownloadService(new DownloadConfiguration());
1925

2026
Stream stream;
2127
ZipArchive archive;
2228
IReader reader;
2329

30+
long byteProgress = 0;
31+
long byteTotal = ((Main)Application.OpenForms["Main"]).DownloadSize;
32+
2433
bool doneCancelling = false;
2534

2635
public Install() => InitializeComponent();
@@ -29,28 +38,59 @@ private async void Install_Load(object sender, EventArgs e)
2938
{
3039
downloader.DownloadProgressChanged += OnDownloadProgressChanged;
3140

32-
//stream = await downloader.DownloadFileTaskAsync("https://bluepload.unstable.life/selif/flashpointdummy.zip");
33-
stream = await downloader.DownloadFileTaskAsync("http://localhost/flashpointdummy.zip");
34-
//stream = System.IO.File.OpenRead(@"E:\flashpointdummy.zip");
41+
void Iterate(TreeNodeCollection parent)
42+
{
43+
foreach (TreeNode childNode in parent)
44+
{
45+
var attributes = childNode.Tag as Dictionary<string, string>;
46+
47+
if (attributes["type"] == "component" && childNode.Checked)
48+
{
49+
componentInfo.Add(childNode.Tag as Dictionary<string, string>);
50+
}
3551

36-
if (!downloader.IsCancelled)
52+
Iterate(childNode.Nodes);
53+
}
54+
}
55+
Iterate(mainForm.ComponentQueue.Nodes);
56+
57+
foreach (var component in componentInfo)
3758
{
38-
Directory.CreateDirectory(mainForm.FolderTextBox.Text);
59+
workingComponent = component;
60+
61+
stream = await downloader.DownloadFileTaskAsync(component["url"]);
3962

40-
await Task.Run(ExtractTask);
63+
if (!downloader.IsCancelled)
64+
{
65+
Directory.CreateDirectory(mainForm.FolderTextBox.Text);
66+
67+
await Task.Run(ExtractTask);
68+
}
69+
else { return; }
70+
71+
byteProgress += int.Parse(component["size"]);
4172
}
73+
74+
FinishInstallation();
4275
}
4376

4477
private void OnDownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
4578
{
79+
double currentProgress = (double)e.ReceivedBytesSize / e.TotalBytesToReceive;
80+
long currentSize = long.Parse(workingComponent["size"]);
81+
4682
Progress.Invoke((MethodInvoker)delegate
4783
{
48-
Progress.Value = (int)((double)e.ReceivedBytesSize / e.TotalBytesToReceive * (Progress.Maximum / 2));
84+
Progress.Value = (int)((double)
85+
((byteProgress + (currentProgress / 2 * currentSize)) / byteTotal * Progress.Maximum)
86+
);
4987
});
50-
88+
5189
Info.Invoke((MethodInvoker)delegate
5290
{
53-
Info.Text = $"1/2: Downloading archive - {e.ReceivedBytesSize / 1000000}MB of {e.TotalBytesToReceive / 1000000}MB";
91+
Info.Text =
92+
$"Downloading component \"{workingComponent["title"]}\"... " +
93+
$"{Math.Truncate(currentProgress * 100)}%";
5494
});
5595
}
5696

@@ -63,29 +103,48 @@ private void ExtractTask()
63103
long extractedSize = 0;
64104
long totalSize = archive.TotalUncompressSize;
65105

106+
string infoPath = Path.Combine(mainForm.FolderTextBox.Text, "Components", workingComponent["path"]);
107+
string infoFile = $"{workingComponent["title"]}.txt";
108+
109+
Directory.CreateDirectory(infoPath);
110+
111+
using (TextWriter writer = File.CreateText(infoPath + infoFile))
112+
{
113+
writer.WriteLine($"{workingComponent["url"]} {workingComponent["hash"]}");
114+
}
115+
66116
while (!reader.Cancelled && reader.MoveToNextEntry())
67117
{
68-
if (reader.Entry.IsDirectory)
69-
{
70-
continue;
71-
}
118+
if (reader.Entry.IsDirectory) { continue; }
72119

73120
reader.WriteEntryToDirectory(
74121
mainForm.FolderTextBox.Text, new ExtractionOptions { ExtractFullPath = true, Overwrite = true }
75122
);
76123

124+
using (TextWriter writer = File.AppendText(infoPath + infoFile))
125+
{
126+
writer.WriteLine(reader.Entry.Key);
127+
}
128+
77129
extractedSize += reader.Entry.Size;
78130

79131
try
80132
{
133+
double currentProgress = (double)extractedSize / totalSize;
134+
long currentSize = long.Parse(workingComponent["size"]);
135+
81136
Progress.Invoke((MethodInvoker)delegate
82137
{
83-
Progress.Value = (Progress.Maximum / 2) + (int)((double)extractedSize / totalSize * (Progress.Maximum / 2));
138+
Progress.Value = (int)(
139+
(byteProgress + (currentSize / 2) + (currentProgress / 2 * currentSize)) / byteTotal * Progress.Maximum
140+
);
84141
});
85142

86143
Info.Invoke((MethodInvoker)delegate
87144
{
88-
Info.Text = $"2/2: Extracting files - {extractedSize / 1000000}MB of {totalSize / 1000000}MB";
145+
Info.Text =
146+
$"Extracting component \"{workingComponent["title"]}\"... " +
147+
$"{Math.Truncate(currentProgress * 100)}%";
89148
});
90149
}
91150
catch { }
@@ -97,22 +156,26 @@ private void ExtractTask()
97156

98157
doneCancelling = true;
99158
}
100-
else
101-
{
102-
FinishInstallation();
103-
}
104159
}
105160
}
106161
}
107162

108163
private void FinishInstallation()
109164
{
110-
if (mainForm.Shortcut.Checked)
165+
var shortcutPaths = new List<string>();
166+
167+
if (mainForm.ShortcutDesktop.Checked)
168+
{
169+
shortcutPaths.Add(Environment.GetFolderPath(Environment.SpecialFolder.Desktop));
170+
}
171+
if (mainForm.ShortcutStartMenu.Checked)
172+
{
173+
shortcutPaths.Add(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu));
174+
}
175+
176+
foreach(string path in shortcutPaths)
111177
{
112-
IWshShortcut shortcut = new WshShell().CreateShortcut(Path.Combine(
113-
Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
114-
"Flashpoint.lnk"
115-
));
178+
IWshShortcut shortcut = new WshShell().CreateShortcut(Path.Combine(path, "Flashpoint.lnk"));
116179
shortcut.TargetPath = Path.Combine(mainForm.FolderTextBox.Text, @"Launcher\Flashpoint.exe");
117180
shortcut.WorkingDirectory = Path.Combine(mainForm.FolderTextBox.Text, @"Launcher");
118181
shortcut.Description = "Shortcut to Flashpoint";

0 commit comments

Comments
 (0)