Skip to content

Commit 0db8336

Browse files
committed
Clean up code of both applications
1 parent c02ec6d commit 0db8336

6 files changed

Lines changed: 45 additions & 55 deletions

File tree

FlashpointInstaller/src/Common.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -216,26 +216,26 @@ public static void IterateXML(XmlNodeList parent, Action<XmlNode> action)
216216
}
217217

218218
// Calls the AddNodeToList method on every child of the specified XML node
219-
public static void RecursiveAddToList(XmlNode sourceNode, TreeNodeCollection destNode, bool setCheckState)
219+
public static void RecursiveAddToList(XmlNode sourceNode, TreeNodeCollection destNode)
220220
{
221221
foreach (XmlNode node in sourceNode.ChildNodes)
222222
{
223-
var listNode = AddNodeToList(node, destNode, setCheckState);
223+
var listNode = AddNodeToList(node, destNode);
224224

225-
RecursiveAddToList(node, listNode.Nodes, setCheckState);
225+
RecursiveAddToList(node, listNode.Nodes);
226226
}
227227
}
228228

229229
// Formats an XML node as a TreeView node and adds it to the specified TreeView
230-
public static TreeNode AddNodeToList(XmlNode child, TreeNodeCollection parent, bool setCheckState)
230+
public static TreeNode AddNodeToList(XmlNode child, TreeNodeCollection parent)
231231
{
232232
TreeNode listNode = new TreeNode();
233233

234234
// Add properties to TreeNode based on the XML element
235235
// (I can use the dynamic type to prevent redundancy, but I noticed it makes the application load significantly slower)
236236
if (child.Name == "component")
237237
{
238-
Component component = new Component(child);
238+
var component = new Component(child);
239239

240240
listNode.Text = component.Title;
241241
listNode.Name = component.ID;
@@ -249,7 +249,7 @@ public static TreeNode AddNodeToList(XmlNode child, TreeNodeCollection parent, b
249249
}
250250
else if (child.Name == "category")
251251
{
252-
Category category = new Category(child);
252+
var category = new Category(child);
253253

254254
listNode.Text = category.Title;
255255
listNode.Name = category.ID;
@@ -266,7 +266,7 @@ public static TreeNode AddNodeToList(XmlNode child, TreeNodeCollection parent, b
266266

267267
// Initialize checkbox
268268
// (the Checked attribute needs to be explicitly set or else the checkbox won't appear)
269-
listNode.Checked = setCheckState && child.Name == "component";
269+
listNode.Checked = child.Name == "component";
270270

271271
return listNode;
272272
}
@@ -278,12 +278,11 @@ public static bool VerifyDestinationPath(string path)
278278

279279
IterateXML(XmlTree.GetElementsByTagName("list")[0].ChildNodes, node =>
280280
{
281-
if (node.Name != "component") return;
281+
if (alreadyExists || node.Name != "component") return;
282282

283283
if (File.Exists(Path.Combine(path, "Components", $"{new Component(node).ID}.txt")))
284284
{
285285
alreadyExists = true;
286-
return;
287286
}
288287
});
289288

@@ -356,7 +355,7 @@ public static void CheckDependencies()
356355
{
357356
if (node.Tag.GetType().ToString().EndsWith("Component"))
358357
{
359-
Component component = node.Tag as Component;
358+
var component = node.Tag as Component;
360359

361360
if (requiredDepends.Any(depend => depend == component.ID) && !node.Checked)
362361
{

FlashpointInstaller/src/Forms/Main.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ private void Main_Load(object sender, EventArgs e)
2121

2222
if (rootElements.Count > 0)
2323
{
24-
FPM.RecursiveAddToList(rootElements[0], ComponentList.Nodes, true);
24+
FPM.RecursiveAddToList(rootElements[0], ComponentList.Nodes);
2525
}
2626
else
2727
{

FlashpointInstaller/src/Forms/Operate.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ await Task.Run(() =>
9393
});
9494
}
9595

96-
TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.NoProgress, FPM.Main.Handle);
97-
9896
FinishOperation();
9997
}
10098
}
@@ -211,6 +209,8 @@ private void ExtractComponents()
211209

212210
private async void FinishOperation()
213211
{
212+
TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.NoProgress, FPM.Main.Handle);
213+
214214
await Task.Run(() =>
215215
{
216216
var shortcutPaths = new List<string>();

FlashpointManager/src/Common.cs

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics;
34
using System.Drawing;
45
using System.IO;
56
using System.Linq;
@@ -175,18 +176,20 @@ public static class FPM
175176
public static XmlDocument XmlTree { get; set; }
176177

177178
// Name of configuration file
178-
public static string ConfigFile { get; } = "fpm.cfg";
179+
public static string ConfigFile { get; set; } = "fpm.cfg";
179180
// Internet location of component list XML
180181
public static string ListURL { get; set; } = "https://nexus-dev.unstable.life/repository/development/components.xml";
181182
// Path to the local Flashpoint copy
182-
public static string SourcePath { get; set; } = "";
183+
public static string SourcePath { get; set; } = Debugger.IsAttached
184+
? Path.Combine(Path.GetPathRoot(AppDomain.CurrentDomain.BaseDirectory), "Flashpoint")
185+
: Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), ".."));
183186

184187
// Flag to control how operation window will function
185188
// 0 is for adding/removing components
186189
// 1 is for updating components
187190
public static int OperateMode { get; set; } = 0;
188191

189-
// Flag to control whether the update tab is selected at launch
192+
// Controls whether the update tab is selected at launch
190193
public static bool OpenUpdateTab { get; set; } = false;
191194

192195
// Object for tracking numerous file size sums
@@ -238,26 +241,26 @@ public static void IterateXML(XmlNodeList parent, Action<XmlNode> action)
238241
}
239242

240243
// Calls the AddNodeToList method on every child of the specified XML node
241-
public static void RecursiveAddToList(XmlNode sourceNode, TreeNodeCollection destNode, bool setCheckState)
244+
public static void RecursiveAddToList(XmlNode sourceNode, TreeNodeCollection destNode)
242245
{
243246
foreach (XmlNode node in sourceNode.ChildNodes)
244247
{
245-
var listNode = AddNodeToList(node, destNode, setCheckState);
248+
var listNode = AddNodeToList(node, destNode);
246249

247-
RecursiveAddToList(node, listNode.Nodes, setCheckState);
250+
RecursiveAddToList(node, listNode.Nodes);
248251
}
249252
}
250253

251254
// Formats an XML node as a TreeView node and adds it to the specified TreeView
252-
public static TreeNode AddNodeToList(XmlNode child, TreeNodeCollection parent, bool setCheckState)
255+
public static TreeNode AddNodeToList(XmlNode child, TreeNodeCollection parent)
253256
{
254257
TreeNode listNode = new TreeNode();
255258

256259
// Add properties to TreeNode based on the XML element
257260
// (I can use the dynamic type to prevent redundancy, but I noticed it makes the application load significantly slower)
258261
if (child.Name == "component")
259262
{
260-
Component component = new Component(child);
263+
var component = new Component(child);
261264

262265
listNode.Text = component.Title;
263266
listNode.Name = component.ID;
@@ -271,7 +274,7 @@ public static TreeNode AddNodeToList(XmlNode child, TreeNodeCollection parent, b
271274
}
272275
else if (child.Name == "category")
273276
{
274-
Category category = new Category(child);
277+
var category = new Category(child);
275278

276279
listNode.Text = category.Title;
277280
listNode.Name = category.ID;
@@ -288,7 +291,7 @@ public static TreeNode AddNodeToList(XmlNode child, TreeNodeCollection parent, b
288291

289292
// Initialize checkbox
290293
// (the Checked attribute needs to be explicitly set or else the checkbox won't appear)
291-
listNode.Checked = setCheckState && child.Name == "component";
294+
listNode.Checked = false;
292295

293296
return listNode;
294297
}
@@ -299,19 +302,18 @@ public static void SyncManager(bool updateLists = false)
299302
ComponentTracker.Downloaded.Clear();
300303
ComponentTracker.ToUpdate.Clear();
301304

302-
IterateXML(XmlTree.GetElementsByTagName("list")[0].ChildNodes, node =>
305+
IterateList(Main.ComponentList.Nodes, node =>
303306
{
304-
if (node.Name != "component") return;
305-
306-
Component component = new Component(node);
307-
string infoPath = Path.Combine(SourcePath, "Components", $"{component.ID}.txt");
308-
309-
if (File.Exists(infoPath)) ComponentTracker.Downloaded.Add(component);
310-
311-
if (updateLists)
307+
if (node.Tag.GetType().ToString().EndsWith("Component"))
312308
{
313-
TreeNode[] nodes = Main.ComponentList.Nodes.Find(component.ID, true);
314-
if (nodes.Length > 0) nodes[0].Checked = File.Exists(infoPath);
309+
var component = node.Tag as Component;
310+
string infoPath = Path.Combine(SourcePath, "Components", $"{component.ID}.txt");
311+
312+
if (File.Exists(infoPath))
313+
{
314+
ComponentTracker.Downloaded.Add(component);
315+
if (updateLists) node.Checked = true;
316+
}
315317
}
316318
});
317319

@@ -356,15 +358,14 @@ public static void VerifySourcePath()
356358

357359
IterateXML(XmlTree.GetElementsByTagName("list")[0].ChildNodes, node =>
358360
{
359-
if (node.Name != "component") return;
361+
if (isFlashpoint || node.Name != "component") return;
360362

361-
Component component = new Component(node);
363+
var component = new Component(node);
362364
string infoPath = Path.Combine(SourcePath, "Components", $"{component.ID}.txt");
363365

364366
if (File.Exists(infoPath))
365367
{
366368
isFlashpoint = true;
367-
return;
368369
}
369370
});
370371

@@ -391,7 +392,7 @@ public static bool CheckDependencies(TreeView sourceTree)
391392
{
392393
if (node.Checked && node.Tag.GetType().ToString().EndsWith("Component"))
393394
{
394-
Component component = node.Tag as Component;
395+
var component = node.Tag as Component;
395396
string infoPath = Path.Combine(SourcePath, "Components", $"{component.ID}.txt");
396397

397398
if (File.Exists(infoPath))
@@ -410,7 +411,7 @@ public static bool CheckDependencies(TreeView sourceTree)
410411
{
411412
if (node.Tag.GetType().ToString().EndsWith("Component"))
412413
{
413-
Component component = node.Tag as Component;
414+
var component = node.Tag as Component;
414415

415416
if (requiredDepends.Any(depend => depend == component.ID) && !node.Checked)
416417
{
@@ -459,7 +460,7 @@ public static long GetTotalSize(TreeView sourceTree)
459460
{
460461
if (node.Checked && node.Tag.GetType().ToString().EndsWith("Component"))
461462
{
462-
Component component = node.Tag as Component;
463+
var component = node.Tag as Component;
463464
string infoPath = Path.Combine(SourcePath, "Components", $"{component.ID}.txt");
464465

465466
size += File.Exists(infoPath)

FlashpointManager/src/Forms/Main.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Diagnostics;
32
using System.IO;
43
using System.Linq;
54
using System.Threading.Tasks;
@@ -22,7 +21,7 @@ private void Main_Load(object sender, EventArgs e)
2221
{
2322
if (rootElements.Count > 0)
2423
{
25-
FPM.RecursiveAddToList(rootElements[0], ComponentList.Nodes, false);
24+
FPM.RecursiveAddToList(rootElements[0], ComponentList.Nodes);
2625
}
2726
else
2827
{

FlashpointManager/src/Program.cs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.Diagnostics;
43
using System.IO;
54
using System.Threading.Tasks;
@@ -50,29 +49,21 @@ static void Main(string[] args)
5049

5150
// Load config, or create if it doesn't exist
5251

53-
var config = new List<string>() {
54-
Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), "..")),
55-
FPM.ListURL
56-
};
57-
5852
try
5953
{
6054
var configReader = File.ReadAllLines(FPM.ConfigFile);
61-
config[0] = configReader[0];
62-
config[1] = configReader[1];
55+
FPM.SourcePath = configReader[0];
56+
FPM.ListURL = configReader[1];
6357
}
6458
catch
6559
{
6660
using (var configWriter = File.CreateText(FPM.ConfigFile))
6761
{
68-
configWriter.WriteLine(config[0]);
69-
configWriter.WriteLine(config[1]);
62+
configWriter.WriteLine(FPM.SourcePath);
63+
configWriter.WriteLine(FPM.ListURL);
7064
}
7165
}
7266

73-
FPM.SourcePath = config[0];
74-
FPM.ListURL = config[1];
75-
7667
// Download and parse component list
7768

7869
Stream listStream = null;

0 commit comments

Comments
 (0)