1
1
using System ;
2
2
using System . Collections . Generic ;
3
+ using System . Diagnostics ;
3
4
using System . Drawing ;
4
5
using System . IO ;
5
6
using System . Linq ;
6
7
using System . Net ;
8
+ using System . Threading . Tasks ;
9
+ using System . Threading ;
7
10
using System . Windows . Forms ;
8
11
using System . Xml ;
12
+ using System . Net . Http ;
9
13
10
14
namespace FlashpointManager
11
15
{
@@ -27,6 +31,9 @@ public class Component : Category
27
31
// This is used to get around edge cases where check events trigger despite the checkbox value not changing
28
32
public bool Checked { get ; set ; } = false ;
29
33
34
+ // this is used for determining if the component should be updated or not
35
+ public bool Checked2 { get ; set ; } = false ;
36
+
30
37
public Component ( XmlNode node ) : base ( node )
31
38
{
32
39
// URL
@@ -161,6 +168,9 @@ public static class FPM
161
168
// Tracks if the manager has been initialized yet
162
169
public static bool Ready { get ; set ; } = false ;
163
170
171
+ // Tracks the total size change of all components
172
+ public static long totalSizeChange = 0 ;
173
+
164
174
// Name of configuration file
165
175
public static string ConfigFile { get ; set ; } = "fpm.cfg" ;
166
176
// Internet locations of component list XMLs
@@ -200,6 +210,12 @@ public static class ComponentTracker
200
210
public static List < Component > Broken { get ; set ; } = new List < Component > ( ) ;
201
211
// Contains all components that no longer exist in the live component repository
202
212
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
+ }
203
219
}
204
220
205
221
// Performs an operation on every node in the specified TreeNodeCollection
@@ -273,8 +289,9 @@ public static void SyncManager()
273
289
ComponentTracker . Downloaded . Clear ( ) ;
274
290
ComponentTracker . Outdated . Clear ( ) ;
275
291
ComponentTracker . Deprecated . Clear ( ) ;
292
+ Main . UpdateList . BeginUpdate ( ) ;
276
293
Main . UpdateList . Items . Clear ( ) ;
277
-
294
+
278
295
IterateList ( Main . ComponentList . Nodes , node =>
279
296
{
280
297
if ( node . Tag . GetType ( ) . ToString ( ) . EndsWith ( "Component" ) )
@@ -328,14 +345,19 @@ public static void SyncManager()
328
345
if ( outdated )
329
346
{
330
347
ComponentTracker . Outdated . Add ( component ) ;
348
+ component . Checked2 = true ;
331
349
332
350
foreach ( string dependID in component . Depends )
333
351
{
334
352
if ( ! ( ComponentTracker . Downloaded . Exists ( c => c . ID == dependID )
335
353
|| ComponentTracker . Outdated . Exists ( c => c . ID == dependID ) ) )
336
354
{
337
355
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
+ }
339
361
}
340
362
}
341
363
}
@@ -365,11 +387,13 @@ public static void SyncManager()
365
387
Hash = header [ 0 ]
366
388
} ;
367
389
390
+ // by defualt we don't want want to remove depricated components
391
+ component . Checked2 = false ;
392
+
368
393
ComponentTracker . Deprecated . Add ( component ) ;
369
394
}
370
395
}
371
396
372
- long totalSizeChange = 0 ;
373
397
374
398
foreach ( var component in ComponentTracker . Outdated )
375
399
{
@@ -387,31 +411,37 @@ public static void SyncManager()
387
411
item . SubItems . Add ( component . Description ) ;
388
412
item . SubItems . Add ( component . LastUpdated ) ;
389
413
item . SubItems . Add ( displayedSize ) ;
414
+ item . Checked = component . Checked2 ;
415
+ item . Tag = new { Component = component , SizeChange = sizeChange } ;
390
416
391
417
Main . UpdateList . Items . Add ( item ) ;
392
418
}
393
419
394
420
foreach ( var component in ComponentTracker . Deprecated )
395
421
{
396
- totalSizeChange -= component . Size ;
422
+ long sizeChange = - component . Size ;
423
+
424
+ totalSizeChange -= sizeChange ;
397
425
398
426
var item = new ListViewItem ( ) ;
399
427
item . Text = component . Title ;
400
428
item . SubItems . Add ( "This component is deprecated and can be deleted." ) ;
401
429
item . SubItems . Add ( "" ) ;
402
430
item . SubItems . Add ( GetFormattedBytes ( - component . Size , true ) ) ;
403
-
431
+ item . Checked = false ;
432
+ item . Tag = new { Component = component , SizeChange = sizeChange } ;
404
433
Main . UpdateList . Items . Add ( item ) ;
405
434
}
406
435
436
+
407
437
Main . ChangeButton . Text = $ "Apply changes";
408
438
Main . ChangeButton . Enabled = false ;
409
439
410
- Main . UpdateButton . Text = "Install updates" ;
411
-
412
440
if ( ComponentTracker . Outdated . Count > 0 || ComponentTracker . Deprecated . Count > 0 )
413
441
{
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 ) } ";
415
445
Main . UpdateButton . Enabled = true ;
416
446
}
417
447
else
@@ -433,8 +463,8 @@ public static void SyncManager()
433
463
Main . CustomRepo . Checked = true ;
434
464
break ;
435
465
}
436
-
437
466
Ready = true ;
467
+ Main . UpdateList . EndUpdate ( ) ;
438
468
}
439
469
440
470
// Deletes a file as well as any directories made empty by its deletion
0 commit comments