@@ -63,6 +63,8 @@ private void Form1_Load(object sender, EventArgs e)
63
63
const string msgError2 =
64
64
"games.js couldn't be found.\n Make sure you run thcrap_configure.exe first!" ;
65
65
if ( ! File . Exists ( "games.js" ) ) ErrorAndExit ( msgError2 ) ;
66
+
67
+ DeleteOutdatedConfig ( ) ;
66
68
67
69
#region Load data from files
68
70
@@ -94,23 +96,15 @@ private void Form1_Load(object sender, EventArgs e)
94
96
file = File . ReadAllText ( ConfigFile ) ;
95
97
Configuration1 = JsonConvert . DeserializeObject < Configuration > ( file , settings ) ;
96
98
}
97
-
98
- if ( Configuration1 . IsDescending . Count == 0 )
99
- for ( var i = 0 ; i < 2 ; i ++ )
100
- Configuration1 . IsDescending . Add ( "false" ) ;
101
-
102
- if ( Configuration1 . OnlyFavourites . Count == 0 )
103
- for ( var i = 0 ; i < 2 ; i ++ )
104
- Configuration1 . OnlyFavourites . Add ( "false" ) ;
99
+
105
100
//Load favourites
106
101
if ( File . Exists ( "favourites.js" ) )
107
102
{
108
103
file = File . ReadAllText ( "favourites.js" ) ;
109
104
Favourites1 = JsonConvert . DeserializeObject < Favourites > ( file ) ;
110
105
}
111
-
112
106
#endregion
113
-
107
+
114
108
#region Fix patch stack list
115
109
116
110
for ( var i = 0 ; i < _jsFiles . Count ; i ++ )
@@ -138,10 +132,6 @@ private void Form1_Load(object sender, EventArgs e)
138
132
139
133
#region Display
140
134
141
- //Change Form settings
142
- SetDesktopLocation ( Configuration1 . Window . Location [ 0 ] , Configuration1 . Window . Location [ 1 ] ) ;
143
- Size = new Size ( Configuration1 . Window . Size [ 0 ] , Configuration1 . Window . Size [ 1 ] ) ;
144
-
145
135
//Display patch stacks
146
136
foreach ( var item in _jsFiles )
147
137
listBox1 . Items . Add ( item ) ;
@@ -151,7 +141,13 @@ private void Form1_Load(object sender, EventArgs e)
151
141
_gamesList . Add ( item . Key ) ;
152
142
listBox2 . Items . Add ( item . Key ) ;
153
143
}
154
-
144
+
145
+ SetDefaultSettings ( ) ;
146
+
147
+ //Change Form settings
148
+ SetDesktopLocation ( Configuration1 . Window . Location [ 0 ] , Configuration1 . Window . Location [ 1 ] ) ;
149
+ Size = new Size ( Configuration1 . Window . Size [ 0 ] , Configuration1 . Window . Size [ 1 ] ) ;
150
+
155
151
//Display config
156
152
checkBox1 . Checked = Configuration1 . ExitAfterStartup ;
157
153
@@ -161,8 +157,38 @@ private void Form1_Load(object sender, EventArgs e)
161
157
162
158
#endregion
163
159
164
- #region Set default state for the sort/filter buttons
165
160
161
+ if ( menuStrip1 == null ) return ;
162
+ menuStrip1 . Items . OfType < ToolStripMenuItem > ( ) . ToList ( ) . ForEach ( x =>
163
+ x . MouseHover += ( obj , arg ) => ( ( ToolStripDropDownItem ) obj ) . ShowDropDown ( ) ) ;
164
+
165
+ Debug . WriteLine ( "Form1 Loaded" ) ;
166
+ }
167
+
168
+ private void SetDefaultSettings ( )
169
+ {
170
+ //Default Configuration setting
171
+ if ( Configuration1 . LastGame == null ) Configuration1 . LastGame = _gamesList [ 0 ] ;
172
+ if ( Configuration1 . LastConfig == null ) Configuration1 . LastConfig = _jsFiles [ 0 ] ;
173
+ if ( Configuration1 . IsDescending == null )
174
+ {
175
+ string [ ] a = { "false" , "false" } ;
176
+ Configuration1 . IsDescending = a ;
177
+ }
178
+
179
+ if ( Configuration1 . OnlyFavourites == null )
180
+ {
181
+ string [ ] a = { "false" , "false" } ;
182
+ Configuration1 . OnlyFavourites = a ;
183
+ }
184
+
185
+ if ( Configuration1 . Window == null )
186
+ {
187
+ var window = new Window { Size = new [ ] { Size . Width , Size . Height } , Location = new [ ] { Location . X , Location . Y } } ;
188
+ Configuration1 . Window = window ;
189
+ }
190
+
191
+
166
192
//Default sort
167
193
for ( var i = 0 ; i < 2 ; i ++ )
168
194
if ( Configuration1 . IsDescending [ i ] == "false" )
@@ -224,15 +250,10 @@ private void Form1_Load(object sender, EventArgs e)
224
250
filterByType_button . BackgroundImage = _gameAndCustom ;
225
251
for ( var i = 0 ; i < Configuration1 . FilterExeType ; i ++ ) filterByType_button_Click ( null , new EventArgs ( ) ) ;
226
252
227
- #endregion
253
+
254
+ }
228
255
229
- if ( menuStrip1 == null ) return ;
230
- menuStrip1 . Items . OfType < ToolStripMenuItem > ( ) . ToList ( ) . ForEach ( x =>
231
- x . MouseHover += ( obj , arg ) => ( ( ToolStripDropDownItem ) obj ) . ShowDropDown ( ) ) ;
232
256
233
- Debug . WriteLine ( "Form1 Loaded" ) ;
234
- }
235
-
236
257
private void Form1_Shown ( object sender , EventArgs e )
237
258
{
238
259
ReadConfig ( ) ;
@@ -245,6 +266,11 @@ private void Form1_Shown(object sender, EventArgs e)
245
266
246
267
UpdateConfigFile ( ) ;
247
268
}
269
+
270
+ private void DeleteOutdatedConfig ( )
271
+ {
272
+ if ( File . Exists ( "uthcrapl_confis.js" ) ) File . Delete ( "uthcrapl_confis.js" ) ;
273
+ }
248
274
249
275
private void Form1_Resize ( object sender , EventArgs e )
250
276
{
@@ -327,7 +353,6 @@ private void UpdateConfig()
327
353
Configuration1 . LastGame = ( ( string ) listBox2 . SelectedItem ) . Replace ( " ★" , "" ) ;
328
354
329
355
var window = new Window { Size = new [ ] { Size . Width , Size . Height } , Location = new [ ] { Location . X , Location . Y } } ;
330
-
331
356
Configuration1 . Window = window ;
332
357
333
358
Favourites1 . Patches . Clear ( ) ;
@@ -677,8 +702,8 @@ public class Configuration
677
702
public bool ExitAfterStartup { get ; set ; }
678
703
public string LastConfig { get ; set ; }
679
704
public string LastGame { get ; set ; }
680
- public List < string > IsDescending { get ; set ; }
681
- public List < string > OnlyFavourites { get ; set ; }
705
+ public string [ ] IsDescending { get ; set ; }
706
+ public string [ ] OnlyFavourites { get ; set ; }
682
707
public byte FilterExeType { get ; set ; }
683
708
public Window Window { get ; set ; }
684
709
}
0 commit comments