mirror of
https://github.com/packwiz/packwiz.git
synced 2025-10-14 15:04:32 +02:00
Add Jumploader to Fabric packs for CurseForge automatically (fixes #5)
This commit is contained in:
@@ -348,7 +348,10 @@ func (u cfUpdater) DoUpdate(mods []*core.Mod, cachedState []interface{}) error {
|
||||
}
|
||||
|
||||
type cfExportData struct {
|
||||
ProjectID int `mapstructure:"project-id"`
|
||||
ProjectID int `mapstructure:"project-id"`
|
||||
DisableJumploader bool `mapstructure:"disable-jumploader"`
|
||||
JumploaderForgeVersion string `mapstructure:"jumploader-forge-version"`
|
||||
JumploaderFileID int `mapstructure:"jumploader-version-id"`
|
||||
}
|
||||
|
||||
func (e cfExportData) ToMap() (map[string]interface{}, error) {
|
||||
|
@@ -3,6 +3,7 @@ package curseforge
|
||||
import (
|
||||
"archive/zip"
|
||||
"bufio"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/spf13/viper"
|
||||
"os"
|
||||
@@ -104,6 +105,8 @@ var exportCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
cfFileRefs := make([]packinterop.AddonFileReference, 0, len(mods))
|
||||
jumploaderIncluded := false
|
||||
jumploaderProjectID := 361988
|
||||
for _, mod := range mods {
|
||||
projectRaw, ok := mod.GetParsedUpdateData("curseforge")
|
||||
// If the mod has curseforge metadata, add it to cfFileRefs
|
||||
@@ -115,6 +118,9 @@ var exportCmd = &cobra.Command{
|
||||
FileID: p.FileID,
|
||||
OptionalDisabled: mod.Option != nil && mod.Option.Optional && !mod.Option.Default,
|
||||
})
|
||||
if p.ProjectID == jumploaderProjectID {
|
||||
jumploaderIncluded = true
|
||||
}
|
||||
} else {
|
||||
// If the mod doesn't have the metadata, save it into the zip
|
||||
path, err := filepath.Rel(filepath.Dir(indexPath), mod.GetDestFilePath())
|
||||
@@ -138,6 +144,82 @@ var exportCmd = &cobra.Command{
|
||||
}
|
||||
}
|
||||
|
||||
fabricVersion, usingFabric := pack.Versions["fabric"]
|
||||
dataUpdated := false
|
||||
|
||||
if usingFabric {
|
||||
if len(fabricVersion) == 0 {
|
||||
fmt.Println("Invalid version of Fabric found!")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if len(exportData.JumploaderForgeVersion) == 0 {
|
||||
dataUpdated = true
|
||||
|
||||
// TODO: this code is horrible, I hate it
|
||||
_, latest, err := core.ModLoaders["forge"][0].VersionListGetter(pack.Versions["minecraft"])
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to get the latest Forge version: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
exportData.JumploaderForgeVersion = latest
|
||||
}
|
||||
}
|
||||
|
||||
if !jumploaderIncluded && usingFabric && !exportData.DisableJumploader {
|
||||
fmt.Println("Fabric isn't natively supported by CurseForge, adding Jumploader...")
|
||||
|
||||
if exportData.JumploaderFileID == 0 {
|
||||
dataUpdated = true
|
||||
modInfoData, err := getModInfo(jumploaderProjectID)
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to fetch Jumploader latest file: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
var fileID int
|
||||
for _, v := range modInfoData.LatestFiles {
|
||||
// Choose "newest" version by largest ID
|
||||
if v.ID > fileID {
|
||||
fileID = v.ID
|
||||
}
|
||||
}
|
||||
if fileID == 0 {
|
||||
fmt.Printf("Failed to fetch Jumploader latest file: no file found")
|
||||
os.Exit(1)
|
||||
}
|
||||
exportData.JumploaderFileID = fileID
|
||||
}
|
||||
|
||||
cfFileRefs = append(cfFileRefs, packinterop.AddonFileReference{
|
||||
ProjectID: jumploaderProjectID,
|
||||
FileID: exportData.JumploaderFileID,
|
||||
OptionalDisabled: false,
|
||||
})
|
||||
|
||||
err = createJumploaderConfig(exp, fabricVersion)
|
||||
if err != nil {
|
||||
fmt.Printf("Error creating Jumploader config file: %s\n", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
if dataUpdated {
|
||||
newMap, err := exportData.ToMap()
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to update metadata: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if pack.Export == nil {
|
||||
pack.Export = make(map[string]map[string]interface{})
|
||||
}
|
||||
pack.Export["curseforge"] = newMap
|
||||
err = pack.Write()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
manifestFile, err := exp.Create("manifest.json")
|
||||
if err != nil {
|
||||
_ = exp.Close()
|
||||
@@ -146,7 +228,7 @@ var exportCmd = &cobra.Command{
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
err = packinterop.WriteManifestFromPack(pack, cfFileRefs, exportData.ProjectID, manifestFile)
|
||||
err = packinterop.WriteManifestFromPack(pack, cfFileRefs, exportData.ProjectID, exportData.JumploaderForgeVersion, manifestFile)
|
||||
if err != nil {
|
||||
_ = exp.Close()
|
||||
_ = expFile.Close()
|
||||
@@ -241,6 +323,39 @@ func createModlist(zw *zip.Writer, mods []core.Mod) error {
|
||||
return w.Flush()
|
||||
}
|
||||
|
||||
type jumploaderConfig struct {
|
||||
ConfigVersion int `json:"configVersion"`
|
||||
Sources []string `json:"sources"`
|
||||
GameVersion string `json:"gameVersion"`
|
||||
GameSide string `json:"gameSide"`
|
||||
DisableUI bool `json:"disableUI"`
|
||||
LoadJarsFromFolder interface{} `json:"loadJarsFromFolder"`
|
||||
OverrideMainClass interface{} `json:"overrideMainClass"`
|
||||
PinFabricLoaderVersion string `json:"pinFabricLoaderVersion"`
|
||||
}
|
||||
|
||||
func createJumploaderConfig(zw *zip.Writer, loaderVersion string) error {
|
||||
jumploaderConfigFile, err := zw.Create("overrides/config/jumploader.json")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
j := jumploaderConfig{
|
||||
ConfigVersion: 2,
|
||||
Sources: []string{"minecraft", "fabric"},
|
||||
GameVersion: "current",
|
||||
GameSide: "current",
|
||||
DisableUI: false,
|
||||
LoadJarsFromFolder: nil,
|
||||
OverrideMainClass: nil,
|
||||
PinFabricLoaderVersion: loaderVersion,
|
||||
}
|
||||
|
||||
w := json.NewEncoder(jumploaderConfigFile)
|
||||
w.SetIndent("", " ") // Match CF export
|
||||
return w.Encode(j)
|
||||
}
|
||||
|
||||
func loadMods(index core.Index) []core.Mod {
|
||||
modPaths := index.GetAllMods()
|
||||
mods := make([]core.Mod, len(modPaths))
|
||||
|
@@ -69,7 +69,7 @@ type AddonFileReference struct {
|
||||
OptionalDisabled bool
|
||||
}
|
||||
|
||||
func WriteManifestFromPack(pack core.Pack, fileRefs []AddonFileReference, projectID int, out io.Writer) error {
|
||||
func WriteManifestFromPack(pack core.Pack, fileRefs []AddonFileReference, projectID int, jumploaderForgeVersion string, out io.Writer) error {
|
||||
files := make([]struct {
|
||||
ProjectID int `json:"projectID"`
|
||||
FileID int `json:"fileID"`
|
||||
@@ -90,6 +90,11 @@ func WriteManifestFromPack(pack core.Pack, fileRefs []AddonFileReference, projec
|
||||
ID: "forge-" + forgeVersion,
|
||||
Primary: true,
|
||||
})
|
||||
} else if len(jumploaderForgeVersion) > 0 {
|
||||
modLoaders = append(modLoaders, modLoaderDef{
|
||||
ID: "forge-" + jumploaderForgeVersion,
|
||||
Primary: true,
|
||||
})
|
||||
}
|
||||
|
||||
manifest := cursePackMeta{
|
||||
|
Reference in New Issue
Block a user