Skip to content

Commit

Permalink
installer: use existing installation path (#1411)
Browse files Browse the repository at this point in the history
The existing installation path - if it exists - will be suggested when
performing an upgrade by selecting the TR1X install source.

Resolves #1350.
  • Loading branch information
lahm86 authored Jul 12, 2024
1 parent 9c6a569 commit c034908
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- added unobtainable secrets stat support in the gameflow (#1379)
- added a wireframe mode
- changed console caret blinking rate (#1377)
- changed the TR1X install source in the installer to suggest using the existing installation directory (#1350)
- fixed config tool and installer missing icons (#1358, regression from 4.0)
- fixed looking forward too far causing an upside down camera frame (#1338)
- fixed the enemy bear behavior in demo mode (#1370, regression since 2.16)
Expand Down
2 changes: 1 addition & 1 deletion tools/installer/Installer/Installers/BaseInstallSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public virtual string ImageSource
public abstract bool IsImportingSavesSupported { get; }
public abstract string SourceName { get; }

public string SuggestedInstallationDirectory
public virtual string SuggestedInstallationDirectory
{
get
{
Expand Down
4 changes: 1 addition & 3 deletions tools/installer/Installer/Installers/InstallExecutor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Installer.Models;
using Microsoft.Win32;
using System;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -66,8 +65,7 @@ protected async Task CopyOriginalGameFiles(string sourceDirectory, string target

protected static async Task CopyTR1XFiles(string targetDirectory, IProgress<InstallProgress> progress)
{
using var key = Registry.CurrentUser.CreateSubKey(@"Software\Tomb1Main");
key?.SetValue("InstallPath", targetDirectory);
InstallUtils.StoreInstallationPath(targetDirectory);

progress.Report(new InstallProgress
{
Expand Down
53 changes: 50 additions & 3 deletions tools/installer/Installer/Installers/InstallUtils.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
using Installer.Utils;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using Installer.Utils;
using System.Threading.Tasks;

namespace Installer.Installers;

public static class InstallUtils
{
private static readonly string _legacyStorageKey = @"Software\Tomb1Main";
private static readonly string _registryStorageKey = @"Software\TR1X";

public static async Task CopyDirectoryTree(
string sourceDirectory,
string targetDirectory,
Expand Down Expand Up @@ -185,4 +189,47 @@ var shortcutPath in Directory.EnumerateFiles(
}
}
}

public static void StoreInstallationPath(string installPath)
{
RenameLegacyStorage();
using var key = Registry.CurrentUser.CreateSubKey(_registryStorageKey);
key?.SetValue("InstallPath", installPath);
}

public static string? GetPreviousInstallationPath()
{
RenameLegacyStorage();
using var key = Registry.CurrentUser.OpenSubKey(_registryStorageKey);
return key?.GetValue("InstallPath")?.ToString();
}

private static void RenameLegacyStorage()
{
// Added in #1411 - to be removed in the future.
using var legacyKey = Registry.CurrentUser.OpenSubKey(_legacyStorageKey);
if (legacyKey is null)
{
return;
}

using var currentKey = Registry.CurrentUser.OpenSubKey(_registryStorageKey);
if (currentKey is not null)
{
return;
}

using var destinationKey = Registry.CurrentUser.CreateSubKey(_registryStorageKey);
foreach (string valueName in legacyKey.GetValueNames())
{
object? objValue = legacyKey.GetValue(valueName);
if (objValue is not null)
{
RegistryValueKind valueKind = legacyKey.GetValueKind(valueName);
destinationKey.SetValue(valueName, objValue, valueKind);
}
}

Registry.CurrentUser.DeleteSubKey(_legacyStorageKey);
}
}
19 changes: 11 additions & 8 deletions tools/installer/Installer/Installers/TR1XInstallSource.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.IO;
Expand All @@ -13,14 +12,10 @@ public override IEnumerable<string> DirectoriesToTry
{
get
{
using var key = Registry.CurrentUser.OpenSubKey(@"Software\Tomb1Main");
if (key is not null)
var previousPath = InstallUtils.GetPreviousInstallationPath();
if (previousPath is not null)
{
var value = key.GetValue("InstallPath")?.ToString();
if (value is not null)
{
yield return value;
}
yield return previousPath;
}

foreach (var path in InstallUtils.GetDesktopShortcutDirectories())
Expand All @@ -30,6 +25,14 @@ public override IEnumerable<string> DirectoriesToTry
}
}

public override string SuggestedInstallationDirectory
{
get
{
return InstallUtils.GetPreviousInstallationPath() ?? base.SuggestedInstallationDirectory;
}
}

public override bool IsImportingSavesSupported => true;
public override string SourceName => "TR1X";

Expand Down

0 comments on commit c034908

Please sign in to comment.