public override async void UpdateAppList() { try { if (IsUpdatingAppList) { return; } IsUpdatingAppList = true; DirectoryList["SteamApps"].Refresh(); if (!DirectoryList["SteamApps"].Exists) { DirectoryList["SteamApps"].Create(); DirectoryList["SteamApps"].Refresh(); if (!DirectoryList["SteamApps"].Exists) { MessageBox.Show(Framework.StringFormat.Format( Functions.SLM.Translate(nameof(Properties.Resources.SteamAppsFolderNotExists)), new { SteamAppsFolderFullPath = DirectoryList["SteamApps"].FullName })); return; } } if (Apps.Count > 0) { Apps.Clear(); } // Foreach *.acf file found in library await DirectoryList["SteamApps"].EnumerateFiles("appmanifest_*.acf", SearchOption.TopDirectoryOnly) .ParallelForEachAsync( async acfFile => { // Define a new value and call KeyValue var keyValReader = new Framework.KeyValue(); // Read the *.acf file as text keyValReader.ReadFileAsText(acfFile.FullName); // If key doesn't contains a child (value in acf file) if (keyValReader.Children.Count == 0) { if (List.IgnoredJunkItems.Contains(acfFile.FullName)) { return; } List.LcProgress.Report(new List.JunkInfo { FSInfo = new FileInfo(acfFile.FullName), Size = Functions.FileSystem.FormatBytes(acfFile.Length), Library = this, Tag = JunkType.CorruptedDataFile }); return; } await Functions.App.AddSteamAppAsync(Convert.ToInt32(keyValReader["appid"].Value), keyValReader["name"].Value ?? keyValReader["UserConfig"]["name"].Value, keyValReader["installdir"].Value, Convert.ToInt32(keyValReader["StateFlags"].Value), this, Convert.ToInt64(keyValReader["SizeOnDisk"].Value), Convert.ToInt64(keyValReader["LastUpdated"].Value), false).ConfigureAwait(false); }).ConfigureAwait(false); // Do a loop for each *.zip file in library await Directory.EnumerateFiles(DirectoryList["SteamApps"].FullName, "*.zip", SearchOption.TopDirectoryOnly) .ParallelForEachAsync(async archive => { await Task.Run(() => Functions.App.ReadDetailsFromZip(archive, this)).ConfigureAwait(false); }).ConfigureAwait(false); DirectoryList["SteamBackups"].Refresh(); if (Type == LibraryType.SLM && DirectoryList["SteamBackups"].Exists) { await DirectoryList["SteamBackups"].EnumerateFiles("*.sis", SearchOption.AllDirectories).ParallelForEachAsync( async skuFile => { var keyValReader = new Framework.KeyValue(); keyValReader.ReadFileAsText(skuFile.FullName); var appNames = System.Text.RegularExpressions.Regex.Split(keyValReader["name"].Value, " and "); var i = 0; var appSize = Functions.FileSystem.GetDirectorySize(skuFile.Directory, true); foreach (var app in keyValReader["apps"].Children) { if (Apps.Count(x => x.AppId == Convert.ToInt32(app.Value) && x.IsSteamBackup) > 0) { continue; } await Functions.App.AddSteamAppAsync(Convert.ToInt32(app.Value), appNames[i], skuFile.DirectoryName, 4, this, appSize, skuFile.LastWriteTimeUtc.ToUnixTimestamp(), false, true).ConfigureAwait(false); if (appNames.Length > 1) { i++; } } }).ConfigureAwait(false); } if (SLM.CurrentSelectedLibrary != null && SLM.CurrentSelectedLibrary == this) { Functions.App.UpdateAppPanel(this); } IsUpdatingAppList = false; } catch (UnauthorizedAccessException ex) { await Main.FormAccessor.AppView.AppPanel.Dispatcher.Invoke( async delegate { await Main.FormAccessor.ShowMessageAsync( Functions.SLM.Translate(nameof(Properties.Resources.UnauthorizedAccessException)), Framework.StringFormat.Format( Functions.SLM.Translate(nameof(Properties.Resources.UnauthorizedAccessExceptionMessage)), new { FullPath, ExceptionMessage = ex.Message })).ConfigureAwait(true); }, System.Windows.Threading.DispatcherPriority.Normal).ConfigureAwait(true); IsUpdatingAppList = false; } catch (DirectoryNotFoundException ex) { await Main.FormAccessor.AppView.AppPanel.Dispatcher.Invoke( async delegate { await Main.FormAccessor.ShowMessageAsync( Functions.SLM.Translate(nameof(Properties.Resources.DirectoryNotFoundException)), Framework.StringFormat.Format( Functions.SLM.Translate(nameof(Properties.Resources.DirectoryNotFoundExceptionMessage)), new { FolderfullPath = FullPath, ExceptionMessage = ex.Message })) .ConfigureAwait(true); }, System.Windows.Threading.DispatcherPriority.Normal).ConfigureAwait(true); IsUpdatingAppList = false; } catch (Exception ex) { MessageBox.Show(ex.ToString()); Logger.Fatal(ex); IsUpdatingAppList = false; } }
public override void UpdateJunks() { try { while (IsUpdatingAppList) { Task.Delay(5000); } DirectoryList["Common"].Refresh(); if (DirectoryList["Common"].Exists) { foreach (var dirInfo in DirectoryList["Common"].GetDirectories().ToList().Where( x => Apps.Count(y => string.Equals(y.InstallationDirectory.Name, x.Name, StringComparison.InvariantCultureIgnoreCase)) == 0 && x.Name != "241100" && // Steam controller configs Functions.TaskManager.TaskList.Count( z => string.Equals(z.App.InstallationDirectory.Name, x.Name, StringComparison.InvariantCultureIgnoreCase) && z.TargetLibrary == this ) == 0 ).OrderByDescending(x => Functions.FileSystem.GetDirectorySize(x, true))) { var junk = new List.JunkInfo { FSInfo = dirInfo, Size = Functions.FileSystem.FormatBytes(Functions.FileSystem.GetDirectorySize(dirInfo, true)), Library = this, Tag = JunkType.HeadlessFolder }; if (List.JunkItems.Count(x => x.FSInfo.FullName == junk.FSInfo.FullName) == 0) { if (List.IgnoredJunkItems.Contains(dirInfo.FullName)) { continue; } List.LcProgress.Report(junk); } } } DirectoryList["Workshop"].Refresh(); if (DirectoryList["Workshop"].Exists) { if (Directory.Exists(Path.Combine(DirectoryList["Workshop"].FullName, "downloads"))) { foreach (var fileDetails in new DirectoryInfo(Path.Combine(DirectoryList["Workshop"].FullName, "downloads")).EnumerateFiles("*.patch", SearchOption.TopDirectoryOnly).ToList().Where( x => Apps.Count(y => x.Name.Contains($"state_{y.AppId}_")) == 0 )) { var junk = new List.JunkInfo { FSInfo = fileDetails, Size = Functions.FileSystem.FormatBytes(fileDetails.Length), Library = this, Tag = JunkType.HeadlessWorkshopFolder }; if (List.JunkItems.Count(x => x.FSInfo.FullName == junk.FSInfo.FullName) == 0) { if (List.IgnoredJunkItems.Contains(fileDetails.FullName)) { continue; } List.LcProgress.Report(junk); } } } } } catch (Exception ex) { Logger.Fatal(ex); } }
public void UpdateJunks() { try { while (UpdatingAppList) { Task.Delay(5000); } CommonFolder.Refresh(); if (CommonFolder.Exists) { foreach (var 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 Functions.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))) { var junk = new List.JunkInfo { FSInfo = dirInfo, Size = Functions.FileSystem.GetDirectorySize(dirInfo, true), Library = Library }; if (List.LcItems.Count(x => x.FSInfo.FullName == junk.FSInfo.FullName) == 0) { List.LCProgress.Report(junk); } } } WorkshopFolder.Refresh(); if (WorkshopFolder.Exists) { foreach (var 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 Functions.TaskManager.TaskList.Count( z => string.Equals(z.SteamApp.WorkShopAcfName, x.Name , StringComparison.InvariantCultureIgnoreCase) && z.TargetLibrary == Library ) == 0 )) { var junk = new List.JunkInfo { FSInfo = fileDetails, Size = fileDetails.Length, Library = Library }; if (List.LcItems.Count(x => x.FSInfo.FullName == junk.FSInfo.FullName) == 0) { List.LCProgress.Report(junk); } } if (Directory.Exists(Path.Combine(WorkshopFolder.FullName, "content"))) { foreach (var 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 Functions.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))) { var junk = new List.JunkInfo { FSInfo = dirInfo, Size = Functions.FileSystem.GetDirectorySize(dirInfo, true), Library = Library }; if (List.LcItems.Count(x => x.FSInfo.FullName == junk.FSInfo.FullName) == 0) { List.LCProgress.Report(junk); } } } if (Directory.Exists(Path.Combine(WorkshopFolder.FullName, "downloads"))) { foreach (var 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 )) { var junk = new List.JunkInfo { FSInfo = fileDetails, Size = fileDetails.Length, Library = Library }; if (List.LcItems.Count(x => x.FSInfo.FullName == junk.FSInfo.FullName) == 0) { List.LCProgress.Report(junk); } } } } } catch (Exception ex) { Logger.Fatal(ex); } }