diff --git a/WinAuth/Resources/strings.Designer.cs b/WinAuth/Resources/strings.Designer.cs index 3c2d9b3..43cd6b2 100644 --- a/WinAuth/Resources/strings.Designer.cs +++ b/WinAuth/Resources/strings.Designer.cs @@ -682,30 +682,19 @@ internal static string AutoExitAfterCopy { get { return ResourceManager.GetString("AutoExitAfterCopy", resourceCulture); } - } - - /// - /// Looks up a localized string similar to Save config file along app. - /// - internal static string HowToMakePortable - { - get - { - return ResourceManager.GetString("HowToMakePortable", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Auto refresh. - /// - internal static string AutoRefresh { + } + + /// + /// Looks up a localized string similar to Auto refresh. + /// + internal static string AutoRefresh { get { return ResourceManager.GetString("AutoRefresh", resourceCulture); } } /// - /// Looks up a localized string similar to Unable to find your configuration file. + /// Looks up a localized string similar to New configuration file was created, because an existing configuration file was not found. /// internal static string CannotFindConfigurationFile { get { @@ -930,6 +919,15 @@ internal static string HotKeyNotAvailable { } } + /// + /// Looks up a localized string similar to Save config file along app. + /// + internal static string HowToMakePortable { + get { + return ResourceManager.GetString("HowToMakePortable", resourceCulture); + } + } + /// /// Looks up a localized string similar to Icon. /// diff --git a/WinAuth/Resources/strings.de.resx b/WinAuth/Resources/strings.de.resx index a1b8766..b4559e8 100644 --- a/WinAuth/Resources/strings.de.resx +++ b/WinAuth/Resources/strings.de.resx @@ -316,7 +316,7 @@ Your code may not be correct Auto Refresh - Unable to find your configuration file + New configuration file was created locally, because an existing configuration file was not found Unable to load authenticator from {0} diff --git a/WinAuth/Resources/strings.resx b/WinAuth/Resources/strings.resx index f8c5205..88c85fb 100644 --- a/WinAuth/Resources/strings.resx +++ b/WinAuth/Resources/strings.resx @@ -132,7 +132,7 @@ Your code may not be correct Auto refresh - Unable to find your configuration file + New configuration file was created locally, because an existing configuration file was not found. Unable to load authenticator from {0} diff --git a/WinAuth/Resources/strings.zh-CN.resx b/WinAuth/Resources/strings.zh-CN.resx index 3ea90ea..b018fc8 100644 --- a/WinAuth/Resources/strings.zh-CN.resx +++ b/WinAuth/Resources/strings.zh-CN.resx @@ -132,7 +132,7 @@ Your code may not be correct 自动刷新 - 无法找到您的配置文件 + New configuration file was created locally, because an existing configuration file was not found Unable to load authenticator from {0} diff --git a/WinAuth/WinAuthHelper.cs b/WinAuth/WinAuthHelper.cs index 9038f7c..5100f29 100644 --- a/WinAuth/WinAuthHelper.cs +++ b/WinAuth/WinAuthHelper.cs @@ -128,6 +128,15 @@ class WinAuthHelper =dvwu -----END PGP PUBLIC KEY BLOCK-----"; + /// + /// Return location of config file + /// + /// new WinAuthConfig location + public static string portableConfigFile() + { + return Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), DEFAULT_AUTHENTICATOR_FILE_NAME); + } + /// /// Return location of config file /// @@ -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) { @@ -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 @@ -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) {