- Massive refactoring and asynchronous fixes
- Disabled file operations from displaying in the install info label, and they now only display in the log
- Disabled selection validation, as previous issues warranting it have since been fixed
This commit is contained in:
pointfeev 2022-01-22 01:47:09 -05:00
parent 70f009abb5
commit 5024cd2194
12 changed files with 414 additions and 580 deletions

219
.editorconfig Normal file
View file

@ -0,0 +1,219 @@
# Remove the line below if you want to inherit .editorconfig settings from higher directories
root = true
# C# files
[*.cs]
#### Core EditorConfig Options ####
# Indentation and spacing
indent_size = 4
indent_style = space
tab_width = 4
# New line preferences
end_of_line = crlf
insert_final_newline = false
#### .NET Coding Conventions ####
# Organize usings
dotnet_separate_import_directive_groups = true
dotnet_sort_system_directives_first = true
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_method = false:suggestion
dotnet_style_qualification_for_property = false:suggestion
# Language keywords vs BCL types preferences
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
dotnet_style_predefined_type_for_member_access = true:suggestion
# Parentheses preferences
dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary:suggestion
dotnet_style_parentheses_in_other_binary_operators = never_if_unnecessary:suggestion
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:suggestion
dotnet_style_parentheses_in_relational_binary_operators = never_if_unnecessary:suggestion
# Modifier preferences
dotnet_style_require_accessibility_modifiers = for_non_interface_members
# Expression-level preferences
dotnet_style_coalesce_expression = true
dotnet_style_collection_initializer = true
dotnet_style_explicit_tuple_names = true
dotnet_style_namespace_match_folder = true
dotnet_style_null_propagation = true
dotnet_style_object_initializer = true
dotnet_style_operator_placement_when_wrapping = beginning_of_line
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_inferred_anonymous_type_member_names = true
dotnet_style_prefer_inferred_tuple_names = true
dotnet_style_prefer_is_null_check_over_reference_equality_method = true
dotnet_style_prefer_simplified_boolean_expressions = true
dotnet_style_prefer_simplified_interpolation = true
# Field preferences
dotnet_style_readonly_field = true
# Parameter preferences
dotnet_code_quality_unused_parameters = all
# Suppression preferences
dotnet_remove_unnecessary_suppression_exclusions = none
# New line preferences
dotnet_style_allow_multiple_blank_lines_experimental = false:suggestion
dotnet_style_allow_statement_immediately_after_block_experimental = true:suggestion
#### C# Coding Conventions ####
# var preferences
csharp_style_var_elsewhere = false:suggestion
csharp_style_var_for_built_in_types = false:suggestion
csharp_style_var_when_type_is_apparent = false:suggestion
# Expression-bodied members
csharp_style_expression_bodied_accessors = true:suggestion
csharp_style_expression_bodied_constructors = true:suggestion
csharp_style_expression_bodied_indexers = true:suggestion
csharp_style_expression_bodied_lambdas = true:suggestion
csharp_style_expression_bodied_local_functions = true:suggestion
csharp_style_expression_bodied_methods = true:suggestion
csharp_style_expression_bodied_operators = true:suggestion
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_not_pattern = true
csharp_style_prefer_pattern_matching = true:suggestion
csharp_style_prefer_switch_expression = true
# Null-checking preferences
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
# Code-block preferences
csharp_prefer_braces = false:suggestion
csharp_prefer_simple_using_statement = true
csharp_style_namespace_declarations = file_scoped: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_null_check_over_type_check = true
csharp_style_prefer_range_operator = true
csharp_style_throw_expression = true
csharp_style_unused_value_assignment_preference = discard_variable
csharp_style_unused_value_expression_statement_preference = unused_local_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_lines_between_consecutive_braces_experimental = false:suggestion
csharp_style_allow_embedded_statements_on_same_line_experimental = true:suggestion
#### C# Formatting Rules ####
# New line preferences
csharp_new_line_before_catch = true
csharp_new_line_before_else = true
csharp_new_line_before_finally = true
csharp_new_line_before_members_in_anonymous_types = true
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_open_brace = all
csharp_new_line_between_query_expression_clauses = true
# Indentation preferences
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_switch_labels = true
# Space preferences
csharp_space_after_cast = false
csharp_space_after_colon_in_inheritance_clause = true
csharp_space_after_comma = true
csharp_space_after_dot = false
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_after_semicolon_in_for_statement = true
csharp_space_around_binary_operators = before_and_after
csharp_space_around_declaration_statements = false
csharp_space_before_colon_in_inheritance_clause = true
csharp_space_before_comma = false
csharp_space_before_dot = false
csharp_space_before_open_square_brackets = false
csharp_space_before_semicolon_in_for_statement = false
csharp_space_between_empty_square_brackets = false
csharp_space_between_method_call_empty_parameter_list_parentheses = false
csharp_space_between_method_call_name_and_opening_parenthesis = false
csharp_space_between_method_call_parameter_list_parentheses = false
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
csharp_space_between_method_declaration_name_and_open_parenthesis = false
csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_parentheses = false
csharp_space_between_square_brackets = false
# Wrapping preferences
csharp_preserve_single_line_blocks = true
csharp_preserve_single_line_statements = true
#### Naming styles ####
# Naming rules
dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i
dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case
dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
# Symbol specifications
dotnet_naming_symbols.interface.applicable_kinds = interface
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.interface.required_modifiers =
dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.types.required_modifiers =
dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.non_field_members.required_modifiers =
# Naming styles
dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case
dotnet_naming_style.begins_with_i.required_prefix = I
dotnet_naming_style.begins_with_i.required_suffix =
dotnet_naming_style.begins_with_i.word_separator =
dotnet_naming_style.begins_with_i.capitalization = pascal_case

View file

@ -53,14 +53,8 @@ namespace CreamInstaller
private readonly string message; private readonly string message;
public override string Message => message ?? "CustomMessageException"; public override string Message => message ?? "CustomMessageException";
public override string ToString() public override string ToString() => Message;
{
return Message;
}
internal CustomMessageException(string message) internal CustomMessageException(string message) => this.message = message;
{
this.message = message;
}
} }
} }

View file

@ -1,9 +1,10 @@
using Gameloop.Vdf.Linq; using System;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using Gameloop.Vdf.Linq;
namespace CreamInstaller namespace CreamInstaller
{ {
internal class ProgramSelection internal class ProgramSelection
@ -81,10 +82,7 @@ namespace CreamInstaller
Enabled = SelectedSteamDlc.Any(); Enabled = SelectedSteamDlc.Any();
} }
internal ProgramSelection() internal ProgramSelection() => All.Add(this);
{
All.Add(this);
}
internal void Validate() internal void Validate()
{ {
@ -95,10 +93,7 @@ namespace CreamInstaller
} }
} }
internal static void ValidateAll() internal static void ValidateAll() => All.ForEach(selection => selection.Validate());
{
All.ForEach(selection => selection.Validate());
}
internal static List<ProgramSelection> All => Program.ProgramSelections; internal static List<ProgramSelection> All => Program.ProgramSelections;
@ -106,10 +101,7 @@ namespace CreamInstaller
internal static List<ProgramSelection> AllSafeEnabled => AllSafe.FindAll(s => s.Enabled); internal static List<ProgramSelection> AllSafeEnabled => AllSafe.FindAll(s => s.Enabled);
internal static ProgramSelection FromAppId(int appId) internal static ProgramSelection FromAppId(int appId) => AllSafe.Find(s => s.SteamAppId == appId);
{
return AllSafe.Find(s => s.SteamAppId == appId);
}
internal static KeyValuePair<int, string>? GetDlcFromAppId(int appId) internal static KeyValuePair<int, string>? GetDlcFromAppId(int appId)
{ {

View file

@ -1,6 +1,4 @@
using Gameloop.Vdf; using System;
using Gameloop.Vdf.Linq;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
@ -11,6 +9,9 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using Gameloop.Vdf;
using Gameloop.Vdf.Linq;
namespace CreamInstaller namespace CreamInstaller
{ {
internal static class SteamCMD internal static class SteamCMD
@ -26,12 +27,9 @@ namespace CreamInstaller
internal static readonly Version MinimumAppInfoVersion = Version.Parse("2.0.3.2"); internal static readonly Version MinimumAppInfoVersion = Version.Parse("2.0.3.2");
internal static readonly string AppInfoVersionPath = AppInfoPath + @"\version.txt"; internal static readonly string AppInfoVersionPath = AppInfoPath + @"\version.txt";
internal static string Run(string command) internal static async Task<string> Run(string command) => await Task.Run(() =>
{ {
if (Program.Canceled) if (Program.Canceled) return "";
{
return "";
}
List<string> logs = new(); List<string> logs = new();
ProcessStartInfo processStartInfo = new() ProcessStartInfo processStartInfo = new()
{ {
@ -55,7 +53,7 @@ namespace CreamInstaller
process.WaitForExit(); process.WaitForExit();
} }
return string.Join("\r\n", logs); return string.Join("\r\n", logs);
} });
internal static async Task Setup() internal static async Task Setup()
{ {
@ -67,56 +65,34 @@ namespace CreamInstaller
byte[] file = await httpClient.GetByteArrayAsync("https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip"); byte[] file = await httpClient.GetByteArrayAsync("https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip");
file.Write(ArchivePath); file.Write(ArchivePath);
} }
ZipFile.ExtractToDirectory(ArchivePath, DirectoryPath); ZipFile.ExtractToDirectory(ArchivePath, DirectoryPath);
File.Delete(ArchivePath); File.Delete(ArchivePath);
} }
if (File.Exists(AppCacheAppInfoPath)) if (File.Exists(AppCacheAppInfoPath)) File.Delete(AppCacheAppInfoPath);
{
File.Delete(AppCacheAppInfoPath);
}
if (!File.Exists(AppInfoVersionPath) || !Version.TryParse(File.ReadAllText(AppInfoVersionPath, Encoding.UTF8), out Version version) || version < MinimumAppInfoVersion) if (!File.Exists(AppInfoVersionPath) || !Version.TryParse(File.ReadAllText(AppInfoVersionPath, Encoding.UTF8), out Version version) || version < MinimumAppInfoVersion)
{ {
if (Directory.Exists(AppInfoPath)) if (Directory.Exists(AppInfoPath)) Directory.Delete(AppInfoPath, true);
{
Directory.Delete(AppInfoPath, true);
}
Directory.CreateDirectory(AppInfoPath); Directory.CreateDirectory(AppInfoPath);
File.WriteAllText(AppInfoVersionPath, Application.ProductVersion, Encoding.UTF8); File.WriteAllText(AppInfoVersionPath, Application.ProductVersion, Encoding.UTF8);
} }
if (!File.Exists(DllPath)) if (!File.Exists(DllPath)) await Run($@"+quit");
{
Run($@"+quit");
}
} }
internal static bool GetAppInfo(int appId, out VProperty appInfo, string branch = "public", int buildId = 0) internal static async Task<VProperty> GetAppInfo(int appId, string branch = "public", int buildId = 0)
{ {
appInfo = null; VProperty appInfo = null;
if (Program.Canceled) if (Program.Canceled) return null;
{
return false;
}
string output; string output;
string appUpdatePath = $@"{AppInfoPath}\{appId}"; string appUpdatePath = $@"{AppInfoPath}\{appId}";
string appUpdateFile = $@"{appUpdatePath}\appinfo.txt"; string appUpdateFile = $@"{appUpdatePath}\appinfo.txt";
restart: restart:
if (Program.Canceled) if (Program.Canceled) return null;
{
return false;
}
if (Directory.Exists(appUpdatePath) && File.Exists(appUpdateFile)) if (Directory.Exists(appUpdatePath) && File.Exists(appUpdateFile))
{
output = File.ReadAllText(appUpdateFile, Encoding.UTF8); output = File.ReadAllText(appUpdateFile, Encoding.UTF8);
}
else else
{ {
Run($@"+@ShutdownOnFailedCommand 0 +login anonymous +app_info_print {appId} +force_install_dir {appUpdatePath} +app_update 4 +quit"); await Run($@"+@ShutdownOnFailedCommand 0 +login anonymous +app_info_print {appId} +force_install_dir {appUpdatePath} +app_update 4 +quit");
output = Run($@"+@ShutdownOnFailedCommand 0 +login anonymous +app_info_print {appId} +quit"); output = await Run($@"+@ShutdownOnFailedCommand 0 +login anonymous +app_info_print {appId} +quit");
int openBracket = output.IndexOf("{"); int openBracket = output.IndexOf("{");
int closeBracket = output.LastIndexOf("}"); int closeBracket = output.LastIndexOf("}");
if (openBracket != -1 && closeBracket != -1) if (openBracket != -1 && closeBracket != -1)
@ -125,11 +101,7 @@ namespace CreamInstaller
File.WriteAllText(appUpdateFile, output, Encoding.UTF8); File.WriteAllText(appUpdateFile, output, Encoding.UTF8);
} }
} }
if (Program.Canceled || output is null) if (Program.Canceled || output is null) return null;
{
return false;
}
try { appInfo = VdfConvert.Deserialize(output); } try { appInfo = VdfConvert.Deserialize(output); }
catch catch
{ {
@ -139,85 +111,46 @@ namespace CreamInstaller
goto restart; goto restart;
} }
} }
if (appInfo.Value is VValue) if (appInfo.Value is VValue) goto restart;
{
goto restart;
}
if (appInfo is null || (appInfo.Value is not VValue && appInfo.Value.Children().ToList().Count == 0)) if (appInfo is null || (appInfo.Value is not VValue && appInfo.Value.Children().ToList().Count == 0))
{ return appInfo;
return true;
}
VToken type = appInfo.Value is VValue ? null : appInfo.Value?["common"]?["type"]; VToken type = appInfo.Value is VValue ? null : appInfo.Value?["common"]?["type"];
if (type is null || type.ToString() == "Game") if (type is null || type.ToString() == "Game")
{ {
string buildid = appInfo.Value is VValue ? null : appInfo.Value["depots"]?["branches"]?[branch]?["buildid"]?.ToString(); string buildid = appInfo.Value is VValue ? null : appInfo.Value["depots"]?["branches"]?[branch]?["buildid"]?.ToString();
if (buildid is null && type is not null) if (buildid is null && type is not null) return appInfo;
{
return true;
}
if (type is null || int.Parse(buildid) < buildId) if (type is null || int.Parse(buildid) < buildId)
{ {
foreach (int id in ParseDlcAppIds(appInfo)) List<int> dlcAppIds = await ParseDlcAppIds(appInfo);
foreach (int id in dlcAppIds)
{ {
string dlcAppUpdatePath = $@"{AppInfoPath}\{id}"; string dlcAppUpdatePath = $@"{AppInfoPath}\{id}";
if (Directory.Exists(dlcAppUpdatePath)) if (Directory.Exists(dlcAppUpdatePath)) Directory.Delete(dlcAppUpdatePath, true);
{
Directory.Delete(dlcAppUpdatePath, true);
}
}
if (Directory.Exists(appUpdatePath))
{
Directory.Delete(appUpdatePath, true);
} }
if (Directory.Exists(appUpdatePath)) Directory.Delete(appUpdatePath, true);
goto restart; goto restart;
} }
} }
return true; return appInfo;
} }
internal static List<int> ParseDlcAppIds(VProperty appInfo) internal static async Task<List<int>> ParseDlcAppIds(VProperty appInfo) => await Task.Run(() =>
{ {
List<int> dlcIds = new(); List<int> dlcIds = new();
if (appInfo is not VProperty) if (appInfo is not VProperty) return dlcIds;
{
return dlcIds;
}
if (appInfo.Value["extended"] is not null) if (appInfo.Value["extended"] is not null)
{
foreach (VProperty property in appInfo.Value["extended"]) foreach (VProperty property in appInfo.Value["extended"])
{
if (property.Key.ToString() == "listofdlc") if (property.Key.ToString() == "listofdlc")
{
foreach (string id in property.Value.ToString().Split(",")) foreach (string id in property.Value.ToString().Split(","))
{
if (!dlcIds.Contains(int.Parse(id))) if (!dlcIds.Contains(int.Parse(id)))
{
dlcIds.Add(int.Parse(id)); dlcIds.Add(int.Parse(id));
}
}
}
}
}
if (appInfo.Value["depots"] is not null) if (appInfo.Value["depots"] is not null)
{
foreach (VProperty _property in appInfo.Value["depots"]) foreach (VProperty _property in appInfo.Value["depots"])
{
if (int.TryParse(_property.Key.ToString(), out int _)) if (int.TryParse(_property.Key.ToString(), out int _))
{
if (int.TryParse(_property.Value?["dlcappid"]?.ToString(), out int appid) && !dlcIds.Contains(appid)) if (int.TryParse(_property.Value?["dlcappid"]?.ToString(), out int appid) && !dlcIds.Contains(appid))
{
dlcIds.Add(appid); dlcIds.Add(appid);
}
}
}
}
return dlcIds; return dlcIds;
} });
internal static async Task Kill() internal static async Task Kill()
{ {
@ -227,10 +160,7 @@ namespace CreamInstaller
process.Kill(); process.Kill();
tasks.Add(Task.Run(() => process.WaitForExit())); tasks.Add(Task.Run(() => process.WaitForExit()));
} }
foreach (Task task in tasks) foreach (Task task in tasks) await task;
{
await task;
}
} }
internal static void Dispose() internal static void Dispose()

View file

@ -5,7 +5,7 @@
<UseWindowsForms>true</UseWindowsForms> <UseWindowsForms>true</UseWindowsForms>
<ApplicationIcon>Resources\ini.ico</ApplicationIcon> <ApplicationIcon>Resources\ini.ico</ApplicationIcon>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract> <IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
<Version>2.2.1.1</Version> <Version>2.2.2.0</Version>
<PackageIcon>Resources\ini.ico</PackageIcon> <PackageIcon>Resources\ini.ico</PackageIcon>
<PackageIconUrl /> <PackageIconUrl />
<Description>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.</Description> <Description>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.</Description>

View file

@ -4,15 +4,9 @@ namespace CreamInstaller
{ {
internal class CustomForm : Form internal class CustomForm : Form
{ {
internal CustomForm() : base() internal CustomForm() : base() => Icon = Properties.Resources.Icon;
{
Icon = Properties.Resources.Icon;
}
internal CustomForm(IWin32Window owner) : this() internal CustomForm(IWin32Window owner) : this() => Owner = owner as Form;
{
Owner = owner as Form;
}
protected override CreateParams CreateParams // Double buffering for all controls protected override CreateParams CreateParams // Double buffering for all controls
{ {

View file

@ -5,10 +5,7 @@ namespace CreamInstaller
{ {
internal partial class DialogForm : CustomForm internal partial class DialogForm : CustomForm
{ {
internal DialogForm(IWin32Window owner) : base(owner) internal DialogForm(IWin32Window owner) : base(owner) => InitializeComponent();
{
InitializeComponent();
}
internal DialogResult Show(string formName, Icon descriptionIcon, string descriptionText, string acceptButtonText, string cancelButtonText = null) internal DialogResult Show(string formName, Icon descriptionIcon, string descriptionText, string acceptButtonText, string cancelButtonText = null)
{ {
@ -21,10 +18,7 @@ namespace CreamInstaller
cancelButton.Enabled = false; cancelButton.Enabled = false;
cancelButton.Visible = false; cancelButton.Visible = false;
} }
else else cancelButton.Text = cancelButtonText;
{
cancelButton.Text = cancelButtonText;
}
return ShowDialog(); return ShowDialog();
} }
} }

View file

@ -51,6 +51,7 @@ namespace CreamInstaller
// //
this.userInfoLabel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) this.userInfoLabel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right))); | System.Windows.Forms.AnchorStyles.Right)));
this.userInfoLabel.AutoEllipsis = true;
this.userInfoLabel.FlatStyle = System.Windows.Forms.FlatStyle.System; this.userInfoLabel.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.userInfoLabel.Location = new System.Drawing.Point(12, 9); this.userInfoLabel.Location = new System.Drawing.Point(12, 9);
this.userInfoLabel.Name = "userInfoLabel"; this.userInfoLabel.Name = "userInfoLabel";

View file

@ -30,23 +30,17 @@ namespace CreamInstaller
internal void UpdateProgress(int progress) internal void UpdateProgress(int progress)
{ {
int value = (int)((float)(CompleteOperationsCount / (float)OperationsCount) * 100) + (progress / OperationsCount); int value = (int)((float)(CompleteOperationsCount / (float)OperationsCount) * 100) + (progress / OperationsCount);
if (value < userProgressBar.Value) if (value < userProgressBar.Value) return;
{
return;
}
userProgressBar.Value = value; userProgressBar.Value = value;
} }
internal async Task UpdateUser(string text, Color color, bool log = true) internal async Task UpdateUser(string text, Color color, bool info = true, bool log = true)
{ {
userInfoLabel.Text = text; if (info) userInfoLabel.Text = text;
if (log && !logTextBox.IsDisposed) if (log && !logTextBox.IsDisposed)
{ {
if (logTextBox.Text.Length > 0) if (logTextBox.Text.Length > 0) logTextBox.AppendText(Environment.NewLine, color);
{ logTextBox.AppendText(text, color);
logTextBox.AppendText(Environment.NewLine, color);
}
logTextBox.AppendText(userInfoLabel.Text, color);
} }
await Task.Run(() => Thread.Sleep(1)); // to keep the text box control from glitching await Task.Run(() => Thread.Sleep(1)); // to keep the text box control from glitching
} }
@ -59,11 +53,11 @@ namespace CreamInstaller
writer.WriteLine($"appid = {steamAppId}"); writer.WriteLine($"appid = {steamAppId}");
writer.WriteLine(); writer.WriteLine();
writer.WriteLine("[dlc]"); writer.WriteLine("[dlc]");
await UpdateUser($"Added game to cream_api.ini with appid {steamAppId} ({name})", InstallationLog.Resource); await UpdateUser($"Added game to cream_api.ini with appid {steamAppId} ({name})", InstallationLog.Resource, info: false);
foreach (KeyValuePair<int, string> dlcApp in steamDlcApps) foreach (KeyValuePair<int, string> dlcApp in steamDlcApps)
{ {
writer.WriteLine($"{dlcApp.Key} = {dlcApp.Value}"); writer.WriteLine($"{dlcApp.Key} = {dlcApp.Value}");
await UpdateUser($"Added DLC to cream_api.ini with appid {dlcApp.Key} ({dlcApp.Value})", InstallationLog.Resource); await UpdateUser($"Added DLC to cream_api.ini with appid {dlcApp.Key} ({dlcApp.Value})", InstallationLog.Resource, info: false);
} }
} }
@ -91,25 +85,25 @@ namespace CreamInstaller
if (File.Exists(api)) if (File.Exists(api))
{ {
File.Delete(api); File.Delete(api);
await UpdateUser($"Deleted file: {Path.GetFileName(api)}", InstallationLog.Resource); await UpdateUser($"Deleted file: {Path.GetFileName(api)}", InstallationLog.Resource, info: false);
} }
File.Move(api_o, api); File.Move(api_o, api);
await UpdateUser($"Renamed file: {Path.GetFileName(api_o)} -> {Path.GetFileName(api)}", InstallationLog.Resource); await UpdateUser($"Renamed file: {Path.GetFileName(api_o)} -> {Path.GetFileName(api)}", InstallationLog.Resource, info: false);
} }
if (File.Exists(api64_o)) if (File.Exists(api64_o))
{ {
if (File.Exists(api64)) if (File.Exists(api64))
{ {
File.Delete(api64); File.Delete(api64);
await UpdateUser($"Deleted file: {Path.GetFileName(api64)}", InstallationLog.Resource); await UpdateUser($"Deleted file: {Path.GetFileName(api64)}", InstallationLog.Resource, info: false);
} }
File.Move(api64_o, api64); File.Move(api64_o, api64);
await UpdateUser($"Renamed file: {Path.GetFileName(api64_o)} -> {Path.GetFileName(api64)}", InstallationLog.Resource); await UpdateUser($"Renamed file: {Path.GetFileName(api64_o)} -> {Path.GetFileName(api64)}", InstallationLog.Resource, info: false);
} }
if (File.Exists(cApi)) if (File.Exists(cApi))
{ {
File.Delete(cApi); File.Delete(cApi);
await UpdateUser($"Deleted file: {Path.GetFileName(cApi)}", InstallationLog.Resource); await UpdateUser($"Deleted file: {Path.GetFileName(cApi)}", InstallationLog.Resource, info: false);
} }
} }
else else
@ -117,22 +111,22 @@ namespace CreamInstaller
if (File.Exists(api) && !File.Exists(api_o)) if (File.Exists(api) && !File.Exists(api_o))
{ {
File.Move(api, api_o); File.Move(api, api_o);
await UpdateUser($"Renamed file: {Path.GetFileName(api)} -> {Path.GetFileName(api_o)}", InstallationLog.Resource); await UpdateUser($"Renamed file: {Path.GetFileName(api)} -> {Path.GetFileName(api_o)}", InstallationLog.Resource, info: false);
} }
if (File.Exists(api_o)) if (File.Exists(api_o))
{ {
Properties.Resources.API.Write(api); Properties.Resources.API.Write(api);
await UpdateUser($"Wrote resource to file: {Path.GetFileName(api)}", InstallationLog.Resource); await UpdateUser($"Wrote resource to file: {Path.GetFileName(api)}", InstallationLog.Resource, info: false);
} }
if (File.Exists(api64) && !File.Exists(api64_o)) if (File.Exists(api64) && !File.Exists(api64_o))
{ {
File.Move(api64, api64_o); File.Move(api64, api64_o);
await UpdateUser($"Renamed file: {Path.GetFileName(api64)} -> {Path.GetFileName(api64_o)}", InstallationLog.Resource); await UpdateUser($"Renamed file: {Path.GetFileName(api64)} -> {Path.GetFileName(api64_o)}", InstallationLog.Resource, info: false);
} }
if (File.Exists(api64_o)) if (File.Exists(api64_o))
{ {
Properties.Resources.API64.Write(api64); Properties.Resources.API64.Write(api64);
await UpdateUser($"Wrote resource to file: {Path.GetFileName(api64)}", InstallationLog.Resource); await UpdateUser($"Wrote resource to file: {Path.GetFileName(api64)}", InstallationLog.Resource, info: false);
} }
await UpdateUser("Generating CreamAPI for " + selection.Name + $" in directory \"{directory}\" . . . ", InstallationLog.Operation); await UpdateUser("Generating CreamAPI for " + selection.Name + $" in directory \"{directory}\" . . . ", InstallationLog.Operation);
File.Create(cApi).Close(); File.Create(cApi).Close();
@ -161,10 +155,7 @@ namespace CreamInstaller
CompleteOperationsCount = 0; CompleteOperationsCount = 0;
foreach (ProgramSelection selection in programSelections) foreach (ProgramSelection selection in programSelections)
{ {
if (!Program.IsProgramRunningDialog(this, selection)) if (!Program.IsProgramRunningDialog(this, selection)) throw new OperationCanceledException();
{
throw new OperationCanceledException();
}
try try
{ {
await OperateFor(selection); await OperateFor(selection);
@ -180,16 +171,8 @@ namespace CreamInstaller
await Program.Cleanup(); await Program.Cleanup();
List<ProgramSelection> FailedSelections = ProgramSelection.AllSafeEnabled; List<ProgramSelection> FailedSelections = ProgramSelection.AllSafeEnabled;
if (FailedSelections.Any()) if (FailedSelections.Any())
{ if (FailedSelections.Count == 1) throw new CustomMessageException($"Operation failed for {FailedSelections.First().Name}.");
if (FailedSelections.Count == 1) else throw new CustomMessageException($"Operation failed for {FailedSelections.Count} programs.");
{
throw new CustomMessageException($"Operation failed for {FailedSelections.First().Name}.");
}
else
{
throw new CustomMessageException($"Operation failed for {FailedSelections.Count} programs.");
}
}
} }
private readonly int ProgramCount = ProgramSelection.AllSafeEnabled.Count; private readonly int ProgramCount = ProgramSelection.AllSafeEnabled.Count;
@ -228,10 +211,7 @@ namespace CreamInstaller
} }
catch (Exception e) catch (Exception e)
{ {
if (ExceptionHandler.OutputException(e)) if (ExceptionHandler.OutputException(e)) goto retry;
{
goto retry;
}
Close(); Close();
} }
} }
@ -248,10 +228,7 @@ namespace CreamInstaller
Start(); Start();
} }
private void OnCancel(object sender, EventArgs e) private void OnCancel(object sender, EventArgs e) => Program.Cleanup().Wait();
{
Program.Cleanup().Wait();
}
private void OnReselect(object sender, EventArgs e) private void OnReselect(object sender, EventArgs e)
{ {

View file

@ -1,8 +1,4 @@
using HtmlAgilityPack; using System;
using Onova;
using Onova.Models;
using Onova.Services;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.IO; using System.IO;
@ -13,6 +9,12 @@ using System.Threading.Tasks;
using System.Web; using System.Web;
using System.Windows.Forms; using System.Windows.Forms;
using HtmlAgilityPack;
using Onova;
using Onova.Models;
using Onova.Services;
namespace CreamInstaller namespace CreamInstaller
{ {
internal partial class MainForm : CustomForm internal partial class MainForm : CustomForm
@ -33,7 +35,6 @@ namespace CreamInstaller
cancellationTokenSource.Dispose(); cancellationTokenSource.Dispose();
cancellationTokenSource = null; cancellationTokenSource = null;
} }
Hide(); Hide();
new SelectForm(this).ShowDialog(); new SelectForm(this).ShowDialog();
Close(); Close();
@ -93,7 +94,6 @@ namespace CreamInstaller
changelogTreeView.Visible = true; changelogTreeView.Visible = true;
Version currentVersion = new(Application.ProductVersion); Version currentVersion = new(Application.ProductVersion);
foreach (Version version in versions) foreach (Version version in versions)
{
if (version > currentVersion && !changelogTreeView.Nodes.ContainsKey(version.ToString())) if (version > currentVersion && !changelogTreeView.Nodes.ContainsKey(version.ToString()))
{ {
TreeNode root = new($"v{version}"); TreeNode root = new($"v{version}");
@ -128,7 +128,6 @@ namespace CreamInstaller
} }
}); });
} }
}
} }
} }
@ -139,7 +138,6 @@ namespace CreamInstaller
{ {
string FileName = Path.GetFileName(Program.CurrentProcessFilePath); string FileName = Path.GetFileName(Program.CurrentProcessFilePath);
if (FileName != "CreamInstaller.exe") if (FileName != "CreamInstaller.exe")
{
if (new DialogForm(this).Show(Program.ApplicationName, SystemIcons.Warning, if (new DialogForm(this).Show(Program.ApplicationName, SystemIcons.Warning,
"WARNING: CreamInstaller.exe was renamed!" + "WARNING: CreamInstaller.exe was renamed!" +
"\n\nThis will cause unwanted behavior when updating the program!", "\n\nThis will cause unwanted behavior when updating the program!",
@ -148,24 +146,16 @@ namespace CreamInstaller
Application.Exit(); Application.Exit();
return; return;
} }
}
OnLoad(); OnLoad();
} }
catch (Exception e) catch (Exception e)
{ {
if (ExceptionHandler.OutputException(e)) if (ExceptionHandler.OutputException(e)) goto retry;
{
goto retry;
}
Close(); Close();
} }
} }
private void OnIgnore(object sender, EventArgs e) private void OnIgnore(object sender, EventArgs e) => StartProgram();
{
StartProgram();
}
private async void OnUpdate(object sender, EventArgs e) private async void OnUpdate(object sender, EventArgs e)
{ {
@ -200,10 +190,7 @@ namespace CreamInstaller
Application.Exit(); Application.Exit();
return; return;
} }
else else OnLoad();
{
OnLoad();
}
} }
private void OnUpdateCancel(object sender, EventArgs e) private void OnUpdateCancel(object sender, EventArgs e)

View file

@ -1,7 +1,4 @@
using Gameloop.Vdf; using System;
using Gameloop.Vdf.Linq;
using Microsoft.Win32;
using System;
using System.Collections; using System.Collections;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
@ -13,6 +10,11 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using Gameloop.Vdf;
using Gameloop.Vdf.Linq;
using Microsoft.Win32;
namespace CreamInstaller namespace CreamInstaller
{ {
internal partial class SelectForm : CustomForm internal partial class SelectForm : CustomForm
@ -24,118 +26,74 @@ namespace CreamInstaller
Program.SelectForm = this; Program.SelectForm = this;
} }
private static List<string> GameLibraryDirectories private static async Task<List<string>> GameLibraryDirectories() => await Task.Run(() =>
{ {
get List<string> gameDirectories = new();
if (Program.Canceled) return gameDirectories;
string steamInstallPath = Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Valve\\Steam", "InstallPath", null) as string;
steamInstallPath ??= Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Valve\\Steam", "InstallPath", null) as string;
if (steamInstallPath != null && Directory.Exists(steamInstallPath))
{ {
List<string> gameDirectories = new(); string libraryFolder = steamInstallPath + @"\steamapps";
if (Program.Canceled) if (Directory.Exists(libraryFolder))
{ {
return gameDirectories; gameDirectories.Add(libraryFolder);
} try
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 && Directory.Exists(steamInstallPath))
{
string libraryFolder = steamInstallPath + @"\steamapps";
if (Directory.Exists(libraryFolder))
{ {
gameDirectories.Add(libraryFolder); string libraryFolders = libraryFolder + @"\libraryfolders.vdf";
try if (File.Exists(libraryFolders))
{ {
string libraryFolders = libraryFolder + @"\libraryfolders.vdf"; dynamic property = VdfConvert.Deserialize(File.ReadAllText(libraryFolders, Encoding.UTF8)).Value;
if (File.Exists(libraryFolders)) foreach (dynamic _property in property)
{ if (int.TryParse(_property.Key, out int _))
dynamic property = VdfConvert.Deserialize(File.ReadAllText(libraryFolders, Encoding.UTF8));
foreach (dynamic _property in property.Value)
{ {
if (int.TryParse(_property.Key, out int _)) string path = _property.Value.path.ToString() + @"\steamapps";
{ if (string.IsNullOrWhiteSpace(path) || !Directory.Exists(path)) continue;
string path = _property.Value.path.ToString() + @"\steamapps"; if (!gameDirectories.Contains(path)) gameDirectories.Add(path);
if (string.IsNullOrWhiteSpace(path) || !Directory.Exists(path))
{
continue;
}
if (!gameDirectories.Contains(path))
{
gameDirectories.Add(path);
}
}
} }
}
} }
catch { }
} }
catch { }
} }
return gameDirectories;
} }
} return gameDirectories;
});
private static bool GetDllDirectoriesFromGameDirectory(string gameDirectory, out List<string> dllDirectories) private static async Task<List<string>> GetDllDirectoriesFromGameDirectory(string gameDirectory) => await Task.Run(async () =>
{ {
dllDirectories = new(); List<string> dllDirectories = new();
if (Program.Canceled || !Directory.Exists(gameDirectory)) if (Program.Canceled || !Directory.Exists(gameDirectory)) return null;
{
return false;
}
string api = gameDirectory + @"\steam_api.dll"; string api = gameDirectory + @"\steam_api.dll";
string api64 = gameDirectory + @"\steam_api64.dll"; string api64 = gameDirectory + @"\steam_api64.dll";
if (File.Exists(api) || File.Exists(api64)) if (File.Exists(api) || File.Exists(api64)) dllDirectories.Add(gameDirectory);
string[] directories = Directory.GetDirectories(gameDirectory);
foreach (string _directory in directories)
{ {
dllDirectories.Add(gameDirectory); if (Program.Canceled) return null;
}
foreach (string _directory in Directory.GetDirectories(gameDirectory))
{
if (Program.Canceled)
{
return false;
}
try try
{ {
if (GetDllDirectoriesFromGameDirectory(_directory, out List<string> _dllDirectories)) List<string> moreDllDirectories = await GetDllDirectoriesFromGameDirectory(_directory);
{ if (moreDllDirectories is not null) dllDirectories.AddRange(moreDllDirectories);
dllDirectories.AddRange(_dllDirectories);
}
} }
catch { } catch { }
} }
if (!dllDirectories.Any()) if (!dllDirectories.Any()) return null;
{ return dllDirectories;
return false; });
}
return true; private static async Task<List<Tuple<int, string, string, int, string>>> GetGamesFromLibraryDirectory(string libraryDirectory) => await Task.Run(() =>
}
private static bool GetGamesFromLibraryDirectory(string libraryDirectory, out List<Tuple<int, string, string, int, string>> games)
{ {
games = new(); List<Tuple<int, string, string, int, string>> games = new();
if (Program.Canceled || !Directory.Exists(libraryDirectory)) if (Program.Canceled || !Directory.Exists(libraryDirectory)) return null;
string[] files = Directory.GetFiles(libraryDirectory);
foreach (string file in files)
{ {
return false; if (Program.Canceled) return null;
} if (Path.GetExtension(file) == ".acf")
foreach (string directory in Directory.GetFiles(libraryDirectory))
{
if (Program.Canceled)
{
return false;
}
if (Path.GetExtension(directory) == ".acf")
{ {
try try
{ {
dynamic property = VdfConvert.Deserialize(File.ReadAllText(directory, Encoding.UTF8)); dynamic property = VdfConvert.Deserialize(File.ReadAllText(file, Encoding.UTF8));
string _appid = property.Value.appid.ToString(); string _appid = property.Value.appid.ToString();
string installdir = property.Value.installdir.ToString(); string installdir = property.Value.installdir.ToString();
string name = property.Value.name.ToString(); string name = property.Value.name.ToString();
@ -144,39 +102,20 @@ namespace CreamInstaller
|| string.IsNullOrWhiteSpace(installdir) || string.IsNullOrWhiteSpace(installdir)
|| string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(name)
|| string.IsNullOrWhiteSpace(_buildid)) || string.IsNullOrWhiteSpace(_buildid))
{
continue; continue;
}
string branch = property.Value.UserConfig?.betakey?.ToString(); string branch = property.Value.UserConfig?.betakey?.ToString();
if (string.IsNullOrWhiteSpace(branch)) if (string.IsNullOrWhiteSpace(branch)) branch = "public";
{
branch = "public";
}
string gameDirectory = libraryDirectory + @"\common\" + installdir; string gameDirectory = libraryDirectory + @"\common\" + installdir;
if (!int.TryParse(_appid, out int appid)) if (!int.TryParse(_appid, out int appid)) continue;
{ if (!int.TryParse(_buildid, out int buildid)) continue;
continue;
}
if (!int.TryParse(_buildid, out int buildid))
{
continue;
}
games.Add(new(appid, name, branch, buildid, gameDirectory)); games.Add(new(appid, name, branch, buildid, gameDirectory));
} }
catch { } catch { }
} }
} }
if (!games.Any()) if (!games.Any()) return null;
{ return games;
return false; });
}
return true;
}
internal List<TreeNode> TreeNodes => GatherTreeNodes(selectionTreeView.Nodes); internal List<TreeNode> TreeNodes => GatherTreeNodes(selectionTreeView.Nodes);
private List<TreeNode> GatherTreeNodes(TreeNodeCollection nodeCollection) private List<TreeNode> GatherTreeNodes(TreeNodeCollection nodeCollection)
@ -194,30 +133,21 @@ namespace CreamInstaller
private async Task GetCreamApiApplicablePrograms(IProgress<int> progress) private async Task GetCreamApiApplicablePrograms(IProgress<int> progress)
{ {
int cur = 0; if (Program.Canceled) return;
if (Program.Canceled)
{
return;
}
List<Tuple<int, string, string, int, string>> applicablePrograms = new(); List<Tuple<int, string, string, int, string>> applicablePrograms = new();
string launcherRootDirectory = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Programs\\Paradox Interactive"; string launcherRootDirectory = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Programs\\Paradox Interactive";
if (Directory.Exists(launcherRootDirectory)) if (Directory.Exists(launcherRootDirectory))
{
applicablePrograms.Add(new(0, "Paradox Launcher", "", 0, launcherRootDirectory)); applicablePrograms.Add(new(0, "Paradox Launcher", "", 0, launcherRootDirectory));
} List<string> gameLibraryDirectories = await GameLibraryDirectories();
foreach (string libraryDirectory in gameLibraryDirectories)
foreach (string libraryDirectory in GameLibraryDirectories)
{ {
if (GetGamesFromLibraryDirectory(libraryDirectory, out List<Tuple<int, string, string, int, string>> games)) List<Tuple<int, string, string, int, string>> games = await GetGamesFromLibraryDirectory(libraryDirectory);
{ if (games is not null)
foreach (Tuple<int, string, string, int, string> game in games) foreach (Tuple<int, string, string, int, string> game in games)
{
applicablePrograms.Add(game); applicablePrograms.Add(game);
}
}
} }
int cur = 0;
RunningTasks.Clear(); RunningTasks.Clear();
foreach (Tuple<int, string, string, int, string> program in applicablePrograms) foreach (Tuple<int, string, string, int, string> program in applicablePrograms)
{ {
@ -227,23 +157,14 @@ namespace CreamInstaller
int buildId = program.Item4; int buildId = program.Item4;
string directory = program.Item5; string directory = program.Item5;
ProgramSelection selection = ProgramSelection.FromAppId(appId); ProgramSelection selection = ProgramSelection.FromAppId(appId);
if (Program.Canceled) if (Program.Canceled) return;
{
return;
}
if (Program.BlockProtectedGames) if (Program.BlockProtectedGames)
{ {
bool blockedGame = Program.ProtectedGameNames.Contains(name); bool blockedGame = Program.ProtectedGameNames.Contains(name);
if (!Program.ProtectedGameDirectoryExceptions.Contains(name)) if (!Program.ProtectedGameDirectoryExceptions.Contains(name))
{
foreach (string path in Program.ProtectedGameDirectories) foreach (string path in Program.ProtectedGameDirectories)
{
if (Directory.Exists(directory + path)) if (Directory.Exists(directory + path))
{
blockedGame = true; blockedGame = true;
}
}
}
if (blockedGame) if (blockedGame)
{ {
if (selection is not null) if (selection is not null)
@ -254,59 +175,32 @@ namespace CreamInstaller
continue; continue;
} }
} }
Task task = Task.Run(async () => RunningTasks.Add(Task.Run(async () =>
{ {
if (Program.Canceled || !GetDllDirectoriesFromGameDirectory(directory, out List<string> dllDirectories)) if (Program.Canceled) return;
{ List<string> dllDirectories = await GetDllDirectoriesFromGameDirectory(directory);
return; if (dllDirectories is null) return;
}
VProperty appInfo = null; VProperty appInfo = null;
if (Program.Canceled || (appId > 0 && !SteamCMD.GetAppInfo(appId, out appInfo, branch, buildId))) if (appId > 0) appInfo = await SteamCMD.GetAppInfo(appId, branch, buildId);
{ if (appId > 0 && appInfo is null) return;
return; if (Program.Canceled) return;
}
if (Program.Canceled)
{
return;
}
ConcurrentDictionary<int, string> dlc = new(); ConcurrentDictionary<int, string> dlc = new();
List<Task> dlcTasks = new(); List<Task> dlcTasks = new();
List<int> dlcIds = SteamCMD.ParseDlcAppIds(appInfo); List<int> dlcIds = await SteamCMD.ParseDlcAppIds(appInfo);
if (dlcIds.Count > 0) if (dlcIds.Count > 0)
{ {
foreach (int id in dlcIds) foreach (int id in dlcIds)
{ {
if (Program.Canceled) if (Program.Canceled) return;
Task task = Task.Run(async () =>
{ {
return; if (Program.Canceled) return;
}
Task task = Task.Run(() =>
{
if (Program.Canceled)
{
return;
}
string dlcName = null; string dlcName = null;
if (SteamCMD.GetAppInfo(id, out VProperty dlcAppInfo)) VProperty dlcAppInfo = await SteamCMD.GetAppInfo(id);
{ if (dlcAppInfo is not null)
dlcName = dlcAppInfo?.Value?["common"]?["name"]?.ToString(); dlcName = dlcAppInfo?.Value?["common"]?["name"]?.ToString();
} if (Program.Canceled) return;
if (string.IsNullOrWhiteSpace(dlcName)) return; //dlcName = "Unknown DLC";
if (Program.Canceled)
{
return;
}
if (string.IsNullOrWhiteSpace(dlcName))
{
return; //dlcName = "Unknown DLC";
}
dlc[id] = /*$"[{id}] " +*/ dlcName; dlc[id] = /*$"[{id}] " +*/ dlcName;
progress.Report(++cur); progress.Report(++cur);
}); });
@ -315,20 +209,9 @@ namespace CreamInstaller
} }
progress.Report(-RunningTasks.Count); progress.Report(-RunningTasks.Count);
} }
else if (appId > 0) else if (appId > 0) return;
{ if (Program.Canceled) return;
return; if (string.IsNullOrWhiteSpace(name)) return;
}
if (Program.Canceled)
{
return;
}
if (string.IsNullOrWhiteSpace(name))
{
return;
}
selection ??= new(); selection ??= new();
selection.Usable = true; selection.Usable = true;
@ -337,31 +220,17 @@ namespace CreamInstaller
selection.SteamAppId = appId; selection.SteamAppId = appId;
selection.SteamApiDllDirectories = dllDirectories; selection.SteamApiDllDirectories = dllDirectories;
selection.AppInfo = appInfo; selection.AppInfo = appInfo;
if (allCheckBox.Checked) if (allCheckBox.Checked) selection.Enabled = true;
{
selection.Enabled = true;
}
foreach (Task task in dlcTasks.ToList()) foreach (Task task in dlcTasks)
{ {
if (Program.Canceled) if (Program.Canceled) return;
{
return;
}
await task; await task;
} }
if (Program.Canceled) if (Program.Canceled) return;
{
return;
}
selectionTreeView.Invoke((MethodInvoker)delegate selectionTreeView.Invoke((MethodInvoker)delegate
{ {
if (Program.Canceled) if (Program.Canceled) return;
{
return;
}
TreeNode programNode = TreeNodes.Find(s => s.Name == "" + appId) ?? new(); TreeNode programNode = TreeNodes.Find(s => s.Name == "" + appId) ?? new();
programNode.Name = "" + appId; programNode.Name = "" + appId;
programNode.Text = /*(appId > 0 ? $"[{appId}] " : "") +*/ name; programNode.Text = /*(appId > 0 ? $"[{appId}] " : "") +*/ name;
@ -374,19 +243,11 @@ namespace CreamInstaller
} }
else else
{ {
foreach (KeyValuePair<int, string> dlcApp in dlc.ToList()) foreach (KeyValuePair<int, string> dlcApp in dlc)
{ {
if (Program.Canceled || programNode is null) if (Program.Canceled || programNode is null) return;
{
return;
}
selection.AllSteamDlc[dlcApp.Key] = dlcApp.Value; selection.AllSteamDlc[dlcApp.Key] = dlcApp.Value;
if (allCheckBox.Checked) if (allCheckBox.Checked) selection.SelectedSteamDlc[dlcApp.Key] = dlcApp.Value;
{
selection.SelectedSteamDlc[dlcApp.Key] = dlcApp.Value;
}
TreeNode dlcNode = TreeNodes.Find(s => s.Name == "" + dlcApp.Key) ?? new(); TreeNode dlcNode = TreeNodes.Find(s => s.Name == "" + dlcApp.Key) ?? new();
dlcNode.Name = "" + dlcApp.Key; dlcNode.Name = "" + dlcApp.Key;
dlcNode.Text = dlcApp.Value; dlcNode.Text = dlcApp.Value;
@ -397,17 +258,13 @@ namespace CreamInstaller
} }
}); });
progress.Report(++cur); progress.Report(++cur);
}); }));
RunningTasks.Add(task);
} }
progress.Report(-RunningTasks.Count); progress.Report(-RunningTasks.Count);
progress.Report(cur); progress.Report(cur);
foreach (Task task in RunningTasks.ToList()) foreach (Task task in RunningTasks.ToList())
{ {
if (Program.Canceled) if (Program.Canceled) return;
{
return;
}
await task; await task;
} }
progress.Report(RunningTasks.Count); progress.Report(RunningTasks.Count);
@ -428,7 +285,6 @@ namespace CreamInstaller
installButton.Enabled = false; installButton.Enabled = false;
uninstallButton.Enabled = installButton.Enabled; uninstallButton.Enabled = installButton.Enabled;
selectionTreeView.Enabled = false; selectionTreeView.Enabled = false;
progressLabel.Visible = true; progressLabel.Visible = true;
progressBar1.Visible = true; progressBar1.Visible = true;
progressBar1.Value = 0; progressBar1.Value = 0;
@ -441,44 +297,20 @@ namespace CreamInstaller
IProgress<int> iProgress = progress; IProgress<int> iProgress = progress;
progress.ProgressChanged += (sender, _progress) => progress.ProgressChanged += (sender, _progress) =>
{ {
if (_progress < 0) if (_progress < 0) maxProgress = -_progress;
{ else curProgress = _progress;
maxProgress = -_progress;
}
else
{
curProgress = _progress;
}
int p = Math.Max(Math.Min((int)((float)(curProgress / (float)maxProgress) * 100), 100), 0); int p = Math.Max(Math.Min((int)((float)(curProgress / (float)maxProgress) * 100), 100), 0);
if (validating) if (validating) progressLabel.Text = $"Validating . . . {p}% ({curProgress}/{maxProgress})";
{ else if (setup) progressLabel.Text = $"Setting up SteamCMD . . . {p}% ({curProgress}/{maxProgress})";
progressLabel.Text = $"Validating . . . {p}% ({curProgress}/{maxProgress})"; else progressLabel.Text = $"Gathering and caching your applicable games and their DLCs . . . {p}% ({curProgress}/{maxProgress})";
}
else if (setup)
{
progressLabel.Text = $"Setting up SteamCMD . . . {p}% ({curProgress}/{maxProgress})";
}
else
{
progressLabel.Text = $"Gathering and caching your applicable games and their DLCs . . . {p}% ({curProgress}/{maxProgress})";
}
progressBar1.Value = p; progressBar1.Value = p;
}; };
iProgress.Report(-1660); // not exact, number varies iProgress.Report(-1660); // not exact, number varies
int cur = 0; int cur = 0;
iProgress.Report(cur); iProgress.Report(cur);
if (!validating) if (!validating) progressLabel.Text = "Setting up SteamCMD . . . ";
{ if (!Directory.Exists(SteamCMD.DirectoryPath)) Directory.CreateDirectory(SteamCMD.DirectoryPath);
progressLabel.Text = "Setting up SteamCMD . . . ";
}
if (!Directory.Exists(SteamCMD.DirectoryPath))
{
Directory.CreateDirectory(SteamCMD.DirectoryPath);
}
FileSystemWatcher watcher = new(SteamCMD.DirectoryPath); FileSystemWatcher watcher = new(SteamCMD.DirectoryPath);
watcher.Changed += (sender, e) => iProgress.Report(++cur); watcher.Changed += (sender, e) => iProgress.Report(++cur);
@ -489,60 +321,42 @@ namespace CreamInstaller
watcher.Dispose(); watcher.Dispose();
setup = false; setup = false;
if (!validating) if (!validating) progressLabel.Text = "Gathering and caching your applicable games and their DLCs . . . ";
{
progressLabel.Text = "Gathering and caching your applicable games and their DLCs . . . ";
}
await GetCreamApiApplicablePrograms(iProgress); await GetCreamApiApplicablePrograms(iProgress);
ProgramSelection.ValidateAll(); ProgramSelection.ValidateAll();
TreeNodes.ForEach(node => TreeNodes.ForEach(node =>
{ {
if (node.Parent is null && ProgramSelection.FromAppId(int.Parse(node.Name)) is null) if (node.Parent is null && ProgramSelection.FromAppId(int.Parse(node.Name)) is null) node.Remove();
{
node.Remove();
}
}); });
progressBar1.Value = 100; progressBar1.Value = 100;
groupBox1.Size = new(groupBox1.Size.Width, groupBox1.Size.Height + 44); groupBox1.Size = new(groupBox1.Size.Width, groupBox1.Size.Height + 44);
progressLabel.Visible = false; progressLabel.Visible = false;
progressBar1.Visible = false; progressBar1.Visible = false;
selectionTreeView.Enabled = ProgramSelection.All.Any(); selectionTreeView.Enabled = ProgramSelection.All.Any();
allCheckBox.Enabled = selectionTreeView.Enabled; allCheckBox.Enabled = selectionTreeView.Enabled;
noneFoundLabel.Visible = !selectionTreeView.Enabled; noneFoundLabel.Visible = !selectionTreeView.Enabled;
installButton.Enabled = ProgramSelection.AllSafeEnabled.Any(); installButton.Enabled = ProgramSelection.AllSafeEnabled.Any();
uninstallButton.Enabled = installButton.Enabled; uninstallButton.Enabled = installButton.Enabled;
cancelButton.Enabled = false; cancelButton.Enabled = false;
scanButton.Enabled = true; scanButton.Enabled = true;
blockedGamesCheckBox.Enabled = true; blockedGamesCheckBox.Enabled = true;
blockProtectedHelpButton.Enabled = true; blockProtectedHelpButton.Enabled = true;
progressLabel.Text = "Validating . . . "; progressLabel.Text = "Validating . . . ";
if (!validating && !Program.Canceled) //if (!validating && !Program.Canceled) OnLoad(true);
{
OnLoad(true);
}
} }
catch (Exception e) catch (Exception e)
{ {
if (ExceptionHandler.OutputException(e)) if (ExceptionHandler.OutputException(e)) goto retry;
{
goto retry;
}
Close(); Close();
} }
} }
private void OnTreeViewNodeCheckedChanged(object sender, TreeViewEventArgs e) private void OnTreeViewNodeCheckedChanged(object sender, TreeViewEventArgs e)
{ {
if (e.Action == TreeViewAction.Unknown) if (e.Action == TreeViewAction.Unknown) return;
{
return;
}
TreeNode node = e.Node; TreeNode node = e.Node;
if (node is not null) if (node is not null)
{ {
@ -563,10 +377,7 @@ namespace CreamInstaller
selection.ToggleAllDlc(node.Checked); selection.ToggleAllDlc(node.Checked);
node.Nodes.Cast<TreeNode>().ToList().ForEach(treeNode => treeNode.Checked = node.Checked); node.Nodes.Cast<TreeNode>().ToList().ForEach(treeNode => treeNode.Checked = node.Checked);
} }
else else selection.Enabled = node.Checked;
{
selection.Enabled = node.Checked;
}
allCheckBox.CheckedChanged -= OnAllCheckBoxChanged; allCheckBox.CheckedChanged -= OnAllCheckBoxChanged;
allCheckBox.Checked = TreeNodes.TrueForAll(treeNode => treeNode.Checked); allCheckBox.Checked = TreeNodes.TrueForAll(treeNode => treeNode.Checked);
allCheckBox.CheckedChanged += OnAllCheckBoxChanged; allCheckBox.CheckedChanged += OnAllCheckBoxChanged;
@ -593,18 +404,13 @@ namespace CreamInstaller
selectionTreeView.NodeMouseClick += (sender, e) => selectionTreeView.NodeMouseClick += (sender, e) =>
{ {
TreeNode node = e.Node; TreeNode node = e.Node;
if (e.Button == MouseButtons.Right && node.Bounds.Contains(e.Location)) string appId = node.Name;
{ if (e.Button == MouseButtons.Right && node.Bounds.Contains(e.Location) && appId != "0")
string appId = node.Name; Process.Start(new ProcessStartInfo
if (appId != "0")
{ {
Process.Start(new ProcessStartInfo FileName = "https://steamdb.info/app/" + appId,
{ UseShellExecute = true
FileName = "https://steamdb.info/app/" + appId, });
UseShellExecute = true
});
}
}
}; };
OnLoad(); OnLoad();
} }
@ -617,31 +423,17 @@ namespace CreamInstaller
paradoxLauncher.ExtraSteamAppIdDlc.Clear(); paradoxLauncher.ExtraSteamAppIdDlc.Clear();
foreach (ProgramSelection selection in ProgramSelection.AllSafeEnabled) foreach (ProgramSelection selection in ProgramSelection.AllSafeEnabled)
{ {
if (selection.Name == paradoxLauncher.Name) if (selection.Name == paradoxLauncher.Name) continue;
{ if (selection.AppInfo.Value["extended"]["publisher"].ToString() != "Paradox Interactive") continue;
continue;
}
if (selection.AppInfo.Value["extended"]["publisher"].ToString() != "Paradox Interactive")
{
continue;
}
paradoxLauncher.ExtraSteamAppIdDlc.Add(new(selection.SteamAppId, selection.Name, selection.SelectedSteamDlc)); paradoxLauncher.ExtraSteamAppIdDlc.Add(new(selection.SteamAppId, selection.Name, selection.SelectedSteamDlc));
} }
if (!paradoxLauncher.ExtraSteamAppIdDlc.Any()) if (!paradoxLauncher.ExtraSteamAppIdDlc.Any())
{
foreach (ProgramSelection selection in ProgramSelection.AllSafe) foreach (ProgramSelection selection in ProgramSelection.AllSafe)
{ {
if (selection.Name == paradoxLauncher.Name) if (selection.Name == paradoxLauncher.Name) continue;
{ if (selection.AppInfo.Value["extended"]["publisher"].ToString() != "Paradox Interactive") continue;
continue;
}
if (selection.AppInfo.Value["extended"]["publisher"].ToString() != "Paradox Interactive")
{
continue;
}
paradoxLauncher.ExtraSteamAppIdDlc.Add(new(selection.SteamAppId, selection.Name, selection.AllSteamDlc)); paradoxLauncher.ExtraSteamAppIdDlc.Add(new(selection.SteamAppId, selection.Name, selection.AllSteamDlc));
} }
}
} }
} }
@ -657,9 +449,7 @@ namespace CreamInstaller
$"WARNING: There are no installed games with DLC that can be added to the Paradox Launcher!" + $"WARNING: There are no installed games with DLC that can be added to the Paradox Launcher!" +
"\n\nInstalling CreamAPI for the Paradox Launcher is pointless, since no DLC will be added to the configuration!", "\n\nInstalling CreamAPI for the Paradox Launcher is pointless, since no DLC will be added to the configuration!",
"Ignore", "Cancel") == DialogResult.OK) "Ignore", "Cancel") == DialogResult.OK)
{
return false; return false;
}
return true; return true;
} }
} }
@ -671,16 +461,8 @@ namespace CreamInstaller
if (ProgramSelection.All.Any()) if (ProgramSelection.All.Any())
{ {
foreach (ProgramSelection selection in ProgramSelection.AllSafeEnabled) foreach (ProgramSelection selection in ProgramSelection.AllSafeEnabled)
{ if (!Program.IsProgramRunningDialog(this, selection)) return;
if (!Program.IsProgramRunningDialog(this, selection)) if (ParadoxLauncherDlcDialog(this)) return;
{
return;
}
}
if (ParadoxLauncherDlcDialog(this))
{
return;
}
Hide(); Hide();
InstallForm installForm = new(this, uninstall); InstallForm installForm = new(this, uninstall);
installForm.ShowDialog(); installForm.ShowDialog();
@ -690,27 +472,13 @@ namespace CreamInstaller
Show(); Show();
OnLoad(); OnLoad();
} }
else else Close();
{
Close();
}
} }
} }
private void OnInstall(object sender, EventArgs e) private void OnInstall(object sender, EventArgs e) => OnAccept(false);
{ private void OnUninstall(object sender, EventArgs e) => OnAccept(true);
OnAccept(false); private void OnScan(object sender, EventArgs e) => OnLoad();
}
private void OnUninstall(object sender, EventArgs e)
{
OnAccept(true);
}
private void OnScan(object sender, EventArgs e)
{
OnLoad();
}
private void OnCancel(object sender, EventArgs e) private void OnCancel(object sender, EventArgs e)
{ {
@ -728,10 +496,7 @@ namespace CreamInstaller
{ {
if (node.Parent is null) if (node.Parent is null)
{ {
if (!node.Checked) if (!node.Checked) shouldCheck = true;
{
shouldCheck = true;
}
if (node.Checked != shouldCheck) if (node.Checked != shouldCheck)
{ {
node.Checked = shouldCheck; node.Checked = shouldCheck;
@ -753,19 +518,13 @@ namespace CreamInstaller
{ {
string blockedGames = ""; string blockedGames = "";
foreach (string name in Program.ProtectedGameNames) foreach (string name in Program.ProtectedGameNames)
{
blockedGames += helpButtonListPrefix + name; blockedGames += helpButtonListPrefix + name;
}
string blockedDirectories = ""; string blockedDirectories = "";
foreach (string path in Program.ProtectedGameDirectories) foreach (string path in Program.ProtectedGameDirectories)
{
blockedDirectories += helpButtonListPrefix + path; blockedDirectories += helpButtonListPrefix + path;
}
string blockedDirectoryExceptions = ""; string blockedDirectoryExceptions = "";
foreach (string name in Program.ProtectedGameDirectoryExceptions) foreach (string name in Program.ProtectedGameDirectoryExceptions)
{
blockedDirectoryExceptions += helpButtonListPrefix + name; blockedDirectoryExceptions += helpButtonListPrefix + name;
}
new DialogForm(this).Show(blockedGamesCheckBox.Text, SystemIcons.Information, new DialogForm(this).Show(blockedGamesCheckBox.Text, SystemIcons.Information,
"Blocks the program from caching and displaying games protected by DLL checks," + "Blocks the program from caching and displaying games protected by DLL checks," +
"\nanti-cheats, or that are confirmed not to be working with CreamAPI." + "\nanti-cheats, or that are confirmed not to be working with CreamAPI." +

View file

@ -41,11 +41,7 @@ namespace CreamInstaller
} }
catch (Exception e) catch (Exception e)
{ {
if (ExceptionHandler.OutputException(e)) if (ExceptionHandler.OutputException(e)) goto retry;
{
goto retry;
}
Application.Exit(); Application.Exit();
return; return;
} }
@ -61,14 +57,9 @@ namespace CreamInstaller
$"ERROR: {selection.Name} is currently running!" + $"ERROR: {selection.Name} is currently running!" +
"\n\nPlease close the program/game to continue . . . ", "\n\nPlease close the program/game to continue . . . ",
"Retry", "Cancel") == DialogResult.OK) "Retry", "Cancel") == DialogResult.OK)
{
return IsProgramRunningDialog(form, selection); return IsProgramRunningDialog(form, selection);
}
}
else
{
return true;
} }
else return true;
return false; return false;
} }
@ -86,17 +77,13 @@ namespace CreamInstaller
internal static List<ProgramSelection> ProgramSelections = new(); internal static List<ProgramSelection> ProgramSelections = new();
internal static bool Canceled = false; internal static bool Canceled = false;
internal static async Task Cleanup(bool cancel = true) internal static async Task Cleanup(bool cancel = true)
{ {
Canceled = cancel; Canceled = cancel;
await SteamCMD.Kill(); await SteamCMD.Kill();
} }
private static void OnApplicationExit(object s, EventArgs e) private static void OnApplicationExit(object s, EventArgs e) => Cleanup().Wait();
{
Cleanup().Wait();
}
internal static void InheritLocation(this Form form, Form fromForm) internal static void InheritLocation(this Form form, Form fromForm)
{ {