Skip to content

Commit c5e0ead

Browse files
committed
[FlashpointManager] Improve startup times and checkbox performance
1 parent 135b76c commit c5e0ead

2 files changed

Lines changed: 21 additions & 10 deletions

File tree

FlashpointManager/src/Common.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ public class Component : Category
2323
public string InfoFile { get => System.IO.Path.Combine(FPM.SourcePath, "Components", ID); }
2424
public bool Downloaded { get => File.Exists(InfoFile); }
2525

26+
// This is used to get around edge cases where check events trigger despite the checkbox value not changing
27+
public bool Checked { get; set; } = false;
28+
2629
public Component(XmlNode node) : base(node)
2730
{
2831
// URL
@@ -146,6 +149,9 @@ public static class FPM
146149
// The parsed component list XML
147150
public static XmlDocument XmlTree { get; } = new XmlDocument();
148151

152+
// Tracks if the manager has been initialized yet
153+
public static bool Ready { get; set; } = false;
154+
149155
// Name of configuration file
150156
public static string ConfigFile { get; set; } = "fpm.cfg";
151157
// Internet locations of component list XMLs
@@ -174,6 +180,8 @@ public static class RepoXmlTemplates
174180

175181
// Total size of every downloaded component; managed by SyncManager() function
176182
public static long DownloadedSize { get; set; } = 0;
183+
// Projected size difference based on changed values of checkboxes
184+
public static long ModifiedSize { get; set; } = 0;
177185

178186
// Object providing easy access to certain groups of components; managed by SyncManager() function
179187
public static class ComponentTracker
@@ -286,6 +294,7 @@ public static void SyncManager(bool init = false)
286294
});
287295

288296
DownloadedSize = ComponentTracker.Downloaded.Sum(c => long.Parse(File.ReadLines(c.InfoFile).First().Split(' ')[1]));
297+
ModifiedSize = 0;
289298

290299
var componentList = new List<string>();
291300

@@ -418,6 +427,8 @@ public static void SyncManager(bool init = false)
418427
Main.CustomRepo.Checked = true;
419428
break;
420429
}
430+
431+
Ready = true;
421432
}
422433

423434
// Deletes a file as well as any directories made empty by its deletion

FlashpointManager/src/Forms/Main.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,20 @@ public void ComponentList_BeforeCheck(object sender, TreeViewCancelEventArgs e)
6767

6868
public void ComponentList_AfterCheck(object sender, TreeViewEventArgs e)
6969
{
70-
long size = 0;
70+
if (!e.Node.Tag.GetType().ToString().EndsWith("Component")) return;
7171

72-
FPM.IterateList(ComponentList.Nodes, node =>
73-
{
74-
if (!node.Checked || !node.Tag.GetType().ToString().EndsWith("Component")) return;
72+
var component = e.Node.Tag as Component;
7573

76-
var component = node.Tag as Component;
74+
if (component.Checked == e.Node.Checked) return;
75+
component.Checked = e.Node.Checked;
7776

78-
size += FPM.ComponentTracker.Downloaded.Exists(c => c.ID == component.ID)
79-
? long.Parse(File.ReadLines(component.InfoFile).First().Split(' ')[1])
80-
: component.Size;
81-
});
77+
if (!FPM.Ready) return;
78+
79+
FPM.ModifiedSize += (e.Node.Checked ? 1 : -1) * (FPM.ComponentTracker.Downloaded.Exists(c => c.ID == component.ID)
80+
? long.Parse(File.ReadLines(component.InfoFile).First().Split(' ')[1])
81+
: component.Size);
8282

83-
ChangeButton.Text = $"Apply changes ({FPM.GetFormattedBytes(size - FPM.DownloadedSize)})";
83+
ChangeButton.Text = $"Apply changes ({FPM.GetFormattedBytes(FPM.ModifiedSize)})";
8484
ChangeButton.Enabled = true;
8585
}
8686

0 commit comments

Comments
 (0)