tools/installer: decouple shortcut and expansion logic

This decouples the shortcut creation so it can be used generically in
either game. It also allows for the expansion pack zip names to be
defined externally rather than guessing from the selected type.
This commit is contained in:
lahm86 2025-03-25 14:46:01 +00:00
parent cf8fc3d6bf
commit 417e7486c8
7 changed files with 33 additions and 15 deletions

View file

@ -1,4 +1,11 @@
{
"Game": "TR1X",
"AllowExpansionTypeSelection": true
"GoldGame": "TR1X - UB",
"GoldFileIdentifier": "cat.phd",
"AllowExpansionTypeSelection": true,
"ShortcutTitle": "Tomb Raider I: Community Edition",
"GoldZips": {
"0": "trub-music.zip",
"1": "trub-vanilla.zip"
}
}

View file

@ -82,10 +82,12 @@ public class InstallExecutor
protected static void CreateDesktopShortcut(string targetDirectory)
{
InstallUtils.CreateDesktopShortcut("TR1X", Path.Combine(targetDirectory, "TR1X.exe"));
if (File.Exists(Path.Combine(targetDirectory, "data", "cat.phd")))
string targetExe = Path.Combine(targetDirectory, TRXConstants.Instance.Exe);
InstallUtils.CreateDesktopShortcut(TRXConstants.Instance.Game!, TRXConstants.Instance.ShortcutTitle!, targetExe);
if (File.Exists(Path.Combine(targetDirectory, "data", TRXConstants.Instance.GoldFileIdentifier!)))
{
InstallUtils.CreateDesktopShortcut("TR1X - UB", Path.Combine(targetDirectory, "TR1X.exe"), new[] { "-gold" });
InstallUtils.CreateDesktopShortcut(TRXConstants.Instance.GoldGame!, TRXConstants.Instance.ShortcutTitle!,
targetExe, new[] { TRXConstants.Instance.GoldArgs! });
}
}
@ -96,8 +98,12 @@ public class InstallExecutor
protected static async Task DownloadExpansionFiles(string targetDirectory, ExpansionPackType type, IProgress<InstallProgress> progress)
{
await InstallUtils.DownloadZip(
$"{_resourceBaseURL}/trub-{type.ToString().ToLower()}.zip",
targetDirectory, progress);
string? zipName = null;
TRXConstants.Instance.GoldZips?.TryGetValue(type, out zipName);
if (zipName == null)
{
throw new ApplicationException(string.Format(Language.Instance.Controls!["progress_expansion_undefined"], type));
}
await InstallUtils.DownloadZip($"{_resourceBaseURL}/{zipName}", targetDirectory, progress);
}
}

View file

@ -69,11 +69,10 @@ public static class InstallUtils
}
}
public static void CreateDesktopShortcut(string name, string targetPath, string[]? args = null)
public static void CreateDesktopShortcut(string name, string title, string targetPath, string[]? args = null)
{
var shortcutPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), $"{name}.lnk");
// TODO: pass extra arg for this
ShortcutUtils.CreateShortcut(shortcutPath, targetPath, "Tomb Raider I: Community Edition", args);
ShortcutUtils.CreateShortcut(shortcutPath, targetPath, title, args);
}
public static async Task<byte[]> DownloadFile(string url, IProgress<InstallProgress> progress)

View file

@ -1,4 +1,3 @@
using System.Diagnostics;
using System.IO;
using System.Windows;
using System.Windows.Input;
@ -102,7 +101,7 @@ public class MainWindowViewModel : BaseLanguageViewModel
{
throw new NullReferenceException();
}
Process.Start(Path.Combine(_installSettings.TargetDirectory, "TR1X.exe"));
ProcessUtils.Start(Path.Combine(_installSettings.TargetDirectory, TRXConstants.Instance.Exe));
}
if (_finishSettings is not null && _finishSettings.OpenGameDirectory)
{
@ -110,7 +109,7 @@ public class MainWindowViewModel : BaseLanguageViewModel
{
throw new NullReferenceException();
}
Process.Start("explorer.exe", _installSettings.TargetDirectory);
ProcessUtils.Start(_installSettings.TargetDirectory);
}
window?.Close();
}

View file

@ -14,6 +14,11 @@ public class TRXConstants
}
public string? Game { get; set; }
public string? GoldGame { get; set; }
public string? GoldFileIdentifier { get; set; }
public string Exe => $"{Game}.exe";
public bool? AllowExpansionTypeSelection { get; set; }
public string? GoldArgs { get; set; }
public string? ShortcutTitle { get; set; }
public Dictionary<ExpansionPackType, string>? GoldZips { get; set; }
}

View file

@ -35,6 +35,7 @@
"progress_copying": "Copying {0}",
"progress_skipped": "Copying {0} - skipped",
"progress_init_download": "Initializing download of {0}",
"progress_expansion_undefined": "No target zip defined for expansion pack type {0}",
"progress_downloading": "Downloading {0}",
"progress_opening_zip": "Opening embedded ZIP",
"progress_zip_failure": "Could not open embedded ZIP.",

View file

@ -1,4 +1,5 @@
{
"Game": "TRX",
"AllowExpansionTypeSelection": false
"AllowExpansionTypeSelection": false,
"GoldArgs": "-gold"
}