Skip to content

Commit

Permalink
bug-fix - unable to start app if config file didnt exist
Browse files Browse the repository at this point in the history
  • Loading branch information
ttodua committed Jun 17, 2022
1 parent 01918d7 commit 8932f03
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 29 deletions.
34 changes: 16 additions & 18 deletions WinAuth/Resources/strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion WinAuth/Resources/strings.de.resx
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ Your code may not be correct</value>
<value>Auto Refresh</value>
</data>
<data name="CannotFindConfigurationFile" xml:space="preserve">
<value>Unable to find your configuration file</value>
<value>New configuration file was created locally, because an existing configuration file was not found</value>
</data>
<data name="CannotLoadAuthenticator" xml:space="preserve">
<value>Unable to load authenticator from {0}</value>
Expand Down
2 changes: 1 addition & 1 deletion WinAuth/Resources/strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ Your code may not be correct</value>
<value>Auto refresh</value>
</data>
<data name="CannotFindConfigurationFile" xml:space="preserve">
<value>Unable to find your configuration file</value>
<value>New configuration file was created locally, because an existing configuration file was not found.</value>
</data>
<data name="CannotLoadAuthenticator" xml:space="preserve">
<value>Unable to load authenticator from {0}</value>
Expand Down
2 changes: 1 addition & 1 deletion WinAuth/Resources/strings.zh-CN.resx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ Your code may not be correct</value>
<value>自动刷新</value>
</data>
<data name="CannotFindConfigurationFile" xml:space="preserve">
<value>无法找到您的配置文件</value>
<value>New configuration file was created locally, because an existing configuration file was not found</value>
</data>
<data name="CannotLoadAuthenticator" xml:space="preserve">
<value>Unable to load authenticator from {0}</value>
Expand Down
26 changes: 18 additions & 8 deletions WinAuth/WinAuthHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ class WinAuthHelper
=dvwu
-----END PGP PUBLIC KEY BLOCK-----";

/// <summary>
/// Return location of config file
/// </summary>
/// <returns>new WinAuthConfig location</returns>
public static string portableConfigFile()
{
return Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), DEFAULT_AUTHENTICATOR_FILE_NAME);
}

/// <summary>
/// Return location of config file
/// </summary>
Expand All @@ -141,7 +150,7 @@ public static string configLocation (string configFile)
}
if (string.IsNullOrEmpty(configFile) == true) {
// check for file in exe directory
configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), DEFAULT_AUTHENTICATOR_FILE_NAME);
configFile = portableConfigFile();
configFile = File.Exists(configFile) ? configFile : null;
}
if (string.IsNullOrEmpty(configFile) == true) {
Expand Down Expand Up @@ -170,15 +179,17 @@ public static WinAuthConfig LoadConfig(Form form, string configFile, string pass
}

configFile = configLocation(configFile);

// if no config file when one was specified; report an error
if (File.Exists(configFile) == false)
{
//MessageBox.Show(form,
// strings.CannotFindConfigurationFile + ": " + configFile,
// form.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
// return config;
throw new ApplicationException(strings.CannotFindConfigurationFile + ": " + configFile);
if (form.InvokeRequired)
{
form.Invoke(new Action( () => { WinAuthForm.ErrorDialog(form, strings.CannotFindConfigurationFile, null, MessageBoxButtons.OK); }) );
}
configFile = portableConfigFile();
config.Filename = configFile;
SaveConfig(config);
//throw new ApplicationException(strings.CannotFindConfigurationFile + ": " + configFile);
}

// check if readonly
Expand Down Expand Up @@ -211,7 +222,6 @@ public static WinAuthConfig LoadConfig(Form form, string configFile, string pass
changed = config.ReadXml(reader, password);
}

config.Filename = configFile;

if (config.Version < WinAuthConfig.CURRENTVERSION)
{
Expand Down

0 comments on commit 8932f03

Please sign in to comment.