Skip to content

Commit dabe054

Browse files
committed
[FlashpointManager] Check dependencies of dependencies, improve dependency prompt
1 parent 610c0ee commit dabe054

File tree

2 files changed

+38
-20
lines changed

2 files changed

+38
-20
lines changed

FlashpointManager/src/Common.cs

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -418,29 +418,37 @@ public static void VerifySourcePath()
418418
// Checks if any dependencies were not marked for download by the user, and marks them accordingly
419419
public static bool CheckDependencies(bool alertDepends = true)
420420
{
421-
List<string> requiredDepends = new List<string>();
422-
List<string> persistDepends = new List<string>();
423-
List<string> missingDepends = new List<string>();
421+
List<string> requiredDepends = new List<string>();
422+
List<string> persistDepends = new List<string>();
423+
List<TreeNode> missingDepends = new List<TreeNode>();
424+
425+
void AddDependencies(string[] depends)
426+
{
427+
requiredDepends.AddRange(depends);
428+
429+
foreach (string depend in depends)
430+
{
431+
var query = Main.ComponentList.Nodes.Find(depend, true);
432+
433+
if (query.Length > 0) AddDependencies((query[0].Tag as Component).Depends);
434+
}
435+
}
424436

425437
// First, fill out a list of dependencies
426438
IterateList(Main.ComponentList.Nodes, node =>
427439
{
428440
if (node.Checked && node.Tag.GetType().ToString().EndsWith("Component"))
429441
{
430442
var component = node.Tag as Component;
431-
432-
if (ComponentTracker.Downloaded.Exists(c => c.ID == component.ID))
433-
{
434-
requiredDepends.AddRange(File.ReadLines(component.InfoFile).First().Split(' ').Skip(2).ToArray());
435-
}
436-
else
437-
{
438-
requiredDepends.AddRange(component.Depends);
439-
}
443+
444+
AddDependencies(ComponentTracker.Downloaded.Exists(c => c.ID == component.ID)
445+
? File.ReadLines(component.InfoFile).First().Split(' ').Skip(2).ToArray()
446+
: component.Depends
447+
);
440448
}
441449
});
442450

443-
// Then make sure they're all marked for installation
451+
// Then make sure they're all marked accordingly
444452
IterateList(Main.ComponentList.Nodes, node =>
445453
{
446454
if (node.Tag.GetType().ToString().EndsWith("Component"))
@@ -449,15 +457,13 @@ public static bool CheckDependencies(bool alertDepends = true)
449457

450458
if (requiredDepends.Any(depend => depend == component.ID) && !node.Checked)
451459
{
452-
node.Checked = true;
453-
454460
if (ComponentTracker.Downloaded.Exists(depend => depend.ID == component.ID))
455461
{
456462
persistDepends.Add(component.Title);
457463
}
458464
else
459465
{
460-
missingDepends.Add(component.Title);
466+
missingDepends.Add(node);
461467
}
462468
}
463469
}
@@ -477,11 +483,23 @@ public static bool CheckDependencies(bool alertDepends = true)
477483

478484
if (missingDepends.Count > 0)
479485
{
480-
MessageBox.Show(
486+
long missingSize = missingDepends.Select(n => (n.Tag as Component).Size).Sum();
487+
488+
var result = MessageBox.Show(
481489
"The following dependencies will also be installed:\n\n" +
482-
string.Join(", ", missingDepends) + "\n\nClick the OK button to proceed.",
483-
"Notice", MessageBoxButtons.OK, MessageBoxIcon.Information
490+
string.Join(", ", missingDepends.Select(n => (n.Tag as Component).Title)) + "\n\n" +
491+
$"This adds an additional {GetFormattedBytes(missingSize)} to your download. Is this OK?",
492+
"Notice", MessageBoxButtons.YesNo, MessageBoxIcon.Information
484493
);
494+
495+
if (result == DialogResult.Yes)
496+
{
497+
missingDepends.ForEach(d => d.Checked = true);
498+
}
499+
else
500+
{
501+
return false;
502+
}
485503
}
486504
}
487505

FlashpointManager/src/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ static void Main(string[] args)
9595
}
9696
else
9797
{
98-
// Automatically download component if /download argument is passed
98+
// Automatically download components if /download argument is passed
9999
var argsList = args.ToList();
100100
int first = argsList.FindIndex(v => v.ToLower() == "/download");
101101

0 commit comments

Comments
 (0)