Skip to content

Commit d745e09

Browse files
committed
[FlashpointManager] Streamline download status, info file checking
1 parent cbecec1 commit d745e09

2 files changed

Lines changed: 15 additions & 20 deletions

File tree

FlashpointManager/src/Common.cs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ public class Component : Category
2121
public string Path { get; set; }
2222
public string[] Depends { get; set; } = new string[] { };
2323

24+
public string InfoFile { get => System.IO.Path.Combine(FPM.SourcePath, "Components", $"{ID}.txt"); }
25+
public bool Downloaded { get => File.Exists(InfoFile); }
26+
2427
public Component(XmlNode node) : base(node)
2528
{
2629
// URL
@@ -293,7 +296,7 @@ public static void SyncManager()
293296
{
294297
var component = node.Tag as Component;
295298

296-
if (File.Exists(Path.Combine(SourcePath, "Components", $"{component.ID}.txt")))
299+
if (component.Downloaded)
297300
{
298301
ComponentTracker.Downloaded.Add(component);
299302
node.Checked = true;
@@ -339,8 +342,7 @@ void AddToQueue(Component component, long oldSize)
339342

340343
if (ComponentTracker.Downloaded.Any(item => item.ID == component.ID))
341344
{
342-
string infoFile = Path.Combine(SourcePath, "Components", $"{component.ID}.txt");
343-
string[] componentData = File.ReadLines(infoFile).First().Split(' ');
345+
string[] componentData = File.ReadLines(component.InfoFile).First().Split(' ');
344346

345347
update = componentData[0] != component.Hash;
346348
oldSize = long.Parse(componentData[1]);
@@ -407,10 +409,7 @@ public static void VerifySourcePath()
407409
{
408410
if (isFlashpoint || node.Name != "component") return;
409411

410-
var component = new Component(node);
411-
string infoPath = Path.Combine(SourcePath, "Components", $"{component.ID}.txt");
412-
413-
if (File.Exists(infoPath))
412+
if (new Component(node).Downloaded)
414413
{
415414
isFlashpoint = true;
416415
}
@@ -440,15 +439,14 @@ public static bool CheckDependencies(bool alertDepends = true)
440439
if (node.Checked && node.Tag.GetType().ToString().EndsWith("Component"))
441440
{
442441
var component = node.Tag as Component;
443-
string infoPath = Path.Combine(SourcePath, "Components", $"{component.ID}.txt");
444-
445-
if (File.Exists(infoPath))
442+
443+
if (component.Downloaded)
446444
{
447-
requiredDepends.AddRange(File.ReadLines(infoPath).First().Split(' ').Skip(2).ToArray());
445+
requiredDepends.AddRange(File.ReadLines(component.InfoFile).First().Split(' ').Skip(2).ToArray());
448446
}
449447
else
450448
{
451-
requiredDepends.AddRange((node.Tag as Component).Depends);
449+
requiredDepends.AddRange(component.Depends);
452450
}
453451
}
454452
});
@@ -511,10 +509,9 @@ public static long GetTotalSize(TreeView sourceTree)
511509
if (node.Checked && node.Tag.GetType().ToString().EndsWith("Component"))
512510
{
513511
var component = node.Tag as Component;
514-
string infoPath = Path.Combine(SourcePath, "Components", $"{component.ID}.txt");
515512

516-
size += File.Exists(infoPath)
517-
? long.Parse(File.ReadLines(infoPath).First().Split(' ')[1])
513+
size += component.Downloaded
514+
? long.Parse(File.ReadLines(component.InfoFile).First().Split(' ')[1])
518515
: component.Size;
519516
}
520517
});

FlashpointManager/src/Forms/Operate.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,7 @@ private void ExtractComponents()
234234

235235
private void RemoveComponents()
236236
{
237-
string infoFile = Path.Combine(FPM.SourcePath, "Components", $"{workingComponent.ID}.txt");
238-
string[] infoText = File.ReadLines(infoFile).Skip(1).ToArray();
237+
string[] infoText = File.ReadLines(workingComponent.InfoFile).Skip(1).ToArray();
239238

240239
long removedFiles = 0;
241240
long totalFiles = infoText.Length - 1;
@@ -272,7 +271,7 @@ private void RemoveComponents()
272271
});
273272
}
274273

275-
FPM.DeleteFileAndDirectories(infoFile);
274+
FPM.DeleteFileAndDirectories(workingComponent.InfoFile);
276275
}
277276

278277
private void ApplyComponents()
@@ -290,8 +289,7 @@ private void ApplyComponents()
290289
try { File.Move(tempFile, destFile); } catch { }
291290
}
292291

293-
string destInfoFile = Path.Combine(FPM.SourcePath, "Components", $"{workingComponent.ID}.txt");
294-
try { File.Move(tempInfoFile, destInfoFile); } catch { }
292+
try { File.Move(tempInfoFile, workingComponent.InfoFile); } catch { }
295293
}
296294

297295
public static void DeleteTempDirectory()

0 commit comments

Comments
 (0)