-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathModInfo.cs
124 lines (99 loc) · 4.59 KB
/
ModInfo.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
using System;
using System.IO;
using System.Linq;
namespace XCom2ModTool
{
internal class ModInfo
{
public static readonly string SolutionExtension = ".XCOM_sln";
public static readonly string SolutionOptionsExtension = ".v12.XCOM_suo";
public static readonly string ProjectExtension = ".x2proj";
public static readonly string SourceCodeExtension = ".uc";
public static readonly string PackageExtension = ".upk";
public static readonly string MapExtension = ".umap";
public static readonly string SourceCodeFolder = "Src";
public static readonly string ContentFolder = "Content";
public static readonly string ConfigFolder = "Config";
public static readonly string LocalizationFolder = "Localization";
public static readonly string[] ShaderContentExtensions = new[] { PackageExtension, MapExtension };
public ModInfo(string path)
{
RootPath = DirectoryHelper.GetExactPathName(path);
RootFolder = Path.GetFileName(RootPath);
ModName = RootFolder;
InnerFolder = ModName;
SolutionName = ModName;
SolutionOptionsName = ModName;
ProjectName = ModName;
SourceCodeInnerFolder = ModName;
}
// MyMod from C:\Mods\MYMOD
public string RootFolder { get; set; }
// C:\Mods\MyMod
public string RootPath { get; set; }
// MyMod
public string ModName { get; set; }
// MyMod from C:\Mods\MyMod\MYMOD
public string InnerFolder { get; set; }
// MyMod from C:\Mods\MyMod\MYMOD.XCOM_sln
public string SolutionName { get; set; }
// MyMod from C:\Mods\MyMod\MYMOD.v12.XCOM_suo
public string SolutionOptionsName { get; set; }
// MyMod from C:\Mods\MyMod\MyMod\MYMOD.x2proj
public string ProjectName { get; set; }
// MyMod from C:\Mods\MyMod\MyMod\Src\MYMOD
public string SourceCodeInnerFolder { get; set; }
// C:\Mods\MyMod\MyMod
public string InnerPath => Path.Combine(RootPath, InnerFolder);
// C:\Mods\MyMod\MyMod.XCOM_sln
public string SolutionPath => Path.Combine(RootPath, SolutionName + SolutionExtension);
// C:\Mods\MyMod\MyMod.v12.XCOM_suo
public string SolutionOptionsPath => Path.Combine(RootPath, SolutionOptionsName + SolutionOptionsExtension);
// C:\Mods\MyMod\MyMod\MyMod.x2proj
public string ProjectPath => Path.Combine(InnerPath, ProjectName + ProjectExtension);
// C:\Mods\MyMod\MyMod\Src
public string SourceCodePath => Path.Combine(InnerPath, SourceCodeFolder);
// C:\Mods\MyMod\MyMod\Src\MyMod
public string SourceCodeInnerPath => Path.Combine(SourceCodePath, SourceCodeInnerFolder);
// C:\Mods\MyMod\MyMod\Content
public string ContentPath => Path.Combine(InnerPath, ContentFolder);
// C:\Mods\MyMod\MyMod\Config
public string ConfigPath => Path.Combine(InnerPath, ConfigFolder);
// C:\Mods\MyMod\MyMod\Localization
public string LocalizationPath => Path.Combine(InnerPath, LocalizationFolder);
public bool HasSourceCode()
{
return Directory.Exists(SourceCodeInnerPath) &&
Directory.EnumerateFiles(SourceCodeInnerPath, "*" + SourceCodeExtension, SearchOption.AllDirectories).Any();
}
public string[] GetShaderContent()
{
if (!Directory.Exists(ContentPath))
{
return new string[0];
}
return Directory.EnumerateFiles(ContentPath, "*.*", SearchOption.AllDirectories)
.Where(x => ShaderContentExtensions.Any(y => string.Equals(Path.GetExtension(x), y)))
.ToArray();
}
public bool HasShaderContent() => GetShaderContent().Any();
public static bool FindModForCurrentDirectory(out ModInfo modInfo)
{
var directory = new DirectoryInfo(Directory.GetCurrentDirectory());
while (directory.Parent != null)
{
var potentialModName = directory.Name;
var potentialModPath = directory.FullName;
var solutionPath = Path.Combine(potentialModPath, potentialModName + SolutionExtension);
if (File.Exists(solutionPath))
{
modInfo = new ModInfo(potentialModPath);
return true;
}
directory = directory.Parent;
}
modInfo = null;
return false;
}
}
}