Ejemplo n.º 1
0
        public static async Task<BackupResultHelper> StartBackup(List<Game> games, BackupType backupType, bool backupEnabled, BackupSyncOptions backupSyncOptions, int intervalMinute = 0, int intervalHour = 0) {
            //Check for problems with parameters
            if (!games.Any() && backupType == BackupType.Autobackup && backupEnabled) {
                _resultHelper = new BackupResultHelper {Message = @"Auto-backup disabled", AutobackupEnabled = false};
                return _resultHelper;
            }
            if (!games.Any()) {
                ErrorResultHelper.Message = @"No games selected";
                return ErrorResultHelper;
            }

            var gamesToBackup= new List<Game>();
            if (!backupEnabled) {
                if (!GetDirectoryOrFile(backupType)) return ErrorResultHelper;
                gamesToBackup = ModifyGamePaths(games);
            }

            switch (backupType) {                  
                case BackupType.ToZip:
                   return await BackupToZip.BackupAndZip(gamesToBackup, _specifiedFile);
                case BackupType.ToFolder:
                    return BackupToFolder.BackupSaves(gamesToBackup, _specifiedFolder);
                case BackupType.Autobackup:
                    return BackupAuto.ToggleAutoBackup(gamesToBackup, backupEnabled, backupSyncOptions, intervalMinute, intervalHour, _specifiedFolder);
            }

            return ErrorResultHelper;
        }
Ejemplo n.º 2
0
        private void HandleBackupResult(BackupResultHelper result) {
            if (!result.Success && result.RemoveFromAutobackup) { //If no source files found for a game added to autobackup
                GamesToBackup.Remove(result.Game);
                MessageBox.Show(result.Message, @"Operation failed", MessageBoxButton.OK, MessageBoxImage.Hand);
                return;
            } 
            if(!result.Success) {
                MessageBox.Show(result.Message, @"Operation failed", MessageBoxButton.OK, MessageBoxImage.Hand);
                return;
            }

            BackupEnabled = result.AutobackupEnabled;
            if (!string.IsNullOrWhiteSpace(result.BackupButtonText))
                BackupButtonText = result.BackupButtonText;

            if (!result.AutobackupEnabled && BackupType != BackupType.Autobackup) LastBackupTime = result.BackupDateTime;
            if (BackupType != BackupType.Autobackup) MessageBox.Show(@"Backup complete");
            if (BackupType == BackupType.Autobackup && !BackupEnabled) BackupButtonText = "Enable auto-backup";
        }