Skip to content

Commit 58168f6

Browse files
committed
[FlashpointManager] Remove deprecated components through the updater
1 parent b3fe542 commit 58168f6

2 files changed

Lines changed: 54 additions & 4 deletions

File tree

FlashpointManager/src/Common.cs

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,14 @@ public static class RepoXmlTemplates
206206
// Object providing easy access to certain groups of components; managed by SyncManager() function
207207
public static class ComponentTracker
208208
{
209-
// Returns all downloaded components
209+
// Contains all downloaded components
210210
public static List<Component> Downloaded { get; set; } = new List<Component>();
211-
// Returns all outdated components
211+
// Contains all outdated components
212212
public static List<Component> Outdated { get; set; } = new List<Component>();
213-
// Returns all components with missing files
213+
// Contains all components with missing files
214214
public static List<Component> Broken { get; set; } = new List<Component>();
215+
// Contains all components that no longer exist in the live component repository
216+
public static List<Component> Deprecated { get; set; } = new List<Component>();
215217
}
216218

217219
// Performs an operation on every node in the specified TreeNodeCollection
@@ -284,6 +286,7 @@ public static void SyncManager(bool init = false)
284286
{
285287
ComponentTracker.Downloaded.Clear();
286288
ComponentTracker.Outdated.Clear();
289+
ComponentTracker.Deprecated.Clear();
287290
Main.UpdateList.Items.Clear();
288291

289292
IterateList(Main.ComponentList.Nodes, node =>
@@ -310,19 +313,25 @@ public static void SyncManager(bool init = false)
310313

311314
DownloadedSize = ComponentTracker.Downloaded.Sum(c => long.Parse(File.ReadLines(c.InfoFile).First().Split(' ')[1]));
312315

316+
var componentList = new List<string>();
317+
313318
IterateXML(XmlTree.GetElementsByTagName("list")[0].ChildNodes, node =>
314319
{
315320
if (node.Name != "component") return;
316321

317322
var component = new Component(node);
318323

324+
componentList.Add(component.ID);
325+
319326
bool downloaded = ComponentTracker.Downloaded.Exists(c => c.ID == component.ID);
320327
bool outdated = false;
321328

322329
if (downloaded)
323330
{
324331
string localHash = File.ReadLines(component.InfoFile).First().Split(' ')[0];
325332
outdated = localHash != component.Hash && component.ID != "core-database";
333+
334+
if (outdated) MessageBox.Show(localHash + " " + component.Hash);
326335
}
327336
else if (component.Required)
328337
{
@@ -346,6 +355,32 @@ public static void SyncManager(bool init = false)
346355

347356
ComponentTracker.Outdated = ComponentTracker.Outdated.Distinct().ToList();
348357

358+
foreach (string filePath in Directory.EnumerateFiles(Path.Combine(SourcePath, "Components")))
359+
{
360+
if (!filePath.EndsWith(".txt")) continue;
361+
362+
string id = Path.GetFileName(filePath).Split('.')[0];
363+
364+
if (componentList.Contains(id)) continue;
365+
366+
string[] header = File.ReadLines(filePath).First().Split(' ');
367+
368+
long size = 0;
369+
370+
if (header.Length >= 2 && long.TryParse(header[1], out size))
371+
{
372+
var component = new Component(XmlTree.SelectSingleNode("//component"))
373+
{
374+
Title = id,
375+
ID = id,
376+
Size = size,
377+
Hash = header[0]
378+
};
379+
380+
ComponentTracker.Deprecated.Add(component);
381+
}
382+
}
383+
349384
long totalSizeChange = 0;
350385

351386
foreach (var component in ComponentTracker.Outdated)
@@ -369,12 +404,25 @@ public static void SyncManager(bool init = false)
369404
Main.UpdateList.Items.Add(item);
370405
}
371406

407+
foreach (var component in ComponentTracker.Deprecated)
408+
{
409+
totalSizeChange -= component.Size;
410+
411+
var item = new ListViewItem();
412+
item.Text = component.Title;
413+
item.SubItems.Add("This component is deprecated and can be deleted.");
414+
item.SubItems.Add("");
415+
item.SubItems.Add(GetFormattedBytes(-component.Size));
416+
417+
Main.UpdateList.Items.Add(item);
418+
}
419+
372420
Main.ChangeButton.Text = $"Apply changes";
373421
Main.ChangeButton.Enabled = false;
374422

375423
Main.UpdateButton.Text = "Install updates";
376424

377-
if (ComponentTracker.Outdated.Count > 0)
425+
if (ComponentTracker.Outdated.Count > 0 || ComponentTracker.Deprecated.Count > 0)
378426
{
379427
Main.UpdateButton.Text += $" ({GetFormattedBytes(totalSizeChange)})";
380428
Main.UpdateButton.Enabled = true;

FlashpointManager/src/Forms/Operate.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ private async void Operation_Load(object sender, EventArgs e)
7070

7171
addedComponents.Add(component);
7272
}
73+
74+
removedComponents.AddRange(FPM.ComponentTracker.Deprecated);
7375
}
7476
else
7577
{

0 commit comments

Comments
 (0)