11using System ;
22using System . Collections . Generic ;
3+ using System . Diagnostics ;
34using System . Drawing ;
45using System . IO ;
56using System . Linq ;
@@ -175,18 +176,20 @@ public static class FPM
175176 public static XmlDocument XmlTree { get ; set ; }
176177
177178 // Name of configuration file
178- public static string ConfigFile { get ; } = "fpm.cfg" ;
179+ public static string ConfigFile { get ; set ; } = "fpm.cfg" ;
179180 // Internet location of component list XML
180181 public static string ListURL { get ; set ; } = "https://nexus-dev.unstable.life/repository/development/components.xml" ;
181182 // Path to the local Flashpoint copy
182- public static string SourcePath { get ; set ; } = "" ;
183+ public static string SourcePath { get ; set ; } = Debugger . IsAttached
184+ ? Path . Combine ( Path . GetPathRoot ( AppDomain . CurrentDomain . BaseDirectory ) , "Flashpoint" )
185+ : Path . GetFullPath ( Path . Combine ( Directory . GetCurrentDirectory ( ) , ".." ) ) ;
183186
184187 // Flag to control how operation window will function
185188 // 0 is for adding/removing components
186189 // 1 is for updating components
187190 public static int OperateMode { get ; set ; } = 0 ;
188191
189- // Flag to control whether the update tab is selected at launch
192+ // Controls whether the update tab is selected at launch
190193 public static bool OpenUpdateTab { get ; set ; } = false ;
191194
192195 // Object for tracking numerous file size sums
@@ -238,26 +241,26 @@ public static void IterateXML(XmlNodeList parent, Action<XmlNode> action)
238241 }
239242
240243 // Calls the AddNodeToList method on every child of the specified XML node
241- public static void RecursiveAddToList ( XmlNode sourceNode , TreeNodeCollection destNode , bool setCheckState )
244+ public static void RecursiveAddToList ( XmlNode sourceNode , TreeNodeCollection destNode )
242245 {
243246 foreach ( XmlNode node in sourceNode . ChildNodes )
244247 {
245- var listNode = AddNodeToList ( node , destNode , setCheckState ) ;
248+ var listNode = AddNodeToList ( node , destNode ) ;
246249
247- RecursiveAddToList ( node , listNode . Nodes , setCheckState ) ;
250+ RecursiveAddToList ( node , listNode . Nodes ) ;
248251 }
249252 }
250253
251254 // Formats an XML node as a TreeView node and adds it to the specified TreeView
252- public static TreeNode AddNodeToList ( XmlNode child , TreeNodeCollection parent , bool setCheckState )
255+ public static TreeNode AddNodeToList ( XmlNode child , TreeNodeCollection parent )
253256 {
254257 TreeNode listNode = new TreeNode ( ) ;
255258
256259 // Add properties to TreeNode based on the XML element
257260 // (I can use the dynamic type to prevent redundancy, but I noticed it makes the application load significantly slower)
258261 if ( child . Name == "component" )
259262 {
260- Component component = new Component ( child ) ;
263+ var component = new Component ( child ) ;
261264
262265 listNode . Text = component . Title ;
263266 listNode . Name = component . ID ;
@@ -271,7 +274,7 @@ public static TreeNode AddNodeToList(XmlNode child, TreeNodeCollection parent, b
271274 }
272275 else if ( child . Name == "category" )
273276 {
274- Category category = new Category ( child ) ;
277+ var category = new Category ( child ) ;
275278
276279 listNode . Text = category . Title ;
277280 listNode . Name = category . ID ;
@@ -288,7 +291,7 @@ public static TreeNode AddNodeToList(XmlNode child, TreeNodeCollection parent, b
288291
289292 // Initialize checkbox
290293 // (the Checked attribute needs to be explicitly set or else the checkbox won't appear)
291- listNode . Checked = setCheckState && child . Name == "component" ;
294+ listNode . Checked = false ;
292295
293296 return listNode ;
294297 }
@@ -299,19 +302,18 @@ public static void SyncManager(bool updateLists = false)
299302 ComponentTracker . Downloaded . Clear ( ) ;
300303 ComponentTracker . ToUpdate . Clear ( ) ;
301304
302- IterateXML ( XmlTree . GetElementsByTagName ( "list" ) [ 0 ] . ChildNodes , node =>
305+ IterateList ( Main . ComponentList . Nodes , node =>
303306 {
304- if ( node . Name != "component" ) return ;
305-
306- Component component = new Component ( node ) ;
307- string infoPath = Path . Combine ( SourcePath , "Components" , $ "{ component . ID } .txt") ;
308-
309- if ( File . Exists ( infoPath ) ) ComponentTracker . Downloaded . Add ( component ) ;
310-
311- if ( updateLists )
307+ if ( node . Tag . GetType ( ) . ToString ( ) . EndsWith ( "Component" ) )
312308 {
313- TreeNode [ ] nodes = Main . ComponentList . Nodes . Find ( component . ID , true ) ;
314- if ( nodes . Length > 0 ) nodes [ 0 ] . Checked = File . Exists ( infoPath ) ;
309+ var component = node . Tag as Component ;
310+ string infoPath = Path . Combine ( SourcePath , "Components" , $ "{ component . ID } .txt") ;
311+
312+ if ( File . Exists ( infoPath ) )
313+ {
314+ ComponentTracker . Downloaded . Add ( component ) ;
315+ if ( updateLists ) node . Checked = true ;
316+ }
315317 }
316318 } ) ;
317319
@@ -356,15 +358,14 @@ public static void VerifySourcePath()
356358
357359 IterateXML ( XmlTree . GetElementsByTagName ( "list" ) [ 0 ] . ChildNodes , node =>
358360 {
359- if ( node . Name != "component" ) return ;
361+ if ( isFlashpoint || node . Name != "component" ) return ;
360362
361- Component component = new Component ( node ) ;
363+ var component = new Component ( node ) ;
362364 string infoPath = Path . Combine ( SourcePath , "Components" , $ "{ component . ID } .txt") ;
363365
364366 if ( File . Exists ( infoPath ) )
365367 {
366368 isFlashpoint = true ;
367- return ;
368369 }
369370 } ) ;
370371
@@ -391,7 +392,7 @@ public static bool CheckDependencies(TreeView sourceTree)
391392 {
392393 if ( node . Checked && node . Tag . GetType ( ) . ToString ( ) . EndsWith ( "Component" ) )
393394 {
394- Component component = node . Tag as Component ;
395+ var component = node . Tag as Component ;
395396 string infoPath = Path . Combine ( SourcePath , "Components" , $ "{ component . ID } .txt") ;
396397
397398 if ( File . Exists ( infoPath ) )
@@ -410,7 +411,7 @@ public static bool CheckDependencies(TreeView sourceTree)
410411 {
411412 if ( node . Tag . GetType ( ) . ToString ( ) . EndsWith ( "Component" ) )
412413 {
413- Component component = node . Tag as Component ;
414+ var component = node . Tag as Component ;
414415
415416 if ( requiredDepends . Any ( depend => depend == component . ID ) && ! node . Checked )
416417 {
@@ -459,7 +460,7 @@ public static long GetTotalSize(TreeView sourceTree)
459460 {
460461 if ( node . Checked && node . Tag . GetType ( ) . ToString ( ) . EndsWith ( "Component" ) )
461462 {
462- Component component = node . Tag as Component ;
463+ var component = node . Tag as Component ;
463464 string infoPath = Path . Combine ( SourcePath , "Components" , $ "{ component . ID } .txt") ;
464465
465466 size += File . Exists ( infoPath )
0 commit comments