-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathGameScanner.cs
128 lines (113 loc) · 3.62 KB
/
GameScanner.cs
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
using PursuitLib;
using PursuitLib.IO;
using PursuitLib.Windows.WPF.Dialogs;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace GTAVModdingLauncher
{
/// <summary>
/// This class is used to scan the game for mods, and to perform integrity checks
/// </summary>
public static class GameScanner
{
/// <summary>
/// The list of all files and folders located at the root of a vanilla copy of GTA V
/// </summary>
private static List<GameFile> gameManifest = new List<GameFile>();
public static void Init()
{
Log.Info("Initializing the game scanner...");
if(File.Exists("GameManifest.xml"))
gameManifest = new XMLFile<List<GameFile>>("GameManifest.xml").Content;
else
{
Log.Error("Fatal error: Unable to find game manifest");
LocalizedMessage.Show("ManifestNotFound", "FatalError", DialogIcon.Error, DialogButtons.Ok);
Environment.Exit(1);
}
}
public static bool IsGTAModded()
{
GTAInstall install = Launcher.Instance.Config.SelectedInstall;
foreach(string file in Directory.GetFileSystemEntries(install.Path))
{
if(!IsVanillaEntry(Path.GetFileName(file)))
return true;
}
if(Directory.Exists(Path.Combine(install.Path, "update\\x64\\dlcpacks")))
{
foreach(string file in Directory.GetFileSystemEntries(Path.Combine(install.Path, "update\\x64\\dlcpacks")))
{
if(Directory.Exists(file))
{
string filename = Path.GetFileName(file).ToLower();
if(!filename.StartsWith("mp") && !filename.StartsWith("patch"))
return true;
}
}
}
return false;
}
/// <summary>
/// List all mods located at the root of the game's directory
/// </summary>
public static void ListRootMods(out List<string> files, out List<string> dirs)
{
GTAInstall install = Launcher.Instance.Config.SelectedInstall;
if(install.Path != null)
{
if(Directory.Exists(install.Path))
{
files = new List<string>();
dirs = new List<string>();
foreach(string file in Directory.EnumerateFileSystemEntries(install.Path))
{
if(!IsVanillaEntry(Path.GetFileName(file)))
{
if(File.Exists(file))
files.Add(file);
else dirs.Add(file);
}
}
}
else throw new ApplicationException("GtaPath doesn't exist.");
}
else throw new ApplicationException("GtaPath is not set.");
}
/// <summary>
/// List all mods located in update\x64\dlcpacks\
/// </summary>
public static List<string> ListDlcMods()
{
GTAInstall install = Launcher.Instance.Config.SelectedInstall;
if(install.Path != null)
{
if(Directory.Exists(install.Path))
{
List<string> mods = new List<string>();
if(Directory.Exists(Path.Combine(install.Path, "update\\x64\\dlcpacks")))
{
foreach(string file in Directory.GetFileSystemEntries(Path.Combine(install.Path, "update\\x64\\dlcpacks")))
{
if(Directory.Exists(file))
{
string filename = Path.GetFileName(file).ToLower();
if(!filename.StartsWith("mp") && !filename.StartsWith("patch"))
mods.Add(file);
}
}
}
return mods;
}
throw new ApplicationException("GtaPath doesn't exist.");
}
else throw new ApplicationException("GtaPath is not set.");
}
private static bool IsVanillaEntry(string name)
{
return gameManifest.FirstOrDefault(f => (f.Type == null || f.Type.Value == Launcher.Instance.Config.SelectedInstall.Type) && String.Equals(f.Name, name, StringComparison.OrdinalIgnoreCase)) != null;
}
}
}