-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanifest.go
112 lines (89 loc) · 2.32 KB
/
manifest.go
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
package main
import (
"encoding/json"
"io/ioutil"
"log"
"strconv"
"github.com/buger/jsonparser"
)
func readExport(exportPath string, manifestType string) {
log.Println("Reading export.json...")
export, err := ioutil.ReadFile(exportPath)
if err != nil {
log.Println(err)
log.Println("***WARNING: export.json is missing, either fill in the json manually",
"or retry with a correct export.json***")
}
json := readExportJSON(export)
if manifestType == "old" {
manifest(json, oldMap, manifestType)
} else {
manifest(json, newMap, manifestType)
}
log.Println("Reading export.json completed.")
}
func readExportJSON(file []byte) ExportJSON {
paths := [][]string{
{"MinecraftVersion"},
{"Modloader"},
{"ModloaderVersion"},
{"ManifestType"},
{"ManifestVersion"},
{"PackName"},
{"PackVersion"},
{"PackAuthors"},
}
var json ExportJSON
jsonparser.EachKey(file, func(idx int, value []byte, vt jsonparser.ValueType, err error) {
switch idx {
case 0:
json.MinecraftVersion = string(value)
case 1:
json.Modloader = string(value)
case 2:
json.ModloaderVersion = string(value)
case 3:
json.ManifestType = string(value)
case 4:
json.ManifestVersion, _ = strconv.Atoi(string(value))
case 5:
json.PackName = string(value)
case 6:
json.PackVersion = string(value)
case 7:
json.PackAuthors = string(value)
}
}, paths...)
return json
}
func manifest(exportjson ExportJSON, xMap map[string][]string, manifestType string) {
var moddedFiles []CurrFile
for key, value := range xMap {
keyInt, _ := strconv.Atoi(key)
valueInt, _ := strconv.Atoi(value[2])
moddedFiles = append(moddedFiles, CurrFile{keyInt, valueInt, true})
}
data := Manifest{
Minecraft: Minecraft{
Version: *gameVersion,
ModLoaders: []ModLoaders{
{
ID: exportjson.Modloader + "-" + exportjson.ModloaderVersion,
Primary: true,
},
},
},
ManifestType: exportjson.ManifestType,
ManifestVersion: exportjson.ManifestVersion,
Name: exportjson.PackName,
Version: exportjson.PackVersion,
Author: exportjson.PackAuthors,
Files: moddedFiles,
}
file, _ := json.MarshalIndent(data, "", " ")
if manifestType == "old" {
_ = ioutil.WriteFile("old.json", file, 0644)
} else {
_ = ioutil.WriteFile("manifest.json", file, 0644)
}
}