Skip to content

Commit eb3c74d

Browse files
dot-mikeWumboSpasm
authored andcommitted
feat: Implement indiviual download for components: Use CancellationToken for handling cancellation.
1 parent 5dadb03 commit eb3c74d

File tree

4 files changed

+333
-134
lines changed

4 files changed

+333
-134
lines changed

FlashpointManager/src/Common.cs

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics;
34
using System.Drawing;
45
using System.IO;
56
using System.Linq;
67
using System.Net;
8+
using System.Threading.Tasks;
9+
using System.Threading;
710
using System.Windows.Forms;
811
using System.Xml;
12+
using System.Net.Http;
913

1014
namespace FlashpointManager
1115
{
@@ -27,6 +31,9 @@ public class Component : Category
2731
// This is used to get around edge cases where check events trigger despite the checkbox value not changing
2832
public bool Checked { get; set; } = false;
2933

34+
// this is used for determining if the component should be updated or not
35+
public bool Checked2 { get; set; } = false;
36+
3037
public Component(XmlNode node) : base(node)
3138
{
3239
// URL
@@ -161,6 +168,9 @@ public static class FPM
161168
// Tracks if the manager has been initialized yet
162169
public static bool Ready { get; set; } = false;
163170

171+
// Tracks the total size change of all components
172+
public static long totalSizeChange = 0;
173+
164174
// Name of configuration file
165175
public static string ConfigFile { get; set; } = "fpm.cfg";
166176
// Internet locations of component list XMLs
@@ -200,6 +210,12 @@ public static class ComponentTracker
200210
public static List<Component> Broken { get; set; } = new List<Component>();
201211
// Contains all components that no longer exist in the live component repository
202212
public static List<Component> Deprecated { get; set; } = new List<Component>();
213+
214+
// Returns a list of outdated and deprecated components
215+
public static List<Component> GetOutdatedAndDeprecated()
216+
{
217+
return Outdated.Concat(Deprecated).ToList();
218+
}
203219
}
204220

205221
// Performs an operation on every node in the specified TreeNodeCollection
@@ -273,8 +289,9 @@ public static void SyncManager()
273289
ComponentTracker.Downloaded.Clear();
274290
ComponentTracker.Outdated.Clear();
275291
ComponentTracker.Deprecated.Clear();
292+
Main.UpdateList.BeginUpdate();
276293
Main.UpdateList.Items.Clear();
277-
294+
278295
IterateList(Main.ComponentList.Nodes, node =>
279296
{
280297
if (node.Tag.GetType().ToString().EndsWith("Component"))
@@ -328,14 +345,19 @@ public static void SyncManager()
328345
if (outdated)
329346
{
330347
ComponentTracker.Outdated.Add(component);
348+
component.Checked2 = true;
331349

332350
foreach (string dependID in component.Depends)
333351
{
334352
if (!(ComponentTracker.Downloaded.Exists(c => c.ID == dependID)
335353
|| ComponentTracker.Outdated.Exists(c => c.ID == dependID)))
336354
{
337355
var query = Main.ComponentList.Nodes.Find(dependID, true);
338-
if (query.Length > 0) ComponentTracker.Outdated.Add(query[0].Tag as Component);
356+
if (query.Length > 0)
357+
{
358+
ComponentTracker.Outdated.Add(query[0].Tag as Component);
359+
component.Checked2 = true;
360+
}
339361
}
340362
}
341363
}
@@ -365,11 +387,13 @@ public static void SyncManager()
365387
Hash = header[0]
366388
};
367389

390+
// by defualt we don't want want to remove depricated components
391+
component.Checked2 = false;
392+
368393
ComponentTracker.Deprecated.Add(component);
369394
}
370395
}
371396

372-
long totalSizeChange = 0;
373397

374398
foreach (var component in ComponentTracker.Outdated)
375399
{
@@ -387,31 +411,37 @@ public static void SyncManager()
387411
item.SubItems.Add(component.Description);
388412
item.SubItems.Add(component.LastUpdated);
389413
item.SubItems.Add(displayedSize);
414+
item.Checked = component.Checked2;
415+
item.Tag = new { Component = component, SizeChange = sizeChange };
390416

391417
Main.UpdateList.Items.Add(item);
392418
}
393419

394420
foreach (var component in ComponentTracker.Deprecated)
395421
{
396-
totalSizeChange -= component.Size;
422+
long sizeChange = -component.Size;
423+
424+
totalSizeChange -= sizeChange;
397425

398426
var item = new ListViewItem();
399427
item.Text = component.Title;
400428
item.SubItems.Add("This component is deprecated and can be deleted.");
401429
item.SubItems.Add("");
402430
item.SubItems.Add(GetFormattedBytes(-component.Size, true));
403-
431+
item.Checked = false;
432+
item.Tag = new { Component = component, SizeChange = sizeChange };
404433
Main.UpdateList.Items.Add(item);
405434
}
406435

436+
407437
Main.ChangeButton.Text = $"Apply changes";
408438
Main.ChangeButton.Enabled = false;
409439

410-
Main.UpdateButton.Text = "Install updates";
411-
412440
if (ComponentTracker.Outdated.Count > 0 || ComponentTracker.Deprecated.Count > 0)
413441
{
414-
Main.UpdateButton.Text += $" ({GetFormattedBytes(totalSizeChange, true)})";
442+
var componentCount = ComponentTracker.Outdated.Count + ComponentTracker.Deprecated.Count;
443+
Main.lblTotalUpdates.Text = $"Total updates: {componentCount}";
444+
Main.lblTotalUpdatesSize.Text = $"Total size: {GetFormattedBytes(totalSizeChange)}";
415445
Main.UpdateButton.Enabled = true;
416446
}
417447
else
@@ -433,8 +463,8 @@ public static void SyncManager()
433463
Main.CustomRepo.Checked = true;
434464
break;
435465
}
436-
437466
Ready = true;
467+
Main.UpdateList.EndUpdate();
438468
}
439469

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

0 commit comments

Comments
 (0)