mirror of
https://github.com/packwiz/packwiz.git
synced 2025-10-14 06:54:32 +02:00
Use the correct directories for non-mod files; use .pw.toml extension
The mods-folder option is now replaced with two new options: meta-folder and meta-folder-base This allows non-mod files to use the correct directory based on their category; with correct import of resource packs/etc from CurseForge packs, and the ability to override this behaviour. To improve the reliability of packwiz metadata file marking (in the index), new files now use .pw.toml as the extension - any extension can be used, but .pw.toml will now be automatically be marked as a metafile regardless of folder, so you can easily move metadata files around. Existing metadata files will still work (as metafile = true is set in the index); though in the future .pw.toml may be required.
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"github.com/spf13/viper"
|
||||
"golang.org/x/exp/slices"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -136,8 +137,7 @@ func parseSlugOrUrl(url string) (game string, category string, slug string, file
|
||||
return
|
||||
}
|
||||
|
||||
// TODO: put projects into folders based on these
|
||||
var defaultFolders = map[int]map[int]string{
|
||||
var defaultFolders = map[uint32]map[uint32]string{
|
||||
432: { // Minecraft
|
||||
5: "plugins", // Bukkit Plugins
|
||||
12: "resourcepacks",
|
||||
@@ -146,6 +146,21 @@ var defaultFolders = map[int]map[int]string{
|
||||
},
|
||||
}
|
||||
|
||||
func getPathForFile(gameID uint32, classID uint32, categoryID uint32, slug string) string {
|
||||
metaFolder := viper.GetString("meta-folder")
|
||||
if metaFolder == "" {
|
||||
if m, ok := defaultFolders[gameID]; ok {
|
||||
if folder, ok := m[classID]; ok {
|
||||
return filepath.Join(viper.GetString("meta-folder-base"), folder, slug+core.MetaExtension)
|
||||
} else if folder, ok := m[categoryID]; ok {
|
||||
return filepath.Join(viper.GetString("meta-folder-base"), folder, slug+core.MetaExtension)
|
||||
}
|
||||
}
|
||||
metaFolder = "."
|
||||
}
|
||||
return filepath.Join(viper.GetString("meta-folder-base"), metaFolder, slug+core.MetaExtension)
|
||||
}
|
||||
|
||||
func createModFile(modInfo modInfo, fileInfo modFileInfo, index *core.Index, optionalDisabled bool) error {
|
||||
updateMap := make(map[string]map[string]interface{})
|
||||
var err error
|
||||
@@ -179,7 +194,7 @@ func createModFile(modInfo modInfo, fileInfo modFileInfo, index *core.Index, opt
|
||||
Option: optional,
|
||||
Update: updateMap,
|
||||
}
|
||||
path := modMeta.SetMetaName(modInfo.Slug, *index)
|
||||
path := modMeta.SetMetaPath(getPathForFile(modInfo.GameID, modInfo.ClassID, modInfo.PrimaryCategoryID, modInfo.Slug))
|
||||
|
||||
// If the file already exists, this will overwrite it!!!
|
||||
// TODO: Should this be improved?
|
||||
|
@@ -266,8 +266,7 @@ var importCmd = &cobra.Command{
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// TODO: just use mods-folder directly? does texture pack importing affect this?
|
||||
modFilePath := core.ResolveMod(modInfoValue.Slug, index)
|
||||
modFilePath := getPathForFile(modInfoValue.GameID, modInfoValue.ClassID, modInfoValue.PrimaryCategoryID, modInfoValue.Slug)
|
||||
ref, err := filepath.Abs(filepath.Join(filepath.Dir(modFilePath), modFileInfoValue.FileName))
|
||||
if err == nil {
|
||||
referencedModPaths = append(referencedModPaths, ref)
|
||||
|
@@ -134,6 +134,9 @@ type modInfo struct {
|
||||
Summary string `json:"summary"`
|
||||
Slug string `json:"slug"`
|
||||
ID int `json:"id"`
|
||||
GameID uint32 `json:"gameId"`
|
||||
PrimaryCategoryID uint32 `json:"primaryCategoryId"`
|
||||
ClassID uint32 `json:"classId"`
|
||||
LatestFiles []modFileInfo `json:"latestFiles"`
|
||||
GameVersionLatestFiles []struct {
|
||||
// TODO: check how twitch launcher chooses which one to use, when you are on beta/alpha channel?!
|
||||
|
Reference in New Issue
Block a user