- Added more files to SteamCMD cleanup
- Added a save and load feature to the new pre-scan choices dialog
- Re-enabled ReadyToRun compilation
- Moved the program to 64-bit
- Added Notepad++ support, so the program opens query files with it if it exists
- Cancelling the pre-scan choices dialog now cancels scanning
- The pre-scan choices dialog now doesn't show at all if no installed games are found on the system
- Fixed the installation form cancel button
- Selection form now no longer scans at unnecessary locations (e.g. after installation form re-select)
- Large code refactoring
This commit is contained in:
pointfeev 2022-03-18 19:04:49 -04:00
parent 55683bd7b2
commit be6a3966dc
13 changed files with 246 additions and 117 deletions

View file

@ -5,7 +5,7 @@
<UseWindowsForms>True</UseWindowsForms>
<ApplicationIcon>Resources\ini.ico</ApplicationIcon>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
<Version>3.3.0.2</Version>
<Version>3.4.0.0</Version>
<PackageIcon>Resources\ini.ico</PackageIcon>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<Copyright>2021, pointfeev (https://github.com/pointfeev)</Copyright>

View file

@ -28,7 +28,7 @@ internal static class EpicStore
{
List<(string id, string name, string product, string icon, string developer)> dlcIds = new();
string cacheFile = ProgramData.AppInfoPath + @$"\{categoryNamespace}.json";
bool cachedExists = Directory.Exists(Directory.GetDirectoryRoot(cacheFile)) && File.Exists(cacheFile);
bool cachedExists = File.Exists(cacheFile);
Response response = null;
if (!cachedExists || ProgramData.CheckCooldown(categoryNamespace, COOLDOWN_ENTITLEMENT))
{

View file

@ -285,17 +285,20 @@ internal partial class InstallForm : CustomForm
int cur = 0;
foreach (string directory in selection.DllDirectories)
{
UpdateUser($"{(Uninstalling ? "Uninstalling" : "Installing")} {(selection.IsSteam ? "CreamAPI" : "ScreamAPI")}" +
string platform = selection.Platform == Platform.Steam ? "CreamAPI"
: selection.Platform == Platform.Epic ? "ScreamAPI"
: throw new InvalidPlatformException(selection.Platform);
UpdateUser($"{(Uninstalling ? "Uninstalling" : "Installing")} {platform}" +
$" {(Uninstalling ? "from" : "for")} " + selection.Name + $" in directory \"{directory}\" . . . ", InstallationLog.Operation);
if (!Program.IsProgramRunningDialog(this, selection)) throw new OperationCanceledException();
if (selection.IsSteam)
if (Program.Canceled || !Program.IsProgramRunningDialog(this, selection)) throw new CustomMessageException("The operation was canceled.");
if (platform == "CreamAPI")
{
if (Uninstalling)
await UninstallCreamAPI(directory, this);
else
await InstallCreamAPI(directory, selection, this);
}
else
else if (platform == "ScreamAPI")
{
if (Uninstalling)
await UninstallScreamAPI(directory, this);
@ -309,13 +312,13 @@ internal partial class InstallForm : CustomForm
private async Task Operate()
{
List<ProgramSelection> programSelections = ProgramSelection.AllUsableEnabled;
List<ProgramSelection> programSelections = ProgramSelection.AllEnabled;
OperationsCount = programSelections.Count;
CompleteOperationsCount = 0;
List<ProgramSelection> disabledSelections = new();
foreach (ProgramSelection selection in programSelections)
{
if (!Program.IsProgramRunningDialog(this, selection)) throw new OperationCanceledException();
if (Program.Canceled || !Program.IsProgramRunningDialog(this, selection)) throw new CustomMessageException("The operation was canceled.");
try
{
await OperateFor(selection);
@ -330,17 +333,18 @@ internal partial class InstallForm : CustomForm
++CompleteOperationsCount;
}
Program.Cleanup();
List<ProgramSelection> FailedSelections = ProgramSelection.AllUsableEnabled;
List<ProgramSelection> FailedSelections = ProgramSelection.AllEnabled;
if (FailedSelections.Any())
if (FailedSelections.Count == 1) throw new CustomMessageException($"Operation failed for {FailedSelections.First().Name}.");
else throw new CustomMessageException($"Operation failed for {FailedSelections.Count} programs.");
foreach (ProgramSelection selection in disabledSelections) selection.Enabled = true;
}
private readonly int ProgramCount = ProgramSelection.AllUsableEnabled.Count;
private readonly int ProgramCount = ProgramSelection.AllEnabled.Count;
private async void Start()
{
Program.Canceled = false;
acceptButton.Enabled = false;
retryButton.Enabled = false;
cancelButton.Enabled = true;

View file

@ -35,6 +35,8 @@ namespace CreamInstaller
this.flowLayoutPanel2 = new System.Windows.Forms.FlowLayoutPanel();
this.allCheckBox = new System.Windows.Forms.CheckBox();
this.cancelButton = new System.Windows.Forms.Button();
this.loadButton = new System.Windows.Forms.Button();
this.saveButton = new System.Windows.Forms.Button();
this.groupBox.SuspendLayout();
this.flowLayoutPanel2.SuspendLayout();
this.SuspendLayout();
@ -124,12 +126,46 @@ namespace CreamInstaller
this.cancelButton.Text = "Cancel";
this.cancelButton.UseVisualStyleBackColor = true;
//
// loadButton
//
this.loadButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.loadButton.AutoSize = true;
this.loadButton.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.loadButton.Enabled = false;
this.loadButton.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.loadButton.Location = new System.Drawing.Point(283, 243);
this.loadButton.Name = "loadButton";
this.loadButton.Padding = new System.Windows.Forms.Padding(12, 0, 12, 0);
this.loadButton.Size = new System.Drawing.Size(71, 24);
this.loadButton.TabIndex = 4;
this.loadButton.Text = "Load";
this.loadButton.UseVisualStyleBackColor = true;
this.loadButton.Click += new System.EventHandler(this.OnLoad);
//
// saveButton
//
this.saveButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.saveButton.AutoSize = true;
this.saveButton.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.saveButton.Enabled = false;
this.saveButton.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.saveButton.Location = new System.Drawing.Point(208, 243);
this.saveButton.Name = "saveButton";
this.saveButton.Padding = new System.Windows.Forms.Padding(12, 0, 12, 0);
this.saveButton.Size = new System.Drawing.Size(69, 24);
this.saveButton.TabIndex = 5;
this.saveButton.Text = "Save";
this.saveButton.UseVisualStyleBackColor = true;
this.saveButton.Click += new System.EventHandler(this.OnSave);
//
// SelectDialogForm
//
this.AcceptButton = this.acceptButton;
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(433, 279);
this.Controls.Add(this.saveButton);
this.Controls.Add(this.loadButton);
this.Controls.Add(this.cancelButton);
this.Controls.Add(this.acceptButton);
this.Controls.Add(this.groupBox);
@ -155,5 +191,7 @@ namespace CreamInstaller
private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel2;
private System.Windows.Forms.CheckBox allCheckBox;
private System.Windows.Forms.Button cancelButton;
private System.Windows.Forms.Button loadButton;
private System.Windows.Forms.Button saveButton;
}
}

View file

@ -1,10 +1,12 @@
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;
namespace CreamInstaller;
@ -15,6 +17,7 @@ internal partial class SelectDialogForm : CustomForm
private readonly List<(string platform, string id, string name)> selected = new();
internal List<(string platform, string id, string name)> QueryUser(string groupBoxText, List<(string platform, string id, string name, bool alreadySelected)> choices)
{
if (!choices.Any()) return null;
groupBox.Text = groupBoxText;
allCheckBox.Enabled = false;
acceptButton.Enabled = false;
@ -29,11 +32,14 @@ internal partial class SelectDialogForm : CustomForm
OnTreeNodeChecked(node);
selectionTreeView.Nodes.Add(node);
}
if (!selected.Any()) OnLoad(null, null);
allCheckBox.CheckedChanged -= OnAllCheckBoxChanged;
allCheckBox.Checked = selectionTreeView.Nodes.Cast<TreeNode>().All(n => n.Checked);
allCheckBox.CheckedChanged += OnAllCheckBoxChanged;
allCheckBox.Enabled = true;
acceptButton.Enabled = selected.Any();
saveButton.Enabled = acceptButton.Enabled;
loadButton.Enabled = File.Exists(ProgramData.ChoicesPath);
OnResize(null, null);
Resize += OnResize;
return ShowDialog() == DialogResult.OK ? selected : null;
@ -43,6 +49,7 @@ internal partial class SelectDialogForm : CustomForm
{
OnTreeNodeChecked(e.Node);
acceptButton.Enabled = selected.Any();
saveButton.Enabled = acceptButton.Enabled;
}
private void OnTreeNodeChecked(TreeNode node)
@ -77,4 +84,24 @@ internal partial class SelectDialogForm : CustomForm
allCheckBox.Checked = shouldCheck;
allCheckBox.CheckedChanged += OnAllCheckBoxChanged;
}
private void OnLoad(object sender, EventArgs e)
{
List<string> choices = ProgramData.ReadChoices();
foreach (TreeNode node in selectionTreeView.Nodes)
{
node.Checked = choices.Contains(node.Name);
OnTreeNodeChecked(node);
}
}
private void OnSave(object sender, EventArgs e)
{
List<string> choices = new();
foreach (TreeNode node in selectionTreeView.Nodes)
if (node.Checked)
choices.Add(node.Name);
ProgramData.WriteChoices(choices);
loadButton.Enabled = File.Exists(ProgramData.ChoicesPath);
}
}

View file

@ -1,8 +1,6 @@

using System.Windows.Forms;
using CreamInstaller.Components;
namespace CreamInstaller
{
partial class SelectForm
@ -33,7 +31,6 @@ namespace CreamInstaller
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.installButton = new System.Windows.Forms.Button();
this.cancelButton = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
@ -42,7 +39,7 @@ namespace CreamInstaller
this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();
this.blockedGamesCheckBox = new System.Windows.Forms.CheckBox();
this.blockProtectedHelpButton = new System.Windows.Forms.Button();
this.selectionTreeView = new CustomTreeView();
this.selectionTreeView = new CreamInstaller.Components.CustomTreeView();
this.flowLayoutPanel2 = new System.Windows.Forms.FlowLayoutPanel();
this.allCheckBox = new System.Windows.Forms.CheckBox();
this.progressBar = new System.Windows.Forms.ProgressBar();
@ -161,17 +158,17 @@ namespace CreamInstaller
//
// selectionTreeView
//
this.selectionTreeView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.selectionTreeView.BackColor = System.Drawing.SystemColors.Control;
this.selectionTreeView.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.selectionTreeView.CheckBoxes = true;
this.selectionTreeView.Dock = System.Windows.Forms.DockStyle.Fill;
this.selectionTreeView.DrawMode = System.Windows.Forms.TreeViewDrawMode.OwnerDrawAll;
this.selectionTreeView.Enabled = false;
this.selectionTreeView.FullRowSelect = true;
this.selectionTreeView.Location = new System.Drawing.Point(6, 22);
this.selectionTreeView.Location = new System.Drawing.Point(3, 19);
this.selectionTreeView.Name = "selectionTreeView";
this.selectionTreeView.Size = new System.Drawing.Size(548, 280);
this.selectionTreeView.Size = new System.Drawing.Size(554, 218);
this.selectionTreeView.Sorted = true;
this.selectionTreeView.TabIndex = 1001;
//
// flowLayoutPanel2
@ -189,6 +186,8 @@ namespace CreamInstaller
// allCheckBox
//
this.allCheckBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.allCheckBox.Checked = true;
this.allCheckBox.CheckState = System.Windows.Forms.CheckState.Checked;
this.allCheckBox.Enabled = false;
this.allCheckBox.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.allCheckBox.Location = new System.Drawing.Point(3, 0);
@ -199,28 +198,12 @@ namespace CreamInstaller
this.allCheckBox.Text = "All";
this.allCheckBox.CheckedChanged += new System.EventHandler(this.OnAllCheckBoxChanged);
//
// selectionTreeView
//
this.selectionTreeView.Dock = System.Windows.Forms.DockStyle.Fill;
this.selectionTreeView.Location = new System.Drawing.Point(3, 19);
this.selectionTreeView.Size = new System.Drawing.Size(554, 218);
this.selectionTreeView.BackColor = System.Drawing.SystemColors.Control;
this.selectionTreeView.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.selectionTreeView.CheckBoxes = true;
this.selectionTreeView.Dock = System.Windows.Forms.DockStyle.Fill;
this.selectionTreeView.DrawMode = System.Windows.Forms.TreeViewDrawMode.OwnerDrawAll;
this.selectionTreeView.Enabled = false;
this.selectionTreeView.FullRowSelect = true;
this.selectionTreeView.LineColor = System.Drawing.Color.Empty;
this.selectionTreeView.Name = "selectionTreeView";
this.selectionTreeView.TabIndex = 1001;
//
// progressBar1
// progressBar
//
this.progressBar.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.progressBar.Location = new System.Drawing.Point(12, 297);
this.progressBar.Name = "progressBar1";
this.progressBar.Name = "progressBar";
this.progressBar.Size = new System.Drawing.Size(560, 23);
this.progressBar.TabIndex = 9;
//
@ -271,13 +254,13 @@ namespace CreamInstaller
this.progressLabelGames.TabIndex = 11;
this.progressLabelGames.Text = "Remaining games (2): Game 1, Game 2";
//
// progressLabelDLC
// progressLabelDLCs
//
this.progressLabelDLCs.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.progressLabelDLCs.Font = new System.Drawing.Font("Segoe UI", 7F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.progressLabelDLCs.Location = new System.Drawing.Point(12, 282);
this.progressLabelDLCs.Name = "progressLabelDLC";
this.progressLabelDLCs.Name = "progressLabelDLCs";
this.progressLabelDLCs.Size = new System.Drawing.Size(560, 12);
this.progressLabelDLCs.TabIndex = 10004;
this.progressLabelDLCs.Text = "Remaining DLC (2): 123456, 654321";
@ -326,7 +309,7 @@ namespace CreamInstaller
private System.Windows.Forms.CheckBox allCheckBox;
private Button scanButton;
private Label noneFoundLabel;
private CustomTreeView selectionTreeView;
private CreamInstaller.Components.CustomTreeView selectionTreeView;
private CheckBox blockedGamesCheckBox;
private Button blockProtectedHelpButton;
private FlowLayoutPanel flowLayoutPanel1;

View file

@ -101,23 +101,28 @@ internal partial class SelectForm : CustomForm
List<Task> appTasks = new();
if (Directory.Exists(ParadoxLauncher.InstallPath) && ProgramsToScan.Any(c => c.platform == "Paradox" && c.id == "ParadoxLauncher"))
{
ProgramSelection selection = ProgramSelection.FromId("ParadoxLauncher");
selection ??= new();
if (allCheckBox.Checked) selection.Enabled = true;
selection.Usable = true;
selection.Id = "ParadoxLauncher";
selection.Name = "Paradox Launcher";
selection.RootDirectory = ParadoxLauncher.InstallPath;
List<string> steamDllDirectories = await SteamLibrary.GetDllDirectoriesFromGameDirectory(selection.RootDirectory);
selection.DllDirectories = steamDllDirectories ?? await EpicLibrary.GetDllDirectoriesFromGameDirectory(selection.RootDirectory);
selection.IsSteam = steamDllDirectories is not null;
List<string> steamDllDirectories = await SteamLibrary.GetDllDirectoriesFromGameDirectory(ParadoxLauncher.InstallPath);
List<string> epicDllDirectories = null;
if (steamDllDirectories is null)
epicDllDirectories = await EpicLibrary.GetDllDirectoriesFromGameDirectory(ParadoxLauncher.InstallPath);
if (steamDllDirectories is not null || epicDllDirectories is not null)
{
ProgramSelection selection = ProgramSelection.FromId("ParadoxLauncher");
selection ??= new();
if (allCheckBox.Checked) selection.Enabled = true;
selection.Id = "ParadoxLauncher";
selection.Name = "Paradox Launcher";
selection.RootDirectory = ParadoxLauncher.InstallPath;
selection.DllDirectories = steamDllDirectories ?? epicDllDirectories;
selection.Platform = steamDllDirectories is not null ? Platform.Steam : Platform.Epic;
TreeNode programNode = treeNodes.Find(s => s.Name == selection.Id) ?? new();
programNode.Name = selection.Id;
programNode.Text = selection.Name;
programNode.Checked = selection.Enabled;
programNode.Remove();
selectionTreeView.Nodes.Add(programNode);
TreeNode programNode = treeNodes.Find(s => s.Name == selection.Id) ?? new();
programNode.Name = selection.Id;
programNode.Text = selection.Name;
programNode.Checked = selection.Enabled;
programNode.Remove();
selectionTreeView.Nodes.Add(programNode);
}
}
if (Directory.Exists(SteamLibrary.InstallPath) && ProgramsToScan.Any(c => c.platform == "Steam"))
{
@ -211,12 +216,11 @@ internal partial class SelectForm : CustomForm
ProgramSelection selection = ProgramSelection.FromId(appId) ?? new();
selection.Enabled = allCheckBox.Checked || selection.SelectedDlc.Any() || selection.ExtraDlc.Any();
selection.Usable = true;
selection.Platform = Platform.Steam;
selection.Id = appId;
selection.Name = appData?.name ?? name;
selection.RootDirectory = directory;
selection.DllDirectories = dllDirectories;
selection.IsSteam = true;
selection.ProductUrl = "https://store.steampowered.com/app/" + appId;
selection.IconUrl = IconGrabber.SteamAppImagesPath + @$"\{appId}\{appInfo?.Value?.GetChild("common")?.GetChild("icon")?.ToString()}.jpg";
selection.SubIconUrl = appData?.header_image ?? IconGrabber.SteamAppImagesPath + @$"\{appId}\{appInfo?.Value?.GetChild("common")?.GetChild("clienticon")?.ToString()}.ico";
@ -313,7 +317,7 @@ internal partial class SelectForm : CustomForm
ProgramSelection selection = ProgramSelection.FromId(@namespace) ?? new();
selection.Enabled = allCheckBox.Checked || selection.SelectedDlc.Any() || selection.ExtraDlc.Any();
selection.Usable = true;
selection.Platform = Platform.Epic;
selection.Id = @namespace;
selection.Name = name;
selection.RootDirectory = directory;
@ -385,7 +389,7 @@ internal partial class SelectForm : CustomForm
}
private List<(string platform, string id, string name)> ProgramsToScan;
private async void OnLoad(bool selectGamesToScan = false)
private async void OnLoad(bool forceScan = false, bool forceProvideChoices = false)
{
Program.Canceled = false;
blockedGamesCheckBox.Enabled = false;
@ -400,7 +404,8 @@ internal partial class SelectForm : CustomForm
progressLabel.Text = "Waiting for user to select which programs/games to scan . . .";
ShowProgressBar();
if (ProgramsToScan is null || !ProgramsToScan.Any() || selectGamesToScan)
bool scan = forceScan;
if (!scan && (ProgramsToScan is null || !ProgramsToScan.Any() || forceProvideChoices))
{
List<(string platform, string id, string name, bool alreadySelected)> gameChoices = new();
if (Directory.Exists(ParadoxLauncher.InstallPath))
@ -417,48 +422,58 @@ internal partial class SelectForm : CustomForm
{
using SelectDialogForm form = new(this);
List<(string platform, string id, string name)> choices = form.QueryUser("Choose which programs/games to scan for DLC:", gameChoices);
if (choices is not null) ProgramsToScan = choices;
noneFoundLabel.Text = "None of the chosen programs/games were CreamAPI-applicable or ScreamAPI-applicable!\n\nPress the \"Rescan Programs / Games\" button to re-choose.";
scan = choices is not null && choices.Any();
string retry = "\n\nPress the \"Rescan Programs / Games\" button to re-choose.";
if (scan)
{
ProgramsToScan = choices;
noneFoundLabel.Text = "None of the chosen programs/games were CreamAPI-applicable or ScreamAPI-applicable!" + retry;
}
else
noneFoundLabel.Text = "You didn't choose any programs/games!" + retry;
}
else
noneFoundLabel.Text = "No CreamAPI-applicable or ScreamAPI-applicable programs/games were found on your computer!";
}
bool setup = true;
int maxProgress = 0;
int curProgress = 0;
Progress<int> progress = new();
IProgress<int> iProgress = progress;
progress.ProgressChanged += (sender, _progress) =>
if (scan)
{
if (Program.Canceled) return;
bool setup = true;
int maxProgress = 0;
int curProgress = 0;
Progress<int> progress = new();
IProgress<int> iProgress = progress;
progress.ProgressChanged += (sender, _progress) =>
{
if (Program.Canceled) return;
Thread.Sleep(0);
if (_progress < 0 || _progress > maxProgress) maxProgress = -_progress;
else curProgress = _progress;
int p = Math.Max(Math.Min((int)((float)(curProgress / (float)maxProgress) * 100), 100), 0);
progressLabel.Text = setup ? $"Setting up SteamCMD . . . {p}%"
: $"Gathering and caching your applicable games and their DLCs . . . {p}%";
progressBar.Value = p;
};
await ProgramData.Setup();
if (Directory.Exists(SteamLibrary.InstallPath) && ProgramsToScan is not null && ProgramsToScan.Any(c => c.platform == "Steam"))
{
progressLabel.Text = $"Setting up SteamCMD . . . ";
await SteamCMD.Setup(iProgress);
}
setup = false;
progressLabel.Text = "Gathering and caching your applicable games and their DLCs . . . ";
ProgramSelection.ValidateAll(ProgramsToScan);
TreeNodes.ForEach(node => node.Remove());
Thread.Sleep(0);
if (_progress < 0 || _progress > maxProgress) maxProgress = -_progress;
else curProgress = _progress;
int p = Math.Max(Math.Min((int)((float)(curProgress / (float)maxProgress) * 100), 100), 0);
progressLabel.Text = setup ? $"Setting up SteamCMD . . . {p}%"
: $"Gathering and caching your applicable games and their DLCs . . . {p}%";
progressBar.Value = p;
};
await ProgramData.Setup();
if (Directory.Exists(SteamLibrary.InstallPath) && ProgramsToScan is not null && ProgramsToScan.Any(c => c.platform == "Steam"))
{
progressLabel.Text = $"Setting up SteamCMD . . . ";
await SteamCMD.Setup(iProgress);
await GetApplicablePrograms(iProgress);
await SteamCMD.Cleanup();
}
setup = false;
progressLabel.Text = "Gathering and caching your applicable games and their DLCs . . . ";
ProgramSelection.ValidateAll(ProgramsToScan);
TreeNodes.ForEach(node => node.Remove());
await GetApplicablePrograms(iProgress);
await SteamCMD.Cleanup();
HideProgressBar();
selectionTreeView.Enabled = ProgramSelection.All.Any();
allCheckBox.Enabled = selectionTreeView.Enabled;
noneFoundLabel.Visible = !selectionTreeView.Enabled;
installButton.Enabled = ProgramSelection.AllUsableEnabled.Any();
installButton.Enabled = ProgramSelection.AllEnabled.Any();
uninstallButton.Enabled = installButton.Enabled;
cancelButton.Enabled = false;
scanButton.Enabled = true;
@ -477,7 +492,7 @@ internal partial class SelectForm : CustomForm
allCheckBox.CheckedChanged -= OnAllCheckBoxChanged;
allCheckBox.Checked = TreeNodes.TrueForAll(treeNode => treeNode.Checked);
allCheckBox.CheckedChanged += OnAllCheckBoxChanged;
installButton.Enabled = ProgramSelection.AllUsableEnabled.Any();
installButton.Enabled = ProgramSelection.AllEnabled.Any();
uninstallButton.Enabled = installButton.Enabled;
}
@ -592,12 +607,17 @@ internal partial class SelectForm : CustomForm
string appInfoVDF = $@"{SteamCMD.AppInfoPath}\{id}.vdf";
string appInfoJSON = $@"{SteamCMD.AppInfoPath}\{id}.json";
string cooldown = $@"{ProgramData.CooldownPath}\{id}.txt";
if (Directory.Exists(Directory.GetDirectoryRoot(appInfoVDF)) && (File.Exists(appInfoVDF) || File.Exists(appInfoJSON)))
if ((File.Exists(appInfoVDF) || File.Exists(appInfoJSON)) && (selection is not null || dlc is not null))
{
List<ContextMenuItem> queries = new();
if (File.Exists(appInfoJSON))
queries.Add(new ContextMenuItem((selection is null || selection.IsSteam) ? "Open Steam Store Query" : "Open Epic GraphQL Query", "Notepad",
{
string platform = (selection is null || selection.Platform == Platform.Steam) ? "Steam Store"
: selection.Platform == Platform.Epic ? "Epic GraphQL"
: throw new InvalidPlatformException(selection.Platform);
queries.Add(new ContextMenuItem($"Open {platform} Query", "Notepad",
new EventHandler((sender, e) => Diagnostics.OpenFileInNotepad(appInfoJSON))));
}
if (File.Exists(appInfoVDF))
queries.Add(new ContextMenuItem("Open SteamCMD Query", "Notepad",
new EventHandler((sender, e) => Diagnostics.OpenFileInNotepad(appInfoVDF))));
@ -624,7 +644,7 @@ internal partial class SelectForm : CustomForm
File.Delete(cooldown);
}
catch { }
OnLoad();
OnLoad(forceScan: true);
})));
}
}
@ -640,16 +660,20 @@ internal partial class SelectForm : CustomForm
contextMenuStrip.Items.Add(new ContextMenuItem("Open Root Directory", "File Explorer",
new EventHandler((sender, e) => Diagnostics.OpenDirectoryInFileExplorer(selection.RootDirectory))));
List<string> directories = selection.DllDirectories.ToList();
string platform = selection.Platform == Platform.Steam ? "Steamworks"
: selection.Platform == Platform.Epic ? "Epic Online Services"
: throw new InvalidPlatformException(selection.Platform);
for (int i = 0; i < directories.Count; i++)
{
string directory = directories[i];
contextMenuStrip.Items.Add(new ContextMenuItem($"Open {(selection.IsSteam ? "Steamworks" : "Epic Online Services")} SDK Directory #{i + 1}", "File Explorer",
contextMenuStrip.Items.Add(new ContextMenuItem($"Open {platform} SDK Directory #{i + 1}", "File Explorer",
new EventHandler((sender, e) => Diagnostics.OpenDirectoryInFileExplorer(directory))));
}
}
if (id != "ParadoxLauncher")
{
if (selection is not null && selection.IsSteam || dlcParentSelection is not null && dlcParentSelection.IsSteam)
if (selection is not null && selection.Platform == Platform.Steam
|| dlcParentSelection is not null && dlcParentSelection.Platform == Platform.Steam)
{
contextMenuStrip.Items.Add(new ToolStripSeparator());
contextMenuStrip.Items.Add(new ContextMenuItem("Open SteamDB", "SteamDB",
@ -657,14 +681,14 @@ internal partial class SelectForm : CustomForm
}
if (selection is not null)
{
if (selection.IsSteam)
if (selection.Platform == Platform.Steam)
{
contextMenuStrip.Items.Add(new ContextMenuItem("Open Steam Store", "Steam Store",
new EventHandler((sender, e) => Diagnostics.OpenUrlInInternetBrowser(selection.ProductUrl))));
contextMenuStrip.Items.Add(new ContextMenuItem("Open Steam Community", (id, selection.SubIconUrl, true), "Steam Community",
new EventHandler((sender, e) => Diagnostics.OpenUrlInInternetBrowser("https://steamcommunity.com/app/" + id))));
}
else
else if (selection.Platform == Platform.Epic)
{
contextMenuStrip.Items.Add(new ToolStripSeparator());
contextMenuStrip.Items.Add(new ContextMenuItem("Open ScreamDB", "ScreamDB",
@ -676,7 +700,7 @@ internal partial class SelectForm : CustomForm
}
contextMenuStrip.Show(selectionTreeView, e.Location);
};
OnLoad(true);
OnLoad(forceProvideChoices: true);
}
catch (Exception e)
{
@ -689,7 +713,7 @@ internal partial class SelectForm : CustomForm
{
if (ProgramSelection.All.Any())
{
foreach (ProgramSelection selection in ProgramSelection.AllUsableEnabled)
foreach (ProgramSelection selection in ProgramSelection.AllEnabled)
if (!Program.IsProgramRunningDialog(this, selection)) return;
if (ParadoxLauncher.DlcDialog(this)) return;
Hide();
@ -709,7 +733,7 @@ internal partial class SelectForm : CustomForm
private void OnUninstall(object sender, EventArgs e) => OnAccept(true);
private void OnScan(object sender, EventArgs e) => OnLoad(true);
private void OnScan(object sender, EventArgs e) => OnLoad(forceProvideChoices: true);
private void OnCancel(object sender, EventArgs e)
{
@ -738,7 +762,7 @@ internal partial class SelectForm : CustomForm
private void OnBlockProtectedGamesCheckBoxChanged(object sender, EventArgs e)
{
Program.BlockProtectedGames = blockedGamesCheckBox.Checked;
OnLoad(true);
OnLoad(forceProvideChoices: true);
}
private readonly string helpButtonListPrefix = "\n • ";

View file

@ -29,13 +29,13 @@ internal static class ParadoxLauncher
if (paradoxLauncher is not null)
{
paradoxLauncher.ExtraDlc.Clear();
foreach (ProgramSelection selection in ProgramSelection.AllUsableEnabled)
foreach (ProgramSelection selection in ProgramSelection.AllEnabled)
{
if (selection == paradoxLauncher || selection.Publisher != "Paradox Interactive") continue;
paradoxLauncher.ExtraDlc.Add(new(selection.Id, selection.Name, selection.SelectedDlc));
}
if (!paradoxLauncher.ExtraDlc.Any())
foreach (ProgramSelection selection in ProgramSelection.AllUsable)
foreach (ProgramSelection selection in ProgramSelection.AllSafe)
{
if (selection == paradoxLauncher || selection.Publisher != "Paradox Interactive") continue;
paradoxLauncher.ExtraDlc.Add(new(selection.Id, selection.Name, selection.AllDlc));

View file

@ -7,7 +7,20 @@ using CreamInstaller.Components;
namespace CreamInstaller;
internal enum DlcType
public enum Platform
{
Steam = 0,
Epic = 1
}
public class InvalidPlatformException : Exception
{
public InvalidPlatformException() : base("Invalid platform!") { }
public InvalidPlatformException(Platform platform) : base($"Invalid platform ({platform})!") { }
public InvalidPlatformException(string message) : base(message) { }
public InvalidPlatformException(string message, Exception innerException) : base(message, innerException) { }
}
public enum DlcType
{
Default = 0,
CatalogItem = 1,
@ -17,7 +30,7 @@ internal enum DlcType
internal class ProgramSelection
{
internal bool Enabled;
internal bool Usable = true;
internal Platform Platform = (Platform)(-1);
internal string Id = "0";
internal string Name = "Program";
@ -31,8 +44,6 @@ internal class ProgramSelection
internal string RootDirectory;
internal List<string> DllDirectories;
internal bool IsSteam;
internal readonly SortedList<string, (DlcType type, string name, string icon)> AllDlc = new(AppIdComparer.Comparer);
internal readonly SortedList<string, (DlcType type, string name, string icon)> SelectedDlc = new(AppIdComparer.Comparer);
internal readonly List<Tuple<string, string, SortedList<string, (DlcType type, string name, string icon)>>> ExtraDlc = new(); // for Paradox Launcher
@ -119,15 +130,13 @@ internal class ProgramSelection
internal static List<ProgramSelection> AllSafe => All.ToList();
internal static List<ProgramSelection> AllUsable => All.FindAll(s => s.Usable);
internal static List<ProgramSelection> AllEnabled => AllSafe.FindAll(s => s.Enabled);
internal static List<ProgramSelection> AllUsableEnabled => AllUsable.FindAll(s => s.Enabled);
internal static ProgramSelection FromId(string gameId) => AllUsable.Find(s => s.Id == gameId);
internal static ProgramSelection FromId(string gameId) => AllSafe.Find(s => s.Id == gameId);
internal static (string gameId, (DlcType type, string name, string icon) app)? GetDlcFromId(string dlcId)
{
foreach (ProgramSelection selection in AllUsable)
foreach (ProgramSelection selection in AllSafe)
foreach (KeyValuePair<string, (DlcType type, string name, string icon)> pair in selection.AllDlc)
if (pair.Key == dlcId) return (selection.Id, pair.Value);
return null;

View file

@ -147,6 +147,7 @@ internal static class SteamCMD
}
internal static readonly string AppCachePath = DirectoryPath + @"\appcache";
internal static readonly string ConfigPath = DirectoryPath + @"\config";
internal static readonly string DumpsPath = DirectoryPath + @"\dumps";
internal static readonly string LogsPath = DirectoryPath + @"\logs";
internal static readonly string SteamAppsPath = DirectoryPath + @"\steamapps";
@ -156,6 +157,21 @@ internal static class SteamCMD
if (!Directory.Exists(DirectoryPath)) return;
await Kill();
try
{
string[] ntfsFiles = Directory.GetFiles(DirectoryPath, "*.ntfs_transaction_failed");
foreach (string file in ntfsFiles) File.Delete(file);
}
catch { }
try
{
if (Directory.Exists(ConfigPath))
{
string[] tmpFiles = Directory.GetFiles(ConfigPath, "*.tmp");
foreach (string file in tmpFiles) File.Delete(file);
}
}
catch { }
try
{
string[] oldFiles = Directory.GetFiles(DirectoryPath, "*.old");
foreach (string file in oldFiles) File.Delete(file);

View file

@ -27,7 +27,7 @@ internal static class SteamStore
{
if (Program.Canceled) return null;
string cacheFile = ProgramData.AppInfoPath + @$"\{appId}.json";
bool cachedExists = Directory.Exists(Directory.GetDirectoryRoot(cacheFile)) && File.Exists(cacheFile);
bool cachedExists = File.Exists(cacheFile);
if (!cachedExists || ProgramData.CheckCooldown(appId, isDlc ? COOLDOWN_DLC : COOLDOWN_GAME))
{
string response = await HttpClientManager.EnsureGet($"https://store.steampowered.com/api/appdetails?appids={appId}");

View file

@ -19,13 +19,16 @@ internal static class Diagnostics
}
}
internal static string GetNotepadPath() => NotepadPlusPlusPath is not null ? NotepadPlusPlusPath + @"\notepad++.exe"
: Environment.GetFolderPath(Environment.SpecialFolder.Windows) + @"\notepad.exe";
internal static string GetNotepadPath()
{
string npp = NotepadPlusPlusPath + @"\notepad++.exe";
return File.Exists(npp) ? npp : Environment.GetFolderPath(Environment.SpecialFolder.Windows) + @"\notepad.exe";
}
internal static void OpenFileInNotepad(string path)
{
string npp = NotepadPlusPlusPath + @"\notepad++.exe";
if (Directory.Exists(NotepadPlusPlusPath) && File.Exists(npp))
if (File.Exists(npp))
OpenFileInNotepadPlusPlus(npp, path);
else
OpenFileInWindowsNotepad(path);

View file

@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
@ -18,6 +20,8 @@ internal static class ProgramData
internal static readonly string CooldownPath = DirectoryPath + @"\cooldown";
internal static readonly string ChoicesPath = DirectoryPath + @"\choices.txt";
internal static async Task Setup() => await Task.Run(() =>
{
if (Directory.Exists(DirectoryPathOld))
@ -73,4 +77,25 @@ internal static class ProgramData
}
catch { }
}
internal static List<string> ReadChoices()
{
if (!File.Exists(ChoicesPath)) return new();
try
{
return File.ReadAllLines(ChoicesPath).ToList();
}
catch
{
return new();
}
}
internal static void WriteChoices(List<string> choices)
{
try
{
File.WriteAllLines(ChoicesPath, choices.ToArray());
}
catch { }
}
}