- Minor refactoring
- Moved from VDF dynamic parsing to the more reliable method introduced in v2.2.4.1
- Fixed a bug where selections were validating prematurely
This commit is contained in:
pointfeev 2022-01-24 14:10:29 -05:00
parent f1b7e04842
commit 947809b4ad
15 changed files with 1363 additions and 1386 deletions

View file

@ -118,8 +118,8 @@ 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
csharp_style_unused_value_assignment_preference = discard_variable:silent
csharp_style_unused_value_expression_statement_preference = discard_variable
# 'using' directive preferences
csharp_using_directive_placement = outside_namespace:suggestion

View file

@ -1,8 +1,8 @@
using System;
using System.Windows.Forms;
namespace CreamInstaller
{
namespace CreamInstaller;
internal static class ExceptionHandler
{
internal static bool OutputException(Exception e)
@ -57,4 +57,3 @@ namespace CreamInstaller
internal CustomMessageException(string message) => this.message = message;
}
}

View file

@ -1,8 +1,8 @@
using System.Drawing;
using System.Windows.Forms;
namespace CreamInstaller
{
namespace CreamInstaller;
internal static class InstallationLog
{
internal static readonly Color Background = Color.DarkSlateGray;
@ -22,4 +22,3 @@ namespace CreamInstaller
logTextBox.SelectionColor = logTextBox.ForeColor;
}
}
}

View file

@ -7,8 +7,8 @@ using System.Threading.Tasks;
using Gameloop.Vdf.Linq;
namespace CreamInstaller
{
namespace CreamInstaller;
internal class ProgramSelection
{
internal bool Enabled = false;
@ -134,4 +134,3 @@ namespace CreamInstaller
return null;
}
}
}

View file

@ -11,8 +11,8 @@ using System.Windows.Forms;
using Gameloop.Vdf.Linq;
namespace CreamInstaller
{
namespace CreamInstaller;
internal static class SteamCMD
{
internal static readonly string DirectoryPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\CreamInstaller";
@ -107,10 +107,10 @@ namespace CreamInstaller
}
if (appInfo.Value is VValue) goto restart;
if (appInfo is null || appInfo.Value?.Children()?.ToList()?.Count == 0) return appInfo;
VToken type = appInfo.Value?.TryGet("common")?.TryGet("type");
VToken type = appInfo.Value?.GetChild("common")?.GetChild("type");
if (type is null || type.ToString() == "Game")
{
string buildid = appInfo.Value?.TryGet("depots")?.TryGet("branches")?.TryGet(branch)?.TryGet("buildid")?.ToString();
string buildid = appInfo.Value?.GetChild("depots")?.GetChild("branches")?.GetChild(branch)?.GetChild("buildid")?.ToString();
if (buildid is null && type is not null) return appInfo;
if (type is null || int.Parse(buildid) < buildId)
{
@ -131,14 +131,16 @@ namespace CreamInstaller
{
List<int> dlcIds = new();
if (Program.Canceled || appInfo is not VProperty) return dlcIds;
VToken extended = appInfo.Value.TryGet("extended");
if (extended is not null) foreach (VProperty property in extended)
if (property.Key.ToString() == "listofdlc") foreach (string id in property.Value.ToString().Split(","))
VToken extended = appInfo.Value.GetChild("extended");
if (extended is not null)
foreach (VProperty property in extended)
if (property.Key.ToString() == "listofdlc")
foreach (string id in property.Value.ToString().Split(","))
if (!dlcIds.Contains(int.Parse(id))) dlcIds.Add(int.Parse(id));
VToken depots = appInfo.Value.TryGet("depots");
VToken depots = appInfo.Value.GetChild("depots");
if (depots is not null) foreach (VProperty property in depots)
if (int.TryParse(property.Key.ToString(), out int _)
&& int.TryParse(property.Value.TryGet("dlcappid")?.ToString(), out int appid)
&& int.TryParse(property.Value.GetChild("dlcappid")?.ToString(), out int appid)
&& !dlcIds.Contains(appid))
dlcIds.Add(appid);
return dlcIds;
@ -164,4 +166,3 @@ namespace CreamInstaller
}
}
}
}

View file

@ -17,7 +17,7 @@ internal static class ValveDataFile
return false;
}
internal static VToken TryGet(this VToken token, string index)
internal static VToken GetChild(this VToken token, string index)
{
try
{

View file

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

View file

@ -1,7 +1,7 @@
using System.Windows.Forms;
namespace CreamInstaller
{
namespace CreamInstaller;
internal class CustomForm : Form
{
internal CustomForm() : base() => Icon = Properties.Resources.Icon;
@ -18,4 +18,3 @@ namespace CreamInstaller
}
}
}
}

View file

@ -2,8 +2,8 @@
using System.Drawing;
using System.Windows.Forms;
namespace CreamInstaller
{
namespace CreamInstaller;
internal class CustomTreeView : TreeView
{
protected override void WndProc(ref Message m)
@ -54,4 +54,3 @@ namespace CreamInstaller
TextRenderer.DrawText(graphics, subText, subFont, subLocation, Color.Gray);
}
}
}

View file

@ -1,8 +1,8 @@
using System.Drawing;
using System.Windows.Forms;
namespace CreamInstaller
{
namespace CreamInstaller;
internal partial class DialogForm : CustomForm
{
internal DialogForm(IWin32Window owner) : base(owner) => InitializeComponent();
@ -22,4 +22,3 @@ namespace CreamInstaller
return ShowDialog();
}
}
}

View file

@ -8,8 +8,8 @@ using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CreamInstaller
{
namespace CreamInstaller;
internal partial class InstallForm : CustomForm
{
internal bool Reselecting = false;
@ -69,10 +69,7 @@ namespace CreamInstaller
foreach (string directory in selection.SteamApiDllDirectories)
{
await UpdateUser($"{(Uninstalling ? "Uninstalling" : "Installing")} CreamAPI for " + selection.Name + $" in directory \"{directory}\" . . . ", InstallationLog.Operation);
if (!Program.IsProgramRunningDialog(this, selection))
{
throw new OperationCanceledException();
}
if (!Program.IsProgramRunningDialog(this, selection)) throw new OperationCanceledException();
string api = directory + @"\steam_api.dll";
string api_o = directory + @"\steam_api_o.dll";
string api64 = directory + @"\steam_api64.dll";
@ -132,14 +129,9 @@ namespace CreamInstaller
File.Create(cApi).Close();
StreamWriter writer = new(cApi, true, Encoding.UTF8);
writer.WriteLine("; " + Application.CompanyName + " v" + Application.ProductVersion);
if (selection.SteamAppId > 0)
{
await WriteConfiguration(writer, selection.SteamAppId, selection.Name, selection.SelectedSteamDlc);
}
if (selection.SteamAppId > 0) await WriteConfiguration(writer, selection.SteamAppId, selection.Name, selection.SelectedSteamDlc);
foreach (Tuple<int, string, SortedList<int, string>> extraAppDlc in selection.ExtraSteamAppIdDlc)
{
await WriteConfiguration(writer, extraAppDlc.Item1, extraAppDlc.Item2, extraAppDlc.Item3);
}
writer.Flush();
writer.Close();
}
@ -240,4 +232,3 @@ namespace CreamInstaller
Close();
}
}
}

View file

@ -15,8 +15,8 @@ using Onova;
using Onova.Models;
using Onova.Services;
namespace CreamInstaller
{
namespace CreamInstaller;
internal partial class MainForm : CustomForm
{
internal MainForm() : base()
@ -200,4 +200,3 @@ namespace CreamInstaller
updateManager = null;
}
}
}

View file

@ -14,8 +14,8 @@ using Gameloop.Vdf.Linq;
using Microsoft.Win32;
namespace CreamInstaller
{
namespace CreamInstaller;
internal partial class SelectForm : CustomForm
{
internal SelectForm(IWin32Window owner) : base(owner)
@ -38,12 +38,12 @@ namespace CreamInstaller
{
gameDirectories.Add(libraryFolder);
string libraryFolders = libraryFolder + @"\libraryfolders.vdf";
if (File.Exists(libraryFolders) && ValveDataFile.TryDeserialize(File.ReadAllText(libraryFolders, Encoding.UTF8), out VProperty _result))
if (File.Exists(libraryFolders) && ValveDataFile.TryDeserialize(File.ReadAllText(libraryFolders, Encoding.UTF8), out VProperty result))
{
dynamic result = _result;
foreach (dynamic property in result?.Value) if (int.TryParse(property.Key, out int _))
foreach (VProperty property in result.Value)
if (int.TryParse(property.Key, out int _))
{
string path = property.Value?.path?.ToString();
string path = property.Value.GetChild("path")?.ToString();
if (string.IsNullOrWhiteSpace(path)) continue;
path += @"\steamapps";
if (Directory.Exists(path) && !gameDirectories.Contains(path)) gameDirectories.Add(path);
@ -72,8 +72,7 @@ namespace CreamInstaller
}
catch { }
}
if (!dllDirectories.Any()) return null;
return dllDirectories;
return !dllDirectories.Any() ? null : dllDirectories;
});
private static async Task<List<Tuple<int, string, string, int, string>>> GetGamesFromLibraryDirectory(string libraryDirectory) => await Task.Run(() =>
@ -84,28 +83,26 @@ namespace CreamInstaller
foreach (string file in files)
{
if (Program.Canceled) return null;
if (Path.GetExtension(file) == ".acf" && ValveDataFile.TryDeserialize(File.ReadAllText(file, Encoding.UTF8), out VProperty _result))
if (Path.GetExtension(file) == ".acf" && ValveDataFile.TryDeserialize(File.ReadAllText(file, Encoding.UTF8), out VProperty result))
{
dynamic result = _result;
string _appid = result.Value?.appid?.ToString();
string installdir = result.Value?.installdir?.ToString();
string name = result.Value?.name?.ToString();
string _buildid = result.Value?.buildid?.ToString();
if (string.IsNullOrWhiteSpace(_appid)
string appId = result.Value.GetChild("appid")?.ToString();
string installdir = result.Value.GetChild("installdir")?.ToString();
string name = result.Value.GetChild("name")?.ToString();
string buildId = result.Value.GetChild("buildid")?.ToString();
if (string.IsNullOrWhiteSpace(appId)
|| string.IsNullOrWhiteSpace(installdir)
|| string.IsNullOrWhiteSpace(name)
|| string.IsNullOrWhiteSpace(_buildid))
|| string.IsNullOrWhiteSpace(buildId))
continue;
string branch = result.Value?.UserConfig?.betakey?.ToString();
string branch = result.Value.GetChild("UserConfig")?.GetChild("betakey")?.ToString();
if (string.IsNullOrWhiteSpace(branch)) branch = "public";
string gameDirectory = libraryDirectory + @"\common\" + installdir;
if (!int.TryParse(_appid, out int appid)) continue;
if (!int.TryParse(_buildid, out int buildid)) continue;
games.Add(new(appid, name, branch, buildid, gameDirectory));
if (!int.TryParse(appId, out int appIdInt)) continue;
if (!int.TryParse(buildId, out int buildIdInt)) continue;
games.Add(new(appIdInt, name, branch, buildIdInt, gameDirectory));
}
}
if (!games.Any()) return null;
return games;
return !games.Any() ? null : games;
});
internal List<TreeNode> TreeNodes => GatherTreeNodes(selectionTreeView.Nodes);
@ -138,7 +135,7 @@ namespace CreamInstaller
applicablePrograms.Add(game);
}
int cur = 0;
int CompleteTasks = 0;
RunningTasks.Clear();
foreach (Tuple<int, string, string, int, string> program in applicablePrograms)
{
@ -148,7 +145,6 @@ namespace CreamInstaller
int buildId = program.Item4;
string directory = program.Item5;
ProgramSelection selection = ProgramSelection.FromAppId(appId);
if (selection is not null) selection.Validate();
if (Program.Canceled) return;
if (Program.BlockProtectedGames && Program.IsGameBlocked(name, directory)) continue;
RunningTasks.Add(Task.Run(async () =>
@ -173,11 +169,11 @@ namespace CreamInstaller
if (Program.Canceled) return;
string dlcName = null;
VProperty dlcAppInfo = await SteamCMD.GetAppInfo(id);
if (dlcAppInfo is not null) dlcName = dlcAppInfo.Value?.TryGet("common")?.TryGet("name")?.ToString();
if (dlcAppInfo is not null) dlcName = dlcAppInfo.Value?.GetChild("common")?.GetChild("name")?.ToString();
if (Program.Canceled) return;
if (string.IsNullOrWhiteSpace(dlcName)) return; //dlcName = "Unknown DLC";
dlc[id] = /*$"[{id}] " +*/ dlcName;
progress.Report(++cur);
progress.Report(++CompleteTasks);
});
dlcTasks.Add(task);
RunningTasks.Add(task);
@ -201,8 +197,8 @@ namespace CreamInstaller
if (appId == 0) selection.Icon = Program.GetFileIconImage(directory + @"\launcher\bootstrapper-v2.exe");
else
{
selection.IconStaticID = appInfo?.Value?.TryGet("common")?.TryGet("icon")?.ToString();
selection.ClientIconStaticID = appInfo?.Value?.TryGet("common")?.TryGet("clienticon")?.ToString();
selection.IconStaticID = appInfo?.Value?.GetChild("common")?.GetChild("icon")?.ToString();
selection.ClientIconStaticID = appInfo?.Value?.GetChild("common")?.GetChild("clienticon")?.ToString();
}
}
if (allCheckBox.Checked) selection.Enabled = true;
@ -242,8 +238,7 @@ namespace CreamInstaller
}
}
});
progress.Report(++cur);
progress.Report(++CompleteTasks);
}));
progress.Report(-RunningTasks.Count);
}
@ -443,14 +438,14 @@ namespace CreamInstaller
foreach (ProgramSelection selection in ProgramSelection.AllUsableEnabled)
{
if (selection.Name == paradoxLauncher.Name) continue;
if (selection.AppInfo.Value?.TryGet("extended")?.TryGet("publisher")?.ToString() != "Paradox Interactive") continue;
if (selection.AppInfo.Value?.GetChild("extended")?.GetChild("publisher")?.ToString() != "Paradox Interactive") continue;
paradoxLauncher.ExtraSteamAppIdDlc.Add(new(selection.SteamAppId, selection.Name, selection.SelectedSteamDlc));
}
if (!paradoxLauncher.ExtraSteamAppIdDlc.Any())
foreach (ProgramSelection selection in ProgramSelection.AllUsable)
{
if (selection.Name == paradoxLauncher.Name) continue;
if (selection.AppInfo.Value?.TryGet("extended")?.TryGet("publisher")?.ToString() != "Paradox Interactive") continue;
if (selection.AppInfo.Value?.GetChild("extended")?.GetChild("publisher")?.ToString() != "Paradox Interactive") continue;
paradoxLauncher.ExtraSteamAppIdDlc.Add(new(selection.SteamAppId, selection.Name, selection.AllSteamDlc));
}
}
@ -548,4 +543,3 @@ namespace CreamInstaller
"OK");
}
}
}

View file

@ -10,8 +10,8 @@ using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CreamInstaller
{
namespace CreamInstaller;
internal static class Program
{
internal static readonly string ApplicationName = Application.CompanyName + " v" + Application.ProductVersion + ": " + Application.ProductName;
@ -131,4 +131,3 @@ namespace CreamInstaller
form.Location = new(X, Y);
}
}
}

View file

@ -1,7 +1,7 @@
using System.IO;
namespace CreamInstaller
{
namespace CreamInstaller;
internal static class FileResourceExtensions
{
internal static void Write(this byte[] resource, string filePath)
@ -10,4 +10,3 @@ namespace CreamInstaller
file.Write(resource);
}
}
}