TRX/tools/installer/TR2X_Installer/Installers/TR2XInstallSource.cs
lahm86 0618baebc9 tools/installer: create TR2 installer
This creates a TR2 installer in similar fashion to TR1. The installers
themselves are basically directory tree copiers, rather than having to
extract from BIN/ISO like TR1.
2025-03-30 12:34:54 +01:00

63 lines
1.8 KiB
C#

using System.IO;
using System.Text.RegularExpressions;
using TRX_InstallerLib.Installers;
using TRX_InstallerLib.Utils;
namespace TR2X_Installer.Installers;
public class TR2XInstallSource : GenericInstallSource
{
public override IEnumerable<string> DirectoriesToTry
{
get
{
var previousPath = InstallUtils.GetPreviousInstallationPath();
if (previousPath is not null)
{
yield return previousPath;
}
foreach (var path in InstallUtils.GetDesktopShortcutDirectories())
{
yield return path;
}
}
}
public override string SuggestedInstallationDirectory
{
get
{
return InstallUtils.GetPreviousInstallationPath() ?? base.SuggestedInstallationDirectory;
}
}
public override bool IsImportingSavesSupported => true;
public override string SourceName => "TR2X";
public override async Task CopyOriginalGameFiles(
string sourceDirectory,
string targetDirectory,
IProgress<InstallProgress> progress,
bool importSaves
)
{
var filterRegex = new Regex(importSaves ? @"(audio|data|fmv|music|saves)[\\/]|save.*\.\d+" : @"(audio|data|fmv|music)[\\/]", RegexOptions.IgnoreCase);
await InstallUtils.CopyDirectoryTree(
sourceDirectory,
targetDirectory,
progress,
file => filterRegex.IsMatch(file)
);
}
public override bool IsDownloadingExpansionNeeded(string sourceDirectory)
{
return !File.Exists(Path.Combine(sourceDirectory, "data", "title_gm.tr2"));
}
public override bool IsGameFound(string sourceDirectory)
{
return File.Exists(Path.Combine(sourceDirectory, "TR2X.exe"));
}
}