11using System ;
22using System . Collections . Generic ;
33using System . Drawing ;
4+ using System . IO ;
45using System . Windows . Forms ;
56using System . Xml ;
67
@@ -13,24 +14,66 @@ public static class FPM
1314 public static Main Main { get { return ( Main ) Application . OpenForms [ "Main" ] ; } }
1415 public static XmlDocument XmlTree { get ; set ; }
1516 public static string ListURL { get ; set ; }
16- public static long DownloadSize { get ; set ; }
17- public static string Path
17+ public static string DownloadPath
1818 {
19- get { return Main . FolderTextBox . Text ; }
20- set { Main . FolderTextBox . Text = value ; }
19+ get { return Main . DownloadPath . Text ; }
20+ set { Main . DownloadPath . Text = value ; }
21+ }
22+ public static string FlashpointPath
23+ {
24+ get { return Main . FlashpointPath . Text ; }
25+ set { Main . FlashpointPath . Text = value ; }
26+ }
27+
28+ private static long downloadSize ;
29+ public static long DownloadSize
30+ {
31+ get => downloadSize ;
32+ set
33+ {
34+ Main . DownloadSizeDisplay . Text = GetFormattedBytes ( value ) ;
35+ downloadSize = value ;
36+ }
37+ }
38+ private static long modifiedSize ;
39+ public static long ModifiedSize
40+ {
41+ get => modifiedSize ;
42+ set
43+ {
44+ modifiedSize = value ;
45+ Main . ManagerSizeDisplay . Text = GetFormattedBytes ( modifiedSize - InitialSize ) ;
46+ }
47+ }
48+ public static long InitialSize { get ; set ; }
49+
50+ public static bool UpdateMode { get ; set ; } = false ;
51+
52+ public static List < Dictionary < string , string > > InitialComponentInfo { get ; set ; } = new List < Dictionary < string , string > > ( ) ;
53+ public static List < Dictionary < string , string > > AddedComponentInfo { get ; set ; } = new List < Dictionary < string , string > > ( ) ;
54+ public static List < Dictionary < string , string > > RemovedComponentInfo { get ; set ; } = new List < Dictionary < string , string > > ( ) ;
55+
56+ public static void Iterate ( TreeNodeCollection parent , Action < TreeNode > action )
57+ {
58+ foreach ( TreeNode childNode in parent )
59+ {
60+ action ( childNode ) ;
61+
62+ Iterate ( childNode . Nodes , action ) ;
63+ }
2164 }
2265
23- public static void RecursiveAddToList ( XmlNode sourceNode , TreeNodeCollection destNode )
66+ public static void RecursiveAddToList ( XmlNode sourceNode , TreeNodeCollection destNode , bool setCheckState )
2467 {
2568 foreach ( XmlNode node in sourceNode . ChildNodes )
2669 {
27- var listNode = FPM . AddNodeToList ( node , destNode ) ;
70+ var listNode = AddNodeToList ( node , destNode , setCheckState ) ;
2871
29- RecursiveAddToList ( node , listNode . Nodes ) ;
72+ RecursiveAddToList ( node , listNode . Nodes , setCheckState ) ;
3073 }
3174 }
3275
33- public static TreeNode AddNodeToList ( XmlNode child , TreeNodeCollection parent )
76+ public static TreeNode AddNodeToList ( XmlNode child , TreeNodeCollection parent , bool setCheckState )
3477 {
3578 var listNode = parent . Add ( child . Attributes [ "title" ] . Value ) ;
3679 listNode . Tag = new Dictionary < string , string >
@@ -48,7 +91,7 @@ public static TreeNode AddNodeToList(XmlNode child, TreeNodeCollection parent)
4891 ( listNode . Tag as Dictionary < string , string > ) . Add ( "size" , child . Attributes [ "size" ] . Value ) ;
4992 ( listNode . Tag as Dictionary < string , string > ) . Add ( "hash" , child . Attributes [ "hash" ] . Value ) ;
5093
51- listNode . Checked = bool . Parse ( child . Attributes [ "checked" ] . Value ) ;
94+ if ( setCheckState ) listNode . Checked = bool . Parse ( child . Attributes [ "checked" ] . Value ) ;
5295 }
5396
5497 if ( ( child . ParentNode . Name == "category" && child . ParentNode . Attributes [ "required" ] . Value == "true" )
@@ -61,25 +104,80 @@ public static TreeNode AddNodeToList(XmlNode child, TreeNodeCollection parent)
61104 return listNode ;
62105 }
63106
64- public static long GetEstimatedSize ( TreeNodeCollection sourceNodes )
107+ public static bool SetDownloadPath ( string path , bool updateText )
65108 {
66- long size = 0 ;
109+ string errorPath ;
67110
68- void Iterate ( TreeNodeCollection parent )
111+ if ( path . StartsWith ( Environment . ExpandEnvironmentVariables ( "%ProgramW6432%" ) )
112+ || path . StartsWith ( Environment . GetFolderPath ( Environment . SpecialFolder . ProgramFilesX86 ) ) )
69113 {
70- foreach ( TreeNode childNode in parent )
71- {
72- var attributes = childNode . Tag as Dictionary < string , string > ;
114+ errorPath = "Program Files" ;
115+ }
116+ else if ( path . StartsWith ( Path . GetTempPath ( ) . Remove ( Path . GetTempPath ( ) . Length - 1 ) ) )
117+ {
118+ errorPath = "Temporary Files" ;
119+ }
120+ else if ( path . StartsWith ( Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . UserProfile ) , "OneDrive" ) ) )
121+ {
122+ errorPath = "OneDrive" ;
123+ }
124+ else
125+ {
126+ if ( updateText ) DownloadPath = Path . Combine ( path , "Flashpoint" ) ;
127+
128+ return true ;
129+ }
130+
131+ MessageBox . Show (
132+ $ "Flashpoint cannot be installed to the { errorPath } directory! Choose a different folder.",
133+ "Error" , MessageBoxButtons . OK , MessageBoxIcon . Error
134+ ) ;
135+
136+ return false ;
137+ }
73138
74- if ( childNode . Checked && attributes [ "type" ] == "component" )
75- {
76- size += int . Parse ( attributes [ "size" ] ) ;
77- }
139+ public static bool SetFlashpointPath ( string path , bool updateText )
140+ {
141+ bool isFlashpoint = false ;
142+
143+ Iterate ( Main . ComponentList2 . Nodes , node =>
144+ {
145+ var attributes = node . Tag as Dictionary < string , string > ;
146+ string infoPath = Path . Combine ( path , "Components" , attributes [ "path" ] , $ "{ attributes [ "title" ] } .txt") ;
78147
79- Iterate ( childNode . Nodes ) ;
148+ if ( File . Exists ( infoPath ) )
149+ {
150+ isFlashpoint = true ;
151+
152+ return ;
80153 }
154+ } ) ;
155+
156+ if ( isFlashpoint )
157+ {
158+ if ( updateText ) FlashpointPath = path ;
159+
160+ return true ;
81161 }
82- Iterate ( sourceNodes ) ;
162+
163+ MessageBox . Show ( $ "Flashpoint was not found in this directory!", "Error" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
164+
165+ return false ;
166+ }
167+
168+ public static long GetEstimatedSize ( TreeNodeCollection sourceNodes )
169+ {
170+ long size = 0 ;
171+
172+ Iterate ( sourceNodes , node =>
173+ {
174+ var attributes = node . Tag as Dictionary < string , string > ;
175+
176+ if ( node . Checked && attributes [ "type" ] == "component" )
177+ {
178+ size += int . Parse ( attributes [ "size" ] ) ;
179+ }
180+ } ) ;
83181
84182 return size ;
85183 }
@@ -132,17 +230,9 @@ public static string GetFormattedBytes(long bytes)
132230 {
133231 return ( Math . Truncate ( ( double ) bytes / 100000000 ) / 10 ) . ToString ( "N1" ) + "GB" ;
134232 }
135- else if ( bytes >= 1000000 )
136- {
137- return ( Math . Truncate ( ( double ) bytes / 100000 ) / 10 ) . ToString ( "N1" ) + "MB" ;
138- }
139- else if ( bytes >= 1000 )
140- {
141- return ( Math . Truncate ( ( double ) bytes / 100 ) / 10 ) . ToString ( "N1" ) + "KB" ;
142- }
143233 else
144234 {
145- return $ " { bytes } B ";
235+ return ( Math . Truncate ( ( double ) bytes / 100000 ) / 10 ) . ToString ( "N1" ) + "MB ";
146236 }
147237 }
148238 }
0 commit comments