Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion scripts/check-i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
# This list IS the handoff to the translation pass. When a feature's UI is final: translate its keys
# across every Strings.<tag>.resx, clear them from here, and this check goes back to demanding full
# parity. Anything left here is untranslated in all 29 languages.
PENDING_TRANSLATION: set[str] = set()
PENDING_TRANSLATION: set[str] = {
"Fixes_Toast_Installed",
"Fixes_Toast_Installed_Body",
}
# Empty on purpose: every key is translated in all 29 languages, so the parity check above is
# unconditional. Add a key here ONLY while its feature's UI is still moving, and clear it again
# as soon as the translations land. Anything listed is English-only for every user.
Expand Down
1 change: 1 addition & 0 deletions src/LuaToolsGui/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public App()
services.AddSingleton<Services.AppInfo.LaunchOptionsService>();
services.AddSingleton<LuaInstaller>();
services.AddSingleton<SteamLibraryService>();
services.AddSingleton<InstallStateRepairService>();
services.AddSingleton<DonateKeysService>();
services.AddSingleton<AnalyticsService>();
services.AddSingleton<GithubProxy>();
Expand Down
2 changes: 2 additions & 0 deletions src/LuaToolsGui/Resources/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/LuaToolsGui/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@ This deletes the .lua files from Steam\config\stplug-in.</value></data>
<data name="Fixes_Toast_FixInstalled" xml:space="preserve"><value>Fix installed</value></data>
<data name="Fixes_Toast_FixInstalled_Body" xml:space="preserve"><value>{0} manifest installed.</value></data>
<data name="Fixes_Toast_GameNotFound" xml:space="preserve"><value>Game not found</value></data>
<data name="Fixes_Toast_Installed" xml:space="preserve"><value>Install repaired</value></data>
<data name="Fixes_Toast_Installed_Body" xml:space="preserve"><value>Steam could not find {0} where it expected it. It points at your existing folder now, so nothing gets downloaded again.</value></data>
<data name="Fixes_Toast_GameNotFound_Body" xml:space="preserve"><value>Install {0} in Steam first, then apply the fix.</value></data>
<data name="Fixes_Toast_PartiallyApplied" xml:space="preserve"><value>Fix partially applied</value></data>
<data name="Fixes_Toast_PartiallyApplied_Body" xml:space="preserve"><value>{0} file(s) couldn't be written. Close the game and try again.</value></data>
Expand Down
102 changes: 102 additions & 0 deletions src/LuaToolsGui/Services/InstallDirMatcher.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
using System.IO;

namespace LuaToolsGui.Services;

/// <summary>
/// Picks the folder a game is really installed in when nothing in Steam points at it.
/// </summary>
/// <remarks>
/// <para>
/// <c>installdir</c> is an appinfo value, and <see cref="SteamLibraryService.GetInstallDir"/> can only
/// follow what an appmanifest states. A folder that was renamed by hand, unpacked out of a repack, or
/// copied in from another drive never matches it, so the payload sits on disk unreachable: no install
/// row, and Steam re-downloads what is already there.
/// </para>
/// <para>
/// Matching is deliberately conservative — normalized-name equality only, plus a requirement that the
/// app's own launch executable is inside. That keeps sibling folders such as <c>Steamworks Shared</c>
/// from ever being mistaken for a game. No fuzzy distance, no "contains": with a fixed, small
/// candidate list, a wrong match is much more expensive than no match.
/// </para>
/// </remarks>
public static class InstallDirMatcher
{
/// <summary>
/// Best candidate folder under <paramref name="candidates"/> for <paramref name="installDir"/>, or
/// null. <paramref name="launchExe"/> is the appinfo launch executable, relative to the install root
/// (it can contain subfolders); when null, any executable will do.
/// </summary>
public static string? Match(string? installDir, string? launchExe, IEnumerable<string>? candidates)
{
if (candidates is null || string.IsNullOrWhiteSpace(installDir)) return null;

string wanted = Normalize(installDir);
if (wanted.Length == 0) return null;

string? best = null;
int bestScore = 0;

foreach (string candidate in candidates)
{
string name = Path.GetFileName(candidate.TrimEnd(Path.DirectorySeparatorChar));
if (name.Length == 0) continue;

int score = string.Equals(name, installDir.Trim(), StringComparison.OrdinalIgnoreCase)
? 2
: string.Equals(Normalize(name), wanted, StringComparison.Ordinal) ? 1 : 0;
if (score == 0 || score < bestScore) continue;

if (!HasLaunchExe(candidate, launchExe)) continue;

// Equal score: keep the first, so the result does not depend on enumeration order beyond it.
if (score > bestScore) { best = candidate; bestScore = score; }
}

return best;
}

/// <summary>
/// Lowercase, single-spaced, minus the decoration people add when they copy a game around: a
/// trailing <c>s</c> ("Astroneer" vs "Astroneers"), version tails ("v1.2.3", "(1.0)"), and
/// "copy"/"backup" suffixes. Applied to both sides, so it never makes two different games equal.
/// </summary>
internal static string Normalize(string value)
{
string s = value.Trim().ToLowerInvariant();
s = string.Join(' ', s.Split(' ', StringSplitOptions.RemoveEmptyEntries));

while (true)
{
int space = s.LastIndexOf(' ');
if (space <= 0) break;

string tail = s[(space + 1)..];
bool drop =
tail is "copy" or "kopie" or "copia" or "backup" ||
VersionTail.IsMatch(tail);
if (!drop) break;

s = s[..space].TrimEnd();
}

s = s.TrimEnd(' ', '.', '-', '_', '(', ')', '[', ']', ',');
if (s.Length > 4 && s.EndsWith('s')) s = s[..^1];
return s;
}

/// <summary>"v1.2.3", "(1.0)", "1.0.0.1" — the shapes a version suffix takes in a folder name.</summary>
private static readonly System.Text.RegularExpressions.Regex VersionTail =
new(@"^\(?v?[0-9]+(\.[0-9]+)+\)?$", System.Text.RegularExpressions.RegexOptions.IgnoreCase);

private static bool HasLaunchExe(string dir, string? launchExe)
{
try
{
if (!string.IsNullOrWhiteSpace(launchExe))
return File.Exists(Path.Combine(dir, launchExe.Replace('/', '\\')));

return Directory.EnumerateFiles(dir, "*.exe", SearchOption.TopDirectoryOnly).Any();
}
catch { return false; }
}
}
Loading