cleaning up, final touches
This commit is contained in:
parent
7cb38f2723
commit
686bb4f50e
7 changed files with 90 additions and 88 deletions
24
CreamInstaller/Classes/Diagnostics.cs
Normal file
24
CreamInstaller/Classes/Diagnostics.cs
Normal file
|
@ -0,0 +1,24 @@
|
|||
using System.Diagnostics;
|
||||
|
||||
namespace CreamInstaller.Classes;
|
||||
|
||||
internal static class Diagnostics
|
||||
{
|
||||
internal static void OpenFileInNotepad(string path) => Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = "notepad.exe",
|
||||
Arguments = path
|
||||
});
|
||||
|
||||
internal static void OpenDirectoryInFileExplorer(string path) => Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = "explorer.exe",
|
||||
Arguments = path
|
||||
});
|
||||
|
||||
internal static void OpenUrlInInternetBrowser(string url) => Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = url,
|
||||
UseShellExecute = true
|
||||
});
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace CreamInstaller.Classes;
|
||||
|
||||
internal static class FileGrabber
|
||||
{
|
||||
internal static string steamInstallPath = null;
|
||||
internal static string SteamInstallPath
|
||||
{
|
||||
get
|
||||
{
|
||||
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;
|
||||
return steamInstallPath;
|
||||
}
|
||||
}
|
||||
|
||||
internal static string paradoxLauncherInstallPath = null;
|
||||
internal static string ParadoxLauncherInstallPath
|
||||
{
|
||||
get
|
||||
{
|
||||
paradoxLauncherInstallPath ??= Registry.GetValue(@"HKEY_CURRENT_USER\Software\Paradox Interactive\Paradox Launcher v2", "LauncherInstallation", null) as string;
|
||||
return paradoxLauncherInstallPath;
|
||||
}
|
||||
}
|
||||
|
||||
internal static void GetApiComponents(this string directory, out string api, out string api_o, out string api64, out string api64_o, out string cApi)
|
||||
{
|
||||
api = directory + @"\steam_api.dll";
|
||||
api_o = directory + @"\steam_api_o.dll";
|
||||
api64 = directory + @"\steam_api64.dll";
|
||||
api64_o = directory + @"\steam_api64_o.dll";
|
||||
cApi = directory + @"\cream_api.ini";
|
||||
}
|
||||
|
||||
internal static bool IsFilePathLocked(this string filePath)
|
||||
{
|
||||
try { File.Open(filePath, FileMode.Open, FileAccess.ReadWrite, FileShare.None).Close(); }
|
||||
catch (FileNotFoundException) { return false; }
|
||||
catch (IOException) { return true; }
|
||||
return false;
|
||||
}
|
||||
|
||||
internal static void OpenFileInNotepad(string path) => Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = "notepad.exe",
|
||||
Arguments = path
|
||||
});
|
||||
|
||||
internal static void OpenDirectoryInFileExplorer(string path) => Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = "explorer.exe",
|
||||
Arguments = path
|
||||
});
|
||||
|
||||
internal static void OpenUrlInInternetBrowser(string url) => Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = url,
|
||||
UseShellExecute = true
|
||||
});
|
||||
}
|
|
@ -54,9 +54,9 @@ internal static class HttpClientManager
|
|||
"//div[@class='recommendation']/div/a");
|
||||
if (nodes is not null)
|
||||
foreach (HtmlNode node in nodes)
|
||||
if (int.TryParse(node.Attributes["data-ds-appid"]?.Value, out int dlcAppId) && !dlcIds.Contains(dlcAppId))
|
||||
if (int.TryParse(node.Attributes?["data-ds-appid"]?.Value, out int dlcAppId) && !dlcIds.Contains(dlcAppId))
|
||||
dlcIds.Add(dlcAppId);
|
||||
}
|
||||
|
||||
internal static void Cleanup() => httpClient.Dispose();
|
||||
internal static void Dispose() => httpClient.Dispose();
|
||||
}
|
||||
|
|
|
@ -7,15 +7,38 @@ using System.Threading.Tasks;
|
|||
|
||||
using Gameloop.Vdf.Linq;
|
||||
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace CreamInstaller.Classes;
|
||||
|
||||
internal static class SteamLibrary
|
||||
{
|
||||
internal static string paradoxLauncherInstallPath = null;
|
||||
internal static string ParadoxLauncherInstallPath
|
||||
{
|
||||
get
|
||||
{
|
||||
paradoxLauncherInstallPath ??= Registry.GetValue(@"HKEY_CURRENT_USER\Software\Paradox Interactive\Paradox Launcher v2", "LauncherInstallation", null) as string;
|
||||
return paradoxLauncherInstallPath;
|
||||
}
|
||||
}
|
||||
|
||||
internal static string steamInstallPath = null;
|
||||
internal static string SteamInstallPath
|
||||
{
|
||||
get
|
||||
{
|
||||
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;
|
||||
return steamInstallPath;
|
||||
}
|
||||
}
|
||||
|
||||
internal static async Task<List<string>> GetLibraryDirectories() => await Task.Run(() =>
|
||||
{
|
||||
List<string> gameDirectories = new();
|
||||
if (Program.Canceled) return gameDirectories;
|
||||
string steamInstallPath = FileGrabber.SteamInstallPath;
|
||||
string steamInstallPath = SteamInstallPath;
|
||||
if (steamInstallPath != null && Directory.Exists(steamInstallPath))
|
||||
{
|
||||
string libraryFolder = steamInstallPath + @"\steamapps";
|
||||
|
|
|
@ -17,4 +17,11 @@ internal class CustomForm : Form
|
|||
return handleParam;
|
||||
}
|
||||
}
|
||||
|
||||
internal void InheritLocation(Form fromForm)
|
||||
{
|
||||
int X = fromForm.Location.X + fromForm.Size.Width / 2 - Size.Width / 2;
|
||||
int Y = fromForm.Location.Y + fromForm.Size.Height / 2 - Size.Height / 2;
|
||||
Location = new(X, Y);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,8 +83,8 @@ internal partial class SelectForm : CustomForm
|
|||
{
|
||||
if (Program.Canceled) return;
|
||||
List<Tuple<int, string, string, int, string>> applicablePrograms = new();
|
||||
if (Directory.Exists(FileGrabber.ParadoxLauncherInstallPath))
|
||||
applicablePrograms.Add(new(0, "Paradox Launcher", "", 0, FileGrabber.ParadoxLauncherInstallPath));
|
||||
if (Directory.Exists(SteamLibrary.ParadoxLauncherInstallPath))
|
||||
applicablePrograms.Add(new(0, "Paradox Launcher", "", 0, SteamLibrary.ParadoxLauncherInstallPath));
|
||||
List<string> gameLibraryDirectories = await SteamLibrary.GetLibraryDirectories();
|
||||
foreach (string libraryDirectory in gameLibraryDirectories)
|
||||
{
|
||||
|
@ -393,9 +393,9 @@ internal partial class SelectForm : CustomForm
|
|||
Dictionary<string, Image> images = new();
|
||||
Task.Run(async () =>
|
||||
{
|
||||
if (Directory.Exists(FileGrabber.ParadoxLauncherInstallPath))
|
||||
if (Directory.Exists(SteamLibrary.ParadoxLauncherInstallPath))
|
||||
{
|
||||
foreach (string file in Directory.GetFiles(FileGrabber.ParadoxLauncherInstallPath, "*.exe"))
|
||||
foreach (string file in Directory.GetFiles(SteamLibrary.ParadoxLauncherInstallPath, "*.exe"))
|
||||
{
|
||||
images["Paradox Launcher"] = IconGrabber.GetFileIconImage(file);
|
||||
break;
|
||||
|
@ -449,7 +449,7 @@ internal partial class SelectForm : CustomForm
|
|||
{
|
||||
nodeContextMenu.Items.Add(new ToolStripSeparator());
|
||||
nodeContextMenu.Items.Add(new ToolStripMenuItem("Open AppInfo", Image("Notepad"),
|
||||
new EventHandler((sender, e) => FileGrabber.OpenFileInNotepad(appInfo))));
|
||||
new EventHandler((sender, e) => Diagnostics.OpenFileInNotepad(appInfo))));
|
||||
nodeContextMenu.Items.Add(new ToolStripMenuItem("Refresh AppInfo", Image("Command Prompt"),
|
||||
new EventHandler((sender, e) =>
|
||||
{
|
||||
|
@ -519,25 +519,25 @@ internal partial class SelectForm : CustomForm
|
|||
}
|
||||
nodeContextMenu.Items.Add(new ToolStripSeparator());
|
||||
nodeContextMenu.Items.Add(new ToolStripMenuItem("Open Root Directory", Image("File Explorer"),
|
||||
new EventHandler((sender, e) => FileGrabber.OpenDirectoryInFileExplorer(selection.RootDirectory))));
|
||||
new EventHandler((sender, e) => Diagnostics.OpenDirectoryInFileExplorer(selection.RootDirectory))));
|
||||
for (int i = 0; i < selection.SteamApiDllDirectories.Count; i++)
|
||||
{
|
||||
string directory = selection.SteamApiDllDirectories[i];
|
||||
nodeContextMenu.Items.Add(new ToolStripMenuItem($"Open Steamworks Directory ({i + 1})", Image("File Explorer"),
|
||||
new EventHandler((sender, e) => FileGrabber.OpenDirectoryInFileExplorer(directory))));
|
||||
new EventHandler((sender, e) => Diagnostics.OpenDirectoryInFileExplorer(directory))));
|
||||
}
|
||||
}
|
||||
if (appId != 0)
|
||||
{
|
||||
nodeContextMenu.Items.Add(new ToolStripSeparator());
|
||||
nodeContextMenu.Items.Add(new ToolStripMenuItem("Open SteamDB", Image("SteamDB"),
|
||||
new EventHandler((sender, e) => FileGrabber.OpenUrlInInternetBrowser("https://steamdb.info/app/" + appId))));
|
||||
new EventHandler((sender, e) => Diagnostics.OpenUrlInInternetBrowser("https://steamdb.info/app/" + appId))));
|
||||
nodeContextMenu.Items.Add(new ToolStripMenuItem("Open Steam Store", Image("Steam Store"),
|
||||
new EventHandler((sender, e) => FileGrabber.OpenUrlInInternetBrowser("https://store.steampowered.com/app/" + appId))));
|
||||
new EventHandler((sender, e) => Diagnostics.OpenUrlInInternetBrowser("https://store.steampowered.com/app/" + appId))));
|
||||
if (selection is not null)
|
||||
{
|
||||
ToolStripMenuItem steamCommunity = new("Open Steam Community", Image("ClientIcon_" + node.Name),
|
||||
new EventHandler((sender, e) => FileGrabber.OpenUrlInInternetBrowser("https://steamcommunity.com/app/" + appId)));
|
||||
new EventHandler((sender, e) => Diagnostics.OpenUrlInInternetBrowser("https://steamcommunity.com/app/" + appId)));
|
||||
nodeContextMenu.Items.Add(steamCommunity);
|
||||
if (steamCommunity.Image is null)
|
||||
{
|
||||
|
@ -603,7 +603,7 @@ internal partial class SelectForm : CustomForm
|
|||
installForm.ShowDialog();
|
||||
if (installForm.Reselecting)
|
||||
{
|
||||
this.InheritLocation(installForm);
|
||||
InheritLocation(installForm);
|
||||
Show();
|
||||
OnLoad();
|
||||
}
|
||||
|
|
|
@ -34,6 +34,14 @@ internal static class Program
|
|||
return false;
|
||||
}
|
||||
|
||||
internal static bool IsFilePathLocked(this string filePath)
|
||||
{
|
||||
try { File.Open(filePath, FileMode.Open, FileAccess.ReadWrite, FileShare.None).Close(); }
|
||||
catch (FileNotFoundException) { return false; }
|
||||
catch (IOException) { return true; }
|
||||
return false;
|
||||
}
|
||||
|
||||
internal static bool IsProgramRunningDialog(Form form, ProgramSelection selection)
|
||||
{
|
||||
if (selection.AreSteamApiDllsLocked)
|
||||
|
@ -48,6 +56,15 @@ internal static class Program
|
|||
return false;
|
||||
}
|
||||
|
||||
internal static void GetApiComponents(this string directory, out string api, out string api_o, out string api64, out string api64_o, out string cApi)
|
||||
{
|
||||
api = directory + @"\steam_api.dll";
|
||||
api_o = directory + @"\steam_api_o.dll";
|
||||
api64 = directory + @"\steam_api64.dll";
|
||||
api64_o = directory + @"\steam_api64_o.dll";
|
||||
cApi = directory + @"\cream_api.ini";
|
||||
}
|
||||
|
||||
[STAThread]
|
||||
private static void Main()
|
||||
{
|
||||
|
@ -76,20 +93,16 @@ internal static class Program
|
|||
|
||||
internal static void Invoke(this Control control, MethodInvoker methodInvoker) => control.Invoke(methodInvoker);
|
||||
|
||||
internal static void InheritLocation(this Form form, Form fromForm)
|
||||
{
|
||||
int X = fromForm.Location.X + fromForm.Size.Width / 2 - form.Size.Width / 2;
|
||||
int Y = fromForm.Location.Y + fromForm.Size.Height / 2 - form.Size.Height / 2;
|
||||
form.Location = new(X, Y);
|
||||
}
|
||||
|
||||
internal static bool Canceled = false;
|
||||
internal static async void Cleanup(bool cancel = true)
|
||||
{
|
||||
Canceled = cancel;
|
||||
HttpClientManager.Cleanup();
|
||||
await SteamCMD.Cleanup();
|
||||
}
|
||||
|
||||
private static void OnApplicationExit(object s, EventArgs e) => Cleanup();
|
||||
private static void OnApplicationExit(object s, EventArgs e)
|
||||
{
|
||||
Cleanup();
|
||||
HttpClientManager.Dispose();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue