diff --git a/Core/LocalAdmin.cs b/Core/LocalAdmin.cs index f732890..d2f2f82 100644 --- a/Core/LocalAdmin.cs +++ b/Core/LocalAdmin.cs @@ -119,12 +119,27 @@ internal async Task Start(string[] args) HeartbeatStopwatch.Reset(); - if (!PathManager.IsLinuxCorrectPath && !args.Contains("--skipHomeCheck", StringComparer.Ordinal)) + if (!PathManager.CorrectPathFound && !args.Contains("--skipHomeCheck", StringComparer.Ordinal)) { ConsoleUtil.WriteLine($"Welcome to LocalAdmin version {VersionString}!", ConsoleColor.Red); ConsoleUtil.WriteLine("Can't obtain a valid user home directory path!", ConsoleColor.Red); - ConsoleUtil.WriteLine("Make sure to export a valid path, for example using command: export HOME=/home/username-here", ConsoleColor.Red); - ConsoleUtil.WriteLine("You may want to add that command to the top of ~/.bashrc file and restart the terminal session to avoid having to enter that command every time.", ConsoleColor.Red); + + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + ConsoleUtil.WriteLine("Make sure to export a valid path, for example using command: export HOME=/home/username-here", ConsoleColor.Red); + ConsoleUtil.WriteLine("You may want to add that command to the top of ~/.bashrc file and restart the terminal session to avoid having to enter that command every time.", ConsoleColor.Red); + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + ConsoleUtil.WriteLine("Such error should never occur on Windows.", ConsoleColor.Red); + ConsoleUtil.WriteLine("Open issue on the LocalAdmin GitHub repository (https://github.com/northwood-studios/LocalAdmin-V2/issues) or contact our technical support!", ConsoleColor.Red); + } + else + { + ConsoleUtil.WriteLine("You are running LocalAdmin on an unsupported platform!", ConsoleColor.Red); + throw new PlatformNotSupportedException(); + } + ConsoleUtil.WriteLine("To skip this check, use --skipHomeCheck argument.", ConsoleColor.Red); Terminate(); diff --git a/IO/PathManager.cs b/IO/PathManager.cs index 601741e..33c4ee8 100644 --- a/IO/PathManager.cs +++ b/IO/PathManager.cs @@ -12,24 +12,62 @@ internal static class PathManager internal static readonly string ConfigPath; internal static readonly string InternalJsonDataPath; + internal static bool CorrectPathFound { get; private set; } + static PathManager() { ProcessHostPolicy(); GameUserDataRoot = _configDirOverride ? "AppData" + Path.DirectorySeparatorChar - : Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + Path.DirectorySeparatorChar + - "SCP Secret Laboratory" + Path.DirectorySeparatorChar; + : GetSpecialFolderPath() + "SCP Secret Laboratory" + Path.DirectorySeparatorChar; ConfigPath = $"{GameUserDataRoot}config{Path.DirectorySeparatorChar}"; InternalJsonDataPath = ConfigPath + "localadmin_internal_data.json"; } - internal static bool IsLinuxCorrectPath => !RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || - !string.IsNullOrWhiteSpace( - Environment.GetFolderPath(Environment.SpecialFolder - .ApplicationData)); + private static string GetSpecialFolderPath() + { + try + { + var path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); + + if (!string.IsNullOrWhiteSpace(path)) + { + CorrectPathFound = true; + return path + Path.DirectorySeparatorChar; + } + + path = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); + + if (!string.IsNullOrWhiteSpace(path)) + { + CorrectPathFound = true; + + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + return path + Path.DirectorySeparatorChar + ".config" + Path.DirectorySeparatorChar; + + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + return path + Path.DirectorySeparatorChar + "AppData" + Path.DirectorySeparatorChar + "Roaming" + Path.DirectorySeparatorChar; + + ConsoleUtil.WriteLine("Failed to get special folder path - unsupported platform!", ConsoleColor.Red); + throw new PlatformNotSupportedException(); + } + + CorrectPathFound = false; + ConsoleUtil.WriteLine($"Failed to get special folder path - it's always null or empty!", ConsoleColor.Red); + + return string.Empty; + } + catch (Exception e) + { + CorrectPathFound = false; + ConsoleUtil.WriteLine($"Failed to get special folder path! Exception: {e.Message}", ConsoleColor.Red); + + throw; + } + } private static void ProcessHostPolicy() {