@@ -846,6 +846,10 @@ public static async Task DownloadAsync(string name) {
846846 }
847847
848848 private static string GetValidEXEConfigurationName ( string name ) {
849+ if ( String . IsNullOrEmpty ( name ) ) {
850+ throw new ConfigurationErrorsException ( ) ;
851+ }
852+
849853 string invalidNameCharacters = new string ( Path . GetInvalidFileNameChars ( ) ) + new string ( Path . GetInvalidPathChars ( ) ) ;
850854 Regex invalidNameCharactersRegex = new Regex ( "[" + Regex . Escape ( invalidNameCharacters ) + "]+" ) ;
851855 return invalidNameCharactersRegex . Replace ( name , "." ) . ToLower ( ) ;
@@ -872,6 +876,10 @@ private static Configuration GetActiveEXEConfiguration() {
872876 // open from configuration folder
873877 ActiveEXEConfiguration = ConfigurationManager . OpenExeConfiguration ( ConfigurationUserLevel . None ) ;
874878
879+ if ( ActiveEXEConfiguration == null ) {
880+ throw new ConfigurationErrorsException ( ) ;
881+ }
882+
875883 if ( ! ActiveEXEConfiguration . HasFile ) {
876884 throw new ConfigurationErrorsException ( ) ;
877885 }
@@ -881,17 +889,21 @@ private static Configuration GetActiveEXEConfiguration() {
881889 // Fail silently.
882890 }
883891
892+ if ( ActiveEXEConfiguration == null ) {
893+ throw new ConfigurationErrorsException ( ) ;
894+ }
895+
884896 // create anew
885897 ActiveEXEConfiguration . Save ( ConfigurationSaveMode . Modified ) ;
886898 // open the new one
887- ActiveEXEConfiguration = ConfigurationManager . OpenExeConfiguration ( ConfigurationUserLevel . None ) ;
899+ ActiveEXEConfiguration = ConfigurationManager . OpenExeConfiguration ( ConfigurationUserLevel . None ) ?? throw new ConfigurationErrorsException ( ) ;
888900 return ActiveEXEConfiguration ;
889901 }
890902
891903 // where should ConfigurationErrorsExceptions all be caught? Review this
892904 private static Configuration GetEXEConfiguration ( string name ) {
893905 // active
894- if ( name == ACTIVE_EXE_CONFIGURATION_NAME ) {
906+ if ( String . IsNullOrEmpty ( name ) ) {
895907 return GetActiveEXEConfiguration ( ) ;
896908 }
897909
@@ -913,19 +925,24 @@ private static Configuration GetEXEConfiguration(string name) {
913925 // open from configuration folder
914926 exeConfiguration = ConfigurationManager . OpenMappedExeConfiguration ( exeConfigurationFileMap , ConfigurationUserLevel . None ) ;
915927
916- if ( ! exeConfiguration . HasFile ) {
928+ if ( exeConfiguration == null ) {
917929 throw new ConfigurationErrorsException ( ) ;
918930 }
919931
920- // presto!
921- EXEConfiguration = exeConfiguration ?? throw new ConfigurationErrorsException ( ) ;
932+ if ( ! exeConfiguration . HasFile ) {
933+ throw new ConfigurationErrorsException ( ) ;
934+ }
922935 } catch ( ConfigurationErrorsException ) {
923936 try {
924937 // nope, so open from configuration download
925938 EXEConfiguration = ConfigurationManager . OpenMappedExeConfiguration ( new ExeConfigurationFileMap {
926939 ExeConfigFilename = Application . StartupPath + "\\ " + HTDOCS + "\\ " + CONFIGURATION_DOWNLOAD_NAME + "\\ " + name + ".config"
927940 } , ConfigurationUserLevel . None ) ;
928941
942+ if ( EXEConfiguration == null ) {
943+ throw new ConfigurationErrorsException ( ) ;
944+ }
945+
929946 if ( ! EXEConfiguration . HasFile ) {
930947 throw new ConfigurationErrorsException ( ) ;
931948 }
@@ -938,10 +955,9 @@ private static Configuration GetEXEConfiguration(string name) {
938955 } catch ( ConfigurationErrorsException ) {
939956 // Fail silently.
940957 }
941-
942- EXEConfiguration = exeConfiguration ?? throw new ConfigurationErrorsException ( ) ;
943958 }
944959
960+ EXEConfiguration = exeConfiguration ?? throw new ConfigurationErrorsException ( ) ;
945961 EXEConfigurationName = name ;
946962 return EXEConfiguration ;
947963 }
@@ -950,7 +966,7 @@ public static FlashpointSecurePlayerSection GetFlashpointSecurePlayerSection(str
950966 FlashpointSecurePlayerSection flashpointSecurePlayerSection = null ;
951967 Configuration exeConfiguration = null ;
952968
953- if ( exeConfigurationName == ACTIVE_EXE_CONFIGURATION_NAME ) {
969+ if ( String . IsNullOrEmpty ( exeConfigurationName ) ) {
954970 if ( Shared . activeFlashpointSecurePlayerSection != null ) {
955971 return Shared . activeFlashpointSecurePlayerSection ;
956972 }
@@ -992,7 +1008,7 @@ public static FlashpointSecurePlayerSection GetFlashpointSecurePlayerSection(str
9921008 throw new ConfigurationErrorsException ( ) ;
9931009 }
9941010
995- if ( exeConfigurationName == ACTIVE_EXE_CONFIGURATION_NAME ) {
1011+ if ( String . IsNullOrEmpty ( exeConfigurationName ) ) {
9961012 Shared . activeFlashpointSecurePlayerSection = flashpointSecurePlayerSection ;
9971013 } else {
9981014 Shared . flashpointSecurePlayerSection = flashpointSecurePlayerSection ;
@@ -1003,8 +1019,12 @@ public static FlashpointSecurePlayerSection GetFlashpointSecurePlayerSection(str
10031019 public static void SetFlashpointSecurePlayerSection ( string exeConfigurationName ) {
10041020 Configuration activeEXEConfiguration = GetActiveEXEConfiguration ( ) ;
10051021 activeEXEConfiguration . Save ( ConfigurationSaveMode . Modified ) ;
1006- Configuration exeConfiguration = GetEXEConfiguration ( exeConfigurationName ) ;
1007- exeConfiguration . Save ( ConfigurationSaveMode . Modified ) ;
1022+
1023+ if ( ! String . IsNullOrEmpty ( exeConfigurationName ) ) {
1024+ Configuration exeConfiguration = GetEXEConfiguration ( exeConfigurationName ) ;
1025+ exeConfiguration . Save ( ConfigurationSaveMode . Modified ) ;
1026+ }
1027+
10081028 ConfigurationManager . RefreshSection ( "flashpointSecurePlayer" ) ;
10091029 }
10101030
0 commit comments