Skip to content

Commit bcfe798

Browse files
committed
Add important variables, more functions to Common namespace
1 parent 15ed79c commit bcfe798

5 files changed

Lines changed: 266 additions & 128 deletions

File tree

Common.cs

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,28 @@ namespace FlashpointInstaller
88
{
99
namespace Common
1010
{
11-
public class FPM
11+
public static class FPM
1212
{
13+
public static Main Main { get { return (Main)Application.OpenForms["Main"]; } }
14+
public static XmlDocument XmlTree { get; set; }
15+
public static string ListURL { get; set; }
16+
public static long DownloadSize { get; set; }
17+
public static string Path
18+
{
19+
get { return Main.FolderTextBox.Text; }
20+
set { Main.FolderTextBox.Text = value; }
21+
}
22+
23+
public static void RecursiveAddToList(XmlNode sourceNode, TreeNodeCollection destNode)
24+
{
25+
foreach (XmlNode node in sourceNode.ChildNodes)
26+
{
27+
var listNode = FPM.AddNodeToList(node, destNode);
28+
29+
RecursiveAddToList(node, listNode.Nodes);
30+
}
31+
}
32+
1333
public static TreeNode AddNodeToList(XmlNode child, TreeNodeCollection parent)
1434
{
1535
var listNode = parent.Add(child.Attributes["title"].Value);
@@ -41,6 +61,29 @@ public static TreeNode AddNodeToList(XmlNode child, TreeNodeCollection parent)
4161
return listNode;
4262
}
4363

64+
public static long GetEstimatedSize(TreeNodeCollection sourceNodes)
65+
{
66+
long size = 0;
67+
68+
void Iterate(TreeNodeCollection parent)
69+
{
70+
foreach (TreeNode childNode in parent)
71+
{
72+
var attributes = childNode.Tag as Dictionary<string, string>;
73+
74+
if (childNode.Checked && attributes["type"] == "component")
75+
{
76+
size += int.Parse(attributes["size"]);
77+
}
78+
79+
Iterate(childNode.Nodes);
80+
}
81+
}
82+
Iterate(sourceNodes);
83+
84+
return size;
85+
}
86+
4487
public static string GetComponentURL(XmlNode node)
4588
{
4689
string path = node.Attributes["url"].Value;

Finish.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
using System.IO;
44
using System.Windows.Forms;
55

6+
using FlashpointInstaller.Common;
7+
68
namespace FlashpointInstaller
79
{
810
public partial class Finish : Form
@@ -16,9 +18,7 @@ private void Exit(object sender, EventArgs e)
1618
var flashpointProcess = new Process();
1719
flashpointProcess.StartInfo.UseShellExecute = true;
1820
flashpointProcess.StartInfo.FileName = "Flashpoint.exe";
19-
flashpointProcess.StartInfo.WorkingDirectory = Path.Combine(
20-
((Main)Application.OpenForms["Main"]).FolderTextBox.Text, @"Launcher"
21-
);
21+
flashpointProcess.StartInfo.WorkingDirectory = Path.Combine(FPM.Path, @"Launcher");
2222
flashpointProcess.Start();
2323
}
2424

Install.cs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ namespace FlashpointInstaller
1818
{
1919
public partial class Install : Form
2020
{
21-
Main mainForm = (Main)Application.OpenForms["Main"];
22-
2321
List<Dictionary<string, string>> componentInfo = new List<Dictionary<string, string>>();
2422
Dictionary<string, string> workingComponent;
2523

@@ -30,7 +28,7 @@ public partial class Install : Form
3028
IReader reader;
3129

3230
long byteProgress = 0;
33-
long byteTotal = ((Main)Application.OpenForms["Main"]).DownloadSize;
31+
long byteTotal = FPM.DownloadSize;
3432

3533
int cancelStatus = 0;
3634

@@ -40,7 +38,7 @@ private async void Install_Load(object sender, EventArgs e)
4038
{
4139
downloader.DownloadProgressChanged += OnDownloadProgressChanged;
4240
downloader.DownloadFileCompleted += OnDownloadFileCompleted;
43-
41+
4442
void Iterate(TreeNodeCollection parent)
4543
{
4644
foreach (TreeNode childNode in parent)
@@ -55,7 +53,7 @@ void Iterate(TreeNodeCollection parent)
5553
Iterate(childNode.Nodes);
5654
}
5755
}
58-
Iterate(mainForm.ComponentQueue.Nodes);
56+
Iterate(FPM.Main.ComponentList.Nodes);
5957

6058
foreach (var component in componentInfo)
6159
{
@@ -64,7 +62,7 @@ void Iterate(TreeNodeCollection parent)
6462

6563
if (cancelStatus != 0) return;
6664

67-
Directory.CreateDirectory(mainForm.FolderTextBox.Text);
65+
Directory.CreateDirectory(FPM.Path);
6866
await Task.Run(ExtractTask);
6967

7068
byteProgress += int.Parse(component["size"]);
@@ -112,7 +110,7 @@ private void ExtractTask()
112110
long extractedSize = 0;
113111
long totalSize = archive.TotalUncompressSize;
114112

115-
string infoPath = Path.Combine(mainForm.FolderTextBox.Text, "Components", workingComponent["path"]);
113+
string infoPath = Path.Combine(FPM.Path, "Components", workingComponent["path"]);
116114
string infoFile = $"{workingComponent["title"]}.txt";
117115

118116
Directory.CreateDirectory(infoPath);
@@ -127,7 +125,7 @@ private void ExtractTask()
127125
if (reader.Entry.IsDirectory) continue;
128126

129127
reader.WriteEntryToDirectory(
130-
mainForm.FolderTextBox.Text, new ExtractionOptions { ExtractFullPath = true, Overwrite = true }
128+
FPM.Path, new ExtractionOptions { ExtractFullPath = true, Overwrite = true }
131129
);
132130

133131
using (TextWriter writer = File.AppendText(infoPath + infoFile))
@@ -169,27 +167,27 @@ await Task.Run(() =>
169167
{
170168
var shortcutPaths = new List<string>();
171169

172-
if (mainForm.ShortcutDesktop.Checked)
170+
if (FPM.Main.ShortcutDesktop.Checked)
173171
{
174172
shortcutPaths.Add(Environment.GetFolderPath(Environment.SpecialFolder.Desktop));
175173
}
176-
if (mainForm.ShortcutStartMenu.Checked)
174+
if (FPM.Main.ShortcutStartMenu.Checked)
177175
{
178176
shortcutPaths.Add(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu));
179177
}
180178

181179
foreach (string path in shortcutPaths)
182180
{
183181
IWshShortcut shortcut = new WshShell().CreateShortcut(Path.Combine(path, "Flashpoint.lnk"));
184-
shortcut.TargetPath = Path.Combine(mainForm.FolderTextBox.Text, @"Launcher\Flashpoint.exe");
185-
shortcut.WorkingDirectory = Path.Combine(mainForm.FolderTextBox.Text, @"Launcher");
182+
shortcut.TargetPath = Path.Combine(FPM.Path, @"Launcher\Flashpoint.exe");
183+
shortcut.WorkingDirectory = Path.Combine(FPM.Path, @"Launcher");
186184
shortcut.Description = "Shortcut to Flashpoint";
187185
shortcut.Save();
188186
}
189187
});
190188

191189
Hide();
192-
mainForm.Hide();
190+
FPM.Main.Hide();
193191

194192
var FinishWindow = new Finish();
195193
FinishWindow.ShowDialog();
@@ -204,9 +202,9 @@ await Task.Run(() =>
204202
{
205203
while (cancelStatus != 2) { }
206204

207-
if (Directory.Exists(mainForm.FolderTextBox.Text))
205+
if (Directory.Exists(FPM.Path))
208206
{
209-
Directory.Delete(mainForm.FolderTextBox.Text, true);
207+
Directory.Delete(FPM.Path, true);
210208
}
211209
});
212210

0 commit comments

Comments
 (0)