Exemple #1
0
        public virtual async Task <bool> DeleteFilesAsync(List.TaskInfo currentTask = null)
        {
            try
            {
                Parallel.ForEach(GetFileList(), currentFile =>
                {
                    try
                    {
                        currentTask?.mre.WaitOne();

                        currentFile.Refresh();
                        if (!currentFile.Exists)
                        {
                            return;
                        }

                        if (currentTask != null)
                        {
                            currentTask.mre.WaitOne();

                            currentTask.TaskStatusInfo = Framework.StringFormat.Format(Functions.SLM.Translate(nameof(Properties.Resources.TaskStatus_DeletingFile)), new { FileName = currentFile.Name, FormattedFileSize = Functions.FileSystem.FormatBytes(currentFile.Length) });

                            if (currentTask.ReportFileMovement)
                            {
                                ReportToTaskManager($"[{DateTime.Now}] [{AppName}] {Framework.StringFormat.Format(Functions.SLM.Translate(nameof(Properties.Resources.TaskStatus_DeletingFile)), new { FileName = currentFile.Name, FormattedFileSize = Functions.FileSystem.FormatBytes(currentFile.Length) })}");
                            }
                        }

                        System.IO.File.SetAttributes(currentFile.FullName, System.IO.FileAttributes.Normal);
                        currentFile.Delete();
                    }
                    catch (Exception ex)
                    {
                        Logger.Fatal(ex);
                    }
                });

                InstallationDirectory.Refresh();
                if (InstallationDirectory.Exists)
                {
                    await Task.Run(() => InstallationDirectory.Delete(true));
                }

                return(true);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                return(false);
            }
        }
Exemple #2
0
        public virtual List <FileInfo> GetFileList()
        {
            try
            {
                InstallationDirectory?.Refresh();

                return(InstallationDirectory.Exists ? InstallationDirectory?.GetFiles("*", System.IO.SearchOption.AllDirectories)?.ToList() : null);
            }
            catch (Exception ex)
            {
                Logger.Fatal(ex);
                return(null);
            }
        }
Exemple #3
0
        public async void ParseMenuItemActionAsync(string action)
        {
            try
            {
                switch (action.ToLowerInvariant())
                {
                default:
                    if (string.IsNullOrEmpty(Properties.Settings.Default.SteamID64))
                    {
                        return;
                    }

                    Process.Start(string.Format(action, AppId, Properties.Settings.Default.SteamID64));
                    break;

                case "compress":
                    if (Functions.TaskManager.TaskList.Count(x => x.SteamApp == this && x.TargetLibrary == Library && x.TaskType == Enums.TaskType.Compress && !x.Completed) == 0)
                    {
                        Functions.TaskManager.AddTask(new List.TaskInfo
                        {
                            SteamApp      = this,
                            TargetLibrary = Library,
                            Compress      = !IsCompressed,
                            TaskType      = Enums.TaskType.Compress
                        });
                    }
                    break;

                case "compact":
                    if (Functions.TaskManager.TaskList.Count(x => x.SteamApp == this && x.TargetLibrary == Library && x.TaskType == Enums.TaskType.Compact && !x.Completed) == 0)
                    {
                        Functions.TaskManager.AddTask(new List.TaskInfo
                        {
                            SteamApp      = this,
                            TargetLibrary = Library,
                            TaskType      = Enums.TaskType.Compact
                        });
                    }
                    break;

                case "disk":
                    InstallationDirectory.Refresh();

                    if (InstallationDirectory.Exists)
                    {
                        Process.Start(InstallationDirectory.FullName);
                    }

                    break;

                case "acffile":
                    FullAcfPath.Refresh();

                    if (FullAcfPath.Exists)
                    {
                        Process.Start(FullAcfPath.FullName);
                    }
                    break;

                case "deleteappfiles":
                    await Task.Run(() => DeleteFilesAsync()).ConfigureAwait(false);

                    Library.Steam.Apps.Remove(this);
                    Functions.SLM.Library.UpdateLibraryVisual();

                    if (SLM.CurrentSelectedLibrary == Library)
                    {
                        Functions.App.UpdateAppPanel(Library);
                    }
                    break;

                case "deleteappfilestm":
                    Functions.TaskManager.AddTask(new List.TaskInfo
                    {
                        SteamApp      = this,
                        TargetLibrary = Library,
                        TaskType      = Enums.TaskType.Delete
                    });
                    break;
                }
            }
            catch (Exception ex)
            {
                Logger.Fatal(ex);
            }
        }
        public override async void ParseMenuItemActionAsync(string action)
        {
            try
            {
                switch (action.ToLowerInvariant())
                {
                default:
                    if (AppId != 0)
                    {
                        Process.Start(string.Format(action, AppId));
                    }

                    break;

                case "disk":
                    InstallationDirectory.Refresh();

                    if (InstallationDirectory.Exists)
                    {
                        Process.Start(InstallationDirectory.FullName);
                    }

                    break;

                case "install":
                    await InstallAsync();

                    break;

                case "compress":
                    if (Functions.TaskManager.TaskList.Count(x => x.App == this && x.TargetLibrary == Library && x.TaskType == Enums.TaskType.Compress) == 0)
                    {
                        Functions.TaskManager.AddTask(new List.TaskInfo
                        {
                            App           = this,
                            TargetLibrary = Library,
                            TaskType      = Enums.TaskType.Compress,
                            Compress      = !IsCompressed
                        });
                    }
                    break;

                case "compact":
                    if (Functions.TaskManager.TaskList.Count(x => x.App == this && x.TargetLibrary == Library && x.TaskType == Enums.TaskType.Compact) == 0)
                    {
                        Functions.TaskManager.AddTask(new List.TaskInfo
                        {
                            App           = this,
                            TargetLibrary = Library,
                            TaskType      = Enums.TaskType.Compact
                        });
                    }
                    break;

                case "deleteappfiles":
                    await Task.Run(async() => await DeleteFilesAsync()).ConfigureAwait(false);

                    Library.Apps.Remove(this);
                    if (SLM.CurrentSelectedLibrary == Library)
                    {
                        Functions.App.UpdateAppPanel(Library);
                    }

                    break;

                case "deleteappfilestm":
                    Functions.TaskManager.AddTask(new List.TaskInfo
                    {
                        App           = this,
                        TargetLibrary = Library,
                        TaskType      = Enums.TaskType.Delete
                    });
                    break;
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }
        }