-
Notifications
You must be signed in to change notification settings - Fork 27
/
diagnose.ts
70 lines (65 loc) · 2.2 KB
/
diagnose.ts
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
import { diagnoseFile, Issue, LibraryIssue, MinecraftFolder, MinecraftLocation, Version } from '@xmcl/core'
import { InstallProfile, resolveProcessors, PostProcessor } from './profile'
export type InstallIssues = ProcessorIssue | LibraryIssue
/**
* The processor issue
*/
export interface ProcessorIssue extends Issue {
role: 'processor'
/**
* The processor
*/
processor: PostProcessor
}
export interface InstallProfileIssueReport {
minecraftLocation: MinecraftFolder
installProfile: InstallProfile
issues: InstallIssues[]
}
/**
* Diagnose a install profile status. Check if it processor output correctly processed.
*
* This can be used for check if forge correctly installed when minecraft >= 1.13
* @beta
*
* @param installProfile The install profile.
* @param minecraftLocation The minecraft location
*/
export async function diagnoseInstall(installProfile: InstallProfile, minecraftLocation: MinecraftLocation, side: 'client' | 'server' = 'client'): Promise<InstallProfileIssueReport> {
const mc = MinecraftFolder.from(minecraftLocation)
const report: InstallProfileIssueReport = {
minecraftLocation: mc,
installProfile,
issues: [],
}
const issues = report.issues
const processors: PostProcessor[] = resolveProcessors(side, installProfile, mc)
await Promise.all(Version.resolveLibraries(installProfile.libraries).map(async (lib) => {
const libPath = mc.getLibraryByPath(lib.download.path)
const issue = await diagnoseFile({
role: 'library',
file: libPath,
expectedChecksum: lib.download.sha1,
hint: 'Problem on install_profile! Please consider to use Installer.installByProfile to fix.',
})
if (issue) {
issues.push(Object.assign(issue, { library: lib }))
}
}))
for (const proc of processors) {
if (proc.outputs) {
for (const [file, checksum] of Object.entries(proc.outputs)) {
const issue = await diagnoseFile({
role: 'processor',
file,
expectedChecksum: checksum.replace(/'/g, ''),
hint: 'Re-install this installer profile!',
})
if (issue) {
issues.push(Object.assign(issue, { processor: proc }))
}
}
}
}
return report
}