public RestoreSyncDataResult RestoreBackupFromSyncFolder(string password) { var restoreSyncDataResult = new RestoreSyncDataResult(); string dbFilePath = GetFullPathToDatabaseFile(); try { if (!File.Exists(GetFullPathToSharedDatabaseFile())) { restoreSyncDataResult.ErrorCode = RestoreSyncDataErrorCodes.MemoDatabaseFileNotFound; } else if (!File.Exists(GetFullPathToSharedEncryptedConfigFile())) { restoreSyncDataResult.ErrorCode = restoreSyncDataResult.ErrorCode | RestoreSyncDataErrorCodes.ApplicationSettingsFileNotFound; } else { var settings = new StorageManagerSettings(true, Environment.ProcessorCount, true, ConfSaltVal + password + ConfSaltVal2); var storageManager = new StorageManager(settings); var secureMemoAppSettings = storageManager.DeserializeObjectFromFile <SecureMemoAppSettings>(GetFullPathToSharedEncryptedConfigFile(), null); if (string.IsNullOrWhiteSpace(secureMemoAppSettings.ApplicationSaltValue) || string.IsNullOrWhiteSpace(secureMemoAppSettings.PasswordDerivedString)) { restoreSyncDataResult.ErrorCode = restoreSyncDataResult.ErrorCode | RestoreSyncDataErrorCodes.ApplicationSettingsFileParseError; restoreSyncDataResult.ErrorText = "Invalid password"; } else { var s = _appSettingsService.Settings; s.ApplicationSaltValue = secureMemoAppSettings.ApplicationSaltValue; s.PasswordDerivedString = secureMemoAppSettings.PasswordDerivedString; s.FontSettings = secureMemoAppSettings.FontSettings; s.UseSharedSyncFolder = secureMemoAppSettings.UseSharedSyncFolder; s.DefaultEmptyTabPages = secureMemoAppSettings.DefaultEmptyTabPages; s.MainWindowHeight = secureMemoAppSettings.MainWindowHeight; s.MainWindowWith = secureMemoAppSettings.MainWindowWith; _appSettingsService.SaveSettings(); _appSettingsService.LoadSettings(); if (File.Exists(dbFilePath)) { File.Delete(dbFilePath); } File.Copy(GetFullPathToSharedDatabaseFile(), dbFilePath); restoreSyncDataResult.Successful = true; } } } catch (Exception ex) { Log.Error(ex, "Error when calling RestoreBackupFromSyncFolder() - {Message}", ex.Message); restoreSyncDataResult.ErrorText = ex.Message; } return(restoreSyncDataResult); }
private void frmMain_Load(object sender, EventArgs e) { try { InitializeTabControls(); _appSettingsService.LoadSettings(); InitFormSettings(); LoadLicenseFile(); _licenseService.Init(SerialNumbersSettings.ProtectedApp.SecureMemo); Text = ConfigHelper.AssemblyTitle + " - v" + Assembly.GetExecutingAssembly().GetName().Version; UpdateApplicationState(); } catch (Exception ex) { MessageBox.Show(this, ex.Message, Resources.FormMain__Error_loading_application_settings, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// DIコンテナへ型を登録します。 /// </summary> /// <param name="containerRegistry">登録用のDIコンテナを表すIContainerRegistry。</param> protected override void RegisterTypes(IContainerRegistry containerRegistry) { containerRegistry.RegisterDialogWindow <ImaZipCoreProto01DialogWindow>(); containerRegistry.RegisterSingleton <ICommonDialogService, CommonDialogService>(); containerRegistry.RegisterInstance(AppSettingsService.LoadSettings()); }