FFXIVLauncher-Netmaui

Форк
0
216 строк · 7.6 Кб
1
using LibDalamud.Common.Util;
2
using System.Text;
3
using XIVLauncher.Common.Util;
4
using static LibDalamud.Common.Util.PlatformHelpers;
5

6
namespace LibDalamud
7
{
8
    [AttributeUsage(AttributeTargets.Field)]
9
    public class SettingsDescriptionAttribute : Attribute
10
    {
11
        public string FriendlyName { get; set; }
12

13
        public string Description { get; set; }
14

15
        public SettingsDescriptionAttribute(string friendlyName, string description)
16
        {
17
            this.FriendlyName = friendlyName;
18
            this.Description = description;
19
        }
20
    }
21
    public static class RepoExtensions
22
    {
23
        public const string BASE_GAME_VERSION = "2012.01.01.0000.0000";
24
        private static DirectoryInfo GetRepoPath(this Repository repo, DirectoryInfo gamePath)
25
        {
26
            switch (repo)
27
            {
28
                case Repository.Boot:
29
                    return new DirectoryInfo(Path.Combine(gamePath.FullName, "boot"));
30
                case Repository.Ffxiv:
31
                    return new DirectoryInfo(Path.Combine(gamePath.FullName, "game"));
32
                case Repository.Ex1:
33
                    return new DirectoryInfo(Path.Combine(gamePath.FullName, "game", "sqpack", "ex1"));
34
                case Repository.Ex2:
35
                    return new DirectoryInfo(Path.Combine(gamePath.FullName, "game", "sqpack", "ex2"));
36
                case Repository.Ex3:
37
                    return new DirectoryInfo(Path.Combine(gamePath.FullName, "game", "sqpack", "ex3"));
38
                case Repository.Ex4:
39
                    return new DirectoryInfo(Path.Combine(gamePath.FullName, "game", "sqpack", "ex4"));
40
                default:
41
                    throw new ArgumentOutOfRangeException(nameof(repo), repo, null);
42
            }
43
        }
44

45
        public static FileInfo GetVerFile(this Repository repo, DirectoryInfo gamePath, bool isBck = false)
46
        {
47
            var repoPath = repo.GetRepoPath(gamePath).FullName;
48
            switch (repo)
49
            {
50
                case Repository.Boot:
51
                    return new FileInfo(Path.Combine(repoPath, "ffxivboot" + (isBck ? ".bck" : ".ver")));
52
                case Repository.Ffxiv:
53
                    return new FileInfo(Path.Combine(repoPath, "ffxivgame" + (isBck ? ".bck" : ".ver")));
54
                case Repository.Ex1:
55
                    return new FileInfo(Path.Combine(repoPath, "ex1" + (isBck ? ".bck" : ".ver")));
56
                case Repository.Ex2:
57
                    return new FileInfo(Path.Combine(repoPath, "ex2" + (isBck ? ".bck" : ".ver")));
58
                case Repository.Ex3:
59
                    return new FileInfo(Path.Combine(repoPath, "ex3" + (isBck ? ".bck" : ".ver")));
60
                case Repository.Ex4:
61
                    return new FileInfo(Path.Combine(repoPath, "ex4" + (isBck ? ".bck" : ".ver")));
62
                default:
63
                    throw new ArgumentOutOfRangeException(nameof(repo), repo, null);
64
            }
65
        }
66

67
        public static string GetVer(this Repository repo, DirectoryInfo gamePath, bool isBck = false)
68
        {
69
            var verFile = repo.GetVerFile(gamePath, isBck);
70

71
            if (!verFile.Exists)
72
                return BASE_GAME_VERSION;
73

74
            var ver = File.ReadAllText(verFile.FullName);
75
            return string.IsNullOrWhiteSpace(ver) ? BASE_GAME_VERSION : ver;
76
        }
77

78
        public static void SetVer(this Repository repo, DirectoryInfo gamePath, string newVer, bool isBck = false)
79
        {
80
            var verFile = GetVerFile(repo, gamePath, isBck);
81

82
            if (!verFile.Directory.Exists)
83
                verFile.Directory.Create();
84

85
            using var fileStream = verFile.Open(FileMode.Create, FileAccess.Write, FileShare.None);
86
            var buffer = Encoding.ASCII.GetBytes(newVer);
87
            fileStream.Write(buffer, 0, buffer.Length);
88
            fileStream.Flush();
89
        }
90

91
        public static bool IsBaseVer(this Repository repo, DirectoryInfo gamePath)
92
        {
93
            return repo.GetVer(gamePath) == BASE_GAME_VERSION;
94
        }
95

96
        // TODO
97
        public static string GetRepoHash(this Repository repo)
98
        {
99
            switch (repo)
100
            {
101
                case Repository.Boot:
102
                    return null;
103
                case Repository.Ffxiv:
104
                    return null;
105
                case Repository.Ex1:
106
                    return null;
107
                case Repository.Ex2:
108
                    return null;
109
                case Repository.Ex3:
110
                    return null;
111
                case Repository.Ex4:
112
                    return null;
113
                default:
114
                    throw new ArgumentOutOfRangeException(nameof(repo), repo, null);
115
            }
116
        }
117
    }
118
    public class Paths
119
    {
120
        static Paths()
121
        {
122
            RoamingPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "XIVLauncher");
123
        }
124

125
        public static string RoamingPath { get; private set; }
126

127
        public static string ResourcesPath => Path.Combine(AppContext.BaseDirectory, "Resources");
128

129
        public static void OverrideRoamingPath(string path)
130
        {
131
            RoamingPath = Environment.ExpandEnvironmentVariables(path);
132
        }
133
    }
134
    public static class EnvironmentSettings
135
    {
136
        public static bool IsWine => CheckEnvBool("XL_WINEONLINUX");
137
        public static bool IsHardwareRendered => CheckEnvBool("XL_HWRENDER");
138
        public static bool IsDisableUpdates => CheckEnvBool("XL_NOAUTOUPDATE");
139
        public static bool IsPreRelease => CheckEnvBool("XL_PRERELEASE");
140
        public static bool IsNoRunas => CheckEnvBool("XL_NO_RUNAS");
141
        public static bool IsIgnoreSpaceRequirements => CheckEnvBool("XL_NO_SPACE_REQUIREMENTS");
142
        private static bool CheckEnvBool(string var) => bool.Parse(System.Environment.GetEnvironmentVariable(var) ?? "false");
143
    }
144
    public enum Repository
145
    {
146
        Boot,
147
        Ffxiv,
148
        Ex1,
149
        Ex2,
150
        Ex3,
151
        Ex4
152
    }
153
    public static class ClientLanguageExtensions
154
    {
155
        public static string GetLangCode(this ClientLanguage language)
156
        {
157
            switch (language)
158
            {
159
                case ClientLanguage.Japanese:
160
                    return "ja";
161

162
                case ClientLanguage.English when GameHelpers.IsRegionNorthAmerica():
163
                    return "en-us";
164

165
                case ClientLanguage.English:
166
                    return "en-gb";
167

168
                case ClientLanguage.German:
169
                    return "de";
170

171
                case ClientLanguage.French:
172
                    return "fr";
173

174
                default:
175
                    return "en-gb";
176
            }
177
        }
178
    }
179
    public enum ClientLanguage
180
    {
181
        Japanese,
182
        English,
183
        German,
184
        French
185
    }
186
    public enum DpiAwareness
187
    {
188
        Aware,
189
        Unaware,
190
    }
191
    public static class Constants
192
    {
193
        public const string BASE_GAME_VERSION = "2012.01.01.0000.0000";
194

195
        public const uint STEAM_APP_ID = 39210;
196
        public const uint STEAM_FT_APP_ID = 312060;
197

198
        public static string PatcherUserAgent => GetPatcherUserAgent(PlatformHelpers.GetPlatform());
199

200
        private static string GetPatcherUserAgent(Platform platform)
201
        {
202
            switch (platform)
203
            {
204
                case Platform.Win32:
205
                case Platform.Win32OnLinux:
206
                    return "FFXIV PATCH CLIENT";
207

208
                case Platform.Mac:
209
                    return "FFXIV-MAC PATCH CLIENT";
210

211
                default:
212
                    throw new ArgumentOutOfRangeException(nameof(platform), platform, null);
213
            }
214
        }
215
    }
216
}

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.