-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathEpic.cs
More file actions
162 lines (132 loc) · 5.79 KB
/
Copy pathEpic.cs
File metadata and controls
162 lines (132 loc) · 5.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.Win32;
using Newtonsoft.Json;
namespace HedgeModManager
{
public class Epic
{
public class EGSInstallation
{
public string InstallLocation { get; set; }
public string NamespaceId { get; set; }
public string ItemId { get; set; }
public string ArtifactId { get; set; }
public string AppVersion { get; set; }
public string AppName { get; set; }
}
public class LegendaryInstallation
{
[JsonProperty("app_name")]
public string AppName { get; set; }
[JsonProperty("executable")]
public string Executable { get; set; }
[JsonProperty("install_path")]
public string InstallPath { get; set; }
[JsonProperty("version")]
public string Version { get; set; }
}
public class EGSLauncherInstalled
{
public List<EGSInstallation> InstallationList { get; set; }
}
public static List<GameInstall> SearchForGames()
{
var games = new List<GameInstall>();
games.AddRange(SearchForGamesEGS() ?? new List<GameInstall>());
games.AddRange(SearchForGamesHeroic() ?? new List<GameInstall>());
return games;
}
public static List<GameInstall> SearchForGamesHeroic()
{
string home = null;
string appdata = null;
if (HedgeApp.IsLinux)
{
home = Environment.GetEnvironmentVariable("WINEHOMEDIR")?.Replace("\\??\\", "");
// Prefix "Z:" if starts with "/"
if (home?.StartsWith("/") == true)
home = $"Z:{home}";
}
else
{
home = Environment.GetEnvironmentVariable("USERPROFILE");
appdata = Environment.GetEnvironmentVariable("APPDATA");
}
// Return if home folder is not found
if (home == null || appdata == null)
return null;
string installedFilePath = Path.Combine(appdata, "heroic", "legendaryConfig", "legendary", "installed.json");
if (!File.Exists(installedFilePath))
installedFilePath = Path.Combine(home, ".config", "legendary", "installed.json");
if (!File.Exists(installedFilePath))
installedFilePath = Path.Combine(home, ".var", "app", "com.heroicgameslauncher.hgl", "config", "heroic", "legendaryConfig", "legendary", "installed.json");
if (!File.Exists(installedFilePath))
installedFilePath = Path.Combine(home, ".var", "app", "com.heroicgameslauncher.hgl", "config", "legendary", "installed.json");
if (!File.Exists(installedFilePath))
return null;
var installations = new Dictionary<string, LegendaryInstallation>();
try
{
installations = JsonConvert.DeserializeObject<Dictionary<string, LegendaryInstallation>>(File.ReadAllText(installedFilePath));
}
catch
{
return null;
}
if (installations == null || installations?.Count == 0)
return null;
var games = new List<GameInstall>();
foreach (var game in Games.GetSupportedGames())
{
var installation = installations.FirstOrDefault(x => x.Key.Equals(game.EGSID, StringComparison.OrdinalIgnoreCase));
if (installation.Value == null)
continue;
string fullPath = Path.Combine(installation.Value.InstallPath, installation.Value.Executable);
if (File.Exists(fullPath))
games.Add(new GameInstall(game, null, fullPath, GameLauncher.Heroic));
}
return games;
}
public static List<GameInstall> SearchForGamesEGS()
{
var eos = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Epic Games\\EOS");
if (eos?.GetValue("ModSdkMetadataDir") is not string modSdkMetadataDir)
return null;
string launcherInstalledFilePath = Path.Combine(modSdkMetadataDir,
"..", "..", "..", "UnrealEngineLauncher", "LauncherInstalled.dat");
EGSLauncherInstalled launcherInstalled;
try
{
launcherInstalled = JsonConvert.DeserializeObject<EGSLauncherInstalled>(File.ReadAllText(launcherInstalledFilePath));
}
catch
{
return null;
}
if (launcherInstalled == null || launcherInstalled.InstallationList?.Count == 0)
return null;
var games = new List<GameInstall>();
foreach (var game in Games.GetSupportedGames())
{
var installation = launcherInstalled.InstallationList
.FirstOrDefault(x => x.AppName.Equals(game.EGSID, StringComparison.OrdinalIgnoreCase));
if (installation == null)
continue;
foreach (string gamePath in game.GamePaths)
{
string path = gamePath;
// Remove first folder from path
if (path.Contains(Path.DirectorySeparatorChar))
path = path.Substring(path.IndexOf(Path.DirectorySeparatorChar) + 1);
var fullPath = Path.Combine(installation.InstallLocation, path);
if (File.Exists(fullPath))
games.Add(new GameInstall(game, null, fullPath, GameLauncher.Epic));
}
}
return games;
}
}
}