-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMinecraftPath.cs
More file actions
104 lines (81 loc) · 3.13 KB
/
MinecraftPath.cs
File metadata and controls
104 lines (81 loc) · 3.13 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
using System.Runtime.InteropServices;
namespace CmlLib.Core;
public class MinecraftPath
{
public static readonly string
MacDefaultPath = Environment.GetEnvironmentVariable("HOME") + "/Library/Application Support/minecraft",
LinuxDefaultPath = Environment.GetEnvironmentVariable("HOME") + "/.minecraft",
WindowsDefaultPath = Environment.GetEnvironmentVariable("appdata") + "\\.minecraft";
public static string GetOSDefaultPath()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
return MacDefaultPath;
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
return WindowsDefaultPath;
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
return LinuxDefaultPath;
else
return Environment.CurrentDirectory;
}
public MinecraftPath() : this(GetOSDefaultPath())
{
}
public MinecraftPath(string basePath) : this(basePath, basePath)
{
}
public MinecraftPath(string basePath, string basePathForAssets)
{
BasePath = NormalizePath(basePath);
Library = NormalizePath(BasePath + "/libraries");
Versions = NormalizePath(BasePath + "/versions");
Resource = NormalizePath(BasePath + "/resources");
Runtime = NormalizePath(BasePath + "/runtime");
Assets = NormalizePath(basePathForAssets + "/assets");
}
public void CreateDirs()
{
Dir(BasePath);
Dir(Library);
Dir(Versions);
Dir(Resource);
Dir(Runtime);
Dir(Assets);
}
public string BasePath { get; set; }
public string Library { get; set; }
public string Versions { get; set; }
public string Resource { get; set; }
public string Assets { get; set; }
public string Runtime { get; set; }
public virtual string GetIndexFilePath(string assetId)
=> NormalizePath($"{Assets}/indexes/{assetId}.json");
public virtual string GetAssetObjectPath(string assetId)
=> NormalizePath($"{Assets}/objects");
public virtual string GetAssetLegacyPath(string assetId)
=> NormalizePath($"{Assets}/virtual/legacy");
public virtual string GetLogConfigFilePath(string configId)
=> NormalizePath($"{Assets}/log_configs/{configId}" + (!configId.EndsWith(".xml") ? ".xml" : ""));
public virtual string GetVersionJarPath(string id)
=> NormalizePath($"{Versions}/{id}/{id}.jar");
public virtual string GetVersionJsonPath(string id)
=> NormalizePath($"{Versions}/{id}/{id}.json");
public virtual string GetNativePath(string id)
=> NormalizePath($"{Versions}/{id}/natives");
public override string ToString()
{
return BasePath;
}
protected static string Dir(string path)
{
string p = NormalizePath(path);
if (!Directory.Exists(p))
Directory.CreateDirectory(p);
return p;
}
protected static string NormalizePath(string path)
{
return Path.GetFullPath(path)
.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar)
.TrimEnd(Path.DirectorySeparatorChar);
}
}