Skip to content

Commit

Permalink
Add support for relative T3 FM install path when SU is portable
Browse files Browse the repository at this point in the history
  • Loading branch information
FenPhoenix committed Aug 25, 2023
1 parent 30409ac commit cf91afd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
6 changes: 3 additions & 3 deletions AngelLoader/Common/Paths.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,15 +343,15 @@ internal static string GetThiefBuddyExePath()
private const string _sneakyOptionsIni = "SneakyOptions.ini";
private static readonly Version _sneakyUpgradeMinimumPortableVersion = new(1, 1, 10, 519);

internal static string GetSneakyOptionsIni()
internal static (string SoIni, bool IsPortable) GetSneakyOptionsIni()
{
if (TryGetSneakyOptionsIniFromGameDir(out string soIni))
{
return soIni;
return (soIni, true);
}
else
{
return GetSneakyOptionsIniFromRegistry();
return (GetSneakyOptionsIniFromRegistry(), false);
}
}

Expand Down
23 changes: 21 additions & 2 deletions AngelLoader/GameConfigFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ internal static (Error Error, bool UseCentralSaves, string FMInstallPath,
string PrevFMSelectorValue, bool AlwaysShowLoader)
GetInfoFromSneakyOptionsIni()
{
string soIni = Paths.GetSneakyOptionsIni();
(string soIni, bool isPortable) = Paths.GetSneakyOptionsIni();
if (soIni.IsEmpty())
{
return (Error.SneakyOptionsNotFound, false, "", "", false);
Expand Down Expand Up @@ -271,6 +271,25 @@ internal static (Error Error, bool UseCentralSaves, string FMInstallPath,
}
}

if (isPortable && PathIsRelative(fmInstPath))
{
try
{
string? soIniDir = Path.GetDirectoryName(soIni);
if (soIniDir != null)
{
fmInstPath = RelativeToAbsolute(soIniDir, fmInstPath);
Directory.CreateDirectory(fmInstPath);
}
}
catch (Exception ex)
{
Log("Unable to resolve the relative path " + fmInstPath + " with the absolute path where " + soIni + " is contained. Returning blank path.", ex);
fmInstPath = "";
fmInstPathFound = false;
}
}

return fmInstPathFound
? (Error.None, !ignoreSavesKey, fmInstPath, prevFMSelectorValue, alwaysShowLoader)
: (Error.GeneralSneakyOptionsIniError, false, "", prevFMSelectorValue, alwaysShowLoader);
Expand Down Expand Up @@ -716,7 +735,7 @@ internal static bool SetT3FMSelector(bool resetSelector = false)
bool existingAlwaysShowKeyOverwritten = false;
int insertLineIndex = -1;

string soIni = Paths.GetSneakyOptionsIni();
(string soIni, _) = Paths.GetSneakyOptionsIni();
if (soIni.IsEmpty())
{
return false;
Expand Down

0 comments on commit cf91afd

Please sign in to comment.