tools/installer: standardize output paths

This standardizes output paths to conform with shipped TRX data.
Folders and files created within the target folder will be in
lower-case; PCX files will be copied to a sub-directory within images
as TRX ships with custom images, and this as a result keeps the data
folder tidy.
This commit is contained in:
lahm86 2025-03-25 18:51:58 +00:00
parent 24fb920cd1
commit 5fb3f84fed
5 changed files with 34 additions and 9 deletions

View file

@ -37,7 +37,8 @@ public class CDRomInstallSource : BaseInstallSource
sourceDirectory,
targetDirectory,
progress,
file => filterRegex.IsMatch(file)
file => filterRegex.IsMatch(file),
path => ConvertTargetPath(path)
);
}

View file

@ -82,7 +82,8 @@ public class GOGInstallSource : BaseInstallSource
});
foreach (var path in filesToExtract)
{
var targetPath = Path.Combine(targetDirectory, path);
var relPath = ConvertTargetPath(path);
var targetPath = Path.Combine(targetDirectory, relPath);
if (!File.Exists(targetPath))
{
Directory.CreateDirectory(Path.GetDirectoryName(targetPath)!);
@ -100,7 +101,7 @@ public class GOGInstallSource : BaseInstallSource
{
MaximumValue = filesToExtract.Count(),
CurrentValue = ++currentProgress,
Description = string.Format(Language.Instance.Controls!["progress_extracting"], path)
Description = string.Format(Language.Instance.Controls!["progress_extracting"], relPath)
});
}
}

View file

@ -38,7 +38,8 @@ public class TombATIInstallSource : BaseInstallSource
sourceDirectory,
targetDirectory,
progress,
file => filterRegex.IsMatch(file)
file => filterRegex.IsMatch(file),
path => ConvertTargetPath(path)
);
}

View file

@ -35,4 +35,22 @@ public abstract class BaseInstallSource : IInstallSource
public abstract bool IsDownloadingExpansionNeeded(string sourceDirectory);
public abstract bool IsGameFound(string sourceDirectory);
public static string ConvertTargetPath(string relPath)
{
string ext = Path.GetExtension(relPath).ToLower();
switch (ext)
{
case ".pcx":
relPath = @$"data\images\og\{Path.GetFileName(relPath)}";
break;
case ".json5":
case ".exe":
return relPath;
default:
break;
}
return relPath.ToLower();
}
}

View file

@ -21,6 +21,7 @@ public static class InstallUtils
string targetDirectory,
IProgress<InstallProgress> progress,
Func<string, bool>? filterCallback = null,
Func<string, string>? targetCallback = null,
Func<string, bool>? overwriteCallback = null
)
{
@ -37,6 +38,10 @@ public static class InstallUtils
continue;
}
var relPath = Path.GetRelativePath(sourceDirectory, sourcePath);
if (targetCallback is not null)
{
relPath = targetCallback(relPath) ?? relPath;
}
var targetPath = Path.Combine(targetDirectory, relPath);
var isSamePath = string.Equals(Path.GetFullPath(sourcePath), Path.GetFullPath(targetPath), StringComparison.OrdinalIgnoreCase);
if (!File.Exists(targetPath) || (overwriteCallback is not null && overwriteCallback(sourcePath) && !isSamePath))
@ -129,9 +134,8 @@ public static class InstallUtils
{
continue;
}
var targetPath = Path.Combine(
targetDirectory,
new Regex(@"[\\/]").Replace(entry.FullName, Path.DirectorySeparatorChar.ToString()));
var relPath = BaseInstallSource.ConvertTargetPath(new Regex(@"[\\/]").Replace(entry.FullName, Path.DirectorySeparatorChar.ToString()));
var targetPath = Path.Combine(targetDirectory, relPath);
if (!File.Exists(targetPath) || overwrite)
{
@ -139,7 +143,7 @@ public static class InstallUtils
{
CurrentValue = currentProgress,
MaximumValue = maximumProgress,
Description = string.Format(Language.Instance.Controls!["progress_extracting"], entry.FullName),
Description = string.Format(Language.Instance.Controls!["progress_extracting"], relPath),
});
Directory.CreateDirectory(Path.GetDirectoryName(targetPath)!);
@ -151,7 +155,7 @@ public static class InstallUtils
{
CurrentValue = currentProgress,
MaximumValue = maximumProgress,
Description = string.Format(Language.Instance.Controls!["progress_extracting_skipped"], entry.FullName),
Description = string.Format(Language.Instance.Controls!["progress_extracting_skipped"], relPath),
});
}