From a9a701a98845935ef79b5322f6de705337e447bc Mon Sep 17 00:00:00 2001 From: pointfeev Date: Fri, 13 Jan 2023 16:48:34 -0500 Subject: [PATCH] more refactoring & optimization --- CreamInstaller/Components/CustomForm.cs | 23 +++--- CreamInstaller/Components/CustomTreeView.cs | 4 +- .../Components/PlatformIdComparer.cs | 8 +- CreamInstaller/Forms/DialogForm.cs | 6 +- CreamInstaller/Forms/InstallForm.cs | 4 +- CreamInstaller/Forms/MainForm.cs | 14 +++- CreamInstaller/Forms/SelectForm.cs | 60 +++++++------- .../Platforms/Paradox/ParadoxLauncher.cs | 3 +- CreamInstaller/Platforms/Steam/SteamCMD.cs | 2 +- .../Platforms/Steam/SteamLibrary.cs | 81 +++++++++---------- CreamInstaller/Platforms/Steam/SteamStore.cs | 2 +- CreamInstaller/Program.cs | 4 +- CreamInstaller/Resources/Koaloader.cs | 4 +- CreamInstaller/Resources/Resources.cs | 2 +- CreamInstaller/Resources/ScreamAPI.cs | 16 ++-- CreamInstaller/Resources/SmokeAPI.cs | 14 ++-- CreamInstaller/Resources/UplayR1.cs | 13 +-- CreamInstaller/Resources/UplayR2.cs | 13 +-- 18 files changed, 140 insertions(+), 133 deletions(-) diff --git a/CreamInstaller/Components/CustomForm.cs b/CreamInstaller/Components/CustomForm.cs index 574af66..2dedb2e 100644 --- a/CreamInstaller/Components/CustomForm.cs +++ b/CreamInstaller/Components/CustomForm.cs @@ -30,15 +30,14 @@ internal class CustomForm : Form internal CustomForm(IWin32Window owner) : this() { - if (owner is Form form) - { - Owner = form; - InheritLocation(form); - SizeChanged += (s, e) => InheritLocation(form); - form.Activated += OnActivation; - FormClosing += (s, e) => form.Activated -= OnActivation; - TopLevel = true; - } + if (owner is not Form form) + return; + Owner = form; + InheritLocation(form); + SizeChanged += (_, _) => InheritLocation(form); + form.Activated += OnActivation; + FormClosing += (_, _) => form.Activated -= OnActivation; + TopLevel = true; } protected override CreateParams CreateParams // Double buffering for all controls @@ -51,7 +50,7 @@ internal class CustomForm : Form } } - internal void OnHelpButtonClicked(object sender, EventArgs args) + private void OnHelpButtonClicked(object sender, EventArgs args) { using DialogForm helpDialog = new(this); helpDialog.HelpButton = false; @@ -85,11 +84,11 @@ internal class CustomForm : Form + $"The program source and other information can be found on [GitHub]({repository})."); } - internal void OnActivation(object sender, EventArgs args) => Activate(); + private void OnActivation(object sender, EventArgs args) => Activate(); [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)] [DefaultDllImportSearchPaths(DllImportSearchPath.System32)] - internal static extern void SetWindowPos(nint hWnd, nint hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags); + private static extern void SetWindowPos(nint hWnd, nint hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags); internal void BringToFrontWithoutActivation() { diff --git a/CreamInstaller/Components/CustomTreeView.cs b/CreamInstaller/Components/CustomTreeView.cs index 33d52e2..5f0e95e 100644 --- a/CreamInstaller/Components/CustomTreeView.cs +++ b/CreamInstaller/Components/CustomTreeView.cs @@ -206,7 +206,7 @@ internal sealed class CustomTreeView : TreeView foreach (string proxy in proxies) { bool canUse = true; - foreach ((string directory, BinaryType binaryType) in pair.Key.ExecutableDirectories) + foreach ((string directory, BinaryType _) in pair.Key.ExecutableDirectories) { string path = directory + @"\" + proxy + ".dll"; if (!File.Exists(path) || path.IsResourceFile(ResourceIdentifier.Koaloader)) @@ -215,7 +215,7 @@ internal sealed class CustomTreeView : TreeView break; } if (canUse) - _ = comboBoxDropDown.Items.Add(new ToolStripButton(proxy + ".dll", null, (s, e) => + _ = comboBoxDropDown.Items.Add(new ToolStripButton(proxy + ".dll", null, (_, _) => { pair.Key.KoaloaderProxy = proxy == ProgramSelection.DefaultKoaloaderProxy ? null : proxy; selectForm.OnKoaloaderChanged(); diff --git a/CreamInstaller/Components/PlatformIdComparer.cs b/CreamInstaller/Components/PlatformIdComparer.cs index ae1d618..d6c43dd 100644 --- a/CreamInstaller/Components/PlatformIdComparer.cs +++ b/CreamInstaller/Components/PlatformIdComparer.cs @@ -39,9 +39,9 @@ internal sealed class StringComparer : IComparer internal sealed class NodeComparer : IComparer { public int Compare(TreeNode a, TreeNode b) - => a.Tag is not Platform A + => a?.Tag is not Platform A ? 1 - : b.Tag is not Platform B + : b?.Tag is not Platform B ? -1 : A > B ? 1 @@ -57,7 +57,7 @@ internal sealed class NodeNameComparer : IComparer ? 1 : b is not TreeNode B ? -1 - : PlatformIdComparer.Node.Compare(A, B) is int c && c != 0 + : PlatformIdComparer.Node.Compare(A, B) is var c && c != 0 ? c : PlatformIdComparer.String.Compare(A.Name, B.Name); } @@ -69,7 +69,7 @@ internal sealed class NodeTextComparer : IComparer ? 1 : b is not TreeNode B ? -1 - : PlatformIdComparer.Node.Compare(A, B) is int c && c != 0 + : PlatformIdComparer.Node.Compare(A, B) is var c && c != 0 ? c : PlatformIdComparer.String.Compare(A.Text, B.Text); } \ No newline at end of file diff --git a/CreamInstaller/Forms/DialogForm.cs b/CreamInstaller/Forms/DialogForm.cs index 4eeeed6..fe1633b 100644 --- a/CreamInstaller/Forms/DialogForm.cs +++ b/CreamInstaller/Forms/DialogForm.cs @@ -56,7 +56,11 @@ internal sealed partial class DialogForm : CustomForm return ShowDialog(); foreach (LinkLabel.Link link in links) _ = descriptionLabel.Links.Add(link); - descriptionLabel.LinkClicked += (s, e) => Process.Start(new ProcessStartInfo((string)e.Link.LinkData) { UseShellExecute = true }); + descriptionLabel.LinkClicked += (_, e) => + { + if (e.Link != null) + Process.Start(new ProcessStartInfo((string)e.Link.LinkData) { UseShellExecute = true }); + }; return ShowDialog(); } diff --git a/CreamInstaller/Forms/InstallForm.cs b/CreamInstaller/Forms/InstallForm.cs index 9aaeddb..02ba6b1 100644 --- a/CreamInstaller/Forms/InstallForm.cs +++ b/CreamInstaller/Forms/InstallForm.cs @@ -71,7 +71,7 @@ internal sealed partial class InstallForm : CustomForm + $" with root directory \"{selection.RootDirectory}\" . . . ", LogTextBox.Operation); IEnumerable invalidDirectories = (await selection.RootDirectory.GetExecutables()) ?.Where(d => selection.ExecutableDirectories.All(s => s.directory != Path.GetDirectoryName(d.path))) - ?.Select(d => Path.GetDirectoryName(d.path)); + .Select(d => Path.GetDirectoryName(d.path)); if (selection.ExecutableDirectories.All(s => s.directory != selection.RootDirectory)) invalidDirectories = invalidDirectories?.Append(selection.RootDirectory); invalidDirectories = invalidDirectories?.Distinct(); @@ -91,7 +91,7 @@ internal sealed partial class InstallForm : CustomForm Thread.Sleep(1); } if (uninstalling || !selection.Koaloader) - foreach ((string directory, BinaryType binaryType) in selection.ExecutableDirectories) + foreach ((string directory, BinaryType _) in selection.ExecutableDirectories) { if (Program.Canceled) throw new CustomMessageException("The operation was canceled."); diff --git a/CreamInstaller/Forms/MainForm.cs b/CreamInstaller/Forms/MainForm.cs index 93da602..57d2452 100644 --- a/CreamInstaller/Forms/MainForm.cs +++ b/CreamInstaller/Forms/MainForm.cs @@ -42,7 +42,7 @@ internal sealed partial class MainForm : CustomForm SelectForm form = new(); #pragma warning restore CA2000 // Dispose objects before losing scope form.InheritLocation(this); - form.FormClosing += (s, e) => Close(); + form.FormClosing += (_, _) => Close(); form.Show(); Hide(); #if DEBUG @@ -89,7 +89,10 @@ internal sealed partial class MainForm : CustomForm DebugForm.Current.Log($"Exception while checking for updates: {e.GetType()} ({e.Message})", LogTextBox.Warning); } #else - catch { } + catch + { + // ignored + } #endif finally { @@ -182,7 +185,7 @@ internal sealed partial class MainForm : CustomForm changelogTreeView.Location = progressBar.Location with { Y = progressBar.Location.Y + progressBar.Size.Height + 6 }; Refresh(); Progress progress = new(); - progress.ProgressChanged += delegate(object sender, double _progress) + progress.ProgressChanged += delegate(object _, double _progress) { progressLabel.Text = $"Updating . . . {(int)_progress}%"; progressBar.Value = (int)_progress; @@ -200,7 +203,10 @@ internal sealed partial class MainForm : CustomForm DebugForm.Current.Log($"Exception while preparing update: {ex.GetType()} ({ex.Message})", LogTextBox.Warning); } #else - catch { } + catch + { + // ignored + } #endif finally { diff --git a/CreamInstaller/Forms/SelectForm.cs b/CreamInstaller/Forms/SelectForm.cs index b6c2387..beef456 100644 --- a/CreamInstaller/Forms/SelectForm.cs +++ b/CreamInstaller/Forms/SelectForm.cs @@ -223,10 +223,10 @@ internal sealed partial class SelectForm : CustomForm VProperty dlcAppInfo = await SteamCMD.GetAppInfo(dlcAppId); if (dlcAppInfo is not null) { - dlcName = dlcAppInfo.Value?.GetChild("common")?.GetChild("name")?.ToString(); - string dlcIconStaticId = dlcAppInfo.Value?.GetChild("common")?.GetChild("icon")?.ToString(); - dlcIconStaticId ??= dlcAppInfo.Value?.GetChild("common")?.GetChild("logo_small")?.ToString(); - dlcIconStaticId ??= dlcAppInfo.Value?.GetChild("common")?.GetChild("logo")?.ToString(); + dlcName = dlcAppInfo.Value.GetChild("common")?.GetChild("name")?.ToString(); + string dlcIconStaticId = dlcAppInfo.Value.GetChild("common")?.GetChild("icon")?.ToString(); + dlcIconStaticId ??= dlcAppInfo.Value.GetChild("common")?.GetChild("logo_small")?.ToString(); + dlcIconStaticId ??= dlcAppInfo.Value.GetChild("common")?.GetChild("logo")?.ToString(); if (dlcIconStaticId is not null) dlcIcon = IconGrabber.SteamAppImagesPath + @$"\{dlcAppId}\{dlcIconStaticId}.jpg"; } @@ -265,10 +265,10 @@ internal sealed partial class SelectForm : CustomForm selection.DllDirectories = dllDirectories; selection.Platform = Platform.Steam; selection.ProductUrl = "https://store.steampowered.com/app/" + appId; - selection.IconUrl = IconGrabber.SteamAppImagesPath + @$"\{appId}\{appInfo?.Value?.GetChild("common")?.GetChild("icon")}.jpg"; + selection.IconUrl = IconGrabber.SteamAppImagesPath + @$"\{appId}\{appInfo?.Value.GetChild("common")?.GetChild("icon")}.jpg"; selection.SubIconUrl = appData?.header_image ?? IconGrabber.SteamAppImagesPath - + @$"\{appId}\{appInfo?.Value?.GetChild("common")?.GetChild("clienticon")}.ico"; - selection.Publisher = appData?.publishers[0] ?? appInfo?.Value?.GetChild("extended")?.GetChild("publisher")?.ToString(); + + @$"\{appId}\{appInfo?.Value.GetChild("common")?.GetChild("clienticon")}.ico"; + selection.Publisher = appData?.publishers[0] ?? appInfo?.Value.GetChild("extended")?.GetChild("publisher")?.ToString(); selection.WebsiteUrl = appData?.website; if (Program.Canceled) return; @@ -412,8 +412,6 @@ internal sealed partial class SelectForm : CustomForm programNode.Nodes.Add(entitlementsNode);*/ foreach (KeyValuePair pair in entitlements) { - if (programNode is null /* || entitlementsNode is null*/) - return; string dlcId = pair.Key; (DlcType type, string name, string icon) dlcApp = (DlcType.EpicEntitlement, pair.Value.name, pair.Value.icon); selection.AllDlc[dlcId] = dlcApp; @@ -526,7 +524,7 @@ internal sealed partial class SelectForm : CustomForm gameChoices.Add((Platform.Paradox, "PL", "Paradox Launcher", programsToScan is not null && programsToScan.Any(p => p.platform is Platform.Paradox && p.id == "PL"))); if (Directory.Exists(SteamLibrary.InstallPath)) - foreach ((string appId, string name, string branch, int buildId, string gameDirectory) in (await SteamLibrary.GetGames()).Where(g + foreach ((string appId, string name, string _, int _, string _) in (await SteamLibrary.GetGames()).Where(g => !Program.IsGameBlocked(g.name, g.gameDirectory))) gameChoices.Add((Platform.Steam, appId, name, programsToScan is not null && programsToScan.Any(p => p.platform is Platform.Steam && p.id == appId))); @@ -534,8 +532,7 @@ internal sealed partial class SelectForm : CustomForm foreach (Manifest manifest in (await EpicLibrary.GetGames()).Where(m => !Program.IsGameBlocked(m.DisplayName, m.InstallLocation))) gameChoices.Add((Platform.Epic, manifest.CatalogNamespace, manifest.DisplayName, programsToScan is not null && programsToScan.Any(p => p.platform is Platform.Epic && p.id == manifest.CatalogNamespace))); - foreach ((string gameId, string name, string gameDirectory) in (await UbisoftLibrary.GetGames()).Where(g - => !Program.IsGameBlocked(g.name, g.gameDirectory))) + foreach ((string gameId, string name, string _) in (await UbisoftLibrary.GetGames()).Where(g => !Program.IsGameBlocked(g.name, g.gameDirectory))) gameChoices.Add((Platform.Ubisoft, gameId, name, programsToScan is not null && programsToScan.Any(p => p.platform is Platform.Ubisoft && p.id == gameId))); if (gameChoices.Any()) @@ -562,7 +559,7 @@ internal sealed partial class SelectForm : CustomForm int curProgress = 0; Progress progress = new(); IProgress iProgress = progress; - progress.ProgressChanged += (sender, _progress) => + progress.ProgressChanged += (_, _progress) => { if (Program.Canceled) return; @@ -761,16 +758,16 @@ internal sealed partial class SelectForm : CustomForm : selection.Platform is Platform.Epic ? "Epic GraphQL " : ""; - queries.Add(new($"Open {platformString}Query", "Notepad", (sender, e) => Diagnostics.OpenFileInNotepad(appInfoJSON))); + queries.Add(new($"Open {platformString}Query", "Notepad", (_, _) => Diagnostics.OpenFileInNotepad(appInfoJSON))); } if (File.Exists(appInfoVDF)) - queries.Add(new("Open SteamCMD Query", "Notepad", (sender, e) => Diagnostics.OpenFileInNotepad(appInfoVDF))); + queries.Add(new("Open SteamCMD Query", "Notepad", (_, _) => Diagnostics.OpenFileInNotepad(appInfoVDF))); if (queries.Any()) { items.Add(new ToolStripSeparator()); foreach (ContextMenuItem query in queries) items.Add(query); - items.Add(new ContextMenuItem("Refresh Queries", "Command Prompt", (sender, e) => + items.Add(new ContextMenuItem("Refresh Queries", "Command Prompt", (_, _) => { try { @@ -810,11 +807,11 @@ internal sealed partial class SelectForm : CustomForm } items.Add(new ToolStripSeparator()); items.Add(new ContextMenuItem("Open Root Directory", "File Explorer", - (sender, e) => Diagnostics.OpenDirectoryInFileExplorer(selection.RootDirectory))); + (_, _) => Diagnostics.OpenDirectoryInFileExplorer(selection.RootDirectory))); int executables = 0; foreach ((string directory, BinaryType binaryType) in selection.ExecutableDirectories.ToList()) items.Add(new ContextMenuItem($"Open Executable Directory #{++executables} ({(binaryType == BinaryType.BIT32 ? "32" : "64")}-bit)", - "File Explorer", (sender, e) => Diagnostics.OpenDirectoryInFileExplorer(directory))); + "File Explorer", (_, _) => Diagnostics.OpenDirectoryInFileExplorer(directory))); List directories = selection.DllDirectories.ToList(); int steam = 0, epic = 0, r1 = 0, r2 = 0; if (selection.Platform is Platform.Steam or Platform.Paradox) @@ -825,7 +822,7 @@ internal sealed partial class SelectForm : CustomForm if (File.Exists(api32) || File.Exists(api32_o) || File.Exists(api64) || File.Exists(api64_o) || File.Exists(old_config) || File.Exists(config) || File.Exists(cache)) items.Add(new ContextMenuItem($"Open Steamworks Directory #{++steam}", "File Explorer", - (sender, e) => Diagnostics.OpenDirectoryInFileExplorer(directory))); + (_, _) => Diagnostics.OpenDirectoryInFileExplorer(directory))); } if (selection.Platform is Platform.Epic or Platform.Paradox) foreach (string directory in directories) @@ -833,7 +830,7 @@ internal sealed partial class SelectForm : CustomForm directory.GetScreamApiComponents(out string api32, out string api32_o, out string api64, out string api64_o, out string config); if (File.Exists(api32) || File.Exists(api32_o) || File.Exists(api64) || File.Exists(api64_o) || File.Exists(config)) items.Add(new ContextMenuItem($"Open EOS Directory #{++epic}", "File Explorer", - (sender, e) => Diagnostics.OpenDirectoryInFileExplorer(directory))); + (_, _) => Diagnostics.OpenDirectoryInFileExplorer(directory))); } if (selection.Platform is Platform.Ubisoft) foreach (string directory in directories) @@ -841,12 +838,12 @@ internal sealed partial class SelectForm : CustomForm directory.GetUplayR1Components(out string api32, out string api32_o, out string api64, out string api64_o, out string config); if (File.Exists(api32) || File.Exists(api32_o) || File.Exists(api64) || File.Exists(api64_o) || File.Exists(config)) items.Add(new ContextMenuItem($"Open Uplay R1 Directory #{++r1}", "File Explorer", - (sender, e) => Diagnostics.OpenDirectoryInFileExplorer(directory))); + (_, _) => Diagnostics.OpenDirectoryInFileExplorer(directory))); directory.GetUplayR2Components(out string old_api32, out string old_api64, out api32, out api32_o, out api64, out api64_o, out config); if (File.Exists(old_api32) || File.Exists(old_api64) || File.Exists(api32) || File.Exists(api32_o) || File.Exists(api64) || File.Exists(api64_o) || File.Exists(config)) items.Add(new ContextMenuItem($"Open Uplay R2 Directory #{++r2}", "File Explorer", - (sender, e) => Diagnostics.OpenDirectoryInFileExplorer(directory))); + (_, _) => Diagnostics.OpenDirectoryInFileExplorer(directory))); } } if (id != "PL") @@ -854,36 +851,35 @@ internal sealed partial class SelectForm : CustomForm if (selection?.Platform is Platform.Steam || dlcParentSelection?.Platform is Platform.Steam) { items.Add(new ToolStripSeparator()); - items.Add(new ContextMenuItem("Open SteamDB", "SteamDB", - (sender, e) => Diagnostics.OpenUrlInInternetBrowser("https://steamdb.info/app/" + id))); + items.Add(new ContextMenuItem("Open SteamDB", "SteamDB", (_, _) => Diagnostics.OpenUrlInInternetBrowser("https://steamdb.info/app/" + id))); } if (selection is not null) switch (selection.Platform) { case Platform.Steam: items.Add(new ContextMenuItem("Open Steam Store", "Steam Store", - (sender, e) => Diagnostics.OpenUrlInInternetBrowser(selection.ProductUrl))); + (_, _) => Diagnostics.OpenUrlInInternetBrowser(selection.ProductUrl))); items.Add(new ContextMenuItem("Open Steam Community", ("Sub_" + id, selection.SubIconUrl), "Steam Community", - (sender, e) => Diagnostics.OpenUrlInInternetBrowser("https://steamcommunity.com/app/" + id))); + (_, _) => Diagnostics.OpenUrlInInternetBrowser("https://steamcommunity.com/app/" + id))); break; case Platform.Epic: items.Add(new ToolStripSeparator()); items.Add(new ContextMenuItem("Open ScreamDB", "ScreamDB", - (sender, e) => Diagnostics.OpenUrlInInternetBrowser("https://scream-db.web.app/offers/" + id))); + (_, _) => Diagnostics.OpenUrlInInternetBrowser("https://scream-db.web.app/offers/" + id))); items.Add(new ContextMenuItem("Open Epic Games Store", "Epic Games", - (sender, e) => Diagnostics.OpenUrlInInternetBrowser(selection.ProductUrl))); + (_, _) => Diagnostics.OpenUrlInInternetBrowser(selection.ProductUrl))); break; case Platform.Ubisoft: items.Add(new ToolStripSeparator()); items.Add(new ContextMenuItem("Open Ubisoft Store", "Ubisoft Store", - (sender, e) => Diagnostics.OpenUrlInInternetBrowser("https://store.ubi.com/us/" - + selection.Name.Replace(" ", "-").ToLowerInvariant()))); + (_, _) => Diagnostics.OpenUrlInInternetBrowser( + "https://store.ubi.com/us/" + selection.Name.Replace(" ", "-").ToLowerInvariant()))); break; } } if (selection?.WebsiteUrl != null) items.Add(new ContextMenuItem("Open Official Website", ("Web_" + id, IconGrabber.GetDomainFaviconUrl(selection.WebsiteUrl)), - (sender, e) => Diagnostics.OpenUrlInInternetBrowser(selection.WebsiteUrl))); + (_, _) => Diagnostics.OpenUrlInInternetBrowser(selection.WebsiteUrl))); contextMenuStrip.Show(selectionTreeView, location); contextMenuStrip.Refresh(); ContextMenuStrip.Tag = null; @@ -917,7 +913,7 @@ internal sealed partial class SelectForm : CustomForm Hide(); InstallForm form = new(uninstall); form.InheritLocation(this); - form.FormClosing += (s, e) => + form.FormClosing += (_, _) => { if (form.Reselecting) { diff --git a/CreamInstaller/Platforms/Paradox/ParadoxLauncher.cs b/CreamInstaller/Platforms/Paradox/ParadoxLauncher.cs index 3579e44..94bbfc5 100644 --- a/CreamInstaller/Platforms/Paradox/ParadoxLauncher.cs +++ b/CreamInstaller/Platforms/Paradox/ParadoxLauncher.cs @@ -100,8 +100,7 @@ internal static class ParadoxLauncher { bool koaloaderInstalled = Koaloader.AutoLoadDLLs.Select(pair => (pair.unlocker, path: directory + @"\" + pair.dll)) .Any(pair => File.Exists(pair.path) && pair.path.IsResourceFile()); - directory.GetSmokeApiComponents(out string api32, out string api32_o, out string api64, out string api64_o, out string old_config, - out string config, out _); + directory.GetSmokeApiComponents(out string api32, out string api32_o, out string api64, out string api64_o, out string _, out string config, out _); smokeInstalled = smokeInstalled || File.Exists(api32_o) || File.Exists(api64_o) || (File.Exists(config) || File.Exists(config)) && !koaloaderInstalled || File.Exists(api32) && api32.IsResourceFile(ResourceIdentifier.Steamworks32) diff --git a/CreamInstaller/Platforms/Steam/SteamCMD.cs b/CreamInstaller/Platforms/Steam/SteamCMD.cs index 77a8dc5..2091649 100644 --- a/CreamInstaller/Platforms/Steam/SteamCMD.cs +++ b/CreamInstaller/Platforms/Steam/SteamCMD.cs @@ -141,7 +141,7 @@ internal static class SteamCMD progress.Report(-1660); // install int cur = 0; progress.Report(cur); - watcher.Changed += (sender, e) => progress.Report(++cur); + watcher.Changed += (_, _) => progress.Report(++cur); _ = await Run(null); watcher.Dispose(); } diff --git a/CreamInstaller/Platforms/Steam/SteamLibrary.cs b/CreamInstaller/Platforms/Steam/SteamLibrary.cs index d81db1d..885f2e8 100644 --- a/CreamInstaller/Platforms/Steam/SteamLibrary.cs +++ b/CreamInstaller/Platforms/Steam/SteamLibrary.cs @@ -44,7 +44,7 @@ internal static class SteamLibrary return games; }); - internal static async Task> + private static async Task> GetGamesFromLibraryDirectory(string libraryDirectory) => await Task.Run(() => { @@ -55,58 +55,55 @@ internal static class SteamLibrary { if (Program.Canceled) return games; - if (ValveDataFile.TryDeserialize(File.ReadAllText(file, Encoding.UTF8), out VProperty result)) - { - string appId = result.Value.GetChild("appid")?.ToString(); - string installdir = result.Value.GetChild("installdir")?.ToString(); - string name = result.Value.GetChild("name")?.ToString(); - string buildId = result.Value.GetChild("buildid")?.ToString(); - if (string.IsNullOrWhiteSpace(appId) || string.IsNullOrWhiteSpace(installdir) || string.IsNullOrWhiteSpace(name) - || string.IsNullOrWhiteSpace(buildId)) - continue; - string gameDirectory = (libraryDirectory + @"\common\" + installdir).BeautifyPath(); - if (games.Any(g => g.appId == appId && g.gameDirectory == gameDirectory)) - continue; - if (!int.TryParse(appId, out int appIdInt)) - continue; - if (!int.TryParse(buildId, out int buildIdInt)) - continue; - string branch = result.Value.GetChild("UserConfig")?.GetChild("betakey")?.ToString(); - if (string.IsNullOrWhiteSpace(branch)) - branch = "public"; - games.Add((appId, name, branch, buildIdInt, gameDirectory)); - } + if (!ValveDataFile.TryDeserialize(File.ReadAllText(file, Encoding.UTF8), out VProperty result)) + continue; + string appId = result.Value.GetChild("appid")?.ToString(); + string installdir = result.Value.GetChild("installdir")?.ToString(); + string name = result.Value.GetChild("name")?.ToString(); + string buildId = result.Value.GetChild("buildid")?.ToString(); + if (string.IsNullOrWhiteSpace(appId) || string.IsNullOrWhiteSpace(installdir) || string.IsNullOrWhiteSpace(name) + || string.IsNullOrWhiteSpace(buildId)) + continue; + string gameDirectory = (libraryDirectory + @"\common\" + installdir).BeautifyPath(); + if (games.Any(g => g.appId == appId && g.gameDirectory == gameDirectory)) + continue; + if (!int.TryParse(appId, out int _)) + continue; + if (!int.TryParse(buildId, out int buildIdInt)) + continue; + string branch = result.Value.GetChild("UserConfig")?.GetChild("betakey")?.ToString(); + if (string.IsNullOrWhiteSpace(branch)) + branch = "public"; + games.Add((appId, name, branch, buildIdInt, gameDirectory)); } return games; }); - internal static async Task> GetLibraryDirectories() + private static async Task> GetLibraryDirectories() => await Task.Run(() => { List gameDirectories = new(); if (Program.Canceled) return gameDirectories; string steamInstallPath = InstallPath; - if (steamInstallPath != null && Directory.Exists(steamInstallPath)) + if (steamInstallPath == null || !Directory.Exists(steamInstallPath)) + return gameDirectories; + string libraryFolder = steamInstallPath + @"\steamapps"; + if (!Directory.Exists(libraryFolder)) + return gameDirectories; + gameDirectories.Add(libraryFolder); + string libraryFolders = libraryFolder + @"\libraryfolders.vdf"; + if (!File.Exists(libraryFolders) || !ValveDataFile.TryDeserialize(File.ReadAllText(libraryFolders, Encoding.UTF8), out VProperty result)) + return gameDirectories; + foreach (VToken vToken in result.Value.Where(p => p is VProperty property && int.TryParse(property.Key, out int _))) { - string libraryFolder = steamInstallPath + @"\steamapps"; - if (Directory.Exists(libraryFolder)) - { - gameDirectories.Add(libraryFolder); - string libraryFolders = libraryFolder + @"\libraryfolders.vdf"; - if (File.Exists(libraryFolders) && ValveDataFile.TryDeserialize(File.ReadAllText(libraryFolders, Encoding.UTF8), out VProperty result)) -#pragma warning disable IDE0220 // Add explicit cast - foreach (VProperty property in result.Value.Where(p => p is VProperty && int.TryParse((p as VProperty).Key, out int _))) - { - string path = property.Value.GetChild("path")?.ToString(); - if (string.IsNullOrWhiteSpace(path)) - continue; - path += @"\steamapps"; - if (Directory.Exists(path) && !gameDirectories.Contains(path)) - gameDirectories.Add(path); - } -#pragma warning restore IDE0220 // Add explicit cast - } + VProperty property = (VProperty)vToken; + string path = property.Value.GetChild("path")?.ToString(); + if (string.IsNullOrWhiteSpace(path)) + continue; + path += @"\steamapps"; + if (Directory.Exists(path) && !gameDirectories.Contains(path)) + gameDirectories.Add(path); } return gameDirectories; }); diff --git a/CreamInstaller/Platforms/Steam/SteamStore.cs b/CreamInstaller/Platforms/Steam/SteamStore.cs index ebb01da..e4f0810 100644 --- a/CreamInstaller/Platforms/Steam/SteamStore.cs +++ b/CreamInstaller/Platforms/Steam/SteamStore.cs @@ -3,12 +3,12 @@ using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; -using CreamInstaller.Forms; using CreamInstaller.Utility; using Newtonsoft.Json; using Newtonsoft.Json.Linq; #if DEBUG using System; +using CreamInstaller.Forms; #endif namespace CreamInstaller.Platforms.Steam; diff --git a/CreamInstaller/Program.cs b/CreamInstaller/Program.cs index 14f0d37..7c3d8b7 100644 --- a/CreamInstaller/Program.cs +++ b/CreamInstaller/Program.cs @@ -79,9 +79,9 @@ internal static class Program Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.ApplicationExit += OnApplicationExit; - Application.ThreadException += (s, e) => e.Exception?.HandleFatalException(); + Application.ThreadException += (_, e) => e.Exception.HandleFatalException(); Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); - AppDomain.CurrentDomain.UnhandledException += (s, e) => (e.ExceptionObject as Exception)?.HandleFatalException(); + AppDomain.CurrentDomain.UnhandledException += (_, e) => (e.ExceptionObject as Exception)?.HandleFatalException(); retry: try { diff --git a/CreamInstaller/Resources/Koaloader.cs b/CreamInstaller/Resources/Koaloader.cs index a70fe1f..554e89e 100644 --- a/CreamInstaller/Resources/Koaloader.cs +++ b/CreamInstaller/Resources/Koaloader.cs @@ -53,7 +53,7 @@ internal static class Koaloader binaryType = bitness switch { "32" => BinaryType.BIT32, "64" => BinaryType.BIT64, _ => BinaryType.Unknown }; } - private static void CheckConfig(string directory, ProgramSelection selection, InstallForm installForm = null) + private static void CheckConfig(string directory, InstallForm installForm = null) { directory.GetKoaloaderComponents(out _, out string old_config, out string config); if (File.Exists(old_config)) @@ -345,6 +345,6 @@ internal static class Koaloader } } if (generateConfig) - CheckConfig(directory, selection, installForm); + CheckConfig(directory, installForm); }); } \ No newline at end of file diff --git a/CreamInstaller/Resources/Resources.cs b/CreamInstaller/Resources/Resources.cs index 667d026..47a4da9 100644 --- a/CreamInstaller/Resources/Resources.cs +++ b/CreamInstaller/Resources/Resources.cs @@ -432,7 +432,7 @@ internal static class Resources { e.path = Path.GetDirectoryName(e.path); return e; - })?.DistinctBy(e => e.path).ToList()); + }).DistinctBy(e => e.path).ToList()); internal static async Task> GetExecutables(this string rootDirectory, bool filterCommon = false, Func validFunc = null) diff --git a/CreamInstaller/Resources/ScreamAPI.cs b/CreamInstaller/Resources/ScreamAPI.cs index ab2aab5..8d3a73c 100644 --- a/CreamInstaller/Resources/ScreamAPI.cs +++ b/CreamInstaller/Resources/ScreamAPI.cs @@ -26,12 +26,14 @@ internal static class ScreamAPI directory.GetScreamApiComponents(out _, out _, out _, out _, out string config); IEnumerable> overrideCatalogItems = selection.AllDlc.Where(pair => pair.Value.type is DlcType.EpicCatalogItem).Except(selection.SelectedDlc); - foreach ((string id, string name, SortedList extraDlc) in selection.ExtraSelectedDlc) + foreach ((string _, string _, SortedList extraDlc) in selection.ExtraSelectedDlc) overrideCatalogItems = overrideCatalogItems.Except(extraDlc); IEnumerable> entitlements = selection.SelectedDlc.Where(pair => pair.Value.type == DlcType.EpicEntitlement); - foreach ((string id, string name, SortedList _dlc) in selection.ExtraSelectedDlc) + foreach ((string _, string _, SortedList _dlc) in selection.ExtraSelectedDlc) entitlements = entitlements.Concat(_dlc.Where(pair => pair.Value.type == DlcType.EpicEntitlement)); + overrideCatalogItems = overrideCatalogItems.ToList(); + entitlements = entitlements.ToList(); if (overrideCatalogItems.Any() || entitlements.Any()) { /*if (installForm is not null) @@ -109,7 +111,7 @@ internal static class ScreamAPI File.Delete(api32); installForm?.UpdateUser($"Deleted ScreamAPI: {Path.GetFileName(api32)}", LogTextBox.Action, false); } - File.Move(api32_o, api32); + File.Move(api32_o, api32!); installForm?.UpdateUser($"Restored EOS: {Path.GetFileName(api32_o)} -> {Path.GetFileName(api32)}", LogTextBox.Action, false); } if (File.Exists(api64_o)) @@ -119,7 +121,7 @@ internal static class ScreamAPI File.Delete(api64); installForm?.UpdateUser($"Deleted ScreamAPI: {Path.GetFileName(api64)}", LogTextBox.Action, false); } - File.Move(api64_o, api64); + File.Move(api64_o, api64!); installForm?.UpdateUser($"Restored EOS: {Path.GetFileName(api64_o)} -> {Path.GetFileName(api64)}", LogTextBox.Action, false); } if (deleteConfig && File.Exists(config)) @@ -132,10 +134,10 @@ internal static class ScreamAPI internal static async Task Install(string directory, ProgramSelection selection, InstallForm installForm = null, bool generateConfig = true) => await Task.Run(() => { - directory.GetScreamApiComponents(out string api32, out string api32_o, out string api64, out string api64_o, out string config); + directory.GetScreamApiComponents(out string api32, out string api32_o, out string api64, out string api64_o, out string _); if (File.Exists(api32) && !File.Exists(api32_o)) { - File.Move(api32, api32_o); + File.Move(api32, api32_o!); installForm?.UpdateUser($"Renamed EOS: {Path.GetFileName(api32)} -> {Path.GetFileName(api32_o)}", LogTextBox.Action, false); } if (File.Exists(api32_o)) @@ -145,7 +147,7 @@ internal static class ScreamAPI } if (File.Exists(api64) && !File.Exists(api64_o)) { - File.Move(api64, api64_o); + File.Move(api64, api64_o!); installForm?.UpdateUser($"Renamed EOS: {Path.GetFileName(api64)} -> {Path.GetFileName(api64_o)}", LogTextBox.Action, false); } if (File.Exists(api64_o)) diff --git a/CreamInstaller/Resources/SmokeAPI.cs b/CreamInstaller/Resources/SmokeAPI.cs index 0051dbc..eb0a41a 100644 --- a/CreamInstaller/Resources/SmokeAPI.cs +++ b/CreamInstaller/Resources/SmokeAPI.cs @@ -27,17 +27,19 @@ internal static class SmokeAPI { directory.GetSmokeApiComponents(out _, out _, out _, out _, out string old_config, out _, out _); IEnumerable> overrideDlc = selection.AllDlc.Except(selection.SelectedDlc); - foreach ((string id, string name, SortedList extraDlc) in selection.ExtraSelectedDlc) + foreach ((string _, string _, SortedList extraDlc) in selection.ExtraSelectedDlc) overrideDlc = overrideDlc.Except(extraDlc); IEnumerable> injectDlc = new List>(); if (selection.AllDlc.Count > 64 || selection.ExtraDlc.Any(e => e.dlc.Count > 64)) { injectDlc = injectDlc.Concat(selection.SelectedDlc.Where(pair => pair.Value.type is DlcType.SteamHidden)); - foreach ((string id, string name, SortedList extraDlc) in selection.ExtraSelectedDlc) + foreach ((string id, string _, SortedList extraDlc) in selection.ExtraSelectedDlc) if (selection.ExtraDlc.Single(e => e.id == id).dlc.Count > 64) injectDlc = injectDlc.Concat(extraDlc.Where(pair => pair.Value.type is DlcType.SteamHidden)); } + overrideDlc = overrideDlc.ToList(); + injectDlc = injectDlc.ToList(); if (overrideDlc.Any() || injectDlc.Any()) { /*if (installForm is not null) @@ -117,7 +119,7 @@ internal static class SmokeAPI File.Delete(api32); installForm?.UpdateUser($"Deleted SmokeAPI: {Path.GetFileName(api32)}", LogTextBox.Action, false); } - File.Move(api32_o, api32); + File.Move(api32_o, api32!); installForm?.UpdateUser($"Restored Steamworks: {Path.GetFileName(api32_o)} -> {Path.GetFileName(api32)}", LogTextBox.Action, false); } if (File.Exists(api64_o)) @@ -127,7 +129,7 @@ internal static class SmokeAPI File.Delete(api64); installForm?.UpdateUser($"Deleted SmokeAPI: {Path.GetFileName(api64)}", LogTextBox.Action, false); } - File.Move(api64_o, api64); + File.Move(api64_o, api64!); installForm?.UpdateUser($"Restored Steamworks: {Path.GetFileName(api64_o)} -> {Path.GetFileName(api64)}", LogTextBox.Action, false); } if (deleteConfig && File.Exists(old_config)) @@ -159,7 +161,7 @@ internal static class SmokeAPI directory.GetSmokeApiComponents(out string api32, out string api32_o, out string api64, out string api64_o, out _, out _, out _); if (File.Exists(api32) && !File.Exists(api32_o)) { - File.Move(api32, api32_o); + File.Move(api32, api32_o!); installForm?.UpdateUser($"Renamed Steamworks: {Path.GetFileName(api32)} -> {Path.GetFileName(api32_o)}", LogTextBox.Action, false); } if (File.Exists(api32_o)) @@ -169,7 +171,7 @@ internal static class SmokeAPI } if (File.Exists(api64) && !File.Exists(api64_o)) { - File.Move(api64, api64_o); + File.Move(api64, api64_o!); installForm?.UpdateUser($"Renamed Steamworks: {Path.GetFileName(api64)} -> {Path.GetFileName(api64_o)}", LogTextBox.Action, false); } if (File.Exists(api64_o)) diff --git a/CreamInstaller/Resources/UplayR1.cs b/CreamInstaller/Resources/UplayR1.cs index 0975df0..ca8af92 100644 --- a/CreamInstaller/Resources/UplayR1.cs +++ b/CreamInstaller/Resources/UplayR1.cs @@ -25,8 +25,9 @@ internal static class UplayR1 { directory.GetUplayR1Components(out _, out _, out _, out _, out string config); IEnumerable> blacklistDlc = selection.AllDlc.Except(selection.SelectedDlc); - foreach ((string id, string name, SortedList extraDlc) in selection.ExtraSelectedDlc) + foreach ((string _, string _, SortedList extraDlc) in selection.ExtraSelectedDlc) blacklistDlc = blacklistDlc.Except(extraDlc); + blacklistDlc = blacklistDlc.ToList(); if (blacklistDlc.Any()) { /*if (installForm is not null) @@ -80,7 +81,7 @@ internal static class UplayR1 File.Delete(api32); installForm?.UpdateUser($"Deleted Uplay R1 Unlocker: {Path.GetFileName(api32)}", LogTextBox.Action, false); } - File.Move(api32_o, api32); + File.Move(api32_o, api32!); installForm?.UpdateUser($"Restored Uplay R1: {Path.GetFileName(api32_o)} -> {Path.GetFileName(api32)}", LogTextBox.Action, false); } if (File.Exists(api64_o)) @@ -90,7 +91,7 @@ internal static class UplayR1 File.Delete(api64); installForm?.UpdateUser($"Deleted Uplay R1 Unlocker: {Path.GetFileName(api64)}", LogTextBox.Action, false); } - File.Move(api64_o, api64); + File.Move(api64_o, api64!); installForm?.UpdateUser($"Restored Uplay R1: {Path.GetFileName(api64_o)} -> {Path.GetFileName(api64)}", LogTextBox.Action, false); } if (deleteConfig && File.Exists(config)) @@ -103,10 +104,10 @@ internal static class UplayR1 internal static async Task Install(string directory, ProgramSelection selection, InstallForm installForm = null, bool generateConfig = true) => await Task.Run(() => { - directory.GetUplayR1Components(out string api32, out string api32_o, out string api64, out string api64_o, out string config); + directory.GetUplayR1Components(out string api32, out string api32_o, out string api64, out string api64_o, out string _); if (File.Exists(api32) && !File.Exists(api32_o)) { - File.Move(api32, api32_o); + File.Move(api32, api32_o!); installForm?.UpdateUser($"Renamed Uplay R1: {Path.GetFileName(api32)} -> {Path.GetFileName(api32_o)}", LogTextBox.Action, false); } if (File.Exists(api32_o)) @@ -116,7 +117,7 @@ internal static class UplayR1 } if (File.Exists(api64) && !File.Exists(api64_o)) { - File.Move(api64, api64_o); + File.Move(api64, api64_o!); installForm?.UpdateUser($"Renamed Uplay R1: {Path.GetFileName(api64)} -> {Path.GetFileName(api64_o)}", LogTextBox.Action, false); } if (File.Exists(api64_o)) diff --git a/CreamInstaller/Resources/UplayR2.cs b/CreamInstaller/Resources/UplayR2.cs index 501e329..6a50ba8 100644 --- a/CreamInstaller/Resources/UplayR2.cs +++ b/CreamInstaller/Resources/UplayR2.cs @@ -27,8 +27,9 @@ internal static class UplayR2 { directory.GetUplayR2Components(out _, out _, out _, out _, out _, out _, out string config); IEnumerable> blacklistDlc = selection.AllDlc.Except(selection.SelectedDlc); - foreach ((string id, string name, SortedList extraDlc) in selection.ExtraSelectedDlc) + foreach ((string _, string _, SortedList extraDlc) in selection.ExtraSelectedDlc) blacklistDlc = blacklistDlc.Except(extraDlc); + blacklistDlc = blacklistDlc.ToList(); if (blacklistDlc.Any()) { /*if (installForm is not null) @@ -86,7 +87,7 @@ internal static class UplayR2 File.Delete(api); installForm?.UpdateUser($"Deleted Uplay R2 Unlocker: {Path.GetFileName(api)}", LogTextBox.Action, false); } - File.Move(api32_o, api); + File.Move(api32_o, api!); installForm?.UpdateUser($"Restored Uplay R2: {Path.GetFileName(api32_o)} -> {Path.GetFileName(api)}", LogTextBox.Action, false); } if (File.Exists(api64_o)) @@ -97,7 +98,7 @@ internal static class UplayR2 File.Delete(api); installForm?.UpdateUser($"Deleted Uplay R2 Unlocker: {Path.GetFileName(api)}", LogTextBox.Action, false); } - File.Move(api64_o, api); + File.Move(api64_o, api!); installForm?.UpdateUser($"Restored Uplay R2: {Path.GetFileName(api64_o)} -> {Path.GetFileName(api)}", LogTextBox.Action, false); } if (deleteConfig && File.Exists(config)) @@ -111,11 +112,11 @@ internal static class UplayR2 => await Task.Run(() => { directory.GetUplayR2Components(out string old_api32, out string old_api64, out string api32, out string api32_o, out string api64, - out string api64_o, out string config); + out string api64_o, out string _); string api = File.Exists(old_api32) ? old_api32 : api32; if (File.Exists(api) && !File.Exists(api32_o)) { - File.Move(api, api32_o); + File.Move(api, api32_o!); installForm?.UpdateUser($"Renamed Uplay R2: {Path.GetFileName(api)} -> {Path.GetFileName(api32_o)}", LogTextBox.Action, false); } if (File.Exists(api32_o)) @@ -126,7 +127,7 @@ internal static class UplayR2 api = File.Exists(old_api64) ? old_api64 : api64; if (File.Exists(api) && !File.Exists(api64_o)) { - File.Move(api, api64_o); + File.Move(api, api64_o!); installForm?.UpdateUser($"Renamed Uplay R2: {Path.GetFileName(api)} -> {Path.GetFileName(api64_o)}", LogTextBox.Action, false); } if (File.Exists(api64_o))