@@ -121,120 +121,7 @@ public string Target
121
121
if ( value == _target ) return ;
122
122
_target = value ;
123
123
OnPropertyChanged ( ) ;
124
-
125
- /**
126
- * Check validity of the specified target value.
127
- */
128
- if ( string . IsNullOrEmpty ( Target ) || ! Directory . Exists ( Target ) )
129
- {
130
- Status = "Enter a valid path." ;
131
- CanInstall = false ;
132
- return ;
133
- }
134
-
135
- if ( Target . Contains ( GetFolderPath ( ProgramFiles ) )
136
- || ! string . IsNullOrEmpty ( GetFolderPath ( ProgramFilesX86 ) ) && Target . Contains ( GetFolderPath ( ProgramFilesX86 ) ) )
137
- {
138
- Status = "The game does not function correctly when install to Program Files. Please choose a difference location." ;
139
- CanInstall = false ;
140
- return ;
141
- }
142
-
143
-
144
- try
145
- {
146
- var exists = Directory . Exists ( Target ) ;
147
- var path = Target ;
148
- var rootExists = Directory . Exists ( Path . GetPathRoot ( Target ) ) ;
149
-
150
- if ( ! exists && ! rootExists )
151
- {
152
- throw new DirectoryNotFoundException ( Target ) ;
153
- }
154
- if ( ! exists && rootExists )
155
- {
156
- while ( ! Directory . Exists ( path ) )
157
- {
158
- path = Directory . GetParent ( path ) . Name ;
159
- if ( path == "Debug" ) return ;
160
- }
161
- }
162
-
163
- // if Target and Root exist...
164
- _target = Path . GetFullPath ( _target ) ;
165
- value = Path . GetFullPath ( value ) ;
166
- var test = Path . Combine ( path , "io.bin" ) ;
167
- WriteAllBytes ( test , new byte [ 8 ] ) ;
168
- Delete ( test ) ;
169
-
170
- Status = "Waiting for user to install SPV3." ;
171
- CanInstall = true ;
172
- }
173
- catch ( Exception e )
174
- {
175
- var msg = "Installation not possible at selected path: " + Target + "\n Error: " + e . ToString ( ) + "\n " ;
176
- var log = ( HXE . File ) Paths . Exception ;
177
- log . AppendAllText ( msg ) ;
178
- Status = msg ;
179
- CanInstall = false ;
180
- return ;
181
- }
182
-
183
- /**
184
- * Check available disk space. This will NOT work on UNC paths!
185
- */
186
- try
187
- {
188
-
189
- /** First, check the C:\ drive to ensure there's enough free space
190
- * for temporary extraction to %temp% */
191
- if ( Directory . Exists ( @"C:\" ) )
192
- {
193
- var systemDrive = new DriveInfo ( @"C:\" ) ;
194
- if ( systemDrive . TotalFreeSpace < 10737418240 )
195
- {
196
- Status = @"Not enough disk space (10GB required) on the C:\ drive. " +
197
- "Clear junk files using Disk Cleanup or allocate more space to the volume" ;
198
- CanInstall = false ;
199
- return ;
200
- }
201
- }
202
-
203
- /**
204
- * Check if the target drive has at least 16GB of free space
205
- */
206
- var targetDrive = new DriveInfo ( Path . GetPathRoot ( Target ) ) ;
207
-
208
- if ( targetDrive . IsReady && targetDrive . TotalFreeSpace > 17179869184 )
209
- {
210
- CanInstall = true ;
211
- }
212
- else
213
- {
214
- Status = "Not enough disk space (16GB required) at selected path: " + Target ;
215
- CanInstall = false ;
216
- return ;
217
- }
218
- }
219
- catch ( Exception e )
220
- {
221
- var msg = "Failed to get drive space.\n Error: " + e . ToString ( ) + "\n " ;
222
- var log = ( HXE . File ) Paths . Exception ;
223
- log . AppendAllText ( msg ) ;
224
- Status = msg ;
225
- CanInstall = false ;
226
- }
227
-
228
- /**
229
- * Prohibit installations to known problematic folders.
230
- */
231
- if ( Exists ( Path . Combine ( Target , HXE . Paths . HCE . Executable ) )
232
- || Exists ( Path . Combine ( Target , HXE . Paths . Executable ) )
233
- || Exists ( Path . Combine ( Target , Paths . Executable ) ) )
234
- {
235
- Status = "Selected folder contains existing HCE or SPV3 data. Please choose a different location." ;
236
- CanInstall = false ;
237
- }
124
+ ValidateTarget ( value ) ;
238
125
}
239
126
}
240
127
@@ -278,10 +165,11 @@ public void Initialise()
278
165
Main = Visible ;
279
166
Activation = Collapsed ;
280
167
168
+ ValidateTarget ( Target ) ;
169
+
281
170
/**
282
171
* Determine if the current environment fulfills the installation requirements.
283
172
*/
284
-
285
173
if ( Registry . GameExists ( "Custom" )
286
174
|| Registry . GameExists ( "Retail" )
287
175
|| ( Kernel . hxe . Tweaks . Patches & Patcher . EXEP . DISABLE_DRM_AND_KEY_CHECKS ) == 1 )
@@ -455,6 +343,116 @@ public void CheckSteamPath(string exe)
455
343
Update_SteamStatus ( ) ;
456
344
}
457
345
346
+ public void ValidateTarget ( string path )
347
+ {
348
+ /**
349
+ * Check validity of the specified target value.
350
+ */
351
+ if ( string . IsNullOrEmpty ( path )
352
+ || ! Directory . Exists ( Path . GetPathRoot ( path ) ) )
353
+ {
354
+ Status = "Enter a valid path." ;
355
+ CanInstall = false ;
356
+ return ;
357
+ }
358
+
359
+ /**
360
+ * Check if path contains Program Files or Program Files (x86)
361
+ */
362
+ if ( path . Contains ( GetFolderPath ( ProgramFiles ) )
363
+ || ! string . IsNullOrEmpty ( GetFolderPath ( ProgramFilesX86 ) )
364
+ && path . Contains ( GetFolderPath ( ProgramFilesX86 ) ) )
365
+ {
366
+ Status = "The game does not function correctly when install to Program Files. Please choose a difference location." ;
367
+ CanInstall = false ;
368
+ return ;
369
+ }
370
+
371
+ try
372
+ {
373
+ var exists = Directory . Exists ( path ) ;
374
+ var root = Path . GetPathRoot ( path ) ;
375
+ var rootExists = Directory . Exists ( root ) ;
376
+
377
+ if ( ! exists && rootExists )
378
+ {
379
+ while ( ! Directory . Exists ( path ) )
380
+ {
381
+ path = Directory . GetParent ( path ) . FullName ;
382
+ if ( path == CurrentDirectory )
383
+ {
384
+ Status = "Enter a valid path." ;
385
+ CanInstall = false ;
386
+ return ;
387
+ }
388
+ }
389
+ }
390
+
391
+ // if Target and Root exist...
392
+ path = Path . GetFullPath ( path ) ;
393
+ var test = Path . Combine ( path , "io.bin" ) ;
394
+ WriteAllBytes ( test , new byte [ 8 ] ) ;
395
+ Delete ( test ) ;
396
+
397
+ Status = "Waiting for user to install SPV3." ;
398
+ CanInstall = true ;
399
+ }
400
+ catch ( Exception e )
401
+ {
402
+ var msg = "Installation not possible at selected path: " + path + "\n Error: " + e . ToString ( ) + "\n " ;
403
+ var log = ( HXE . File ) Paths . Exception ;
404
+ log . AppendAllText ( msg ) ;
405
+ Status = msg ;
406
+ CanInstall = false ;
407
+ return ;
408
+ }
409
+
410
+ /**
411
+ * Check available disk space. This will NOT work on UNC paths!
412
+ */
413
+ try
414
+ {
415
+ /** First, check the user's temp folder's drive to ensure there's enough free space
416
+ * for temporary extraction to %temp%
417
+ */
418
+ {
419
+ var tmpath = Path . GetPathRoot ( Path . GetTempPath ( ) ) ;
420
+ var systemDrive = new DriveInfo ( tmpath ) ;
421
+ if ( systemDrive . TotalFreeSpace < 11811160064 )
422
+ {
423
+ Status = $ "Not enough disk space (11GB required) on the { tmpath } drive. " +
424
+ "Clear junk files using Disk Cleanup or allocate more space to the volume" ;
425
+ CanInstall = false ;
426
+ return ;
427
+ }
428
+ }
429
+
430
+ /**
431
+ * Check if the target drive has at least 16GB of free space
432
+ */
433
+ var targetDrive = new DriveInfo ( Path . GetPathRoot ( path ) ) ;
434
+
435
+ if ( targetDrive . IsReady && targetDrive . TotalFreeSpace > 17179869184 )
436
+ {
437
+ CanInstall = true ;
438
+ }
439
+ else
440
+ {
441
+ Status = "Not enough disk space (16GB required) at selected path: " + path ;
442
+ CanInstall = false ;
443
+ return ;
444
+ }
445
+ }
446
+ catch ( Exception e )
447
+ {
448
+ var msg = "Failed to get drive space.\n Error: " + e . ToString ( ) + "\n " ;
449
+ var log = ( HXE . File ) Paths . Exception ;
450
+ log . AppendAllText ( msg ) ;
451
+ Status = msg ;
452
+ CanInstall = false ;
453
+ }
454
+ }
455
+
458
456
public void ViewActivation ( ) // Debug widget
459
457
{
460
458
Main = Collapsed ;
0 commit comments