public static async void CheckForBackupUpdatesAsync() { try { if (Definitions.List.Libraries.Count(x => x.Type == Definitions.Enums.LibraryType.Uplay && x.DirectoryInfo.Exists) == 0) { return; } var progressInformationMessage = await Main.FormAccessor.ShowProgressAsync(SLM.Translate(nameof(Properties.Resources.PleaseWait)), SLM.Translate(nameof(Properties.Resources.Steam_CheckForBackupUpdates))).ConfigureAwait(true); progressInformationMessage.SetIndeterminate(); foreach (var currentLibrary in Definitions.List.Libraries.Where(x => x.Type == Definitions.Enums.LibraryType.Uplay && x.DirectoryInfo.Exists).ToList()) { if (currentLibrary.Apps.Count == 0) { continue; } foreach (var libraryToCheck in Definitions.List.Libraries.Where(x => x != currentLibrary && x.Type == Definitions.Enums.LibraryType.Uplay)) { foreach (var currentApp in currentLibrary.Apps.Where(x => !x.IsCompressed).ToList()) { progressInformationMessage.SetMessage(Framework.StringFormat.Format(SLM.Translate(nameof(Properties.Resources.Steam_CheckForBackupUpdates_Progress)), new { CurrentAppName = currentApp.AppName })); foreach (var latestApp in libraryToCheck.Apps.Where(x => x.AppId == currentApp.AppId && x.LastUpdated > currentApp.LastUpdated && !x.IsCompressed)) { if (TaskManager.TaskList.Count(x => x.App.AppId == currentApp.AppId && !x.Completed && (x.TargetLibrary == latestApp.Library || x.TargetLibrary == currentApp.Library)) != 0) { continue; } var newTask = new Definitions.List.TaskInfo { App = latestApp, TargetLibrary = currentApp.Library, TaskType = Definitions.Enums.TaskType.Copy }; TaskManager.AddTask(newTask); Main.FormAccessor.TmLogs.Report(Framework.StringFormat.Format(SLM.Translate(nameof(Properties.Resources.Steam_CheckForBackupUpdates_UpdateFound)), new { CurrentTime = DateTime.Now, CurrentAppName = currentApp.AppName, NewAppLastUpdatedOn = latestApp.LastUpdated, CurrentAppLastUpdatedOn = currentApp.LastUpdated, CurrentAppSteamFullPath = currentApp.Library.FullPath, NewAppSteamFullPath = latestApp.Library.FullPath })); } } } } await progressInformationMessage.CloseAsync().ConfigureAwait(true); } catch (Exception ex) { Logger.Fatal(ex); } }
public static async void CheckForBackupUpdatesAsync() { try { if (Definitions.List.Libraries.Count(x => x.Type == Definitions.Enums.LibraryType.SLM && x.DirectoryInfo.Exists) == 0) { return; } var ProgressInformationMessage = await Main.FormAccessor.ShowProgressAsync("Please wait...", "Checking for backup updates as you have requested."); ProgressInformationMessage.SetIndeterminate(); foreach (var CurrentLibrary in Definitions.List.Libraries.Where(x => x.Type == Definitions.Enums.LibraryType.SLM && x.DirectoryInfo.Exists).ToList()) { if (CurrentLibrary.Steam.Apps.Count == 0) { continue; } foreach (var LibraryToCheck in Definitions.List.Libraries.Where(x => x.Type == Definitions.Enums.LibraryType.Steam)) { foreach (var CurrentApp in CurrentLibrary.Steam.Apps.Where(x => !x.IsSteamBackup).ToList()) { ProgressInformationMessage.SetMessage("Checking for:\n\n" + CurrentApp.AppName); if (LibraryToCheck.Steam.Apps.Count(x => x.AppID == CurrentApp.AppID && x.LastUpdated > CurrentApp.LastUpdated) > 0) { var LatestApp = LibraryToCheck.Steam.Apps.First(x => x.AppID == CurrentApp.AppID && x.LastUpdated > CurrentApp.LastUpdated && !x.IsSteamBackup); if (Framework.TaskManager.TaskList.Count(x => x.SteamApp.AppID == CurrentApp.AppID && !x.Completed && (x.TargetLibrary == LatestApp.Library || x.TargetLibrary == CurrentApp.Library)) == 0) { Definitions.List.TaskInfo NewTask = new Definitions.List.TaskInfo { SteamApp = LatestApp, TargetLibrary = CurrentApp.Library }; Framework.TaskManager.AddTask(NewTask); Main.FormAccessor.TaskManager_Logs.Add($"[{DateTime.Now}] An update is available for: {CurrentApp.AppName} - Old backup time: {LatestApp.LastUpdated} - Updated on: {CurrentApp.LastUpdated} - Target: {CurrentApp.Library.Steam.FullPath} - Source: {LatestApp.Library.Steam.FullPath}"); } } } } } await ProgressInformationMessage.CloseAsync(); Main.FormAccessor.TaskManager_Logs.Add($"[{DateTime.Now}] Check for Backup updates completed."); } catch (Exception ex) { logger.Fatal(ex); Definitions.SLM.RavenClient.Capture(new SharpRaven.Data.SentryEvent(ex)); } }
public static async void CheckForBackupUpdatesAsync() { try { if (Definitions.List.Libraries.Count(x => x.Type == Definitions.Enums.LibraryType.SLM && x.DirectoryInfo.Exists) == 0) { return; } var ProgressInformationMessage = await Main.FormAccessor.ShowProgressAsync(SLM.Translate(nameof(Properties.Resources.PleaseWait)), SLM.Translate(nameof(Properties.Resources.Steam_CheckForBackupUpdates))); ProgressInformationMessage.SetIndeterminate(); foreach (var CurrentLibrary in Definitions.List.Libraries.Where(x => x.Type == Definitions.Enums.LibraryType.SLM && x.DirectoryInfo.Exists).ToList()) { if (CurrentLibrary.Steam.Apps.Count == 0) { continue; } foreach (var LibraryToCheck in Definitions.List.Libraries.Where(x => x.Type == Definitions.Enums.LibraryType.Steam)) { foreach (var CurrentApp in CurrentLibrary.Steam.Apps.Where(x => !x.IsSteamBackup && !x.IsCompressed).ToList()) { ProgressInformationMessage.SetMessage(Framework.StringFormat.Format(SLM.Translate(nameof(Properties.Resources.Steam_CheckForBackupUpdates_Progress)), new { CurrentAppName = CurrentApp.AppName })); if (LibraryToCheck.Steam.Apps.Count(x => x.AppID == CurrentApp.AppID && x.LastUpdated > CurrentApp.LastUpdated && !x.IsSteamBackup) > 0) { var LatestApp = LibraryToCheck.Steam.Apps.First(x => x.AppID == CurrentApp.AppID && x.LastUpdated > CurrentApp.LastUpdated && !x.IsSteamBackup); if (Framework.TaskManager.TaskList.Count(x => x.SteamApp.AppID == CurrentApp.AppID && !x.Completed && (x.TargetLibrary == LatestApp.Library || x.TargetLibrary == CurrentApp.Library)) == 0) { Definitions.List.TaskInfo NewTask = new Definitions.List.TaskInfo { SteamApp = LatestApp, TargetLibrary = CurrentApp.Library }; Framework.TaskManager.AddTask(NewTask); Main.FormAccessor.TaskManager_Logs.Add(Framework.StringFormat.Format(SLM.Translate(nameof(Properties.Resources.Steam_CheckForBackupUpdates_UpdateFound)), new { CurrentTime = DateTime.Now, CurrentAppName = CurrentApp.AppName, NewAppLastUpdatedOn = LatestApp.LastUpdated, CurrentAppLastUpdatedOn = CurrentApp.LastUpdated, CurrentAppSteamFullPath = CurrentApp.Library.Steam.FullPath, NewAppSteamFullPath = LatestApp.Library.Steam.FullPath })); } } } } } await ProgressInformationMessage.CloseAsync(); Main.FormAccessor.TaskManager_Logs.Add(Framework.StringFormat.Format(SLM.Translate(nameof(Properties.Resources.Steam_CheckForBackupUpdates_Completed)), new { CurrentTime = DateTime.Now })); } catch (Exception ex) { logger.Fatal(ex); Definitions.SLM.RavenClient.Capture(new SharpRaven.Data.SentryEvent(ex)); } }
public static void RemoveTask(Definitions.List.TaskInfo Task) { try { TaskList.Remove(Task); } catch (Exception ex) { logger.Fatal(ex); } }
public static void AddTask(Definitions.List.TaskInfo Task) { try { TaskList.Add(Task); TmInfoUpdate(); } catch (Exception ex) { Logger.Fatal(ex); } }
public static void AddTask(Definitions.List.TaskInfo task) { try { AddTaskProgress.Report(task); TmInfoUpdate(); } catch (Exception ex) { Logger.Fatal(ex); } }
public static async Task ProcessTaskAsync(Definitions.List.TaskInfo CurrentTask) { try { ActiveTask = CurrentTask; CurrentTask.Active = true; if (CurrentTask.SteamApp != null) { switch (CurrentTask.TaskType) { default: await CurrentTask.SteamApp.CopyFilesAsync(CurrentTask, CancellationToken.Token); break; case Definitions.Enums.TaskType.Delete: await CurrentTask.SteamApp.DeleteFilesAsync(CurrentTask); CurrentTask.SteamApp.Library.Steam.Apps.Remove(CurrentTask.SteamApp); break; } if (!CancellationToken.IsCancellationRequested && !CurrentTask.ErrorHappened) { if (CurrentTask.RemoveOldFiles && CurrentTask.TaskType != Definitions.Enums.TaskType.Delete) { Main.FormAccessor.TaskManager_Logs.Add($"[{DateTime.Now}] [{CurrentTask.SteamApp.AppName}] Removing moved files as requested. This may take a while, please wait."); await CurrentTask.SteamApp.DeleteFilesAsync(CurrentTask); CurrentTask.SteamApp.Library.Steam.Apps.Remove(CurrentTask.SteamApp); Main.FormAccessor.TaskManager_Logs.Add($"[{DateTime.Now}] [{CurrentTask.SteamApp.AppName}] Files removed, task is completed now."); } if (CurrentTask.TargetLibrary?.Type == Definitions.Enums.LibraryType.Steam) { IsRestartRequired = true; } CurrentTask.TaskStatusInfo = "Completed"; CurrentTask.Active = false; CurrentTask.Completed = true; CurrentTask.TargetLibrary?.Steam.UpdateAppList(); // Update library details if (Definitions.SLM.CurrentSelectedLibrary == CurrentTask.SteamApp.Library) { Functions.App.UpdateAppPanel(CurrentTask.SteamApp.Library); } } } else if (CurrentTask.OriginApp != null) { switch (CurrentTask.TaskType) { default: CurrentTask.OriginApp.CopyFilesAsync(CurrentTask, CancellationToken.Token); break; case Definitions.Enums.TaskType.Delete: CurrentTask.OriginApp.DeleteFiles(CurrentTask); CurrentTask.OriginApp.Library.Origin.Apps.Remove(CurrentTask.OriginApp); break; } if (!CancellationToken.IsCancellationRequested && !CurrentTask.ErrorHappened) { if (CurrentTask.RemoveOldFiles && CurrentTask.TaskType != Definitions.Enums.TaskType.Delete) { Main.FormAccessor.TaskManager_Logs.Add($"[{DateTime.Now}] [{CurrentTask.OriginApp.AppName}] Removing moved files as requested. This may take a while, please wait."); CurrentTask.OriginApp.DeleteFiles(CurrentTask); CurrentTask.OriginApp.Library.Origin.Apps.Remove(CurrentTask.OriginApp); Main.FormAccessor.TaskManager_Logs.Add($"[{DateTime.Now}] [{CurrentTask.OriginApp.AppName}] Files removed, task is completed now."); } CurrentTask.TaskStatusInfo = "Completed"; CurrentTask.Active = false; CurrentTask.Completed = true; CurrentTask.TargetLibrary?.Origin.UpdateAppList(); if (CurrentTask.Compress) { await CurrentTask.TargetLibrary?.Origin.Apps.FirstOrDefault(x => x.AppID == CurrentTask.OriginApp.AppID)?.InstallAsync(); } // Update library details if (Definitions.SLM.CurrentSelectedLibrary == CurrentTask.OriginApp.Library) { Functions.App.UpdateAppPanel(CurrentTask.OriginApp.Library); } } } if (TaskList.Count(x => !x.Completed) == 0) { if (Properties.Settings.Default.PlayASoundOnCompletion) { if (!string.IsNullOrEmpty(Properties.Settings.Default.CustomSoundFile) && File.Exists(Properties.Settings.Default.CustomSoundFile)) { new System.Media.SoundPlayer(Properties.Settings.Default.CustomSoundFile).Play(); } else { System.Media.SystemSounds.Exclamation.Play(); } } if (IsRestartRequired) { Functions.Steam.RestartSteamAsync(); IsRestartRequired = false; } } Functions.SLM.Library.UpdateLibraryVisual(); } catch (Exception ex) { Debug.WriteLine(ex); logger.Fatal(ex); } }
public static void RemoveGivenFiles(ConcurrentBag <string> FileList, ConcurrentBag <string> DirectoryList = null, Definitions.List.TaskInfo CurrentTask = null) { try { Parallel.ForEach(FileList, currentFile => { FileInfo File = new FileInfo(currentFile); if (File.Exists) { if (CurrentTask != null) { CurrentTask.TaskStatusInfo = $"Deleting: {File.Name} ({FormatBytes(File.Length)})"; } System.IO.File.SetAttributes(File.FullName, FileAttributes.Normal); File.Delete(); } }); if (DirectoryList != null) { Parallel.ForEach(DirectoryList, currentDirectory => { DirectoryInfo Directory = new DirectoryInfo(currentDirectory); if (Directory.Exists) { if (CurrentTask != null) { CurrentTask.TaskStatusInfo = $"Deleting directory: {Directory.Name}"; } Directory.Delete(); } }); } if (CurrentTask != null) { CurrentTask.TaskStatusInfo = ""; } } catch (DirectoryNotFoundException ex) { logger.Error(ex); } catch (IOException ex) { logger.Error(ex); } catch (AggregateException ex) { logger.Error(ex); } catch (UnauthorizedAccessException ex) { logger.Error(ex); } catch (Exception ex) { logger.Fatal(ex); Definitions.SLM.RavenClient.Capture(new SharpRaven.Data.SentryEvent(ex)); } }
public static void RemoveGivenFiles(List <string> FileList, List <string> DirectoryList = null, Definitions.List.TaskInfo CurrentTask = null) { try { Parallel.ForEach(FileList, currentFile => { FileInfo File = new FileInfo(currentFile); if (File.Exists) { if (CurrentTask != null) { CurrentTask.TaskStatusInfo = Framework.StringFormat.Format(SLM.Translate(nameof(Properties.Resources.TaskStatus_DeletingFile)), new { FileName = File.Name, FormattedFileSize = FormatBytes(File.Length) }); } System.IO.File.SetAttributes(File.FullName, FileAttributes.Normal); File.Delete(); } }); if (DirectoryList != null) { Parallel.ForEach(DirectoryList, currentDirectory => { DirectoryInfo Directory = new DirectoryInfo(currentDirectory); if (Directory.Exists) { if (CurrentTask != null) { CurrentTask.TaskStatusInfo = Framework.StringFormat.Format(SLM.Translate(nameof(Properties.Resources.TaskStatus_DeletingDirectory)), new { DirectoryName = Directory.Name }); } Directory.Delete(); } }); } if (CurrentTask != null) { CurrentTask.TaskStatusInfo = ""; } } catch (DirectoryNotFoundException ex) { logger.Error(ex); } catch (IOException ex) { logger.Error(ex); } catch (AggregateException ex) { logger.Error(ex); } catch (UnauthorizedAccessException ex) { logger.Error(ex); } catch (Exception ex) { logger.Fatal(ex); } }
private static async Task ProcessTaskAsync(Definitions.List.TaskInfo CurrentTask) { try { TmInfoUpdate(); ActiveTask = CurrentTask; CurrentTask.Active = true; if (CurrentTask.SteamApp != null) { switch (CurrentTask.TaskType) { default: await CurrentTask.SteamApp.CopyFilesAsync(CurrentTask, CancellationToken.Token).ConfigureAwait(false); break; case Definitions.Enums.TaskType.Delete: await CurrentTask.SteamApp.DeleteFilesAsync(CurrentTask).ConfigureAwait(false); CurrentTask.SteamApp.Library.Steam.Apps.Remove(CurrentTask.SteamApp); break; case Definitions.Enums.TaskType.Compact: await CurrentTask.SteamApp.CompactTask(CurrentTask, CancellationToken.Token).ConfigureAwait(false); break; } if (!CancellationToken.IsCancellationRequested && !CurrentTask.ErrorHappened) { if (CurrentTask.RemoveOldFiles && CurrentTask.TaskType != Definitions.Enums.TaskType.Delete) { Main.FormAccessor.TmLogs.Report(Framework.StringFormat.Format(SLM.Translate(nameof(Properties.Resources.TaskManager_RemoveOldFiles)), new { CurrentTime = DateTime.Now, CurrentTask.SteamApp.AppName })); await CurrentTask.SteamApp.DeleteFilesAsync(CurrentTask).ConfigureAwait(false); CurrentTask.SteamApp.Library.Steam.Apps.Remove(CurrentTask.SteamApp); Main.FormAccessor.TmLogs.Report(Framework.StringFormat.Format(SLM.Translate(nameof(Properties.Resources.TaskManager_RemoveOldFilesCompleted)), new { CurrentTime = DateTime.Now, CurrentTask.SteamApp.AppName })); } if (CurrentTask.TargetLibrary?.Type == Definitions.Enums.LibraryType.Steam) { IsRestartRequired = true; } CurrentTask.TaskStatusInfo = SLM.Translate(nameof(Properties.Resources.TaskStatus_Completed)); CurrentTask.Active = false; CurrentTask.Completed = true; CurrentTask.TargetLibrary?.Steam.UpdateAppListAsync(); // Update library details if (Definitions.SLM.CurrentSelectedLibrary == CurrentTask.SteamApp.Library) { App.UpdateAppPanel(CurrentTask.SteamApp.Library); } } } else if (CurrentTask.OriginApp != null) { switch (CurrentTask.TaskType) { default: await CurrentTask.OriginApp.CopyFilesAsync(CurrentTask, CancellationToken.Token).ConfigureAwait(false); break; case Definitions.Enums.TaskType.Delete: await CurrentTask.OriginApp.DeleteFilesAsync(CurrentTask); CurrentTask.OriginApp.Library.Origin.Apps.Remove(CurrentTask.OriginApp); break; case Definitions.Enums.TaskType.Compact: await CurrentTask.OriginApp.CompactTask(CurrentTask, CancellationToken.Token).ConfigureAwait(false); break; } if (!CancellationToken.IsCancellationRequested && !CurrentTask.ErrorHappened) { if (CurrentTask.RemoveOldFiles && CurrentTask.TaskType != Definitions.Enums.TaskType.Delete) { Main.FormAccessor.TmLogs.Report(Framework.StringFormat.Format(SLM.Translate(nameof(Properties.Resources.TaskManager_RemoveOldFiles)), new { CurrentTime = DateTime.Now, CurrentTask.OriginApp.AppName })); await CurrentTask.OriginApp.DeleteFilesAsync(CurrentTask); CurrentTask.OriginApp.Library.Origin.Apps.Remove(CurrentTask.OriginApp); Main.FormAccessor.TmLogs.Report(Framework.StringFormat.Format(SLM.Translate(nameof(Properties.Resources.TaskManager_RemoveOldFilesCompleted)), new { CurrentTime = DateTime.Now, CurrentTask.OriginApp.AppName })); } CurrentTask.TaskStatusInfo = SLM.Translate(nameof(Properties.Resources.TaskStatus_Completed)); CurrentTask.Active = false; CurrentTask.Completed = true; CurrentTask.TargetLibrary?.Origin.UpdateAppListAsync(); if (CurrentTask.Compress) { await CurrentTask.TargetLibrary?.Origin.Apps.FirstOrDefault(x => x.AppId == CurrentTask.OriginApp.AppId)?.InstallAsync(); } // Update library details if (Definitions.SLM.CurrentSelectedLibrary == CurrentTask.OriginApp.Library) { App.UpdateAppPanel(CurrentTask.OriginApp.Library); } } } if (TaskList.Count(x => !x.Completed) == 0) { if (Properties.Settings.Default.PlayASoundOnCompletion) { if (!string.IsNullOrEmpty(Properties.Settings.Default.CustomSoundFile) && File.Exists(Properties.Settings.Default.CustomSoundFile)) { new System.Media.SoundPlayer(Properties.Settings.Default.CustomSoundFile).Play(); } else { System.Media.SystemSounds.Exclamation.Play(); } } if (IsRestartRequired) { Steam.RestartSteamAsync(); IsRestartRequired = false; } } if (Properties.Settings.Default.TaskManager_AutoClear && !CurrentTask.ErrorHappened) { RemoveTaskProgress.Report(CurrentTask); } SLM.Library.UpdateLibraryVisual(); } catch (Exception ex) { Debug.WriteLine(ex); Logger.Fatal(ex); } finally { TmInfoUpdate(); } }
private static async Task ProcessTaskAsync(Definitions.List.TaskInfo currentTask) { try { TmInfoUpdate(); ActiveTask = currentTask; currentTask.Active = true; switch (currentTask.TaskType) { default: await currentTask.App.CopyFilesAsync(currentTask, CancellationToken.Token).ConfigureAwait(false); break; case TaskType.Delete: await currentTask.App.DeleteFilesAsync(currentTask).ConfigureAwait(false); currentTask.App.Library.Apps.Remove(currentTask.App); break; case TaskType.Compact: await currentTask.App.CompactTask(currentTask, CancellationToken.Token).ConfigureAwait(false); break; } if (!CancellationToken.IsCancellationRequested && !currentTask.ErrorHappened) { if (currentTask.RemoveOldFiles && currentTask.TaskType != TaskType.Delete && currentTask.TaskType != TaskType.Compact) { Main.FormAccessor.TmLogs.Report(Framework.StringFormat.Format(SLM.Translate(nameof(Properties.Resources.TaskManager_RemoveOldFiles)), new { CurrentTime = DateTime.Now, currentTask.App.AppName })); await currentTask.App.DeleteFilesAsync(currentTask).ConfigureAwait(false); currentTask.App.Library.Apps.Remove(currentTask.App); Main.FormAccessor.TmLogs.Report(Framework.StringFormat.Format(SLM.Translate(nameof(Properties.Resources.TaskManager_RemoveOldFilesCompleted)), new { CurrentTime = DateTime.Now, currentTask.App.AppName })); } if (currentTask.TargetLibrary?.Type == LibraryType.Steam) { _isRestartRequired = true; } currentTask.TaskStatusInfo = SLM.Translate(nameof(Properties.Resources.TaskStatus_Completed)); currentTask.Active = false; currentTask.Completed = true; currentTask.TargetLibrary?.UpdateAppList(); if (currentTask.AutoInstall && !currentTask.Compress) { while (currentTask.TargetLibrary.IsUpdatingAppList) { await Task.Delay(100); } switch (currentTask.TargetLibrary.Type) { case LibraryType.Steam: case LibraryType.SLM: // Not available break; case LibraryType.Origin: case LibraryType.Uplay: currentTask.TargetLibrary.Apps.First(x => x.AppId == currentTask.App.AppId && x.IsCompressed == currentTask.Compress)?.InstallAsync(); break; } } // Update library details if (Definitions.SLM.CurrentSelectedLibrary == currentTask.App.Library) { App.UpdateAppPanel(currentTask.App.Library); } } if (TaskList.Count(x => !x.Completed) == 0) { if (Properties.Settings.Default.PlayASoundOnCompletion) { if (!string.IsNullOrEmpty(Properties.Settings.Default.CustomSoundFile) && File.Exists(Properties.Settings.Default.CustomSoundFile)) { using (var soundPlayer = new System.Media.SoundPlayer(Properties.Settings.Default.CustomSoundFile)) { soundPlayer.Play(); } } else { System.Media.SystemSounds.Exclamation.Play(); } } if (_isRestartRequired && !Properties.Settings.Default.TaskManager_SteamRestartSkip) { Steam.RestartSteamAsync(); _isRestartRequired = false; } } if (Properties.Settings.Default.TaskManager_AutoClear && !currentTask.ErrorHappened) { RemoveTaskProgress.Report(currentTask); } SLM.Library.UpdateLibraryVisual(); } catch (Exception ex) { Debug.WriteLine(ex); Logger.Fatal(ex); } finally { TmInfoUpdate(); } }