This repository was archived by the owner on May 6, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathfolder.ts
More file actions
183 lines (172 loc) · 5.21 KB
/
Copy pathfolder.ts
File metadata and controls
183 lines (172 loc) · 5.21 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import { join } from 'path'
export interface MinecraftFolder {
readonly root: string
}
/**
* The Minecraft folder structure. All method will return the path related to a minecraft root like `.minecraft`.
*/
export class MinecraftFolder {
/**
* Normal a Minecraft folder from a folder or string
*/
static from(location: MinecraftLocation) {
return typeof location === 'string'
? new MinecraftFolder(location)
: location instanceof MinecraftFolder
? location
: new MinecraftFolder((location as any).root)
}
constructor(readonly root: string) {}
get mods(): string {
return join(this.root, 'mods')
}
get resourcepacks(): string {
return join(this.root, 'resourcepacks')
}
get assets(): string {
return join(this.root, 'assets')
}
get libraries(): string {
return join(this.root, 'libraries')
}
get versions(): string {
return this.getPath('versions')
}
get logs(): string {
return this.getPath('logs')
}
get options(): string {
return this.getPath('options.txt')
}
get launcherProfile(): string {
return this.getPath('launcher_profiles.json')
}
get lastestLog(): string {
return this.getPath('logs', 'latest.log')
}
get maps(): string {
return this.getPath('saves')
}
get saves(): string {
return this.getPath('saves')
}
get screenshots(): string {
return this.getPath('screenshots')
}
getNativesRoot(version: string) {
return join(this.getVersionRoot(version), version + '-natives')
}
getVersionRoot(version: string) {
return join(this.versions, version)
}
getVersionJson(version: string) {
return join(this.getVersionRoot(version), version + '.json')
}
getVersionServerJson(version: string) {
return join(this.getVersionRoot(version), 'server.json')
}
getVersionJar(version: string, type?: string) {
if (type === 'client' || !type) return join(this.getVersionRoot(version), version + '.jar')
if (type === 'server')
return this.getPath(
'libraries',
'net',
'minecraft',
'server',
version,
`server-${version}-bundled.jar`,
)
return join(this.getVersionRoot(version), version + `-${type}.jar`)
}
getVersionAll(version: string) {
return [
join(this.versions, version),
join(this.versions, version, version + '.json'),
join(this.versions, version, version + '.jar'),
]
}
getResourcePack(fileName: string) {
return join(this.resourcepacks, fileName)
}
getMod(fileName: string) {
return join(this.mods, fileName)
}
getLog(fileName: string) {
return join(this.logs, fileName)
}
getMapInfo(map: string) {
return this.getPath('saves', map, 'level.dat')
}
getMapIcon(map: string) {
return this.getPath('saves', map, 'icon.png')
}
getLibraryByPath(libraryPath: string): string {
return join(this.libraries, libraryPath)
}
getAssetsIndex(versionAssets: string): string {
return this.getPath('assets', 'indexes', versionAssets + '.json')
}
getAsset(hash: string): string {
return this.getPath('assets', 'objects', hash.substring(0, 2), hash)
}
getLogConfig(file: string): string {
return this.getPath('assets', 'log_configs', file)
}
getPath(...path: string[]) {
return join(this.root, ...path)
}
}
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace MinecraftPath {
export const mods = 'mods'
export const resourcepacks = 'resourcepacks'
export const assets = 'assets'
export const libraries = 'libraries'
export const versions = 'versions'
export const logs = 'logs'
export const options = 'options.txt'
export const launcherProfile = 'launcher_profiles.json'
export const lastestLog = 'logs/latest.log'
export const maps = MinecraftPath.saves
export const saves = 'saves'
export const screenshots = 'screenshots'
export function getVersionRoot(version: string) {
return join('versions', version)
}
export function getNativesRoot(version: string) {
return join('versions', version, version + '-natives')
}
export function getVersionJson(version: string) {
return join('versions', version, version + '.json')
}
export function getVersionJar(version: string, type?: string) {
return type === 'client' || type === undefined
? join('versions', version, version + '.jar')
: join('versions', version, `${version}-${type}.jar`)
}
export function getResourcePack(fileName: string) {
return join('resourcepacks', fileName)
}
export function getMod(fileName: string) {
return join('mods', fileName)
}
export function getLog(fileName: string) {
return join('logs', fileName)
}
export function getMapInfo(map: string) {
return join('saves', map, 'level.dat')
}
export function getMapIcon(map: string) {
return join('saves', map, 'icon.png')
}
export function getLibraryByPath(libraryPath: string) {
return join('libraries', libraryPath)
}
export function getAssetsIndex(versionAssets: string) {
return join('assets', 'indexes', versionAssets + '.json')
}
export function getAsset(hash: string): string {
return join('assets', 'objects', hash.substring(0, 2), hash)
}
}
export type MinecraftLocation = MinecraftFolder | string