@@ -75,8 +75,8 @@ private void ShowError(string errorLabelText) {
7575 this . errorLabel . Text = errorLabelText ;
7676 }
7777
78- private void AskLaunchInAdministratorMode ( ) {
79- if ( ! TestProcessRunningAsAdministrator ( ) ) {
78+ private void AskLaunchAsAdministratorUser ( ) {
79+ if ( ! TestLaunchedAsAdministratorUser ( ) ) {
8080 // popup message box and restart program here
8181 // https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.messagebox?view=netframework-4.8
8282 /*
@@ -89,7 +89,7 @@ then there'd be no dialog except this one - and I don't want
8989 the program to enter an infinite restart loop
9090 */
9191 ShowOutput ( ) ;
92- DialogResult dialogResult = MessageBox . Show ( Properties . Resources . LaunchInAdministratorMode , Properties . Resources . FlashpointSecurePlayer , MessageBoxButtons . YesNo , MessageBoxIcon . None ) ;
92+ DialogResult dialogResult = MessageBox . Show ( String . Format ( Properties . Resources . LaunchGame , Properties . Resources . AsAdministratorUser ) , Properties . Resources . FlashpointSecurePlayer , MessageBoxButtons . YesNo , MessageBoxIcon . None ) ;
9393
9494 if ( dialogResult == DialogResult . No ) {
9595 Application . Exit ( ) ;
@@ -101,7 +101,20 @@ the program to enter an infinite restart loop
101101 }
102102
103103 // we're already running as admin?
104- ShowError ( Properties . Resources . GameFailedAdministratorMode ) ;
104+ ShowError ( String . Format ( Properties . Resources . GameFailedLaunch , Properties . Resources . AsAdministratorUser ) ) ;
105+ throw new InvalidModificationException ( ) ;
106+ }
107+
108+ private void AskLaunchWithCompatibilitySettings ( ) {
109+ ShowOutput ( ) ;
110+ DialogResult dialogResult = MessageBox . Show ( String . Format ( Properties . Resources . LaunchGame , Properties . Resources . WithCompatibilitySettings ) , Properties . Resources . FlashpointSecurePlayer , MessageBoxButtons . YesNo , MessageBoxIcon . None ) ;
111+
112+ if ( dialogResult == DialogResult . No ) {
113+ Application . Exit ( ) ;
114+ throw new InvalidModificationException ( ) ;
115+ }
116+
117+ RestartApplication ( false , this , APPLICATION_MUTEX_NAME ) ;
105118 throw new InvalidModificationException ( ) ;
106119 }
107120
@@ -164,7 +177,7 @@ private async Task ActivateModificationsAsync(string commandLine, ErrorDelegate
164177 } catch ( System . Configuration . ConfigurationErrorsException ) {
165178 errorDelegate ( Properties . Resources . ConfigurationFailedLoad ) ;
166179 } catch ( TaskRequiresElevationException ) {
167- AskLaunchInAdministratorMode ( ) ;
180+ AskLaunchAsAdministratorUser ( ) ;
168181 }
169182
170183 if ( modificationsElement . ModeTemplates . ServerModeTemplate . ElementInformation . IsPresent || modificationsElement . ModeTemplates . SoftwareModeTemplate . ElementInformation . IsPresent ) {
@@ -175,7 +188,7 @@ private async Task ActivateModificationsAsync(string commandLine, ErrorDelegate
175188 } catch ( System . Configuration . ConfigurationErrorsException ) {
176189 errorDelegate ( Properties . Resources . ConfigurationFailedLoad ) ;
177190 } catch ( TaskRequiresElevationException ) {
178- AskLaunchInAdministratorMode ( ) ;
191+ AskLaunchAsAdministratorUser ( ) ;
179192 }
180193 }
181194
@@ -187,7 +200,9 @@ private async Task ActivateModificationsAsync(string commandLine, ErrorDelegate
187200 } catch ( System . Configuration . ConfigurationErrorsException ) {
188201 errorDelegate ( Properties . Resources . ConfigurationFailedLoad ) ;
189202 } catch ( TaskRequiresElevationException ) {
190- AskLaunchInAdministratorMode ( ) ;
203+ AskLaunchAsAdministratorUser ( ) ;
204+ } catch ( CompatibilityLayersException ) {
205+ AskLaunchWithCompatibilitySettings ( ) ;
191206 }
192207 }
193208
@@ -209,7 +224,7 @@ private async Task ActivateModificationsAsync(string commandLine, ErrorDelegate
209224 } catch ( System . Configuration . ConfigurationErrorsException ) {
210225 errorDelegate ( Properties . Resources . ConfigurationFailedLoad ) ;
211226 } catch ( TaskRequiresElevationException ) {
212- AskLaunchInAdministratorMode ( ) ;
227+ AskLaunchAsAdministratorUser ( ) ;
213228 }
214229 }
215230
@@ -219,7 +234,7 @@ private async Task ActivateModificationsAsync(string commandLine, ErrorDelegate
219234 } catch ( InvalidModificationException ex ) {
220235 throw ex ;
221236 } catch ( TaskRequiresElevationException ) {
222- AskLaunchInAdministratorMode ( ) ;
237+ AskLaunchAsAdministratorUser ( ) ;
223238 } catch {
224239 errorDelegate ( Properties . Resources . UnknownProcessCompatibilityConflict ) ;
225240 }
@@ -242,17 +257,19 @@ private async Task DeactivateModificationsAsync(ErrorDelegate errorDelegate) {
242257 } catch ( System . Configuration . ConfigurationErrorsException ) {
243258 errorDelegate ( Properties . Resources . ConfigurationFailedLoad ) ;
244259 } catch ( TaskRequiresElevationException ) {
245- AskLaunchInAdministratorMode ( ) ;
260+ AskLaunchAsAdministratorUser ( ) ;
246261 }
247262
248263 try {
249- EnvironmentVariables . Deactivate ( ) ;
264+ EnvironmentVariables . Deactivate ( Server ) ;
250265 } catch ( EnvironmentVariablesFailedException ) {
251266 errorDelegate ( Properties . Resources . EnvironmentVariablesFailed ) ;
252267 } catch ( System . Configuration . ConfigurationErrorsException ) {
253268 errorDelegate ( Properties . Resources . ConfigurationFailedLoad ) ;
254269 } catch ( TaskRequiresElevationException ) {
255- AskLaunchInAdministratorMode ( ) ;
270+ AskLaunchAsAdministratorUser ( ) ;
271+ } catch ( CompatibilityLayersException ) {
272+ AskLaunchWithCompatibilitySettings ( ) ;
256273 }
257274
258275 try {
@@ -278,12 +295,9 @@ private async Task StartSecurePlayback() {
278295 throw new InvalidModificationException ( ) ;
279296 }
280297
281- //this.ShowInTaskbar = true;
282- //this.WindowState = FormWindowState.Normal;
283-
284298 // this requires admin
285- if ( ! TestProcessRunningAsAdministrator ( ) ) {
286- AskLaunchInAdministratorMode ( ) ;
299+ if ( ! TestLaunchedAsAdministratorUser ( ) ) {
300+ AskLaunchAsAdministratorUser ( ) ;
287301 }
288302
289303 ResetProgressBar ( ) ;
@@ -341,7 +355,7 @@ private async Task StartSecurePlayback() {
341355 return ;
342356 } catch ( TaskRequiresElevationException ) {
343357 // we're already running as admin?
344- ShowError ( Properties . Resources . GameFailedAdministratorMode ) ;
358+ ShowError ( String . Format ( Properties . Resources . GameFailedLaunch , Properties . Resources . AsAdministratorUser ) ) ;
345359 return ;
346360 } catch ( InvalidOperationException ) {
347361 ShowError ( Properties . Resources . RegistryBackupAlreadyRunning ) ;
@@ -535,13 +549,15 @@ private async void FlashpointSecurePlayer_Load(object sender, EventArgs e) {
535549 }
536550 } catch ( TaskRequiresElevationException ) {
537551 try {
538- AskLaunchInAdministratorMode ( ) ;
552+ AskLaunchAsAdministratorUser ( ) ;
539553 } catch ( InvalidModificationException ) {
540554 Application . Exit ( ) ;
541555 return ;
542556 }
543557 }
544558
559+ BringToFront ( ) ;
560+ Activate ( ) ;
545561 ShowOutput ( Properties . Resources . RequiredComponentsAreUnloading ) ;
546562
547563 string arg = null ;
0 commit comments