ProjectArcade

Форк
0
207 строк · 6.4 Кб
1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Runtime.Serialization;
6
using System.IO;
7
using EmulatorLauncher.Common.FileFormats;
8
using Microsoft.Win32;
9
using EmulatorLauncher.Common.Launchers.Epic;
10

11
namespace EmulatorLauncher.Common.Launchers
12
{
13
    public class EpicLibrary
14
    {
15
        const string GameLaunchUrl = @"com.epicgames.launcher://apps/{0}?action=launch&silent=true";
16

17
        public static string GetEpicGameExecutableName(Uri uri)
18
        {
19
            string shorturl = uri.LocalPath.ExtractString("/", ":");
20

21
            var modSdkMetadataDir = GetMetadataPath();
22
            if (modSdkMetadataDir != null)
23
            {
24
                string manifestPath = modSdkMetadataDir.ToString();
25

26
                string gameExecutable = null;
27

28
                if (Directory.Exists(manifestPath))
29
                {
30
                    foreach (var manifest in GetInstalledManifests())
31
                    {
32
                        if (shorturl.Equals(manifest.CatalogNamespace))
33
                        {
34
                            gameExecutable = manifest.LaunchExecutable;
35
                            break;
36
                        }
37
                    }
38
                }
39

40
                if (gameExecutable == null)
41
                    throw new ApplicationException("There is a problem: The Game is not installed");
42

43
                return Path.GetFileNameWithoutExtension(gameExecutable);
44
            }
45

46
            throw new ApplicationException("There is a problem: Epic Launcher is not installed");
47
        }
48

49
        public static LauncherGameInfo[] GetInstalledGames()
50
        {
51
            var games = new List<LauncherGameInfo>();
52

53
            if (!IsInstalled)
54
                return games.ToArray();
55

56
            var appList = GetInstalledAppList();
57
            var manifests = GetInstalledManifests();
58

59
            if (appList == null || manifests == null)
60
                return games.ToArray();
61

62
            foreach (var app in appList)
63
            {
64
                if (app.AppName.StartsWith("UE_"))
65
                    continue;
66

67
                var manifest = manifests.FirstOrDefault(a => a.AppName == app.AppName);
68
                if (manifest == null)
69
                    continue;
70

71
                // Skip DLCs
72
                if (manifest.AppName != manifest.MainGameAppName)
73
                    continue;
74

75
                // Skip Plugins
76
                if (manifest.AppCategories == null || manifest.AppCategories.Any(a => a == "plugins" || a == "plugins/engine"))
77
                    continue;
78

79
                var gameName = manifest.DisplayName ?? Path.GetFileName(app.InstallLocation);
80

81
                var installLocation = manifest.InstallLocation ?? app.InstallLocation;
82
                if (string.IsNullOrEmpty(installLocation))
83
                    continue;
84

85
                var game = new LauncherGameInfo()
86
                {
87
                    Id = app.AppName,
88
                    Name = gameName,
89
                    LauncherUrl = string.Format(GameLaunchUrl, manifest.AppName),
90
                    InstallDirectory = Path.GetFullPath(installLocation),
91
                    ExecutableName = manifest.LaunchExecutable,
92
                    Launcher = GameLauncherType.Epic
93
                };
94

95
                games.Add(game);
96
            }
97

98
            return games.ToArray();
99
        }
100

101

102
        static string AllUsersPath { get { return Path.Combine(Environment.ExpandEnvironmentVariables("%PROGRAMDATA%"), "Epic"); } }
103

104
        public static bool IsInstalled
105
        {
106
            get
107
            {
108
                return File.Exists(GetExecutablePath());
109
            }
110
        }
111

112
        static string GetExecutablePath()
113
        {
114
            var modSdkMetadataDir = Registry.GetValue("HKEY_CURRENT_USER\\Software\\Epic Games\\EOS", "ModSdkCommand", null);
115
            if (modSdkMetadataDir != null)
116
                return modSdkMetadataDir.ToString();
117

118
            return null;
119
        }
120

121
        static string GetMetadataPath()
122
        {
123
            var modSdkMetadataDir = Registry.GetValue("HKEY_CURRENT_USER\\Software\\Epic Games\\EOS", "ModSdkMetadataDir", null);
124
            if (modSdkMetadataDir != null)
125
                return modSdkMetadataDir.ToString();
126

127
            return null;
128
        }
129

130
        static List<LauncherInstalled.InstalledApp> GetInstalledAppList()
131
        {
132
            var installListPath = Path.Combine(AllUsersPath, "UnrealEngineLauncher", "LauncherInstalled.dat");
133
            if (!File.Exists(installListPath))
134
                return new List<LauncherInstalled.InstalledApp>();
135

136
            var list = JsonSerializer.DeserializeString<LauncherInstalled>(File.ReadAllText(installListPath));
137
            return list.InstallationList;
138
        }
139

140
        static IEnumerable<EpicGame> GetInstalledManifests()
141
        {
142
            var installListPath = GetMetadataPath();
143
            if (Directory.Exists(installListPath))
144
            {
145
                foreach (var manFile in Directory.GetFiles(installListPath, "*.item"))
146
                {
147
                    EpicGame manifest = null;
148

149
                    try { manifest = JsonSerializer.DeserializeString<EpicGame>(File.ReadAllText(manFile)); }
150
                    catch { }
151

152
                    if (manifest != null)
153
                        yield return manifest;
154
                }
155
            }
156
        }
157

158
    }    
159
}
160

161
namespace EmulatorLauncher.Common.Launchers.Epic
162
{
163
    [DataContract]
164
    public class LauncherInstalled
165
    {
166
        [DataContract]
167
        public class InstalledApp
168
        {
169
            [DataMember]
170
            public string InstallLocation { get; set; }
171
            [DataMember]
172
            public string AppName { get; set; }
173
            [DataMember]
174
            public long AppID { get; set; }
175
            [DataMember]
176
            public string AppVersion { get; set; }
177
        }
178

179
        [DataMember]
180
        public List<InstalledApp> InstallationList { get; set; }
181
    }
182

183
    [DataContract]
184
    public class EpicGame
185
    {
186
        [DataMember]
187
        public string AppName { get; set; }
188

189
        [DataMember]
190
        public string CatalogNamespace { get; set; }
191

192
        [DataMember]
193
        public string LaunchExecutable { get; set; }
194

195
        [DataMember]
196
        public string InstallLocation;
197

198
        [DataMember]
199
        public string MainGameAppName;
200

201
        [DataMember]
202
        public string DisplayName;
203

204
        [DataMember]
205
        public List<string> AppCategories { get; set; }
206
    }
207
}
208

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

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

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

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