FFXIVLauncher-Netmaui
216 строк · 7.6 Кб
1using LibDalamud.Common.Util;2using System.Text;3using XIVLauncher.Common.Util;4using static LibDalamud.Common.Util.PlatformHelpers;5
6namespace LibDalamud7{
8[AttributeUsage(AttributeTargets.Field)]9public class SettingsDescriptionAttribute : Attribute10{11public string FriendlyName { get; set; }12
13public string Description { get; set; }14
15public SettingsDescriptionAttribute(string friendlyName, string description)16{17this.FriendlyName = friendlyName;18this.Description = description;19}20}21public static class RepoExtensions22{23public const string BASE_GAME_VERSION = "2012.01.01.0000.0000";24private static DirectoryInfo GetRepoPath(this Repository repo, DirectoryInfo gamePath)25{26switch (repo)27{28case Repository.Boot:29return new DirectoryInfo(Path.Combine(gamePath.FullName, "boot"));30case Repository.Ffxiv:31return new DirectoryInfo(Path.Combine(gamePath.FullName, "game"));32case Repository.Ex1:33return new DirectoryInfo(Path.Combine(gamePath.FullName, "game", "sqpack", "ex1"));34case Repository.Ex2:35return new DirectoryInfo(Path.Combine(gamePath.FullName, "game", "sqpack", "ex2"));36case Repository.Ex3:37return new DirectoryInfo(Path.Combine(gamePath.FullName, "game", "sqpack", "ex3"));38case Repository.Ex4:39return new DirectoryInfo(Path.Combine(gamePath.FullName, "game", "sqpack", "ex4"));40default:41throw new ArgumentOutOfRangeException(nameof(repo), repo, null);42}43}44
45public static FileInfo GetVerFile(this Repository repo, DirectoryInfo gamePath, bool isBck = false)46{47var repoPath = repo.GetRepoPath(gamePath).FullName;48switch (repo)49{50case Repository.Boot:51return new FileInfo(Path.Combine(repoPath, "ffxivboot" + (isBck ? ".bck" : ".ver")));52case Repository.Ffxiv:53return new FileInfo(Path.Combine(repoPath, "ffxivgame" + (isBck ? ".bck" : ".ver")));54case Repository.Ex1:55return new FileInfo(Path.Combine(repoPath, "ex1" + (isBck ? ".bck" : ".ver")));56case Repository.Ex2:57return new FileInfo(Path.Combine(repoPath, "ex2" + (isBck ? ".bck" : ".ver")));58case Repository.Ex3:59return new FileInfo(Path.Combine(repoPath, "ex3" + (isBck ? ".bck" : ".ver")));60case Repository.Ex4:61return new FileInfo(Path.Combine(repoPath, "ex4" + (isBck ? ".bck" : ".ver")));62default:63throw new ArgumentOutOfRangeException(nameof(repo), repo, null);64}65}66
67public static string GetVer(this Repository repo, DirectoryInfo gamePath, bool isBck = false)68{69var verFile = repo.GetVerFile(gamePath, isBck);70
71if (!verFile.Exists)72return BASE_GAME_VERSION;73
74var ver = File.ReadAllText(verFile.FullName);75return string.IsNullOrWhiteSpace(ver) ? BASE_GAME_VERSION : ver;76}77
78public static void SetVer(this Repository repo, DirectoryInfo gamePath, string newVer, bool isBck = false)79{80var verFile = GetVerFile(repo, gamePath, isBck);81
82if (!verFile.Directory.Exists)83verFile.Directory.Create();84
85using var fileStream = verFile.Open(FileMode.Create, FileAccess.Write, FileShare.None);86var buffer = Encoding.ASCII.GetBytes(newVer);87fileStream.Write(buffer, 0, buffer.Length);88fileStream.Flush();89}90
91public static bool IsBaseVer(this Repository repo, DirectoryInfo gamePath)92{93return repo.GetVer(gamePath) == BASE_GAME_VERSION;94}95
96// TODO97public static string GetRepoHash(this Repository repo)98{99switch (repo)100{101case Repository.Boot:102return null;103case Repository.Ffxiv:104return null;105case Repository.Ex1:106return null;107case Repository.Ex2:108return null;109case Repository.Ex3:110return null;111case Repository.Ex4:112return null;113default:114throw new ArgumentOutOfRangeException(nameof(repo), repo, null);115}116}117}118public class Paths119{120static Paths()121{122RoamingPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "XIVLauncher");123}124
125public static string RoamingPath { get; private set; }126
127public static string ResourcesPath => Path.Combine(AppContext.BaseDirectory, "Resources");128
129public static void OverrideRoamingPath(string path)130{131RoamingPath = Environment.ExpandEnvironmentVariables(path);132}133}134public static class EnvironmentSettings135{136public static bool IsWine => CheckEnvBool("XL_WINEONLINUX");137public static bool IsHardwareRendered => CheckEnvBool("XL_HWRENDER");138public static bool IsDisableUpdates => CheckEnvBool("XL_NOAUTOUPDATE");139public static bool IsPreRelease => CheckEnvBool("XL_PRERELEASE");140public static bool IsNoRunas => CheckEnvBool("XL_NO_RUNAS");141public static bool IsIgnoreSpaceRequirements => CheckEnvBool("XL_NO_SPACE_REQUIREMENTS");142private static bool CheckEnvBool(string var) => bool.Parse(System.Environment.GetEnvironmentVariable(var) ?? "false");143}144public enum Repository145{146Boot,147Ffxiv,148Ex1,149Ex2,150Ex3,151Ex4
152}153public static class ClientLanguageExtensions154{155public static string GetLangCode(this ClientLanguage language)156{157switch (language)158{159case ClientLanguage.Japanese:160return "ja";161
162case ClientLanguage.English when GameHelpers.IsRegionNorthAmerica():163return "en-us";164
165case ClientLanguage.English:166return "en-gb";167
168case ClientLanguage.German:169return "de";170
171case ClientLanguage.French:172return "fr";173
174default:175return "en-gb";176}177}178}179public enum ClientLanguage180{181Japanese,182English,183German,184French
185}186public enum DpiAwareness187{188Aware,189Unaware,190}191public static class Constants192{193public const string BASE_GAME_VERSION = "2012.01.01.0000.0000";194
195public const uint STEAM_APP_ID = 39210;196public const uint STEAM_FT_APP_ID = 312060;197
198public static string PatcherUserAgent => GetPatcherUserAgent(PlatformHelpers.GetPlatform());199
200private static string GetPatcherUserAgent(Platform platform)201{202switch (platform)203{204case Platform.Win32:205case Platform.Win32OnLinux:206return "FFXIV PATCH CLIENT";207
208case Platform.Mac:209return "FFXIV-MAC PATCH CLIENT";210
211default:212throw new ArgumentOutOfRangeException(nameof(platform), platform, null);213}214}215}216}