private PandorasBackupObject GetRestoredFile(string aFilePath) { if (!File.Exists(aFilePath)) { throw new Exception($"Invalid restore file path {aFilePath}"); } byte[] lFileBytes = OnGetBytesFromFilePath.Invoke(aFilePath); PandorasBackupObject lRestoredFile = null; var lBackupSerializableTypes = GetBackupSerializableClasses(); try { lRestoredFile = new PandorasBackupObject(FileBackupProcessor.GetRetoreObjectFromBytes <BasePandoraBackupObject, BackupSerializableObject>(lFileBytes)); } catch (Exception ex) { Log.Write(LogLevel.Warning, $"Failed to retore from file. Trying to open it with old backup style. Path: {aFilePath}. Exception thrown: {ex}"); if (!TryRestoreFromOldBackupFile(lFileBytes, out lRestoredFile)) { lRestoredFile = null; } } if (lRestoredFile == null || (lRestoredFile.IsOldBackupData && lRestoredFile.ExchangeKeys == null) || (!lRestoredFile.IsOldBackupData && lRestoredFile.WalletData == null)) { throw new BackupExceptions.BadRecoveryFile($"Error reading recovery file {aFilePath}"); } return(lRestoredFile); }
private void FBackupWindow_OnBackupByFileNeeded(string aPathToSaveTo) { if (string.IsNullOrEmpty(aPathToSaveTo)) { throw new Exception("You must provide a valid path to save your backup file"); } var lObjectToBackup = GetObjectToBackup.Invoke(); var lBackupFileBytes = FileBackupProcessor.GetBackupFileBytes(lObjectToBackup); OnSaveFile.Invoke(lBackupFileBytes, aPathToSaveTo); }