This commit is contained in:
pointfeev 2021-11-13 20:49:28 -05:00
parent ed7d1a6757
commit fb100c10ae
No known key found for this signature in database
GPG key ID: AA14DC36C4D7D13C
6 changed files with 97 additions and 39 deletions

View file

@ -6,7 +6,7 @@
<UseWindowsForms>true</UseWindowsForms>
<ApplicationIcon>ini.ico</ApplicationIcon>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
<Version>2.0.2.1</Version>
<Version>2.0.2.2</Version>
<PackageIcon>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>
@ -48,6 +48,7 @@
<ItemGroup>
<PackageReference Include="Gameloop.Vdf" Version="0.6.1" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.38" />
<PackageReference Include="Onova" Version="2.6.2" />
</ItemGroup>

View file

@ -37,6 +37,7 @@ namespace CreamInstaller
this.updateButton = new System.Windows.Forms.Button();
this.ignoreButton = new System.Windows.Forms.Button();
this.progressBar1 = new System.Windows.Forms.ProgressBar();
this.changelogTreeView = new System.Windows.Forms.TreeView();
this.SuspendLayout();
//
// label1
@ -78,11 +79,19 @@ namespace CreamInstaller
this.progressBar1.TabIndex = 4;
this.progressBar1.Visible = false;
//
// changelogTreeView
//
this.changelogTreeView.Location = new System.Drawing.Point(12, 70);
this.changelogTreeView.Name = "changelogTreeView";
this.changelogTreeView.Size = new System.Drawing.Size(380, 179);
this.changelogTreeView.TabIndex = 5;
//
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(404, 46);
this.ClientSize = new System.Drawing.Size(404, 261);
this.Controls.Add(this.changelogTreeView);
this.Controls.Add(this.progressBar1);
this.Controls.Add(this.ignoreButton);
this.Controls.Add(this.updateButton);
@ -91,6 +100,7 @@ namespace CreamInstaller
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MaximumSize = new System.Drawing.Size(420, 300);
this.MinimizeBox = false;
this.Name = "MainForm";
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
@ -108,6 +118,7 @@ namespace CreamInstaller
private Button updateButton;
private Button ignoreButton;
private ProgressBar progressBar1;
private TreeView changelogTreeView;
}
}

View file

@ -1,10 +1,14 @@
using Onova;
using HtmlAgilityPack;
using Onova;
using Onova.Models;
using Onova.Services;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CreamInstaller
@ -33,26 +37,31 @@ namespace CreamInstaller
Close();
}
private static readonly HttpClient httpClient = new();
private static UpdateManager updateManager = null;
private static Version latestVersion = null;
private static IReadOnlyList<Version> versions;
private async void OnLoad()
{
Size = new Size(420, 85);
Size = new(420, 85);
progressBar1.Visible = false;
ignoreButton.Visible = true;
updateButton.Text = "Update";
updateButton.Click -= OnUpdateCancel;
label1.Text = "Checking for updates . . .";
changelogTreeView.Visible = false;
changelogTreeView.Location = new(12, 41);
changelogTreeView.Size = new(380, 208);
GithubPackageResolver resolver = new GithubPackageResolver("pointfeev", "CreamInstaller", "CreamInstaller.zip");
ZipPackageExtractor extractor = new ZipPackageExtractor();
updateManager = new UpdateManager(AssemblyMetadata.FromAssembly(Program.EntryAssembly, Program.CurrentProcessFilePath), resolver, extractor);
GithubPackageResolver resolver = new("pointfeev", "CreamInstaller", "CreamInstaller.zip");
ZipPackageExtractor extractor = new();
updateManager = new(AssemblyMetadata.FromAssembly(Program.EntryAssembly, Program.CurrentProcessFilePath), resolver, extractor);
if (latestVersion is null)
{
CheckForUpdatesResult checkForUpdatesResult = null;
cancellationTokenSource = new CancellationTokenSource();
cancellationTokenSource = new();
try
{
checkForUpdatesResult = await updateManager.CheckForUpdatesAsync(cancellationTokenSource.Token);
@ -61,6 +70,7 @@ namespace CreamInstaller
if (checkForUpdatesResult.CanUpdate)
{
latestVersion = checkForUpdatesResult.LastVersion;
versions = checkForUpdatesResult.Versions;
}
}
catch { }
@ -73,10 +83,50 @@ namespace CreamInstaller
}
else
{
Size = new(420, 300);
label1.Text = $"An update is available: v{latestVersion}";
ignoreButton.Enabled = true;
updateButton.Enabled = true;
updateButton.Click += new EventHandler(OnUpdate);
updateButton.Click += new(OnUpdate);
changelogTreeView.Visible = true;
Version currentVersion = new(Application.ProductVersion);
foreach (Version version in versions)
{
if (version > currentVersion && !changelogTreeView.Nodes.ContainsKey(version.ToString()))
{
TreeNode root = new($"v{version}");
root.Name = version.ToString();
changelogTreeView.Nodes.Add(root);
new Task(async () =>
{
try
{
string url = $"https://github.com/pointfeev/CreamInstaller/releases/tag/v{version}";
using HttpRequestMessage request = new(HttpMethod.Get, url);
using HttpResponseMessage response = await httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);
response.EnsureSuccessStatusCode();
using Stream stream = await response.Content.ReadAsStreamAsync();
using StreamReader reader = new(stream);
HtmlAgilityPack.HtmlDocument document = new();
document.LoadHtml(reader.ReadToEnd());
foreach (HtmlNode node in document.DocumentNode.SelectNodes("//div[@data-test-selector='body-content']/ul/li"))
{
changelogTreeView.Invoke((MethodInvoker)delegate
{
TreeNode change = new();
change.Text = $"{node.InnerText}";
root.Nodes.Add(change);
root.Expand();
});
}
}
catch
{
changelogTreeView.Nodes.Remove(root);
}
}).Start();
}
}
}
}
@ -103,22 +153,23 @@ namespace CreamInstaller
private async void OnUpdate(object sender, EventArgs e)
{
Size = new Size(420, 115);
progressBar1.Visible = true;
ignoreButton.Visible = false;
updateButton.Text = "Cancel";
updateButton.Click -= OnUpdate;
updateButton.Click += new EventHandler(OnUpdateCancel);
updateButton.Click += new(OnUpdateCancel);
changelogTreeView.Location = new(12, 70);
changelogTreeView.Size = new(380, 179);
Progress<double> progress = new Progress<double>();
progress.ProgressChanged += new EventHandler<double>(delegate (object sender, double _progress)
Progress<double> progress = new();
progress.ProgressChanged += new(delegate (object sender, double _progress)
{
label1.Text = $"Updating . . . {(int)_progress}%";
progressBar1.Value = (int)_progress;
});
label1.Text = "Updating . . . ";
cancellationTokenSource = new CancellationTokenSource();
cancellationTokenSource = new();
try
{
await updateManager.PrepareUpdateAsync(latestVersion, progress, cancellationTokenSource.Token);

View file

@ -23,11 +23,11 @@ namespace CreamInstaller
Text = Program.ApplicationName;
}
private List<string> GameLibraryDirectories
private static List<string> GameLibraryDirectories
{
get
{
List<string> gameDirectories = new List<string>();
List<string> gameDirectories = new();
if (Program.Canceled) return gameDirectories;
string steamInstallPath = Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Valve\\Steam", "InstallPath", null) as string;
if (steamInstallPath == null) steamInstallPath = Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Valve\\Steam", "InstallPath", null) as string;
@ -55,7 +55,7 @@ namespace CreamInstaller
}
}
private bool GetDllDirectoriesFromGameDirectory(string gameDirectory, out List<string> dllDirectories)
private static bool GetDllDirectoriesFromGameDirectory(string gameDirectory, out List<string> dllDirectories)
{
dllDirectories = new();
if (Program.Canceled) return false;
@ -76,7 +76,7 @@ namespace CreamInstaller
return true;
}
private bool GetGamesFromLibraryDirectory(string libraryDirectory, out List<Tuple<int, string, string, int, string>> games)
private static bool GetGamesFromLibraryDirectory(string libraryDirectory, out List<Tuple<int, string, string, int, string>> games)
{
games = new();
if (Program.Canceled) return false;
@ -111,7 +111,6 @@ namespace CreamInstaller
}
private readonly List<TreeNode> treeNodes = new();
internal List<Task> RunningTasks = new();
private void GetCreamApiApplicablePrograms(IProgress<int> progress)
@ -134,9 +133,9 @@ namespace CreamInstaller
int buildId = program.Item4;
string directory = program.Item5;
if (Program.Canceled) return;
// easy anti cheat detects DLL changes, so skip those games
// EasyAntiCheat detects DLL changes, so skip those games
if (Directory.Exists(directory + @"\EasyAntiCheat")) continue;
// battleye in DayZ detects DLL changes, but not in Arma3?
// BattlEye in DayZ detects DLL changes, but not in Arma3?
if (name != "Arma 3" && Directory.Exists(directory + @"\BattlEye")) continue;
Task task = new(() =>
{
@ -156,8 +155,7 @@ namespace CreamInstaller
{
if (Program.Canceled) return;
string dlcName = null;
VProperty dlcAppInfo = null;
if (SteamCMD.GetAppInfo(id, out dlcAppInfo)) dlcName = dlcAppInfo?.Value?["common"]?["name"]?.ToString();
if (SteamCMD.GetAppInfo(id, out VProperty dlcAppInfo)) dlcName = dlcAppInfo?.Value?["common"]?["name"]?.ToString();
if (Program.Canceled) return;
if (string.IsNullOrWhiteSpace(dlcName)) return;
dlc[id] = dlcName;
@ -243,7 +241,7 @@ namespace CreamInstaller
label2.Visible = true;
progressBar1.Visible = true;
progressBar1.Value = 0;
groupBox1.Size = new Size(groupBox1.Size.Width, groupBox1.Size.Height - 44);
groupBox1.Size = new(groupBox1.Size.Width, groupBox1.Size.Height - 44);
bool setup = true;
int maxProgress = 0;
@ -284,7 +282,7 @@ namespace CreamInstaller
treeNode.Remove();
progressBar1.Value = 100;
groupBox1.Size = new Size(groupBox1.Size.Width, groupBox1.Size.Height + 44);
groupBox1.Size = new(groupBox1.Size.Width, groupBox1.Size.Height + 44);
label2.Visible = false;
progressBar1.Visible = false;
@ -397,7 +395,7 @@ namespace CreamInstaller
{
if (ProgramSelection.All.Count > 0)
{
foreach (ProgramSelection selection in ProgramSelection.AllSafe)
foreach (ProgramSelection selection in ProgramSelection.AllSafeEnabled)
{
if (!Program.IsProgramRunningDialog(this, selection))
{
@ -417,7 +415,7 @@ namespace CreamInstaller
}
int X = installForm.Location.X + installForm.Size.Width / 2 - Size.Width / 2;
int Y = installForm.Location.Y + installForm.Size.Height / 2 - Size.Height / 2;
Location = new Point(X, Y);
Location = new(X, Y);
Show();
}
else

View file

@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.IO.Compression;
using System.Reflection;
using System.Threading;
using System.Windows.Forms;
@ -28,7 +27,7 @@ namespace CreamInstaller
Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.ApplicationExit += new EventHandler(OnApplicationExit);
Application.ApplicationExit += new(OnApplicationExit);
retry:
try
{
@ -82,8 +81,6 @@ namespace CreamInstaller
public static List<ProgramSelection> ProgramSelections = new();
public static bool Canceled = false;
public static string OutputFile = null; // placeholder, won't exist in new system
public static ZipArchive OutputArchive = null; // placeholder, won't exist in new system
public static void Cleanup(bool cancel = true)
{

View file

@ -13,14 +13,14 @@ namespace CreamInstaller
{
public static class SteamCMD
{
public static string DirectoryPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\CreamInstaller";
public static string FilePath = DirectoryPath + @"\steamcmd.exe";
public static string ArchivePath = DirectoryPath + @"\steamcmd.zip";
public static string DllPath = DirectoryPath + @"\steamclient.dll";
public static string AppCachePath = DirectoryPath + @"\appcache";
public static string AppCacheAppInfoPath = AppCachePath + @"\appinfo.vdf";
public static string AppInfoPath = DirectoryPath + @"\appinfo";
public static string AppInfoVersionPath = AppInfoPath + @"\version.txt";
public static readonly string DirectoryPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\CreamInstaller";
public static readonly string FilePath = DirectoryPath + @"\steamcmd.exe";
public static readonly string ArchivePath = DirectoryPath + @"\steamcmd.zip";
public static readonly string DllPath = DirectoryPath + @"\steamclient.dll";
public static readonly string AppCachePath = DirectoryPath + @"\appcache";
public static readonly string AppCacheAppInfoPath = AppCachePath + @"\appinfo.vdf";
public static readonly string AppInfoPath = DirectoryPath + @"\appinfo";
public static readonly string AppInfoVersionPath = AppInfoPath + @"\version.txt";
public static bool Run(string command, out string output)
{