Пример #1
0
        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();
            }
        }
Пример #2
0
        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();
            }
        }