18
18
namespace FlashpointSecurePlayer {
19
19
public partial class FlashpointSecurePlayer : Form {
20
20
private const string APPLICATION_MUTEX_NAME = "Flashpoint Secure Player" ;
21
+ private const string EMPTY_MODE_NAME = "" ;
21
22
private const string FLASHPOINT_LAUNCHER_PARENT_PROCESS_EXE_FILE_NAME = "cmd.exe" ;
22
23
private const string FLASHPOINT_LAUNCHER_PROCESS_NAME = "flashpoint" ;
24
+ private Mutex ApplicationMutex = null ;
23
25
private static SemaphoreSlim ModificationsSemaphoreSlim = new SemaphoreSlim ( 1 , 1 ) ;
24
26
private readonly RunAsAdministrator RunAsAdministrator ;
25
27
private readonly ModeTemplates ModeTemplates ;
26
28
private readonly EnvironmentVariables EnvironmentVariables ;
27
29
private readonly DownloadsBefore DownloadsBefore ;
28
30
private readonly RegistryBackups RegistryBackup ;
29
31
private readonly SingleInstance SingleInstance ;
30
- string ModificationsName = ACTIVE_EXE_CONFIGURATION_NAME ;
31
- bool RunAsAdministratorModification = false ;
32
- List < string > DownloadsBeforeModificationNames = null ;
33
- bool ActiveX = false ;
34
- string Server = null ;
35
- string Software = null ;
36
- ProcessStartInfo SoftwareProcessStartInfo = null ;
37
- public delegate void ErrorDelegate ( string text ) ;
32
+ private string ModificationsName = ACTIVE_EXE_CONFIGURATION_NAME ;
33
+ private bool RunAsAdministratorModification = false ;
34
+ private List < string > DownloadsBeforeModificationNames = null ;
35
+ private bool ActiveX = false ;
36
+ private string Server = EMPTY_MODE_NAME ;
37
+ private string Software = EMPTY_MODE_NAME ;
38
+ private ProcessStartInfo SoftwareProcessStartInfo = null ;
39
+ private delegate void ErrorDelegate ( string text ) ;
38
40
39
41
public FlashpointSecurePlayer ( ) {
40
42
InitializeComponent ( ) ;
@@ -314,7 +316,7 @@ private async Task StartSecurePlayback() {
314
316
ShowError ( Properties . Resources . GameNotActiveXControl ) ;
315
317
return ;
316
318
}
317
-
319
+
318
320
GetBinaryType ( ModificationsName , out BINARY_TYPE binaryType ) ;
319
321
320
322
// first, we install the control without a registry backup running
@@ -404,33 +406,7 @@ private async Task StartSecurePlayback() {
404
406
securePlaybackProgressBar . Value = 100 ;
405
407
ShowOutput ( Properties . Resources . RegistryBackupWasSuccessful ) ;
406
408
return ;
407
- } else if ( ! String . IsNullOrEmpty ( Server ) ) {
408
- // switch to server form
409
- ResetProgressBar ( ) ;
410
- ShowOutput ( Properties . Resources . RequiredComponentsAreLoading ) ;
411
-
412
- try {
413
- await ActivateModificationsAsync ( null , delegate ( string text ) {
414
- if ( text . IndexOf ( "\n " ) == - 1 ) {
415
- ShowError ( text ) ;
416
- } else {
417
- ShowError ( ) ;
418
- MessageBox . Show ( text , Properties . Resources . FlashpointSecurePlayer , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
419
- }
420
-
421
- throw new InvalidModificationException ( ) ;
422
- } ) . ConfigureAwait ( true ) ;
423
- } catch ( InvalidModificationException ) {
424
- return ;
425
- }
426
-
427
- Server serverForm = new Server ( new Uri ( Server ) ) ;
428
-
429
- securePlaybackProgressBar . Value = 100 ;
430
- Hide ( ) ;
431
- serverForm . Show ( ) ;
432
- return ;
433
- } else if ( ! String . IsNullOrEmpty ( Software ) ) {
409
+ } else {
434
410
// switch to synced process
435
411
ResetProgressBar ( ) ;
436
412
ShowOutput ( Properties . Resources . RequiredComponentsAreLoading ) ;
@@ -450,50 +426,60 @@ await ActivateModificationsAsync(Software, delegate (string text) {
450
426
return ;
451
427
}
452
428
453
- securePlaybackProgressBar . Value = 50 ;
429
+ if ( ! String . IsNullOrEmpty ( Server ) ) {
430
+ securePlaybackProgressBar . Value = 50 ;
431
+ Server serverForm = new Server ( new Uri ( Server ) ) ;
454
432
455
- try {
456
- // default to zero in case of error
457
- int argc = 0 ;
458
- string [ ] argv = CommandLineToArgv ( Software , out argc ) ;
433
+ securePlaybackProgressBar . Value = 100 ;
434
+ Hide ( ) ;
435
+ serverForm . Show ( ) ;
436
+ return ;
437
+ } else if ( ! String . IsNullOrEmpty ( Software ) ) {
438
+ securePlaybackProgressBar . Value = 50 ;
459
439
460
- if ( SoftwareProcessStartInfo == null ) {
461
- SoftwareProcessStartInfo = new ProcessStartInfo ( ) ;
462
- }
440
+ try {
441
+ // default to zero in case of error
442
+ int argc = 0 ;
443
+ string [ ] argv = CommandLineToArgv ( Software , out argc ) ;
463
444
464
- SoftwareProcessStartInfo . FileName = Path . GetFullPath ( argv [ 0 ] ) ;
465
- SoftwareProcessStartInfo . Arguments = GetCommandLineArgumentRange ( Software , 1 , - 1 ) ;
466
- SoftwareProcessStartInfo . ErrorDialog = false ;
467
- SoftwareProcessStartInfo . WorkingDirectory = Path . GetDirectoryName ( Path . GetFullPath ( argv [ 0 ] ) ) ;
445
+ if ( SoftwareProcessStartInfo == null ) {
446
+ SoftwareProcessStartInfo = new ProcessStartInfo ( ) ;
447
+ }
468
448
469
- Process process = Process . Start ( SoftwareProcessStartInfo ) ;
449
+ SoftwareProcessStartInfo . FileName = Path . GetFullPath ( argv [ 0 ] ) ;
450
+ SoftwareProcessStartInfo . Arguments = GetCommandLineArgumentRange ( Software , 1 , - 1 ) ;
451
+ SoftwareProcessStartInfo . ErrorDialog = false ;
452
+ SoftwareProcessStartInfo . WorkingDirectory = Path . GetDirectoryName ( Path . GetFullPath ( argv [ 0 ] ) ) ;
470
453
471
- try {
472
- ProcessSync . Start ( process ) ;
473
- } catch ( JobObjectException ) {
474
- // popup message box and blow up
475
- ShowError ( ) ;
476
- MessageBox . Show ( Properties . Resources . JobObjectNotCreated , Properties . Resources . FlashpointSecurePlayer , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
477
- process . Kill ( ) ;
478
- Environment . Exit ( - 1 ) ;
479
- return ;
480
- }
454
+ Process process = Process . Start ( SoftwareProcessStartInfo ) ;
481
455
482
- securePlaybackProgressBar . Value = 100 ;
483
- Hide ( ) ;
456
+ try {
457
+ ProcessSync . Start ( process ) ;
458
+ } catch ( JobObjectException ) {
459
+ // popup message box and blow up
460
+ ShowError ( ) ;
461
+ MessageBox . Show ( Properties . Resources . JobObjectNotCreated , Properties . Resources . FlashpointSecurePlayer , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
462
+ process . Kill ( ) ;
463
+ Environment . Exit ( - 1 ) ;
464
+ return ;
465
+ }
484
466
485
- if ( ! process . HasExited ) {
486
- process . WaitForExit ( ) ;
487
- }
467
+ securePlaybackProgressBar . Value = 100 ;
468
+ Hide ( ) ;
488
469
489
- Application . Exit ( ) ;
490
- } catch {
491
- Show ( ) ;
492
- ShowError ( ) ;
493
- MessageBox . Show ( Properties . Resources . ProcessFailedStart , Properties . Resources . FlashpointSecurePlayer , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
494
- Application . Exit ( ) ;
470
+ if ( ! process . HasExited ) {
471
+ process . WaitForExit ( ) ;
472
+ }
473
+
474
+ Application . Exit ( ) ;
475
+ } catch {
476
+ Show ( ) ;
477
+ ShowError ( ) ;
478
+ MessageBox . Show ( Properties . Resources . ProcessFailedStart , Properties . Resources . FlashpointSecurePlayer , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
479
+ Application . Exit ( ) ;
480
+ }
481
+ return ;
495
482
}
496
- return ;
497
483
}
498
484
throw new InvalidCurationException ( ) ;
499
485
}
@@ -515,7 +501,7 @@ private async void FlashpointSecurePlayer_Load(object sender, EventArgs e) {
515
501
// default to false in case of error
516
502
bool createdNew = false ;
517
503
// signals the Mutex if it has not been
518
- Mutex flashpointSecurePlayerMutex = new Mutex ( true , APPLICATION_MUTEX_NAME , out createdNew ) ;
504
+ ApplicationMutex = new Mutex ( true , APPLICATION_MUTEX_NAME , out createdNew ) ;
519
505
520
506
if ( ! createdNew ) {
521
507
// multiple instances open, blow up immediately
0 commit comments