diff --git a/CreamInstaller/Classes/ExceptionHandler.cs b/CreamInstaller/Classes/ExceptionHandler.cs index 7b5e7f9..2384f99 100644 --- a/CreamInstaller/Classes/ExceptionHandler.cs +++ b/CreamInstaller/Classes/ExceptionHandler.cs @@ -7,7 +7,11 @@ namespace CreamInstaller { public static bool OutputException(Exception e) { - while (!(e.InnerException is null)) e = e.InnerException; + while (!(e.InnerException is null)) + { + e = e.InnerException; + } + string output = ""; string[] stackTrace = e.StackTrace?.Split('\n'); if (!(stackTrace is null) && stackTrace.Length > 0) @@ -25,7 +29,11 @@ namespace CreamInstaller string[] messageLines = e.Message?.Split('\n'); if (!(messageLines is null) && messageLines.Length > 0) { - if (output.Length > 0) output += "\n\n"; + if (output.Length > 0) + { + output += "\n\n"; + } + output += "MESSAGE\n"; for (int i = 0; i < messageLines.Length; i++) { @@ -42,10 +50,13 @@ namespace CreamInstaller public class CustomMessageException : Exception { - private string message; + private readonly string message; public override string Message => message ?? "CustomMessageException"; - public override string ToString() => Message; + public override string ToString() + { + return Message; + } public CustomMessageException(string message) { diff --git a/CreamInstaller/Classes/ProgramSelection.cs b/CreamInstaller/Classes/ProgramSelection.cs index 98b3ce6..7c36e52 100644 --- a/CreamInstaller/Classes/ProgramSelection.cs +++ b/CreamInstaller/Classes/ProgramSelection.cs @@ -28,7 +28,10 @@ namespace CreamInstaller { string api = directory + @"\steam_api.dll"; string api64 = directory + @"\steam_api64.dll"; - if (api.IsFilePathLocked() || api64.IsFilePathLocked()) return true; + if (api.IsFilePathLocked() || api64.IsFilePathLocked()) + { + return true; + } } return false; } @@ -36,8 +39,14 @@ namespace CreamInstaller private void Toggle(KeyValuePair dlcApp, bool enabled) { - if (enabled) SelectedSteamDlc[dlcApp.Key] = dlcApp.Value; - else SelectedSteamDlc.Remove(dlcApp.Key); + if (enabled) + { + SelectedSteamDlc[dlcApp.Key] = dlcApp.Value; + } + else + { + SelectedSteamDlc.Remove(dlcApp.Key); + } } public void ToggleDlc(int dlcAppId, bool enabled) @@ -55,12 +64,25 @@ namespace CreamInstaller public void ToggleAllDlc(bool enabled) { - if (!enabled) SelectedSteamDlc.Clear(); - else foreach (KeyValuePair dlcApp in AllSteamDlc) Toggle(dlcApp, enabled); + if (!enabled) + { + SelectedSteamDlc.Clear(); + } + else + { + foreach (KeyValuePair dlcApp in AllSteamDlc) + { + Toggle(dlcApp, enabled); + } + } + Enabled = SelectedSteamDlc.Any(); } - public ProgramSelection() => All.Add(this); + public ProgramSelection() + { + All.Add(this); + } public static List All => Program.ProgramSelections; @@ -68,13 +90,24 @@ namespace CreamInstaller public static List AllSafeEnabled => AllSafe.FindAll(s => s.Enabled); - public static ProgramSelection FromAppId(int appId) => AllSafe.Find(s => s.SteamAppId == appId); + public static ProgramSelection FromAppId(int appId) + { + return AllSafe.Find(s => s.SteamAppId == appId); + } public static KeyValuePair? GetDlcFromAppId(int appId) { foreach (ProgramSelection selection in AllSafe) + { foreach (KeyValuePair app in selection.AllSteamDlc) - if (app.Key == appId) return app; + { + if (app.Key == appId) + { + return app; + } + } + } + return null; } } diff --git a/CreamInstaller/Classes/SteamCMD.cs b/CreamInstaller/Classes/SteamCMD.cs index 6034f0b..d2ce6bd 100644 --- a/CreamInstaller/Classes/SteamCMD.cs +++ b/CreamInstaller/Classes/SteamCMD.cs @@ -59,29 +59,51 @@ namespace CreamInstaller Kill(); if (!File.Exists(FilePath)) { - using (WebClient webClient = new()) webClient.DownloadFile("https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip", ArchivePath); + using (WebClient webClient = new()) + { + webClient.DownloadFile("https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip", ArchivePath); + } + ZipFile.ExtractToDirectory(ArchivePath, DirectoryPath); File.Delete(ArchivePath); } - if (File.Exists(AppCacheAppInfoPath)) File.Delete(AppCacheAppInfoPath); + if (File.Exists(AppCacheAppInfoPath)) + { + File.Delete(AppCacheAppInfoPath); + } + if (!File.Exists(AppInfoVersionPath) || !Version.TryParse(File.ReadAllText(AppInfoVersionPath, Encoding.UTF8), out Version version) || version < MinimumAppInfoVersion) { - if (Directory.Exists(AppInfoPath)) Directory.Delete(AppInfoPath, true); + if (Directory.Exists(AppInfoPath)) + { + Directory.Delete(AppInfoPath, true); + } + Directory.CreateDirectory(AppInfoPath); File.WriteAllText(AppInfoVersionPath, Application.ProductVersion, Encoding.UTF8); } - if (!File.Exists(DllPath)) Run($@"+quit", out _); + if (!File.Exists(DllPath)) + { + Run($@"+quit", out _); + } } public static bool GetAppInfo(int appId, out VProperty appInfo, string branch = "public", int buildId = 0) { appInfo = null; - if (Program.Canceled) return false; + if (Program.Canceled) + { + return false; + } + string output; string appUpdatePath = $@"{AppInfoPath}\{appId}"; string appUpdateFile = $@"{appUpdatePath}\appinfo.txt"; restart: - if (Directory.Exists(appUpdatePath) && File.Exists(appUpdateFile)) output = File.ReadAllText(appUpdateFile, Encoding.UTF8); + if (Directory.Exists(appUpdatePath) && File.Exists(appUpdateFile)) + { + output = File.ReadAllText(appUpdateFile, Encoding.UTF8); + } else { Run($@"+@ShutdownOnFailedCommand 0 +login anonymous +app_info_print {appId} +force_install_dir {appUpdatePath} +app_update 4 +quit", out _); @@ -94,7 +116,11 @@ namespace CreamInstaller File.WriteAllText(appUpdateFile, output, Encoding.UTF8); } } - if (Program.Canceled || output is null) return false; + if (Program.Canceled || output is null) + { + return false; + } + try { appInfo = VdfConvert.Deserialize(output); } catch { @@ -104,21 +130,40 @@ namespace CreamInstaller goto restart; } } - if (appInfo.Value is VValue) goto restart; - if (appInfo is null || (!(appInfo.Value is VValue) && appInfo.Value.Children().ToList().Count == 0)) return true; + if (appInfo.Value is VValue) + { + goto restart; + } + + if (appInfo is null || (!(appInfo.Value is VValue) && appInfo.Value.Children().ToList().Count == 0)) + { + return true; + } + VToken type = appInfo.Value is VValue ? null : appInfo.Value?["common"]?["type"]; if (type is null || type.ToString() == "Game") { string buildid = appInfo.Value is VValue ? null : appInfo.Value["depots"]?["branches"]?[branch]?["buildid"]?.ToString(); - if (buildid is null && !(type is null)) return true; + if (buildid is null && !(type is null)) + { + return true; + } + if (type is null || int.Parse(buildid) < buildId) { foreach (int id in ParseDlcAppIds(appInfo)) { string dlcAppUpdatePath = $@"{AppInfoPath}\{id}"; - if (Directory.Exists(dlcAppUpdatePath)) Directory.Delete(dlcAppUpdatePath, true); + if (Directory.Exists(dlcAppUpdatePath)) + { + Directory.Delete(dlcAppUpdatePath, true); + } } - if (Directory.Exists(appUpdatePath)) Directory.Delete(appUpdatePath, true); + if (Directory.Exists(appUpdatePath)) + { + Directory.Delete(appUpdatePath, true); + } + goto restart; } } @@ -128,30 +173,60 @@ namespace CreamInstaller public static List ParseDlcAppIds(VProperty appInfo) { List dlcIds = new(); - if (!(appInfo is VProperty)) return dlcIds; + if (!(appInfo is VProperty)) + { + return dlcIds; + } + if (!(appInfo.Value["extended"] is null)) + { foreach (VProperty property in appInfo.Value["extended"]) + { if (property.Key.ToString() == "listofdlc") + { foreach (string id in property.Value.ToString().Split(",")) + { if (!dlcIds.Contains(int.Parse(id))) + { dlcIds.Add(int.Parse(id)); + } + } + } + } + } + if (!(appInfo.Value["depots"] is null)) + { foreach (VProperty _property in appInfo.Value["depots"]) + { if (int.TryParse(_property.Key.ToString(), out int _)) + { if (int.TryParse(_property.Value?["dlcappid"]?.ToString(), out int appid) && !dlcIds.Contains(appid)) + { dlcIds.Add(appid); + } + } + } + } + return dlcIds; } public static void Kill() { - foreach (Process process in Process.GetProcessesByName("steamcmd")) process.Kill(); + foreach (Process process in Process.GetProcessesByName("steamcmd")) + { + process.Kill(); + } } public static void Dispose() { Kill(); - if (Directory.Exists(DirectoryPath)) Directory.Delete(DirectoryPath, true); + if (Directory.Exists(DirectoryPath)) + { + Directory.Delete(DirectoryPath, true); + } } } } \ No newline at end of file diff --git a/CreamInstaller/CreamInstaller.csproj b/CreamInstaller/CreamInstaller.csproj index 913cc90..bfc78d2 100644 --- a/CreamInstaller/CreamInstaller.csproj +++ b/CreamInstaller/CreamInstaller.csproj @@ -5,7 +5,7 @@ true Resources\ini.ico true - 2.0.4.0 + 2.0.4.1 Resources\ini.ico Automatically generates and installs CreamAPI files for Steam games on the user's computer. It can also generate and install CreamAPI for the Paradox Launcher should the user select a Paradox Interactive game. diff --git a/CreamInstaller/Forms/Components/CustomTreeView.cs b/CreamInstaller/Forms/Components/CustomTreeView.cs index a883b3d..802661f 100644 --- a/CreamInstaller/Forms/Components/CustomTreeView.cs +++ b/CreamInstaller/Forms/Components/CustomTreeView.cs @@ -9,8 +9,14 @@ namespace CreamInstaller { protected override void WndProc(ref Message m) { - if (m.Msg == 0x203) m.Result = IntPtr.Zero; - else base.WndProc(ref m); + if (m.Msg == 0x203) + { + m.Result = IntPtr.Zero; + } + else + { + base.WndProc(ref m); + } } public CustomTreeView() : base() @@ -27,17 +33,27 @@ namespace CreamInstaller private void DrawTreeNode(object sender, DrawTreeNodeEventArgs e) { - if (!e.Node.IsVisible) return; + if (!e.Node.IsVisible) + { + return; + } + e.Graphics.FillRectangle(new SolidBrush(BackColor), e.Bounds); int startX = e.Bounds.X + (e.Node.Parent is null ? 22 : 41); int startY = e.Bounds.Y; if (e.Node.Parent is null && e.Node.Nodes.Count > 0) + { if (e.Node.IsExpanded) + { openedGlyphRenderer.DrawBackground(e.Graphics, new(e.Bounds.X + startX / 2 - 8, startY, 16, 16)); + } else + { closedGlyphRenderer.DrawBackground(e.Graphics, new(e.Bounds.X + startX / 2 - 8, startY, 16, 16)); + } + } CheckBoxState checkBoxState = e.Node.TreeView.Enabled ? (e.Node.Checked ? CheckBoxState.CheckedNormal : CheckBoxState.UncheckedNormal) diff --git a/CreamInstaller/Forms/InstallForm.cs b/CreamInstaller/Forms/InstallForm.cs index 4c530be..b4815b4 100644 --- a/CreamInstaller/Forms/InstallForm.cs +++ b/CreamInstaller/Forms/InstallForm.cs @@ -30,7 +30,11 @@ namespace CreamInstaller public void UpdateProgress(int progress) { int value = (int)((float)(CompleteOperationsCount / (float)OperationsCount) * 100) + (progress / OperationsCount); - if (value < userProgressBar.Value) return; + if (value < userProgressBar.Value) + { + return; + } + userProgressBar.Value = value; } @@ -55,7 +59,11 @@ namespace CreamInstaller foreach (string directory in selection.SteamApiDllDirectories) { UpdateUser("Installing CreamAPI for " + selection.Name + $" in directory \"{directory}\" . . . ", InstallationLog.Operation); - if (!Program.IsProgramRunningDialog(this, selection)) throw new OperationCanceledException(); + if (!Program.IsProgramRunningDialog(this, selection)) + { + throw new OperationCanceledException(); + } + string api = directory + @"\steam_api.dll"; string api_o = directory + @"\steam_api_o.dll"; if (File.Exists(api) && !File.Exists(api_o)) @@ -128,8 +136,16 @@ namespace CreamInstaller CompleteOperationsCount = 0; foreach (ProgramSelection selection in ProgramSelection.AllSafe) { - if (!selection.Enabled) continue; - if (!Program.IsProgramRunningDialog(this, selection)) throw new OperationCanceledException(); + if (!selection.Enabled) + { + continue; + } + + if (!Program.IsProgramRunningDialog(this, selection)) + { + throw new OperationCanceledException(); + } + try { await OperateFor(selection); @@ -193,7 +209,11 @@ namespace CreamInstaller } catch (Exception e) { - if (ExceptionHandler.OutputException(e)) goto retry; + if (ExceptionHandler.OutputException(e)) + { + goto retry; + } + Close(); } } diff --git a/CreamInstaller/Forms/MainForm.cs b/CreamInstaller/Forms/MainForm.cs index c3655b3..2e78b71 100644 --- a/CreamInstaller/Forms/MainForm.cs +++ b/CreamInstaller/Forms/MainForm.cs @@ -154,7 +154,11 @@ namespace CreamInstaller } catch (Exception e) { - if (ExceptionHandler.OutputException(e)) goto retry; + if (ExceptionHandler.OutputException(e)) + { + goto retry; + } + Close(); } } diff --git a/CreamInstaller/Forms/SelectForm.cs b/CreamInstaller/Forms/SelectForm.cs index 4c5ad06..0012539 100644 --- a/CreamInstaller/Forms/SelectForm.cs +++ b/CreamInstaller/Forms/SelectForm.cs @@ -31,9 +31,17 @@ namespace CreamInstaller get { List gameDirectories = new(); - if (Program.Canceled) return gameDirectories; + if (Program.Canceled) + { + return gameDirectories; + } + string steamInstallPath = Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Valve\\Steam", "InstallPath", null) as string; - if (steamInstallPath == null) steamInstallPath = Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Valve\\Steam", "InstallPath", null) as string; + if (steamInstallPath == null) + { + steamInstallPath = Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Valve\\Steam", "InstallPath", null) as string; + } + if (steamInstallPath != null && Directory.Exists(steamInstallPath)) { string libraryFolder = steamInstallPath + @"\steamapps"; @@ -51,8 +59,15 @@ namespace CreamInstaller if (int.TryParse(_property.Key, out int _)) { string path = _property.Value.path.ToString() + @"\steamapps"; - if (string.IsNullOrWhiteSpace(path) || !Directory.Exists(path)) continue; - if (!gameDirectories.Contains(path)) gameDirectories.Add(path); + if (string.IsNullOrWhiteSpace(path) || !Directory.Exists(path)) + { + continue; + } + + if (!gameDirectories.Contains(path)) + { + gameDirectories.Add(path); + } } } } @@ -67,31 +82,57 @@ namespace CreamInstaller private static bool GetDllDirectoriesFromGameDirectory(string gameDirectory, out List dllDirectories) { dllDirectories = new(); - if (Program.Canceled || !Directory.Exists(gameDirectory)) return false; + if (Program.Canceled || !Directory.Exists(gameDirectory)) + { + return false; + } + string api = gameDirectory + @"\steam_api.dll"; string api64 = gameDirectory + @"\steam_api64.dll"; - if (File.Exists(api) || File.Exists(api64)) dllDirectories.Add(gameDirectory); + if (File.Exists(api) || File.Exists(api64)) + { + dllDirectories.Add(gameDirectory); + } + foreach (string _directory in Directory.GetDirectories(gameDirectory)) { - if (Program.Canceled) return false; + if (Program.Canceled) + { + return false; + } + try { if (GetDllDirectoriesFromGameDirectory(_directory, out List _dllDirectories)) + { dllDirectories.AddRange(_dllDirectories); + } } catch { } } - if (!dllDirectories.Any()) return false; + if (!dllDirectories.Any()) + { + return false; + } + return true; } private static bool GetGamesFromLibraryDirectory(string libraryDirectory, out List> games) { games = new(); - if (Program.Canceled || !Directory.Exists(libraryDirectory)) return false; + if (Program.Canceled || !Directory.Exists(libraryDirectory)) + { + return false; + } + foreach (string directory in Directory.GetFiles(libraryDirectory)) { - if (Program.Canceled) return false; + if (Program.Canceled) + { + return false; + } + if (Path.GetExtension(directory) == ".acf") { try @@ -104,18 +145,38 @@ namespace CreamInstaller if (string.IsNullOrWhiteSpace(_appid) || string.IsNullOrWhiteSpace(installdir) || string.IsNullOrWhiteSpace(name) - || string.IsNullOrWhiteSpace(_buildid)) continue; + || string.IsNullOrWhiteSpace(_buildid)) + { + continue; + } + string branch = property.Value.UserConfig?.betakey?.ToString(); - if (string.IsNullOrWhiteSpace(branch)) branch = "public"; + if (string.IsNullOrWhiteSpace(branch)) + { + branch = "public"; + } + string gameDirectory = libraryDirectory + @"\common\" + installdir; - if (!int.TryParse(_appid, out int appid)) continue; - if (!int.TryParse(_buildid, out int buildid)) continue; + if (!int.TryParse(_appid, out int appid)) + { + continue; + } + + if (!int.TryParse(_buildid, out int buildid)) + { + continue; + } + games.Add(new(appid, name, branch, buildid, gameDirectory)); } catch { } } } - if (!games.Any()) return false; + if (!games.Any()) + { + return false; + } + return true; } @@ -125,14 +186,29 @@ namespace CreamInstaller private void GetCreamApiApplicablePrograms(IProgress progress) { int cur = 0; - if (Program.Canceled) return; + if (Program.Canceled) + { + return; + } + List> applicablePrograms = new(); string launcherRootDirectory = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Programs\\Paradox Interactive"; - if (Directory.Exists(launcherRootDirectory)) applicablePrograms.Add(new(0, "Paradox Launcher", "", 0, launcherRootDirectory)); + if (Directory.Exists(launcherRootDirectory)) + { + applicablePrograms.Add(new(0, "Paradox Launcher", "", 0, launcherRootDirectory)); + } + foreach (string libraryDirectory in GameLibraryDirectories) + { if (GetGamesFromLibraryDirectory(libraryDirectory, out List> games)) + { foreach (Tuple game in games) + { applicablePrograms.Add(game); + } + } + } + RunningTasks.Clear(); foreach (Tuple program in applicablePrograms) { @@ -141,17 +217,39 @@ namespace CreamInstaller string branch = program.Item3; int buildId = program.Item4; string directory = program.Item5; - if (Program.Canceled) return; + if (Program.Canceled) + { + return; + } // EasyAntiCheat detects DLL changes, so skip those games - if (Directory.Exists(directory + @"\EasyAntiCheat")) continue; + if (Directory.Exists(directory + @"\EasyAntiCheat")) + { + continue; + } // BattlEye in DayZ detects DLL changes, but not in Arma3? - if (name != "Arma 3" && Directory.Exists(directory + @"\BattlEye")) continue; + if (name != "Arma 3" && Directory.Exists(directory + @"\BattlEye")) + { + continue; + } + Task task = Task.Run(() => { - if (Program.Canceled || !GetDllDirectoriesFromGameDirectory(directory, out List dllDirectories)) return; + if (Program.Canceled || !GetDllDirectoriesFromGameDirectory(directory, out List dllDirectories)) + { + return; + } + VProperty appInfo = null; - if (Program.Canceled || (appId > 0 && !SteamCMD.GetAppInfo(appId, out appInfo, branch, buildId))) return; - if (Program.Canceled) return; + if (Program.Canceled || (appId > 0 && !SteamCMD.GetAppInfo(appId, out appInfo, branch, buildId))) + { + return; + } + + if (Program.Canceled) + { + return; + } + ConcurrentDictionary dlc = new(); List dlcTasks = new(); List dlcIds = SteamCMD.ParseDlcAppIds(appInfo); @@ -159,14 +257,34 @@ namespace CreamInstaller { foreach (int id in dlcIds) { - if (Program.Canceled) return; + if (Program.Canceled) + { + return; + } + Task task = Task.Run(() => { - if (Program.Canceled) return; + if (Program.Canceled) + { + return; + } + string dlcName = null; - if (SteamCMD.GetAppInfo(id, out VProperty dlcAppInfo)) dlcName = dlcAppInfo?.Value?["common"]?["name"]?.ToString(); - if (Program.Canceled) return; - if (string.IsNullOrWhiteSpace(dlcName)) return; //dlcName = "Unknown DLC"; + if (SteamCMD.GetAppInfo(id, out VProperty dlcAppInfo)) + { + dlcName = dlcAppInfo?.Value?["common"]?["name"]?.ToString(); + } + + if (Program.Canceled) + { + return; + } + + if (string.IsNullOrWhiteSpace(dlcName)) + { + return; //dlcName = "Unknown DLC"; + } + dlc[id] = /*$"[{id}] " +*/ dlcName; progress.Report(++cur); }); @@ -175,9 +293,20 @@ namespace CreamInstaller } progress.Report(-RunningTasks.Count); } - else if (appId > 0) return; - if (Program.Canceled) return; - if (string.IsNullOrWhiteSpace(name)) return; + else if (appId > 0) + { + return; + } + + if (Program.Canceled) + { + return; + } + + if (string.IsNullOrWhiteSpace(name)) + { + return; + } ProgramSelection selection = ProgramSelection.FromAppId(appId) ?? new(); selection.Name = name; @@ -188,13 +317,25 @@ namespace CreamInstaller foreach (Task task in dlcTasks.ToList()) { - if (Program.Canceled) return; + if (Program.Canceled) + { + return; + } + task.Wait(); } - if (Program.Canceled) return; + if (Program.Canceled) + { + return; + } + treeView1.Invoke((MethodInvoker)delegate { - if (Program.Canceled) return; + if (Program.Canceled) + { + return; + } + TreeNode programNode = treeNodes.Find(s => s.Name == "" + appId) ?? new(); programNode.Name = "" + appId; programNode.Text = /*(appId > 0 ? $"[{appId}] " : "") +*/ name; @@ -207,9 +348,15 @@ namespace CreamInstaller { // maybe add game and/or dlc choice here? } - else foreach (KeyValuePair dlcApp in dlc.ToList()) + else + { + foreach (KeyValuePair dlcApp in dlc.ToList()) { - if (Program.Canceled || programNode is null) return; + if (Program.Canceled || programNode is null) + { + return; + } + TreeNode dlcNode = treeNodes.Find(s => s.Name == "" + dlcApp.Key) ?? new(); dlcNode.Name = "" + dlcApp.Key; dlcNode.Text = dlcApp.Value; @@ -220,6 +367,7 @@ namespace CreamInstaller treeNodes.Add(dlcNode); selection.AllSteamDlc[dlcApp.Key] = dlcApp.Value; } + } }); progress.Report(++cur); }); @@ -229,7 +377,11 @@ namespace CreamInstaller progress.Report(cur); foreach (Task task in RunningTasks.ToList()) { - if (Program.Canceled) return; + if (Program.Canceled) + { + return; + } + task.Wait(); } progress.Report(RunningTasks.Count); @@ -257,20 +409,45 @@ namespace CreamInstaller IProgress iProgress = progress; progress.ProgressChanged += (sender, _progress) => { - if (_progress < 0) maxProgress = -_progress; - else curProgress = _progress; + if (_progress < 0) + { + maxProgress = -_progress; + } + else + { + curProgress = _progress; + } + int p = Math.Max(Math.Min((int)((float)(curProgress / (float)maxProgress) * 100), 100), 0); - if (validating) label2.Text = $"Validating . . . {p}% ({curProgress}/{maxProgress})"; - else if (setup) label2.Text = $"Setting up SteamCMD . . . {p}% ({curProgress}/{maxProgress})"; - else label2.Text = $"Gathering and caching your applicable games and their DLCs . . . {p}% ({curProgress}/{maxProgress})"; + if (validating) + { + label2.Text = $"Validating . . . {p}% ({curProgress}/{maxProgress})"; + } + else if (setup) + { + label2.Text = $"Setting up SteamCMD . . . {p}% ({curProgress}/{maxProgress})"; + } + else + { + label2.Text = $"Gathering and caching your applicable games and their DLCs . . . {p}% ({curProgress}/{maxProgress})"; + } + progressBar1.Value = p; }; iProgress.Report(-1660); // not exact, number varies int cur = 0; iProgress.Report(cur); - if (!validating) label2.Text = "Setting up SteamCMD . . . "; - if (!Directory.Exists(SteamCMD.DirectoryPath)) Directory.CreateDirectory(SteamCMD.DirectoryPath); + if (!validating) + { + label2.Text = "Setting up SteamCMD . . . "; + } + + if (!Directory.Exists(SteamCMD.DirectoryPath)) + { + Directory.CreateDirectory(SteamCMD.DirectoryPath); + } + FileSystemWatcher watcher = new(SteamCMD.DirectoryPath); watcher.Changed += (sender, e) => iProgress.Report(++cur); watcher.Filter = "*"; @@ -280,13 +457,21 @@ namespace CreamInstaller watcher.Dispose(); setup = false; - if (!validating) label2.Text = "Gathering and caching your applicable games and their DLCs . . . "; + if (!validating) + { + label2.Text = "Gathering and caching your applicable games and their DLCs . . . "; + } + await Task.Run(() => GetCreamApiApplicablePrograms(iProgress)); ProgramSelection.All.ForEach(selection => selection.SteamApiDllDirectories.RemoveAll(directory => !Directory.Exists(directory))); ProgramSelection.All.RemoveAll(selection => !Directory.Exists(selection.RootDirectory) || !selection.SteamApiDllDirectories.Any()); foreach (TreeNode treeNode in treeNodes) + { if (treeNode.Parent is null && ProgramSelection.FromAppId(int.Parse(treeNode.Name)) is null) + { treeNode.Remove(); + } + } //SetMinimumSizeFromTreeView(); progressBar1.Value = 100; @@ -303,7 +488,10 @@ namespace CreamInstaller scanButton.Enabled = true; label2.Text = "Validating . . . "; - if (!validating && !Program.Canceled) OnLoad(true); + if (!validating && !Program.Canceled) + { + OnLoad(true); + } } /*private const int GWL_STYLE = -16; @@ -337,7 +525,11 @@ namespace CreamInstaller private void OnTreeViewNodeCheckedChanged(object sender, TreeViewEventArgs e) { - if (e.Action == TreeViewAction.Unknown) return; + if (e.Action == TreeViewAction.Unknown) + { + return; + } + ProgramSelection selection = ProgramSelection.FromAppId(int.Parse(e.Node.Name)); if (selection is null) { @@ -351,7 +543,11 @@ namespace CreamInstaller selection.ToggleAllDlc(e.Node.Checked); e.Node.Nodes.Cast().ToList().ForEach(treeNode => treeNode.Checked = e.Node.Checked); } - else selection.Enabled = e.Node.Checked; + else + { + selection.Enabled = e.Node.Checked; + } + allCheckBox.CheckedChanged -= OnAllCheckBoxChanged; allCheckBox.Checked = treeNodes.TrueForAll(treeNode => treeNode.Checked); allCheckBox.CheckedChanged += OnAllCheckBoxChanged; @@ -380,11 +576,14 @@ namespace CreamInstaller ProgramSelection selection = ProgramSelection.FromAppId(int.Parse(e.Node.Name)); KeyValuePair? dlc = ProgramSelection.GetDlcFromAppId(int.Parse(e.Node.Name)); int appId = selection?.SteamAppId ?? dlc?.Key ?? 0; - if (appId > 0) Process.Start(new ProcessStartInfo + if (appId > 0) { - FileName = "https://steamdb.info/app/" + appId, - UseShellExecute = true - }); + Process.Start(new ProcessStartInfo + { + FileName = "https://steamdb.info/app/" + appId, + UseShellExecute = true + }); + } } }; retry: @@ -394,7 +593,11 @@ namespace CreamInstaller } catch (Exception e) { - if (ExceptionHandler.OutputException(e)) goto retry; + if (ExceptionHandler.OutputException(e)) + { + goto retry; + } + Close(); } } @@ -407,16 +610,32 @@ namespace CreamInstaller paradoxLauncher.ExtraSteamAppIdDlc.Clear(); foreach (ProgramSelection selection in ProgramSelection.AllSafeEnabled) { - if (selection.Name == paradoxLauncher.Name) continue; - if (selection.AppInfo.Value["extended"]["publisher"].ToString() != "Paradox Interactive") continue; + if (selection.Name == paradoxLauncher.Name) + { + continue; + } + + if (selection.AppInfo.Value["extended"]["publisher"].ToString() != "Paradox Interactive") + { + continue; + } + paradoxLauncher.ExtraSteamAppIdDlc.Add(new(selection.SteamAppId, selection.Name, selection.SelectedSteamDlc)); } if (!paradoxLauncher.ExtraSteamAppIdDlc.Any()) { foreach (ProgramSelection selection in ProgramSelection.AllSafe) { - if (selection.Name == paradoxLauncher.Name) continue; - if (selection.AppInfo.Value["extended"]["publisher"].ToString() != "Paradox Interactive") continue; + if (selection.Name == paradoxLauncher.Name) + { + continue; + } + + if (selection.AppInfo.Value["extended"]["publisher"].ToString() != "Paradox Interactive") + { + continue; + } + paradoxLauncher.ExtraSteamAppIdDlc.Add(new(selection.SteamAppId, selection.Name, selection.AllSteamDlc)); } } @@ -449,16 +668,31 @@ namespace CreamInstaller if (ProgramSelection.All.Count > 0) { foreach (ProgramSelection selection in ProgramSelection.AllSafeEnabled) - if (!Program.IsProgramRunningDialog(this, selection)) return; - if (ParadoxLauncherDlcDialog(this)) return; + { + if (!Program.IsProgramRunningDialog(this, selection)) + { + return; + } + } + + if (ParadoxLauncherDlcDialog(this)) + { + return; + } + Hide(); InstallForm installForm = new(this); installForm.ShowDialog(); if (installForm.Reselecting) { foreach (TreeNode treeNode in treeNodes) + { if (!(treeNode.Parent is null) || int.Parse(treeNode.Name) == 0) + { OnTreeViewNodeCheckedChanged(null, new(treeNode, TreeViewAction.ByMouse)); + } + } + this.InheritLocation(installForm); Show(); } @@ -486,7 +720,11 @@ namespace CreamInstaller { if (treeNode.Parent is null) { - if (!treeNode.Checked) shouldCheck = true; + if (!treeNode.Checked) + { + shouldCheck = true; + } + treeNode.Checked = shouldCheck; OnTreeViewNodeCheckedChanged(null, new(treeNode, TreeViewAction.ByMouse)); } diff --git a/CreamInstaller/Program.cs b/CreamInstaller/Program.cs index 939ed3c..a2fd66f 100644 --- a/CreamInstaller/Program.cs +++ b/CreamInstaller/Program.cs @@ -35,7 +35,11 @@ namespace CreamInstaller } catch (Exception e) { - if (ExceptionHandler.OutputException(e)) goto retry; + if (ExceptionHandler.OutputException(e)) + { + goto retry; + } + Application.Exit(); return; } @@ -83,7 +87,10 @@ namespace CreamInstaller SteamCMD.Kill(); } - private static void OnApplicationExit(object s, EventArgs e) => Cleanup(); + private static void OnApplicationExit(object s, EventArgs e) + { + Cleanup(); + } internal static void InheritLocation(this Form form, Form fromForm) {