From e4a90d9c8da3d8b850fce3f6d150df2ff9898672 Mon Sep 17 00:00:00 2001 From: pointfeev Date: Tue, 16 Aug 2022 17:15:29 -0400 Subject: [PATCH] intermediary updates - Uplay R1 & R2 preparation - Minor refactoring - Install form whiteout fix --- .editorconfig | 24 +++++---- CreamInstaller/Components/ContextMenuItem.cs | 8 +-- CreamInstaller/Epic/EpicLibrary.cs | 15 +++--- CreamInstaller/Epic/EpicStore.cs | 14 ++--- CreamInstaller/Epic/GraphQL/Response.cs | 4 +- CreamInstaller/Forms/DialogForm.cs | 11 ++-- CreamInstaller/Forms/InstallForm.cs | 31 +++++------ CreamInstaller/Forms/MainForm.cs | 24 ++++----- CreamInstaller/Forms/SelectDialogForm.cs | 12 ++--- CreamInstaller/Forms/SelectForm.cs | 54 +++++++++++--------- CreamInstaller/Paradox/ParadoxLauncher.cs | 29 +++++------ CreamInstaller/Program.cs | 10 ++-- CreamInstaller/ProgramSelection.cs | 25 +++++---- CreamInstaller/Resources/Resources.cs | 51 ++++++++++++++++-- CreamInstaller/Steam/SteamCMD.cs | 27 +++++----- CreamInstaller/Steam/SteamLibrary.cs | 14 ++--- CreamInstaller/Steam/SteamStore.cs | 39 +++++++++----- CreamInstaller/Utility/Diagnostics.cs | 6 +-- CreamInstaller/Utility/ExceptionHandler.cs | 10 ++-- CreamInstaller/Utility/HttpClientManager.cs | 8 +-- CreamInstaller/Utility/ProgramData.cs | 8 +-- 21 files changed, 241 insertions(+), 183 deletions(-) diff --git a/.editorconfig b/.editorconfig index 8c57ea5..2c33dd5 100644 --- a/.editorconfig +++ b/.editorconfig @@ -19,12 +19,12 @@ insert_final_newline = false # Organize usings dotnet_separate_import_directive_groups = true -dotnet_sort_system_directives_first = true +dotnet_sort_system_directives_first = false file_header_template = unset # this. and Me. preferences dotnet_style_qualification_for_event = false:suggestion -dotnet_style_qualification_for_field = false +dotnet_style_qualification_for_field = false:suggestion dotnet_style_qualification_for_method = false:suggestion dotnet_style_qualification_for_property = false:suggestion @@ -53,6 +53,7 @@ dotnet_style_prefer_auto_properties = true:suggestion dotnet_style_prefer_compound_assignment = true dotnet_style_prefer_conditional_expression_over_assignment = true:suggestion dotnet_style_prefer_conditional_expression_over_return = true:suggestion +dotnet_style_prefer_foreach_explicit_cast_in_source = when_strongly_typed dotnet_style_prefer_inferred_anonymous_type_member_names = true dotnet_style_prefer_inferred_tuple_names = true dotnet_style_prefer_is_null_check_over_reference_equality_method = true @@ -92,6 +93,7 @@ csharp_style_expression_bodied_properties = true:suggestion # Pattern matching preferences csharp_style_pattern_matching_over_as_with_null_check = true csharp_style_pattern_matching_over_is_with_cast_check = true +csharp_style_prefer_extended_property_pattern = true csharp_style_prefer_not_pattern = true csharp_style_prefer_pattern_matching = true:suggestion csharp_style_prefer_switch_expression = true @@ -101,31 +103,35 @@ csharp_style_conditional_delegate_call = true # Modifier preferences csharp_prefer_static_local_function = true -csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async +csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,required,volatile,async # Code-block preferences csharp_prefer_braces = false:suggestion csharp_prefer_simple_using_statement = true csharp_style_namespace_declarations = file_scoped:suggestion +csharp_style_prefer_method_group_conversion = true:suggestion +csharp_style_prefer_top_level_statements = true:suggestion # Expression-level preferences csharp_prefer_simple_default_expression = true csharp_style_deconstructed_variable_declaration = true csharp_style_implicit_object_creation_when_type_is_apparent = true csharp_style_inlined_variable_declaration = true -csharp_style_pattern_local_over_anonymous_function = true csharp_style_prefer_index_operator = true +csharp_style_prefer_local_over_anonymous_function = true csharp_style_prefer_null_check_over_type_check = true csharp_style_prefer_range_operator = true +csharp_style_prefer_tuple_swap = true +csharp_style_prefer_utf8_string_literals = true csharp_style_throw_expression = true -csharp_style_unused_value_assignment_preference = discard_variable:silent -csharp_style_unused_value_expression_statement_preference = discard_variable +csharp_style_unused_value_assignment_preference = discard_variable +csharp_style_unused_value_expression_statement_preference = discard_variable:suggestion # 'using' directive preferences csharp_using_directive_placement = outside_namespace:suggestion # New line preferences -csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true:suggestion +csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = false:suggestion csharp_style_allow_blank_lines_between_consecutive_braces_experimental = false:suggestion csharp_style_allow_embedded_statements_on_same_line_experimental = true:suggestion @@ -144,8 +150,8 @@ csharp_new_line_between_query_expression_clauses = true csharp_indent_block_contents = true csharp_indent_braces = false csharp_indent_case_contents = true -csharp_indent_case_contents_when_block = true -csharp_indent_labels = one_less_than_current +csharp_indent_case_contents_when_block = false +csharp_indent_labels = no_change csharp_indent_switch_labels = true # Space preferences diff --git a/CreamInstaller/Components/ContextMenuItem.cs b/CreamInstaller/Components/ContextMenuItem.cs index daf74e1..5eddf62 100644 --- a/CreamInstaller/Components/ContextMenuItem.cs +++ b/CreamInstaller/Components/ContextMenuItem.cs @@ -1,13 +1,13 @@ -using System; +using CreamInstaller.Paradox; +using CreamInstaller.Utility; + +using System; using System.Collections.Concurrent; using System.Drawing; using System.IO; using System.Threading.Tasks; using System.Windows.Forms; -using CreamInstaller.Paradox; -using CreamInstaller.Utility; - namespace CreamInstaller.Components; internal class ContextMenuItem : ToolStripMenuItem diff --git a/CreamInstaller/Epic/EpicLibrary.cs b/CreamInstaller/Epic/EpicLibrary.cs index b4adf22..ac0660b 100644 --- a/CreamInstaller/Epic/EpicLibrary.cs +++ b/CreamInstaller/Epic/EpicLibrary.cs @@ -1,14 +1,14 @@ -using System.Collections.Generic; +using CreamInstaller.Resources; + +using Microsoft.Win32; + +using System.Collections.Generic; using System.IO; using System.Linq; using System.Text.Json; using System.Threading; using System.Threading.Tasks; -using CreamInstaller.Resources; - -using Microsoft.Win32; - namespace CreamInstaller.Epic; internal static class EpicLibrary @@ -53,13 +53,12 @@ internal static class EpicLibrary { List dllDirectories = new(); if (Program.Canceled || !Directory.Exists(gameDirectory)) return null; - gameDirectory.GetScreamApiComponents(out string sdk32, out string sdk32_o, out string sdk64, out string sdk64_o, out string config, out string cache); + gameDirectory.GetScreamApiComponents(out string sdk32, out string sdk32_o, out string sdk64, out string sdk64_o, out string config); if (File.Exists(sdk32) || File.Exists(sdk32_o) || File.Exists(sdk64) || File.Exists(sdk64_o) - || File.Exists(config) - || File.Exists(cache)) + || File.Exists(config)) dllDirectories.Add(gameDirectory); string[] directories = Directory.GetDirectories(gameDirectory); foreach (string _directory in directories) diff --git a/CreamInstaller/Epic/EpicStore.cs b/CreamInstaller/Epic/EpicStore.cs index 2acc802..ce5713f 100644 --- a/CreamInstaller/Epic/EpicStore.cs +++ b/CreamInstaller/Epic/EpicStore.cs @@ -1,4 +1,9 @@ -using System; +using CreamInstaller.Epic.GraphQL; +using CreamInstaller.Utility; + +using Newtonsoft.Json; + +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -7,11 +12,6 @@ using System.Net.Http.Headers; using System.Threading.Tasks; using System.Web; -using CreamInstaller.Epic.GraphQL; -using CreamInstaller.Utility; - -using Newtonsoft.Json; - namespace CreamInstaller.Epic; internal static class EpicStore @@ -124,7 +124,7 @@ internal static class EpicStore HttpClient client = HttpClientManager.HttpClient; if (client is null) return null; HttpResponseMessage httpResponse = await client.PostAsync(new Uri("https://graphql.epicgames.com/graphql"), content); - httpResponse.EnsureSuccessStatusCode(); + _ = httpResponse.EnsureSuccessStatusCode(); string response = await httpResponse.Content.ReadAsStringAsync(); return JsonConvert.DeserializeObject(response); } diff --git a/CreamInstaller/Epic/GraphQL/Response.cs b/CreamInstaller/Epic/GraphQL/Response.cs index 4a1f9ba..dbee62b 100644 --- a/CreamInstaller/Epic/GraphQL/Response.cs +++ b/CreamInstaller/Epic/GraphQL/Response.cs @@ -1,9 +1,9 @@ #pragma warning disable CA1819 // Properties should not return arrays -using System; - using Newtonsoft.Json; +using System; + namespace CreamInstaller.Epic.GraphQL; public class Response diff --git a/CreamInstaller/Forms/DialogForm.cs b/CreamInstaller/Forms/DialogForm.cs index 6767087..503b412 100644 --- a/CreamInstaller/Forms/DialogForm.cs +++ b/CreamInstaller/Forms/DialogForm.cs @@ -1,19 +1,18 @@ -using System; +using CreamInstaller.Components; + +using System; using System.Drawing; using System.Windows.Forms; -using CreamInstaller.Components; - namespace CreamInstaller; internal partial class DialogForm : CustomForm { internal DialogForm(IWin32Window owner) : base(owner) => InitializeComponent(); - internal DialogResult Show(Icon descriptionIcon, string descriptionText, string acceptButtonText, string cancelButtonText = null, string customFormText = null, Icon customFormIcon = null) + internal DialogResult Show(Icon descriptionIcon, string descriptionText, string acceptButtonText = "OK", string cancelButtonText = null, string customFormText = null, Icon customFormIcon = null) { - if (descriptionIcon is null) - descriptionIcon = Icon; + descriptionIcon ??= Icon; icon.Image = descriptionIcon.ToBitmap(); descriptionLabel.Text = descriptionText; acceptButton.Text = acceptButtonText; diff --git a/CreamInstaller/Forms/InstallForm.cs b/CreamInstaller/Forms/InstallForm.cs index b355b30..331b944 100644 --- a/CreamInstaller/Forms/InstallForm.cs +++ b/CreamInstaller/Forms/InstallForm.cs @@ -1,4 +1,8 @@ -using System; +using CreamInstaller.Components; +using CreamInstaller.Resources; +using CreamInstaller.Utility; + +using System; using System.Collections.Generic; using System.Drawing; using System.IO; @@ -8,10 +12,6 @@ using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; -using CreamInstaller.Components; -using CreamInstaller.Resources; -using CreamInstaller.Utility; - using static CreamInstaller.Paradox.ParadoxLauncher; namespace CreamInstaller; @@ -45,13 +45,14 @@ internal partial class InstallForm : CustomForm internal void UpdateUser(string text, Color color, bool info = true, bool log = true) { - if (info) userInfoLabel.Invoke(() => userInfoLabel.Text = text); + if (info) _ = userInfoLabel.Invoke(() => userInfoLabel.Text = text); if (log && !logTextBox.Disposing && !logTextBox.IsDisposed) { logTextBox.Invoke(() => { if (logTextBox.Text.Length > 0) logTextBox.AppendText(Environment.NewLine, color); logTextBox.AppendText(text, color); + logTextBox.Refresh(); }); Thread.Sleep(0); } @@ -268,7 +269,7 @@ internal partial class InstallForm : CustomForm internal static async Task UninstallScreamAPI(string directory, InstallForm installForm = null, bool deleteConfig = true) => await Task.Run(() => { - directory.GetScreamApiComponents(out string sdk32, out string sdk32_o, out string sdk64, out string sdk64_o, out string config, out string cache); + directory.GetScreamApiComponents(out string sdk32, out string sdk32_o, out string sdk64, out string sdk64_o, out string config); if (File.Exists(sdk32_o)) { if (File.Exists(sdk32)) @@ -299,17 +300,11 @@ internal partial class InstallForm : CustomForm if (installForm is not null) installForm.UpdateUser($"Deleted configuration: {Path.GetFileName(config)}", InstallationLog.Action, info: false); } - if (deleteConfig && File.Exists(cache)) - { - File.Delete(cache); - if (installForm is not null) - installForm.UpdateUser($"Deleted cache: {Path.GetFileName(cache)}", InstallationLog.Action, info: false); - } }); internal static async Task InstallScreamAPI(string directory, ProgramSelection selection, InstallForm installForm = null, bool generateConfig = true) => await Task.Run(() => { - directory.GetScreamApiComponents(out string sdk32, out string sdk32_o, out string sdk64, out string sdk64_o, out string config, out _); + directory.GetScreamApiComponents(out string sdk32, out string sdk32_o, out string sdk64, out string sdk64_o, out string config); if (File.Exists(sdk32) && !File.Exists(sdk32_o)) { File.Move(sdk32, sdk32_o); @@ -372,7 +367,7 @@ internal partial class InstallForm : CustomForm if (selection.Id == "ParadoxLauncher") { UpdateUser($"Repairing Paradox Launcher . . . ", InstallationLog.Operation); - await Repair(this, selection); + _ = await Repair(this, selection); } foreach (string directory in selection.DllDirectories) { @@ -394,8 +389,8 @@ internal partial class InstallForm : CustomForm if (selection.IsEpic && selection.SelectedDlc.Any(d => d.Value.type is DlcType.EpicCatalogItem or DlcType.EpicEntitlement) || selection.ExtraSelectedDlc.Any(item => item.dlc.Any(dlc => dlc.Value.type is DlcType.EpicCatalogItem or DlcType.EpicEntitlement))) { - directory.GetScreamApiComponents(out string sdk32, out string sdk32_o, out string sdk64, out string sdk64_o, out string config, out string cache); - if (File.Exists(sdk32) || File.Exists(sdk32_o) || File.Exists(sdk64) || File.Exists(sdk64_o) || File.Exists(config) || File.Exists(cache)) + directory.GetScreamApiComponents(out string sdk32, out string sdk32_o, out string sdk64, out string sdk64_o, out string config); + if (File.Exists(sdk32) || File.Exists(sdk32_o) || File.Exists(sdk64) || File.Exists(sdk64_o) || File.Exists(config)) { UpdateUser($"{(Uninstalling ? "Uninstalling" : "Installing")} ScreamAPI" + $" {(Uninstalling ? "from" : "for")} " + selection.Name + $" in directory \"{directory}\" . . . ", InstallationLog.Operation); @@ -469,7 +464,7 @@ internal partial class InstallForm : CustomForm private void OnLoad(object sender, EventArgs _) { - retry: + retry: try { userInfoLabel.Text = "Loading . . . "; diff --git a/CreamInstaller/Forms/MainForm.cs b/CreamInstaller/Forms/MainForm.cs index 33433db..405f3dc 100644 --- a/CreamInstaller/Forms/MainForm.cs +++ b/CreamInstaller/Forms/MainForm.cs @@ -1,4 +1,13 @@ -using System; +using CreamInstaller.Components; +using CreamInstaller.Utility; + +using HtmlAgilityPack; + +using Onova; +using Onova.Models; +using Onova.Services; + +using System; using System.Collections.Generic; using System.Drawing; using System.IO; @@ -8,15 +17,6 @@ using System.Threading.Tasks; using System.Web; using System.Windows.Forms; -using CreamInstaller.Components; -using CreamInstaller.Utility; - -using HtmlAgilityPack; - -using Onova; -using Onova.Models; -using Onova.Services; - namespace CreamInstaller; internal partial class MainForm : CustomForm @@ -39,7 +39,7 @@ internal partial class MainForm : CustomForm } Hide(); using SelectForm form = new(this); - form.ShowDialog(); + _ = form.ShowDialog(); Close(); } @@ -146,7 +146,7 @@ internal partial class MainForm : CustomForm private void OnLoad(object sender, EventArgs _) { - retry: + retry: try { string FileName = Path.GetFileName(Program.CurrentProcessFilePath); diff --git a/CreamInstaller/Forms/SelectDialogForm.cs b/CreamInstaller/Forms/SelectDialogForm.cs index f0a0421..579c79c 100644 --- a/CreamInstaller/Forms/SelectDialogForm.cs +++ b/CreamInstaller/Forms/SelectDialogForm.cs @@ -1,13 +1,13 @@ -using System; +using CreamInstaller.Components; +using CreamInstaller.Utility; + +using System; using System.Collections.Generic; using System.Drawing; using System.IO; using System.Linq; using System.Windows.Forms; -using CreamInstaller.Components; -using CreamInstaller.Utility; - using static CreamInstaller.Components.CustomTreeView; namespace CreamInstaller; @@ -34,7 +34,7 @@ internal partial class SelectDialogForm : CustomForm Checked = alreadySelected }; OnTreeNodeChecked(node); - selectionTreeView.Nodes.Add(node); + _ = selectionTreeView.Nodes.Add(node); } if (!selected.Any()) OnLoad(null, null); allCheckBox.CheckedChanged -= OnAllCheckBoxChanged; @@ -62,7 +62,7 @@ internal partial class SelectDialogForm : CustomForm if (node.Checked) selected.Add((node.Tag as string, id, node.Text)); else - selected.RemoveAll(s => s.id == id); + _ = selected.RemoveAll(s => s.id == id); allCheckBox.CheckedChanged -= OnAllCheckBoxChanged; allCheckBox.Checked = selectionTreeView.Nodes.Cast().All(n => n.Checked); allCheckBox.CheckedChanged += OnAllCheckBoxChanged; diff --git a/CreamInstaller/Forms/SelectForm.cs b/CreamInstaller/Forms/SelectForm.cs index 2aafe0f..a0d856e 100644 --- a/CreamInstaller/Forms/SelectForm.cs +++ b/CreamInstaller/Forms/SelectForm.cs @@ -1,13 +1,4 @@ -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Drawing; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using System.Windows.Forms; +#pragma warning disable IDE0058 using CreamInstaller.Components; using CreamInstaller.Epic; @@ -18,6 +9,17 @@ using CreamInstaller.Utility; using Gameloop.Vdf.Linq; +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using System.Windows.Forms; + namespace CreamInstaller; internal partial class SelectForm : CustomForm @@ -51,7 +53,7 @@ internal partial class SelectForm : CustomForm { if (Program.Canceled) return; if (RemainingGames.Contains(gameName)) - RemainingGames.Remove(gameName); + _ = RemainingGames.Remove(gameName); UpdateRemainingGames(); }); } @@ -76,7 +78,7 @@ internal partial class SelectForm : CustomForm { if (Program.Canceled) return; if (RemainingDLCs.Contains(dlcId)) - RemainingDLCs.Remove(dlcId); + _ = RemainingDLCs.Remove(dlcId); UpdateRemainingDLCs(); }); } @@ -123,7 +125,7 @@ internal partial class SelectForm : CustomForm programNode.Text = selection.Name; programNode.Checked = selection.Enabled; programNode.Remove(); - selectionTreeView.Nodes.Add(programNode); + _ = selectionTreeView.Nodes.Add(programNode); } } if (Directory.Exists(SteamLibrary.InstallPath) && ProgramsToScan.Any(c => c.platform == "Steam")) @@ -245,7 +247,7 @@ internal partial class SelectForm : CustomForm programNode.Text = appData?.name ?? name; programNode.Checked = selection.Enabled; programNode.Remove(); - selectionTreeView.Nodes.Add(programNode); + _ = selectionTreeView.Nodes.Add(programNode); foreach (KeyValuePair pair in dlc) { if (Program.Canceled || programNode is null) return; @@ -259,7 +261,7 @@ internal partial class SelectForm : CustomForm dlcNode.Text = dlcApp.name; dlcNode.Checked = selection.SelectedDlc.ContainsKey(appId); dlcNode.Remove(); - programNode.Nodes.Add(dlcNode); + _ = programNode.Nodes.Add(dlcNode); } }); if (Program.Canceled) return; @@ -352,7 +354,7 @@ internal partial class SelectForm : CustomForm programNode.Text = name; programNode.Checked = selection.Enabled; programNode.Remove(); - selectionTreeView.Nodes.Add(programNode); + _ = selectionTreeView.Nodes.Add(programNode); /*TreeNode catalogItemsNode = treeNodes.Find(s => s.Name == @namespace + "_catalogItems") ?? new(); catalogItemsNode.Name = @namespace + "_catalogItems"; catalogItemsNode.Text = "Catalog Items"; @@ -380,7 +382,7 @@ internal partial class SelectForm : CustomForm dlcNode.Text = dlcApp.name; dlcNode.Checked = selection.SelectedDlc.ContainsKey(dlcId); dlcNode.Remove(); - programNode.Nodes.Add(dlcNode); //entitlementsNode.Nodes.Add(dlcNode); + _ = programNode.Nodes.Add(dlcNode); //entitlementsNode.Nodes.Add(dlcNode); } } }); @@ -585,7 +587,7 @@ internal partial class SelectForm : CustomForm private void OnLoad(object sender, EventArgs _) { - retry: + retry: try { HideProgressBar(); @@ -683,8 +685,8 @@ internal partial class SelectForm : CustomForm for (int i = 0; i < directories.Count; i++) { string directory = directories[i]; - directory.GetScreamApiComponents(out string sdk32, out string sdk32_o, out string sdk64, out string sdk64_o, out string config, out string cache); - if (File.Exists(sdk32) || File.Exists(sdk32_o) || File.Exists(sdk64) || File.Exists(sdk64_o) || File.Exists(config) || File.Exists(cache)) + directory.GetScreamApiComponents(out string sdk32, out string sdk32_o, out string sdk64, out string sdk64_o, out string config); + if (File.Exists(sdk32) || File.Exists(sdk32_o) || File.Exists(sdk64) || File.Exists(sdk64_o) || File.Exists(config)) { contextMenuStrip.Items.Add(new ContextMenuItem($"Open Epic Online Services SDK Directory #{i + 1}", "File Explorer", new EventHandler((sender, e) => Diagnostics.OpenDirectoryInFileExplorer(directory)))); @@ -743,7 +745,7 @@ internal partial class SelectForm : CustomForm if (ParadoxLauncher.DlcDialog(this)) return; Hide(); using InstallForm installForm = new(this, uninstall); - installForm.ShowDialog(); + _ = installForm.ShowDialog(); if (installForm.Reselecting) { InheritLocation(installForm); @@ -795,15 +797,15 @@ internal partial class SelectForm : CustomForm { StringBuilder blockedGames = new(); foreach (string name in Program.ProtectedGames) - blockedGames.Append(helpButtonListPrefix + name); + _ = blockedGames.Append(helpButtonListPrefix + name); StringBuilder blockedDirectories = new(); foreach (string path in Program.ProtectedGameDirectories) - blockedDirectories.Append(helpButtonListPrefix + path); + _ = blockedDirectories.Append(helpButtonListPrefix + path); StringBuilder blockedDirectoryExceptions = new(); foreach (string name in Program.ProtectedGameDirectoryExceptions) - blockedDirectoryExceptions.Append(helpButtonListPrefix + name); + _ = blockedDirectoryExceptions.Append(helpButtonListPrefix + name); using DialogForm form = new(this); - form.Show(SystemIcons.Information, + _ = form.Show(SystemIcons.Information, "Blocks the program from caching and displaying games protected by DLL checks," + "\nanti-cheats, or that are confirmed not to be working with SmokeAPI or ScreamAPI." + "\n\nBlocked games:" + blockedGames + @@ -812,3 +814,5 @@ internal partial class SelectForm : CustomForm "OK", customFormText: "Block Protected Games"); } } + +#pragma warning restore IDE0058 \ No newline at end of file diff --git a/CreamInstaller/Paradox/ParadoxLauncher.cs b/CreamInstaller/Paradox/ParadoxLauncher.cs index 1194c16..09943d2 100644 --- a/CreamInstaller/Paradox/ParadoxLauncher.cs +++ b/CreamInstaller/Paradox/ParadoxLauncher.cs @@ -1,14 +1,14 @@ -using System.Drawing; +using CreamInstaller.Resources; +using CreamInstaller.Utility; + +using Microsoft.Win32; + +using System.Drawing; using System.IO; using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; -using CreamInstaller.Resources; -using CreamInstaller.Utility; - -using Microsoft.Win32; - using static CreamInstaller.Resources.Resources; namespace CreamInstaller.Paradox; @@ -97,7 +97,7 @@ internal static class ParadoxLauncher if (steamOriginalSdk64 is null && File.Exists(sdk64) && !sdk64.IsResourceFile(ResourceIdentifier.Steamworks64)) steamOriginalSdk64 = File.ReadAllBytes(sdk64); - directory.GetScreamApiComponents(out sdk32, out _, out sdk64, out _, out config, out _); + directory.GetScreamApiComponents(out sdk32, out _, out sdk64, out _, out config); screamConfig = screamConfig || File.Exists(config); await InstallForm.UninstallScreamAPI(directory, deleteConfig: false); if (epicOriginalSdk32 is null && File.Exists(sdk32) && !sdk32.IsResourceFile(ResourceIdentifier.EpicOnlineServices32)) @@ -129,7 +129,7 @@ internal static class ParadoxLauncher if (smokeConfig) await InstallForm.InstallSmokeAPI(directory, selection, generateConfig: false); - directory.GetScreamApiComponents(out sdk32, out _, out sdk64, out _, out _, out _); + directory.GetScreamApiComponents(out sdk32, out _, out sdk64, out _, out _); if (epicOriginalSdk32 is not null && sdk32.IsResourceFile(ResourceIdentifier.EpicOnlineServices32)) { epicOriginalSdk32.Write(sdk32); @@ -152,7 +152,7 @@ internal static class ParadoxLauncher if (installForm is not null) installForm.UpdateUser("Paradox Launcher successfully repaired!", InstallationLog.Success); else - dialogForm.Show(form.Icon, "Paradox Launcher successfully repaired!", "OK", customFormText: "Paradox Launcher"); + _ = dialogForm.Show(form.Icon, "Paradox Launcher successfully repaired!", "OK", customFormText: "Paradox Launcher"); return RepairResult.Success; } else @@ -160,18 +160,17 @@ internal static class ParadoxLauncher if (installForm is not null) installForm.UpdateUser("Paradox Launcher did not need to be repaired.", InstallationLog.Success); else - dialogForm.Show(SystemIcons.Information, "Paradox Launcher does not need to be repaired.", "OK", customFormText: "Paradox Launcher"); + _ = dialogForm.Show(SystemIcons.Information, "Paradox Launcher does not need to be repaired.", "OK", customFormText: "Paradox Launcher"); return RepairResult.Unnecessary; } } else { - if (form is InstallForm) - throw new CustomMessageException("Repair failed! " + + _ = form is InstallForm + ? throw new CustomMessageException("Repair failed! " + "An original Steamworks/Epic Online Services SDK file could not be found. " + - "You will likely have to reinstall Paradox Launcher to fix this issue."); - else - dialogForm.Show(SystemIcons.Error, "Paradox Launcher repair failed!" + "You will likely have to reinstall Paradox Launcher to fix this issue.") + : dialogForm.Show(SystemIcons.Error, "Paradox Launcher repair failed!" + "\n\nAn original Steamworks/Epic Online Services SDK file could not be found." + "\nYou will likely have to reinstall Paradox Launcher to fix this issue.", "OK", customFormText: "Paradox Launcher"); return RepairResult.Failure; diff --git a/CreamInstaller/Program.cs b/CreamInstaller/Program.cs index 0d13e6a..1cda271 100644 --- a/CreamInstaller/Program.cs +++ b/CreamInstaller/Program.cs @@ -1,3 +1,6 @@ +using CreamInstaller.Steam; +using CreamInstaller.Utility; + using System; using System.Diagnostics; using System.Drawing; @@ -7,9 +10,6 @@ using System.Reflection; using System.Threading; using System.Windows.Forms; -using CreamInstaller.Steam; -using CreamInstaller.Utility; - namespace CreamInstaller; internal static class Program @@ -62,14 +62,14 @@ internal static class Program using Mutex mutex = new(true, "CreamInstaller", out bool createdNew); if (createdNew) { - Application.SetHighDpiMode(HighDpiMode.SystemAware); + _ = Application.SetHighDpiMode(HighDpiMode.SystemAware); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.ApplicationExit += new(OnApplicationExit); Application.ThreadException += new((s, e) => e.Exception?.HandleFatalException()); Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); AppDomain.CurrentDomain.UnhandledException += new((s, e) => (e.ExceptionObject as Exception)?.HandleFatalException()); - retry: + retry: try { HttpClientManager.Setup(); diff --git a/CreamInstaller/ProgramSelection.cs b/CreamInstaller/ProgramSelection.cs index 93f8c42..bdc14b3 100644 --- a/CreamInstaller/ProgramSelection.cs +++ b/CreamInstaller/ProgramSelection.cs @@ -1,10 +1,10 @@ -using System.Collections.Generic; +using CreamInstaller.Components; +using CreamInstaller.Resources; + +using System.Collections.Generic; using System.IO; using System.Linq; -using CreamInstaller.Components; -using CreamInstaller.Resources; - namespace CreamInstaller; public enum DlcType @@ -56,13 +56,12 @@ internal class ProgramSelection || config.IsFilePathLocked() || cache.IsFilePathLocked()) return true; - directory.GetScreamApiComponents(out sdk32, out sdk32_o, out sdk64, out sdk64_o, out config, out cache); + directory.GetScreamApiComponents(out sdk32, out sdk32_o, out sdk64, out sdk64_o, out config); if (sdk32.IsFilePathLocked() || sdk32_o.IsFilePathLocked() || sdk64.IsFilePathLocked() || sdk64_o.IsFilePathLocked() - || config.IsFilePathLocked() - || cache.IsFilePathLocked()) + || config.IsFilePathLocked()) return true; } return false; @@ -72,7 +71,7 @@ internal class ProgramSelection private void Toggle(string dlcAppId, (DlcType type, string name, string icon) dlcApp, bool enabled) { if (enabled) SelectedDlc[dlcAppId] = dlcApp; - else SelectedDlc.Remove(dlcAppId); + else _ = SelectedDlc.Remove(dlcAppId); } internal void ToggleDlc(string dlcId, bool enabled) @@ -96,23 +95,23 @@ internal class ProgramSelection { if (Program.IsGameBlocked(Name, RootDirectory)) { - All.Remove(this); + _ = All.Remove(this); return; } if (!Directory.Exists(RootDirectory)) { - All.Remove(this); + _ = All.Remove(this); return; } - DllDirectories.RemoveAll(directory => !Directory.Exists(directory)); - if (!DllDirectories.Any()) All.Remove(this); + _ = DllDirectories.RemoveAll(directory => !Directory.Exists(directory)); + if (!DllDirectories.Any()) _ = All.Remove(this); } internal void Validate(List<(string platform, string id, string name)> programsToScan) { if (programsToScan is null || !programsToScan.Any(p => p.id == Id)) { - All.Remove(this); + _ = All.Remove(this); return; } Validate(); diff --git a/CreamInstaller/Resources/Resources.cs b/CreamInstaller/Resources/Resources.cs index 611cce5..5f1592b 100644 --- a/CreamInstaller/Resources/Resources.cs +++ b/CreamInstaller/Resources/Resources.cs @@ -31,7 +31,11 @@ internal static class Resources return false; } - internal static void GetCreamApiComponents(this string directory, out string sdk32, out string sdk32_o, out string sdk64, out string sdk64_o, out string config) + internal static void GetCreamApiComponents( + this string directory, + out string sdk32, out string sdk32_o, + out string sdk64, out string sdk64_o, + out string config) { sdk32 = directory + @"\steam_api.dll"; sdk32_o = directory + @"\steam_api_o.dll"; @@ -40,7 +44,12 @@ internal static class Resources config = directory + @"\cream_api.ini"; } - internal static void GetSmokeApiComponents(this string directory, out string sdk32, out string sdk32_o, out string sdk64, out string sdk64_o, out string config, out string cache) + internal static void GetSmokeApiComponents( + this string directory, + out string sdk32, out string sdk32_o, + out string sdk64, out string sdk64_o, + out string config, + out string cache) { sdk32 = directory + @"\steam_api.dll"; sdk32_o = directory + @"\steam_api_o.dll"; @@ -50,14 +59,48 @@ internal static class Resources cache = directory + @"\SmokeAPI.cache.json"; } - internal static void GetScreamApiComponents(this string directory, out string sdk32, out string sdk32_o, out string sdk64, out string sdk64_o, out string config, out string cache) + internal static void GetScreamApiComponents( + this string directory, + out string sdk32, out string sdk32_o, + out string sdk64, out string sdk64_o, + out string config + ) { sdk32 = directory + @"\EOSSDK-Win32-Shipping.dll"; sdk32_o = directory + @"\EOSSDK-Win32-Shipping_o.dll"; sdk64 = directory + @"\EOSSDK-Win64-Shipping.dll"; sdk64_o = directory + @"\EOSSDK-Win64-Shipping_o.dll"; config = directory + @"\ScreamAPI.json"; - cache = directory + @"\ScreamAPI.cache.json"; + } + + internal static void GetUplayR1Components( + this string directory, + out string sdk32, out string sdk32_o, + out string sdk64, out string sdk64_o, + out string config + ) + { + sdk32 = directory + @"\uplay_r1_loader.dll"; + sdk32_o = directory + @"\uplay_r1_loader_o.dll"; + sdk64 = directory + @"\uplay_r1_loader64.dll"; + sdk64_o = directory + @"\uplay_r1_loader64_o.dll"; + config = directory + @"\UplayR1Unlocker.jsonc"; + } + + internal static void GetUplayR2Components( + this string directory, + out string old_sdk32, out string old_sdk64, + out string sdk32, out string sdk32_o, + out string sdk64, out string sdk64_o, + out string config) + { + old_sdk32 = directory + @"\uplay_r2_loader.dll"; + old_sdk64 = directory + @"\uplay_r2_loader64.dll"; + sdk32 = directory + @"\upc_r2_loader.dll"; + sdk32_o = directory + @"\upc_r2_loader_o.dll"; + sdk64 = directory + @"\upc_r2_loader64.dll"; + sdk64_o = directory + @"\upc_r2_loader64_o.dll"; + config = directory + @"\UplayR2Unlocker.jsonc"; } public enum ResourceIdentifier diff --git a/CreamInstaller/Steam/SteamCMD.cs b/CreamInstaller/Steam/SteamCMD.cs index a582e94..9daafe7 100644 --- a/CreamInstaller/Steam/SteamCMD.cs +++ b/CreamInstaller/Steam/SteamCMD.cs @@ -1,4 +1,9 @@ -using System; +using CreamInstaller.Resources; +using CreamInstaller.Utility; + +using Gameloop.Vdf.Linq; + +using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; @@ -10,11 +15,6 @@ using System.Text; using System.Threading; using System.Threading.Tasks; -using CreamInstaller.Resources; -using CreamInstaller.Utility; - -using Gameloop.Vdf.Linq; - namespace CreamInstaller.Steam; internal static class SteamCMD @@ -34,7 +34,7 @@ internal static class SteamCMD private static readonly int[] locks = new int[ProcessLimit]; internal static async Task Run(string appId) => await Task.Run(() => { - wait_for_lock: + wait_for_lock: if (Program.Canceled) return ""; Thread.Sleep(0); for (int i = 0; i < locks.Length; i++) @@ -84,8 +84,7 @@ internal static class SteamCMD lastOutput = DateTime.UtcNow; char ch = (char)c; if (ch == '{') appInfoStarted = true; - if (appInfoStarted) appInfo.Append(ch); - else output.Append(ch); + _ = appInfoStarted ? appInfo.Append(ch) : output.Append(ch); } DateTime now = DateTime.UtcNow; TimeSpan timeDiff = now - lastOutput; @@ -99,13 +98,13 @@ internal static class SteamCMD processStartInfo.Arguments = GetArguments(appId); process = Process.Start(processStartInfo); appInfoStarted = false; - output.Clear(); - appInfo.Clear(); + _ = output.Clear(); + _ = appInfo.Clear(); } else break; } } - Interlocked.Decrement(ref locks[i]); + _ = Interlocked.Decrement(ref locks[i]); return appInfo.ToString(); } Thread.Sleep(200); @@ -142,7 +141,7 @@ internal static class SteamCMD int cur = 0; progress.Report(cur); watcher.Changed += (sender, e) => progress.Report(++cur); - await Run(null); + _ = await Run(null); watcher.Dispose(); } } @@ -187,7 +186,7 @@ internal static class SteamCMD if (Program.Canceled) return null; string output; string appUpdateFile = $@"{AppInfoPath}\{appId}.vdf"; - restart: + restart: if (Program.Canceled) return null; if (File.Exists(appUpdateFile)) output = File.ReadAllText(appUpdateFile, Encoding.UTF8); else diff --git a/CreamInstaller/Steam/SteamLibrary.cs b/CreamInstaller/Steam/SteamLibrary.cs index ba1f1a2..402c9cc 100644 --- a/CreamInstaller/Steam/SteamLibrary.cs +++ b/CreamInstaller/Steam/SteamLibrary.cs @@ -1,16 +1,16 @@ -using System.Collections.Generic; +using CreamInstaller.Resources; + +using Gameloop.Vdf.Linq; + +using Microsoft.Win32; + +using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; -using CreamInstaller.Resources; - -using Gameloop.Vdf.Linq; - -using Microsoft.Win32; - namespace CreamInstaller.Steam; internal static class SteamLibrary diff --git a/CreamInstaller/Steam/SteamStore.cs b/CreamInstaller/Steam/SteamStore.cs index 105ed2e..ca9c40b 100644 --- a/CreamInstaller/Steam/SteamStore.cs +++ b/CreamInstaller/Steam/SteamStore.cs @@ -1,12 +1,17 @@ -using System.Collections.Generic; +using CreamInstaller.Utility; + +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; + +using System.Collections.Generic; using System.IO; using System.Threading; using System.Threading.Tasks; -using CreamInstaller.Utility; - -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; +#if DEBUG +using System; +using System.Drawing; +#endif namespace CreamInstaller.Steam; @@ -34,7 +39,7 @@ internal static class SteamStore string response = await HttpClientManager.EnsureGet($"https://store.steampowered.com/api/appdetails?appids={appId}"); if (response is not null) { - IDictionary apps = JsonConvert.DeserializeObject(response) as dynamic; + IDictionary apps = (IDictionary)JsonConvert.DeserializeObject(response); if (apps is not null) foreach (KeyValuePair app in apps) { @@ -47,19 +52,29 @@ internal static class SteamStore { File.WriteAllText(cacheFile, JsonConvert.SerializeObject(data, Formatting.Indented)); } - catch //(Exception e) + catch +#if DEBUG + (Exception e) { - //using DialogForm dialogForm = new(null); - //dialogForm.Show(SystemIcons.Error, "Unsuccessful serialization of query for appid " + appId + ":\n\n" + e.ToString(), "FUCK"); + using DialogForm dialogForm = new(null); + dialogForm.Show(SystemIcons.Error, "Unsuccessful serialization of query for appid " + appId + ":\n\n" + e.ToString()); } +#else + { } +#endif return data; } } - catch //(Exception e) + catch +#if DEBUG + (Exception e) { - //using DialogForm dialogForm = new(null); - //dialogForm.Show(SystemIcons.Error, "Unsuccessful deserialization of query for appid " + appId + ":\n\n" + e.ToString(), "FUCK"); + using DialogForm dialogForm = new(null); + dialogForm.Show(SystemIcons.Error, "Unsuccessful deserialization of query for appid " + appId + ":\n\n" + e.ToString()); } +#else + { } +#endif } } } diff --git a/CreamInstaller/Utility/Diagnostics.cs b/CreamInstaller/Utility/Diagnostics.cs index fc8c9b4..b5caf8b 100644 --- a/CreamInstaller/Utility/Diagnostics.cs +++ b/CreamInstaller/Utility/Diagnostics.cs @@ -1,9 +1,9 @@ -using System; +using Microsoft.Win32; + +using System; using System.Diagnostics; using System.IO; -using Microsoft.Win32; - namespace CreamInstaller.Utility; internal static class Diagnostics diff --git a/CreamInstaller/Utility/ExceptionHandler.cs b/CreamInstaller/Utility/ExceptionHandler.cs index 02ba797..a1ccd28 100644 --- a/CreamInstaller/Utility/ExceptionHandler.cs +++ b/CreamInstaller/Utility/ExceptionHandler.cs @@ -15,7 +15,7 @@ internal static class ExceptionHandler string[] stackTrace = e.StackTrace?.Split('\n'); if (stackTrace is not null && stackTrace.Length > 0) { - output.Append("STACK TRACE\n"); + _ = output.Append("STACK TRACE\n"); for (int i = 0; i < Math.Min(stackTrace.Length, 3); i++) { string line = stackTrace[i]; @@ -24,7 +24,7 @@ internal static class ExceptionHandler int ciNum = line.LastIndexOf(@"CreamInstaller\"); int lineNum = line.LastIndexOf(":line "); if (line is not null && atNum != -1) - output.Append("\n " + (inNum != -1 ? line[atNum..(inNum - 1)] : line[atNum..]) + _ = output.Append("\n " + (inNum != -1 ? line[atNum..(inNum - 1)] : line[atNum..]) + (inNum != -1 ? ("\n " + (ciNum != -1 ? ("in " + (lineNum != -1 ? line[ciNum..lineNum] @@ -38,13 +38,13 @@ internal static class ExceptionHandler if (messageLines is not null && messageLines.Length > 0) { if (output.Length > 0) - output.Append("\n\n"); - output.Append("MESSAGE\n"); + _ = output.Append("\n\n"); + _ = output.Append("MESSAGE\n"); for (int i = 0; i < messageLines.Length; i++) { string line = messageLines[i]; if (line is not null) - output.Append("\n " + line); + _ = output.Append("\n " + line); } } using DialogForm dialogForm = new(form ?? Form.ActiveForm); diff --git a/CreamInstaller/Utility/HttpClientManager.cs b/CreamInstaller/Utility/HttpClientManager.cs index 3ec3b36..87fe149 100644 --- a/CreamInstaller/Utility/HttpClientManager.cs +++ b/CreamInstaller/Utility/HttpClientManager.cs @@ -1,11 +1,11 @@ -using System; +using HtmlAgilityPack; + +using System; using System.Drawing; using System.Net.Http; using System.Threading.Tasks; using System.Windows.Forms; -using HtmlAgilityPack; - namespace CreamInstaller.Utility; internal static class HttpClientManager @@ -23,7 +23,7 @@ internal static class HttpClientManager { using HttpRequestMessage request = new(HttpMethod.Get, url); using HttpResponseMessage response = await HttpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead); - response.EnsureSuccessStatusCode(); + _ = response.EnsureSuccessStatusCode(); return await response.Content.ReadAsStringAsync(); } catch diff --git a/CreamInstaller/Utility/ProgramData.cs b/CreamInstaller/Utility/ProgramData.cs index 95e769b..b4a1fe7 100644 --- a/CreamInstaller/Utility/ProgramData.cs +++ b/CreamInstaller/Utility/ProgramData.cs @@ -29,15 +29,15 @@ internal static class ProgramData if (Directory.Exists(DirectoryPath)) Directory.Delete(DirectoryPath, true); Directory.Move(DirectoryPathOld, DirectoryPath); } - if (!Directory.Exists(DirectoryPath)) Directory.CreateDirectory(DirectoryPath); + if (!Directory.Exists(DirectoryPath)) _ = Directory.CreateDirectory(DirectoryPath); if (!File.Exists(AppInfoVersionPath) || !Version.TryParse(File.ReadAllText(AppInfoVersionPath, Encoding.UTF8), out Version version) || version < MinimumAppInfoVersion) { if (Directory.Exists(AppInfoPath)) Directory.Delete(AppInfoPath, true); - Directory.CreateDirectory(AppInfoPath); + _ = Directory.CreateDirectory(AppInfoPath); File.WriteAllText(AppInfoVersionPath, Application.ProductVersion, Encoding.UTF8); } if (!Directory.Exists(CooldownPath)) - Directory.CreateDirectory(CooldownPath); + _ = Directory.CreateDirectory(CooldownPath); }); internal static bool CheckCooldown(string identifier, int cooldown) @@ -69,7 +69,7 @@ internal static class ProgramData private static void SetCooldown(string identifier, DateTime time) { if (!Directory.Exists(CooldownPath)) - Directory.CreateDirectory(CooldownPath); + _ = Directory.CreateDirectory(CooldownPath); string cooldownFile = CooldownPath + @$"\{identifier}.txt"; try {