public List <FileInfo> GetFileList(bool includeDownloads = true, bool includeWorkshop = true) { try { List <FileInfo> FileList = new List <FileInfo>(); if (IsCompressed) { FileList.Add(CompressedArchiveName); } else { CommonFolder.Refresh(); if (CommonFolder.Exists) { FileList.AddRange(GetCommonFiles()); } DownloadFolder.Refresh(); if (includeDownloads && DownloadFolder.Exists) { FileList.AddRange(GetDownloadFiles()); FileList.AddRange(GetPatchFiles()); } WorkShopPath.Refresh(); if (includeWorkshop && WorkShopPath.Exists) { FileList.AddRange(GetWorkshopFiles()); } FullAcfPath.Refresh(); if (FullAcfPath.Exists) { FileList.Add(FullAcfPath); } WorkShopPath.Refresh(); if (WorkShopAcfPath.Exists) { FileList.Add(WorkShopAcfPath); } } return(FileList); } catch (Exception ex) { SLM.RavenClient.Capture(new SharpRaven.Data.SentryEvent(ex)); return(null); } }
private IEnumerable <FileInfo> GetCommonFiles() { try { CommonFolder.Refresh(); return(CommonFolder.EnumerateFiles("*", SearchOption.AllDirectories)); } catch (Exception ex) { MessageBox.Show(Framework.StringFormat.Format(Functions.SLM.Translate(nameof(Properties.Resources.SteamApp_GetCommonFilesError)), new { AppName, CommonFolderFullPath = CommonFolder.FullName, ExceptionMessage = ex.Message })); return(null); } }
public List <FileInfo> GetCommonFiles() { try { CommonFolder.Refresh(); return(CommonFolder.EnumerateFiles("*", SearchOption.AllDirectories).ToList()); } catch (Exception ex) { MessageBox.Show($"An error happened while populating files at common directory for game: {AppName} - Directory:\n{CommonFolder.FullName}\nError:\n{ex.Message}"); return(null); } }
public async Task <bool> DeleteFilesAsync(List.TaskInfo CurrentTask = null) { try { if (IsCompressed) { CompressedArchiveName.Refresh(); if (CompressedArchiveName.Exists) { await Task.Run(() => CompressedArchiveName.Delete()); } } else { List <FileInfo> FileList = GetFileList(); if (FileList.Count > 0) { Parallel.ForEach(FileList, currentFile => { try { CurrentTask?.mre.WaitOne(); currentFile.Refresh(); if (currentFile.Exists) { 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) { Main.FormAccessor.TaskManager_Logs.Report($"[{DateTime.Now}] [{AppName}] {Framework.StringFormat.Format(Functions.SLM.Translate(nameof(Properties.Resources.TaskStatus_DeletingFile)), new { FileName = currentFile.Name, FormattedFileSize = Functions.FileSystem.FormatBytes(currentFile.Length) })}"); } } File.SetAttributes(currentFile.FullName, FileAttributes.Normal); currentFile.Delete(); } } catch (Exception ex) { Logger.Fatal(ex); } } ); } CommonFolder.Refresh(); // common folder, if exists if (CommonFolder.Exists) { await Task.Run(() => CommonFolder.Delete(true)); } DownloadFolder.Refresh(); // downloading folder, if exists if (DownloadFolder.Exists) { await Task.Run(() => DownloadFolder.Delete(true)); } WorkShopPath.Refresh(); // workshop folder, if exists if (WorkShopPath.Exists) { await Task.Run(() => WorkShopPath.Delete(true)); } FullAcfPath.Refresh(); // game .acf file if (FullAcfPath.Exists) { File.SetAttributes(FullAcfPath.FullName, FileAttributes.Normal); FullAcfPath.Delete(); } WorkShopAcfPath.Refresh(); // workshop .acf file if (WorkShopAcfPath.Exists) { File.SetAttributes(WorkShopAcfPath.FullName, FileAttributes.Normal); WorkShopAcfPath.Delete(); } if (CurrentTask != null) { CurrentTask.TaskStatusInfo = ""; } } return(true); } catch (FileNotFoundException ex) { Logger.Error(ex); return(true); } catch (DirectoryNotFoundException ex) { Logger.Error(ex); return(true); } catch (IOException ex) { Logger.Error(ex); return(true); } catch (UnauthorizedAccessException ex) { Logger.Error(ex); return(true); } catch (Exception ex) { MessageBox.Show(ex.ToString()); Logger.Fatal(ex); return(false); } }
public List <FileInfo> GetFileList(bool includeDownloads = true, bool includeWorkshop = true) { try { var FileList = new List <FileInfo>(); if (IsCompressed) { FileList.Add(CompressedArchiveName); } else { CommonFolder.Refresh(); if (CommonFolder.Exists) { var commonFiles = GetCommonFiles(); if (commonFiles != null) { FileList.AddRange(commonFiles); } } DownloadFolder.Refresh(); if (includeDownloads && DownloadFolder.Exists) { var downloadFiles = GetDownloadFiles(); var patchFiles = GetPatchFiles(); if (downloadFiles != null) { FileList.AddRange(downloadFiles); } if (patchFiles != null) { FileList.AddRange(patchFiles); } } WorkShopPath.Refresh(); if (includeWorkshop && WorkShopPath.Exists) { var workshopPath = GetWorkshopFiles(); FileList.AddRange(workshopPath); } FullAcfPath.Refresh(); if (FullAcfPath.Exists) { FileList.Add(FullAcfPath); } WorkShopPath.Refresh(); if (WorkShopAcfPath.Exists) { FileList.Add(WorkShopAcfPath); } } return(FileList); } catch (Exception ex) { Logger.Fatal(ex); return(null); } }
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) == 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) == 0) { Functions.TaskManager.AddTask(new List.TaskInfo { SteamApp = this, TargetLibrary = Library, TaskType = Enums.TaskType.Compact }); } break; case "disk": CommonFolder.Refresh(); if (CommonFolder.Exists) { Process.Start(CommonFolder.FullName); } break; case "acffile": FullAcfPath.Refresh(); if (FullAcfPath.Exists) { Process.Start(FullAcfPath.FullName); } break; case "deleteappfiles": await Task.Run(() => DeleteFilesAsync()); 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 async Task <bool> DeleteFilesAsync(List.TaskInfo CurrentTask = null) { try { if (IsCompressed) { CompressedArchiveName.Refresh(); if (CompressedArchiveName.Exists) { await Task.Run(() => CompressedArchiveName.Delete()); } } else { List <FileInfo> FileList = GetFileList(); if (FileList.Count > 0) { Parallel.ForEach(FileList, currentFile => { try { CurrentTask?.mre.WaitOne(); currentFile.Refresh(); if (currentFile.Exists) { if (CurrentTask != null) { CurrentTask.mre.WaitOne(); CurrentTask.TaskStatusInfo = $"Deleting: {currentFile.Name} ({Functions.FileSystem.FormatBytes(currentFile.Length)})"; Main.FormAccessor.TaskManager_Logs.Add($"[{DateTime.Now}] [{CurrentTask.SteamApp.AppName}] Deleting file: {currentFile.FullName}"); } File.SetAttributes(currentFile.FullName, FileAttributes.Normal); currentFile.Delete(); } } catch (Exception ex) { logger.Fatal(ex); } } ); } CommonFolder.Refresh(); // common folder, if exists if (CommonFolder.Exists) { await Task.Run(() => CommonFolder.Delete(true)); } DownloadFolder.Refresh(); // downloading folder, if exists if (DownloadFolder.Exists) { await Task.Run(() => DownloadFolder.Delete(true)); } WorkShopPath.Refresh(); // workshop folder, if exists if (WorkShopPath.Exists) { await Task.Run(() => WorkShopPath.Delete(true)); } FullAcfPath.Refresh(); // game .acf file if (FullAcfPath.Exists) { File.SetAttributes(FullAcfPath.FullName, FileAttributes.Normal); FullAcfPath.Delete(); } WorkShopAcfPath.Refresh(); // workshop .acf file if (WorkShopAcfPath.Exists) { File.SetAttributes(WorkShopAcfPath.FullName, FileAttributes.Normal); WorkShopAcfPath.Delete(); } if (CurrentTask != null) { CurrentTask.TaskStatusInfo = ""; } } return(true); } catch (FileNotFoundException ex) { logger.Error(ex); return(true); } catch (DirectoryNotFoundException ex) { logger.Error(ex); return(true); } catch (IOException ex) { logger.Error(ex); return(true); } catch (UnauthorizedAccessException ex) { logger.Error(ex); return(true); } catch (Exception ex) { MessageBox.Show(ex.ToString()); logger.Fatal(ex); await SLM.RavenClient.CaptureAsync(new SharpRaven.Data.SentryEvent(ex)); return(false); } }
public void UpdateJunks() { try { CommonFolder.Refresh(); if (CommonFolder.Exists) { foreach (DirectoryInfo DirInfo in CommonFolder.GetDirectories().ToList().Where( x => Apps.Count(y => string.Equals(y.InstallationDirectory.Name, x.Name, StringComparison.InvariantCultureIgnoreCase)) == 0 && x.Name != "241100" && // Steam controller configs Framework.TaskManager.TaskList.Count( z => string.Equals(z.SteamApp.InstallationDirectory.Name, x.Name, StringComparison.InvariantCultureIgnoreCase) && z.TargetLibrary == Library ) == 0 ).OrderByDescending(x => Functions.FileSystem.GetDirectorySize(x, true))) { List.JunkInfo Junk = new List.JunkInfo { FSInfo = DirInfo, Size = Functions.FileSystem.GetDirectorySize(DirInfo, true), Library = Library }; if (List.LCItems.ToList().Count(x => x.FSInfo.FullName == Junk.FSInfo.FullName) == 0) { List.LCItems.Add(Junk); } } } WorkshopFolder.Refresh(); if (WorkshopFolder.Exists) { foreach (FileInfo FileDetails in WorkshopFolder.EnumerateFiles("appworkshop_*.acf", SearchOption.TopDirectoryOnly).ToList().Where( x => Apps.Count(y => x.Name == y.WorkShopAcfName) == 0 && !string.Equals(x.Name, "appworkshop_241100.acf" // Steam Controller Configs , StringComparison.InvariantCultureIgnoreCase) && // Steam Controller Configs Framework.TaskManager.TaskList.Count( z => string.Equals(z.SteamApp.WorkShopAcfName, x.Name , StringComparison.InvariantCultureIgnoreCase) && z.TargetLibrary == Library ) == 0 )) { List.JunkInfo Junk = new List.JunkInfo { FSInfo = FileDetails, Size = FileDetails.Length, Library = Library }; if (List.LCItems.ToList().Count(x => x.FSInfo.FullName == Junk.FSInfo.FullName) == 0) { List.LCItems.Add(Junk); } } if (Directory.Exists(Path.Combine(WorkshopFolder.FullName, "content"))) { foreach (DirectoryInfo DirInfo in new DirectoryInfo(Path.Combine(WorkshopFolder.FullName, "content")).GetDirectories().ToList().Where( x => Apps.Count(y => y.AppID.ToString() == x.Name) == 0 && x.Name != "241100" && // Steam controller configs Framework.TaskManager.TaskList.Count( z => string.Equals(z.SteamApp.WorkShopPath.Name, x.Name , StringComparison.InvariantCultureIgnoreCase) && z.TargetLibrary == Library ) == 0 ).OrderByDescending(x => Functions.FileSystem.GetDirectorySize(x, true))) { List.JunkInfo Junk = new List.JunkInfo { FSInfo = DirInfo, Size = Functions.FileSystem.GetDirectorySize(DirInfo, true), Library = Library }; if (List.LCItems.ToList().Count(x => x.FSInfo.FullName == Junk.FSInfo.FullName) == 0) { List.LCItems.Add(Junk); } } } if (Directory.Exists(Path.Combine(WorkshopFolder.FullName, "downloads"))) { foreach (FileInfo FileDetails in new DirectoryInfo(Path.Combine(WorkshopFolder.FullName, "downloads")).EnumerateFiles("*.patch", SearchOption.TopDirectoryOnly).ToList().Where( x => Apps.Count(y => x.Name.Contains($"state_{y.AppID}_")) == 0 )) { List.JunkInfo Junk = new List.JunkInfo { FSInfo = FileDetails, Size = FileDetails.Length, Library = Library }; if (List.LCItems.ToList().Count(x => x.FSInfo.FullName == Junk.FSInfo.FullName) == 0) { List.LCItems.Add(Junk); } } } } } catch (Exception ex) { logger.Fatal(ex); SLM.RavenClient.Capture(new SharpRaven.Data.SentryEvent(ex)); } }
public async void ParseMenuItemActionAsync(string Action) { try { switch (Action.ToLowerInvariant()) { default: if (string.IsNullOrEmpty(SLM.UserSteamID64)) { return; } Process.Start(string.Format(Action, AppID, SLM.UserSteamID64)); break; case "disk": CommonFolder.Refresh(); if (CommonFolder.Exists) { Process.Start(CommonFolder.FullName); } break; case "acffile": FullAcfPath.Refresh(); if (FullAcfPath.Exists) { Process.Start(FullAcfPath.FullName); } break; case "deleteappfiles": await Task.Run(() => DeleteFilesAsync()); Library.Steam.Apps.Remove(this); Functions.SLM.Library.UpdateLibraryVisual(); if (SLM.CurrentSelectedLibrary == Library) { Functions.App.UpdateAppPanel(Library); } break; case "deleteappfilestm": Framework.TaskManager.AddTask(new List.TaskInfo { SteamApp = this, TargetLibrary = Library, TaskType = Enums.TaskType.Delete }); break; } } catch (Exception ex) { logger.Fatal(ex); } }