@@ -15,7 +15,7 @@ namespace FlashpointSecurePlayer {
1515 class EnvironmentVariables : Modifications {
1616 const string COMPATIBILITY_LAYER_NAME = "__COMPAT_LAYER" ;
1717
18- public EnvironmentVariables ( Form Form ) : base ( Form ) { }
18+ public EnvironmentVariables ( Form form ) : base ( form ) { }
1919
2020 public void Activate ( string name , string server , string applicationMutexName ) {
2121 base . Activate ( name ) ;
@@ -28,48 +28,56 @@ public void Activate(string name, string server, string applicationMutexName) {
2828 try {
2929 compatibilityLayerValue = Environment . GetEnvironmentVariable ( COMPATIBILITY_LAYER_NAME ) ;
3030 } catch ( ArgumentException ) {
31- throw new EnvironmentVariablesFailedException ( ) ;
31+ throw new EnvironmentVariablesFailedException ( "Failed to get the " + COMPATIBILITY_LAYER_NAME + " Environment Variable." ) ;
3232 } catch ( SecurityException ) {
33- throw new TaskRequiresElevationException ( ) ;
33+ throw new TaskRequiresElevationException ( "Getting the " + COMPATIBILITY_LAYER_NAME + " Environment Variable requires elevation." ) ;
3434 }
3535
36- EnvironmentVariablesElement environmentVariablesElement = null ;
36+ ProgressManager . CurrentGoal . Start ( modificationsElement . EnvironmentVariables . Count ) ;
3737
38- for ( int i = 0 ; i < modificationsElement . EnvironmentVariables . Count ; i ++ ) {
39- environmentVariablesElement = modificationsElement . EnvironmentVariables . Get ( i ) as EnvironmentVariablesElement ;
40-
41- if ( environmentVariablesElement == null ) {
42- throw new EnvironmentVariablesFailedException ( ) ;
43- }
38+ try {
39+ EnvironmentVariablesElement environmentVariablesElement = null ;
4440
45- value = environmentVariablesElement . Value ;
41+ for ( int i = 0 ; i < modificationsElement . EnvironmentVariables . Count ; i ++ ) {
42+ environmentVariablesElement = modificationsElement . EnvironmentVariables . Get ( i ) as EnvironmentVariablesElement ;
4643
47- try {
48- Environment . SetEnvironmentVariable ( environmentVariablesElement . Name , RemoveVariablesFromLengthenedValue ( value ) as string ) ;
49- } catch ( ArgumentException ) {
50- throw new EnvironmentVariablesFailedException ( ) ;
51- } catch ( SecurityException ) {
52- throw new TaskRequiresElevationException ( ) ;
53- }
44+ if ( environmentVariablesElement == null ) {
45+ throw new System . Configuration . ConfigurationErrorsException ( "The Environment Variables Element (" + i + ") is null." ) ;
46+ }
5447
55- // if this is the compatibility layer variable
56- // and the value is not what we want to set it to
57- // and we're in server mode...
58- if ( environmentVariablesElement . Name == COMPATIBILITY_LAYER_NAME && ! String . IsNullOrEmpty ( server ) ) {
59- values = new List < string > ( ) ;
48+ value = environmentVariablesElement . Value ;
6049
61- if ( compatibilityLayerValue != null ) {
62- compatibilityLayerValues = compatibilityLayerValue . ToUpper ( ) . Split ( ' ' ) . ToList ( ) ;
50+ try {
51+ Environment . SetEnvironmentVariable ( environmentVariablesElement . Name , RemoveVariablesFromLengthenedValue ( value ) as string ) ;
52+ } catch ( ArgumentException ) {
53+ throw new EnvironmentVariablesFailedException ( "Failed to set the " + environmentVariablesElement . Name + " Environment Variable." ) ;
54+ } catch ( SecurityException ) {
55+ throw new TaskRequiresElevationException ( "Setting the " + environmentVariablesElement . Name + " Environment Variable requires elevation." ) ;
6356 }
6457
65- if ( value != null ) {
66- values = value . ToUpper ( ) . Split ( ' ' ) . ToList ( ) ;
67- }
68-
69- if ( values . Except ( compatibilityLayerValues ) . Any ( ) ) {
70- throw new CompatibilityLayersException ( ) ;
58+ // if this is the compatibility layer variable
59+ // and the value is not what we want to set it to
60+ // and we're in server mode...
61+ if ( environmentVariablesElement . Name == COMPATIBILITY_LAYER_NAME && ! String . IsNullOrEmpty ( server ) ) {
62+ values = new List < string > ( ) ;
63+
64+ if ( compatibilityLayerValue != null ) {
65+ compatibilityLayerValues = compatibilityLayerValue . ToUpper ( ) . Split ( ' ' ) . ToList ( ) ;
66+ }
67+
68+ if ( value != null ) {
69+ values = value . ToUpper ( ) . Split ( ' ' ) . ToList ( ) ;
70+ }
71+
72+ if ( values . Except ( compatibilityLayerValues ) . Any ( ) ) {
73+ throw new CompatibilityLayersException ( "The Compatibility Layers (" + String . Join ( ", " , compatibilityLayerValues ) + ") cannot be set." ) ;
74+ }
7175 }
76+
77+ ProgressManager . CurrentGoal . Steps ++ ;
7278 }
79+ } finally {
80+ ProgressManager . CurrentGoal . Stop ( ) ;
7381 }
7482 }
7583
@@ -94,43 +102,51 @@ public void Deactivate(string server) {
94102 try {
95103 compatibilityLayerValue = Environment . GetEnvironmentVariable ( COMPATIBILITY_LAYER_NAME ) ;
96104 } catch ( ArgumentException ) {
97- throw new EnvironmentVariablesFailedException ( ) ;
105+ throw new EnvironmentVariablesFailedException ( "Failed to get the " + COMPATIBILITY_LAYER_NAME + " Environment Variable." ) ;
98106 } catch ( SecurityException ) {
99- throw new TaskRequiresElevationException ( ) ;
107+ throw new TaskRequiresElevationException ( "Getting the " + COMPATIBILITY_LAYER_NAME + " Environment Variable requires elevation." ) ;
100108 }
101109
102110 if ( compatibilityLayerValue != null ) {
103111 compatibilityLayerValues = compatibilityLayerValue . ToUpper ( ) . Split ( ' ' ) . ToList ( ) ;
104112 }
105113
106- EnvironmentVariablesElement environmentVariablesElement = null ;
114+ ProgressManager . CurrentGoal . Start ( modificationsElement . EnvironmentVariables . Count ) ;
107115
108- for ( int i = 0 ; i < modificationsElement . EnvironmentVariables . Count ; i ++ ) {
109- environmentVariablesElement = modificationsElement . EnvironmentVariables . Get ( i ) as EnvironmentVariablesElement ;
116+ try {
117+ EnvironmentVariablesElement environmentVariablesElement = null ;
110118
111- if ( environmentVariablesElement == null ) {
112- throw new EnvironmentVariablesFailedException ( ) ;
113- }
119+ for ( int i = 0 ; i < modificationsElement . EnvironmentVariables . Count ; i ++ ) {
120+ environmentVariablesElement = modificationsElement . EnvironmentVariables . Get ( i ) as EnvironmentVariablesElement ;
114121
115- value = environmentVariablesElement . Value ;
116- values = new List < string > ( ) ;
122+ if ( environmentVariablesElement == null ) {
123+ throw new System . Configuration . ConfigurationErrorsException ( "The Environment Variables Element (" + i + ") is null." ) ;
124+ }
117125
118- if ( value != null ) {
119- values = value . ToUpper ( ) . Split ( ' ' ) . ToList ( ) ;
120- }
126+ value = environmentVariablesElement . Value ;
127+ values = new List < string > ( ) ;
121128
122- // if this isn't the compatibility layer variable
123- // or the value isn't what we want to set it to
124- // or we're not in server mode...
125- if ( environmentVariablesElement . Name != COMPATIBILITY_LAYER_NAME || values . Except ( compatibilityLayerValues ) . Any ( ) || String . IsNullOrEmpty ( server ) ) {
126- try {
127- Environment . SetEnvironmentVariable ( environmentVariablesElement . Name , null ) ;
128- } catch ( ArgumentException ) {
129- throw new EnvironmentVariablesFailedException ( ) ;
130- } catch ( SecurityException ) {
131- throw new TaskRequiresElevationException ( ) ;
129+ if ( value != null ) {
130+ values = value . ToUpper ( ) . Split ( ' ' ) . ToList ( ) ;
132131 }
132+
133+ // if this isn't the compatibility layer variable
134+ // or the value isn't what we want to set it to
135+ // or we're not in server mode...
136+ if ( environmentVariablesElement . Name != COMPATIBILITY_LAYER_NAME || values . Except ( compatibilityLayerValues ) . Any ( ) || String . IsNullOrEmpty ( server ) ) {
137+ try {
138+ Environment . SetEnvironmentVariable ( environmentVariablesElement . Name , null ) ;
139+ } catch ( ArgumentException ) {
140+ throw new EnvironmentVariablesFailedException ( "Failed to set the " + environmentVariablesElement . Name + " Environment Variable." ) ;
141+ } catch ( SecurityException ) {
142+ throw new TaskRequiresElevationException ( "Getting the " + COMPATIBILITY_LAYER_NAME + " Environment Variable requires elevation." ) ;
143+ }
144+ }
145+
146+ ProgressManager . CurrentGoal . Steps ++ ;
133147 }
148+ } finally {
149+ ProgressManager . CurrentGoal . Stop ( ) ;
134150 }
135151 }
136152 }
0 commit comments