private void BtnImport_Click(object sender, EventArgs e) { var res = openFileImport.ShowDialog(); if (res == DialogResult.Cancel) { return; } try { SettingsHelper.ImportSettings(CurrentState, openFileImport.FileName); SettingsbindingSource.ResetBindings(true); Refresh(); return; } catch (InvalidOperationException) { do { var inBox = new InputDialog(Language.Data.ConfigExportPwdPromptText, Language.Data.ConfigExportPwdPromptTitle); res = inBox.ShowDialog(); if (res == DialogResult.Cancel) { return; } try { SettingsHelper.ImportSettings(CurrentState, openFileImport.FileName, inBox.Input); MessageBox.Show(Language.Data.ConfigImportMessageSucc, Language.Data.ConfigImportMessageTitle, MessageBoxButtons.OK, MessageBoxIcon.Information); SettingsbindingSource.ResetBindings(true); Refresh(); return; } catch (System.Security.Cryptography.CryptographicException) { res = MessageBox.Show(Language.Data.ConfigExportPwdFailText, Language.Data.ConfigExportPwdFailTitle, MessageBoxButtons.RetryCancel, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); if (res == DialogResult.Cancel) { return; } } catch (Exception ex) { Logger.LogException(ex); MessageBox.Show(Language.Data.ConfigImportMessageFail, Language.Data.ConfigImportMessageTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } while (res == DialogResult.Retry); } }
private void InitRest() { Settings = new Settings(); CurrentState = new SettingsData(Settings); initState = new SettingsData(Settings); InitNoWebHook(); cmbLang.DisplayMember = "name"; cmbLang.ValueMember = "value"; cmbLang.DataSource = EnumHelper.GetValues <eLanguage>().Select(e => new { name = e.GetAttribute <CombBoxView>().Name, value = e }).ToList(); SettingsbindingSource.DataSource = CurrentState; SettingsbindingSource.ResetBindings(true); UpdateWebHooks(); //openFileImport.Filter = "LogUploaderSettings files|*.lus|All files|*.*"; openFileImport.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); //saveFileExport.Filter = "LogUploaderSettings files|*.lus|All files|*.*"; saveFileExport.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); saveFileExport.FileName = $"LogUploaderSettings{Environment.UserName}.lus"; ApplyLanguage(Language.Data); }