1818namespace FlashpointSecurePlayer {
1919 public partial class FlashpointSecurePlayer : Form {
2020 private const string APPLICATION_MUTEX_NAME = "Flashpoint Secure Player" ;
21+ private const string EMPTY_MODE_NAME = "" ;
2122 private const string FLASHPOINT_LAUNCHER_PARENT_PROCESS_EXE_FILE_NAME = "cmd.exe" ;
2223 private const string FLASHPOINT_LAUNCHER_PROCESS_NAME = "flashpoint" ;
24+ private Mutex ApplicationMutex = null ;
2325 private static SemaphoreSlim ModificationsSemaphoreSlim = new SemaphoreSlim ( 1 , 1 ) ;
2426 private readonly RunAsAdministrator RunAsAdministrator ;
2527 private readonly ModeTemplates ModeTemplates ;
2628 private readonly EnvironmentVariables EnvironmentVariables ;
2729 private readonly DownloadsBefore DownloadsBefore ;
2830 private readonly RegistryBackups RegistryBackup ;
2931 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 ) ;
3840
3941 public FlashpointSecurePlayer ( ) {
4042 InitializeComponent ( ) ;
@@ -314,7 +316,7 @@ private async Task StartSecurePlayback() {
314316 ShowError ( Properties . Resources . GameNotActiveXControl ) ;
315317 return ;
316318 }
317-
319+
318320 GetBinaryType ( ModificationsName , out BINARY_TYPE binaryType ) ;
319321
320322 // first, we install the control without a registry backup running
@@ -404,33 +406,7 @@ private async Task StartSecurePlayback() {
404406 securePlaybackProgressBar . Value = 100 ;
405407 ShowOutput ( Properties . Resources . RegistryBackupWasSuccessful ) ;
406408 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 {
434410 // switch to synced process
435411 ResetProgressBar ( ) ;
436412 ShowOutput ( Properties . Resources . RequiredComponentsAreLoading ) ;
@@ -450,50 +426,60 @@ await ActivateModificationsAsync(Software, delegate (string text) {
450426 return ;
451427 }
452428
453- securePlaybackProgressBar . Value = 50 ;
429+ if ( ! String . IsNullOrEmpty ( Server ) ) {
430+ securePlaybackProgressBar . Value = 50 ;
431+ Server serverForm = new Server ( new Uri ( Server ) ) ;
454432
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 ;
459439
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 ) ;
463444
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+ }
468448
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 ] ) ) ;
470453
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 ) ;
481455
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+ }
484466
485- if ( ! process . HasExited ) {
486- process . WaitForExit ( ) ;
487- }
467+ securePlaybackProgressBar . Value = 100 ;
468+ Hide ( ) ;
488469
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 ;
495482 }
496- return ;
497483 }
498484 throw new InvalidCurationException ( ) ;
499485 }
@@ -515,7 +501,7 @@ private async void FlashpointSecurePlayer_Load(object sender, EventArgs e) {
515501 // default to false in case of error
516502 bool createdNew = false ;
517503 // 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 ) ;
519505
520506 if ( ! createdNew ) {
521507 // multiple instances open, blow up immediately
0 commit comments