From 86bf5ac9f3bec75aba0989f5f5f2b6cff18168c9 Mon Sep 17 00:00:00 2001 From: Miepee Date: Tue, 7 Feb 2023 00:47:19 +0100 Subject: [PATCH] Fix Unix having lower and uppercase files for songs --- .../CrossPlatformOperations.cs | 1 + AM2RLauncher/AM2RLauncherLib/HelperMethods.cs | 30 +++++++++++++++++++ AM2RLauncher/AM2RLauncherLib/Profile.cs | 7 +++++ 3 files changed, 38 insertions(+) diff --git a/AM2RLauncher/AM2RLauncherLib/CrossPlatformOperations.cs b/AM2RLauncher/AM2RLauncherLib/CrossPlatformOperations.cs index 9873453..2662618 100644 --- a/AM2RLauncher/AM2RLauncherLib/CrossPlatformOperations.cs +++ b/AM2RLauncher/AM2RLauncherLib/CrossPlatformOperations.cs @@ -217,6 +217,7 @@ public static class CrossPlatformOperations { const string process = "xdelta3"; const string arguments = "-V"; + // TODO: for mac, we need to embed two xdelta binaries, for x64 and arm ProcessStartInfo xdeltaStart = new ProcessStartInfo { diff --git a/AM2RLauncher/AM2RLauncherLib/HelperMethods.cs b/AM2RLauncher/AM2RLauncherLib/HelperMethods.cs index 9182c57..bfc5965 100644 --- a/AM2RLauncher/AM2RLauncherLib/HelperMethods.cs +++ b/AM2RLauncher/AM2RLauncherLib/HelperMethods.cs @@ -87,6 +87,36 @@ public static class HelperMethods Directory.Delete(targetDir, false); } + + /// + /// Recursively lowercases all files and folders from a specified directory. + /// + /// The path to the directory whose contents should be lowercased. + public static void LowercaseFolder(string directory) + { + DirectoryInfo dir = new DirectoryInfo(directory); + + foreach(var file in dir.GetFiles()) + { + if (file.Name == file.Name.ToLower()) continue; + // Windows is dumb, thus we need to move in two trips + file.MoveTo(file.DirectoryName + "/" + file.Name.ToLower() + "_"); + string newPath = file.FullName.Substring(0, file.FullName.Length - 1); + File.Delete(newPath); + file.MoveTo(newPath); + } + + foreach(var subDir in dir.GetDirectories()) + { + if (subDir.Name == subDir.Name.ToLower()) continue; + // ReSharper disable once PossibleNullReferenceException - since this is a subdirectory, it always has a parent + // Windows is dumb, thus we need to move in two trips + subDir.MoveTo(subDir.Parent.FullName + "/" + subDir.Name.ToLower() + "_"); + // -2 because after a moving operation, DirInfo already appends a / + subDir.MoveTo(subDir.FullName.Substring(0, subDir.FullName.Length-2)); + LowercaseFolder(subDir.FullName); + } + } /// /// Calculates an MD5 hash from a given file. diff --git a/AM2RLauncher/AM2RLauncherLib/Profile.cs b/AM2RLauncher/AM2RLauncherLib/Profile.cs index bdb962f..0d8dfc2 100644 --- a/AM2RLauncher/AM2RLauncherLib/Profile.cs +++ b/AM2RLauncher/AM2RLauncherLib/Profile.cs @@ -12,6 +12,8 @@ using AM2RLauncherLib.XML; namespace AM2RLauncherLib; +// TODO: grey out create desktop shortcut on download mode + /// /// An enum, that has possible return codes for . /// @@ -50,6 +52,7 @@ public static class Profile /// /// Determines if the AM2R_11 Cache should be invalidated. /// + // TODO: returns ^ public static bool Is11Installed(bool invalidateCache = false) { // Only invalidate if we need to @@ -458,6 +461,10 @@ public static class Profile if (!profile.UsesCustomMusic && useHqMusic) HelperMethods.DirectoryCopy($"{Core.PatchDataPath}/data/HDR_HQ_in-game_music", tempPath); + // On Unix, everything needs to be lowercased, so we need to fix the AM2R_11 files / HQ songs + if (OS.IsUnix) + HelperMethods.LowercaseFolder(tempPath); + // Linux post-process if (OS.IsLinux) {