Skip to content

Commit b380b35

Browse files
committed
[FlashpointInstaller] Minor refactoring
1 parent 9002051 commit b380b35

4 files changed

Lines changed: 17 additions & 40 deletions

File tree

FlashpointInstaller/src/Common.cs

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -160,23 +160,6 @@ public static bool RedistInstalled
160160
get => Registry.LocalMachine.OpenSubKey("SOFTWARE\\WOW6432Node\\Microsoft\\VisualStudio\\14.0\\VC\\Runtimes\\X86") != null;
161161
}
162162

163-
// Object for tracking numerous file size sums
164-
public static class SizeTracker
165-
{
166-
private static long toDownload;
167-
168-
// Tracks total size of the pending Flashpoint download
169-
public static long ToDownload
170-
{
171-
get => toDownload;
172-
set
173-
{
174-
toDownload = value;
175-
Main.InstallButton.Text = $"Install Flashpoint ({GetFormattedBytes(toDownload)})";
176-
}
177-
}
178-
}
179-
180163
// Performs an operation on every node in the specified TreeNodeCollection
181164
public static void IterateList(TreeNodeCollection parent, Action<TreeNode> action)
182165
{
@@ -384,22 +367,6 @@ void AddDependencies(string[] depends)
384367
return true;
385368
}
386369

387-
// Gets total size in bytes of all checked components in the specified TreeView
388-
public static long GetTotalSize(TreeView sourceTree)
389-
{
390-
long size = 0;
391-
392-
IterateList(sourceTree.Nodes, node =>
393-
{
394-
if (node.Checked && node.Tag.GetType().ToString().EndsWith("Component"))
395-
{
396-
size += (node.Tag as Component).Size;
397-
}
398-
});
399-
400-
return size;
401-
}
402-
403370
// Formats bytes as a human-readable string
404371
public static string GetFormattedBytes(long bytes)
405372
{

FlashpointInstaller/src/Forms/Main.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.

FlashpointInstaller/src/Forms/Main.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,16 @@ public void ComponentList_BeforeCheck(object sender, TreeViewCancelEventArgs e)
5353

5454
private void ComponentList_AfterCheck(object sender, TreeViewEventArgs e)
5555
{
56-
FPM.SizeTracker.ToDownload = FPM.GetTotalSize(ComponentList);
56+
long size = 0;
57+
58+
FPM.IterateList(ComponentList.Nodes, node =>
59+
{
60+
if (!node.Checked || !node.Tag.GetType().ToString().EndsWith("Component")) return;
61+
62+
size += (node.Tag as Component).Size;
63+
});
64+
65+
InstallButton.Text = $"Install Flashpoint ({FPM.GetFormattedBytes(size)})";
5766
}
5867

5968
private void ComponentList_BeforeSelect(object _, TreeViewCancelEventArgs e)
@@ -99,12 +108,12 @@ private void DestinationPath_KeyPress(object sender, KeyPressEventArgs e)
99108
{
100109
if (e.KeyChar == (char)Keys.Return)
101110
{
102-
DownloadButton_Click(this, e);
111+
InstallButton_Click(this, e);
103112
e.Handled = true;
104113
}
105114
}
106115

107-
private void DownloadButton_Click(object sender, EventArgs e)
116+
private void InstallButton_Click(object sender, EventArgs e)
108117
{
109118
if (!FPM.VerifyDestinationPath(DestinationPath.Text) || !FPM.CheckDependencies()) return;
110119

FlashpointInstaller/src/Forms/Operate.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,13 @@ private async void Operation_Load(object sender, EventArgs e)
4545
{
4646
if (node.Checked && node.Tag.GetType().ToString().EndsWith("Component"))
4747
{
48-
markedComponents.Add(node.Tag as Component);
48+
var component = node.Tag as Component;
49+
50+
markedComponents.Add(component);
51+
byteTotal += component.Size;
4952
}
5053
});
5154

52-
byteTotal = FPM.SizeTracker.ToDownload;
53-
5455
foreach (var component in markedComponents)
5556
{
5657
workingComponent = component;

0 commit comments

Comments
 (0)