@@ -193,30 +193,16 @@ public static class FPM
193193 // Controls which component (if any) will be automatically downloaded at launch
194194 public static string AutoDownload { get ; set ; } = "" ;
195195
196- // Object for tracking numerous file size sums
197- public static class SizeTracker
198- {
199- // Tracks total size of components available locally
200- public static long Downloaded { get ; set ; }
201- // Tracks size difference from checking/unchecking components in the manager tab
202- private static long toChange ;
203- public static long ToChange
204- {
205- get => toChange ;
206- set {
207- toChange = value ;
208- Main . ChangeButton . Text = $ "Apply changes ({ GetFormattedBytes ( toChange - Downloaded ) } )";
209- }
210- }
211- }
196+ // Total size of every downloaded component; managed by SyncManager() function
197+ public static long DownloadedSize { get ; set ; } = 0 ;
212198
213- // Object for tracking information about certain groups of components
199+ // Object providing easy access to certain groups of components; managed by SyncManager() function
214200 public static class ComponentTracker
215201 {
216- // Information about components that are available locally
202+ // Returns all downloaded components
217203 public static List < Component > Downloaded { get ; set ; } = new List < Component > ( ) ;
218- // Information about components that are to be updated or added through the updater
219- public static List < Component > ToUpdate { get ; set ; } = new List < Component > ( ) ;
204+ // Returns all outdated components
205+ public static List < Component > Outdated { get ; set ; } = new List < Component > ( ) ;
220206 }
221207
222208 // Performs an operation on every node in the specified TreeNodeCollection
@@ -288,7 +274,8 @@ public static TreeNode AddNodeToList(XmlNode child, TreeNodeCollection parent)
288274 public static void SyncManager ( )
289275 {
290276 ComponentTracker . Downloaded . Clear ( ) ;
291- ComponentTracker . ToUpdate . Clear ( ) ;
277+ ComponentTracker . Outdated . Clear ( ) ;
278+ Main . UpdateList . Items . Clear ( ) ;
292279
293280 IterateList ( Main . ComponentList . Nodes , node =>
294281 {
@@ -308,8 +295,7 @@ public static void SyncManager()
308295 }
309296 } ) ;
310297
311- Main . UpdateList . Items . Clear ( ) ;
312- Main . UpdateButton . Text = "Install updates" ;
298+ DownloadedSize = ComponentTracker . Downloaded . Sum ( c => long . Parse ( File . ReadLines ( c . InfoFile ) . First ( ) . Split ( ' ' ) [ 1 ] ) ) ;
313299
314300 long totalSizeChange = 0 ;
315301
@@ -326,9 +312,9 @@ void AddToQueue(Component component, long oldSize)
326312 item . SubItems . Add ( component . Description ) ;
327313 item . SubItems . Add ( component . LastUpdated ) ;
328314 item . SubItems . Add ( displayedSize ) ;
329- Main . UpdateList . Items . Add ( item ) ;
330315
331- ComponentTracker . ToUpdate . Add ( component ) ;
316+ Main . UpdateList . Items . Add ( item ) ;
317+ ComponentTracker . Outdated . Add ( component ) ;
332318 }
333319
334320 IterateXML ( XmlTree . GetElementsByTagName ( "list" ) [ 0 ] . ChildNodes , node =>
@@ -367,18 +353,20 @@ void AddToQueue(Component component, long oldSize)
367353 }
368354 } ) ;
369355
370- if ( ComponentTracker . ToUpdate . Count > 0 )
356+ Main . ChangeButton . Text = $ "Apply changes";
357+ Main . ChangeButton . Enabled = false ;
358+
359+ Main . UpdateButton . Text = "Install updates" ;
360+
361+ if ( ComponentTracker . Outdated . Count > 0 )
371362 {
372- Main . UpdateButton . Enabled = true ;
373363 Main . UpdateButton . Text += $ " ({ GetFormattedBytes ( totalSizeChange ) } )";
364+ Main . UpdateButton . Enabled = true ;
374365 }
375366 else
376367 {
377368 Main . UpdateButton . Enabled = false ;
378369 }
379-
380- SizeTracker . Downloaded = GetTotalSize ( Main . ComponentList ) ;
381- SizeTracker . ToChange = SizeTracker . Downloaded ;
382370 }
383371
384372 // Deletes a file as well as any directories made empty by its deletion
@@ -499,26 +487,6 @@ public static bool CheckDependencies(bool alertDepends = true)
499487 return true ;
500488 }
501489
502- // Gets total size in bytes of all checked components in the specified TreeView
503- public static long GetTotalSize ( TreeView sourceTree )
504- {
505- long size = 0 ;
506-
507- IterateList ( sourceTree . Nodes , node =>
508- {
509- if ( node . Checked && node . Tag . GetType ( ) . ToString ( ) . EndsWith ( "Component" ) )
510- {
511- var component = node . Tag as Component ;
512-
513- size += component . Downloaded
514- ? long . Parse ( File . ReadLines ( component . InfoFile ) . First ( ) . Split ( ' ' ) [ 1 ] )
515- : component . Size ;
516- }
517- } ) ;
518-
519- return size ;
520- }
521-
522490 // Formats bytes as a human-readable string
523491 public static string GetFormattedBytes ( long bytes )
524492 {
0 commit comments