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:
@@ -150,16 +150,9 @@ func (in *Index) updateFile(path string) error {
|
||||
}
|
||||
|
||||
mod := false
|
||||
// If the file has an extension of toml and is in the mods folder, set mod to true
|
||||
absFileDir, err := filepath.Abs(filepath.Dir(path))
|
||||
if err == nil {
|
||||
modsDir := filepath.Join(in.GetPackRoot(), viper.GetString("mods-folder"))
|
||||
absModsDir, err := filepath.Abs(modsDir)
|
||||
if err == nil {
|
||||
if absFileDir == absModsDir && strings.HasSuffix(filepath.Base(path), ".toml") {
|
||||
mod = true
|
||||
}
|
||||
}
|
||||
// If the file has an extension of pw.toml, set mod to true
|
||||
if strings.HasSuffix(filepath.Base(path), MetaExtension) {
|
||||
mod = true
|
||||
}
|
||||
|
||||
return in.updateFileHashGiven(path, "sha256", hashString, mod)
|
||||
@@ -341,7 +334,7 @@ func (in Index) FindMod(modName string) (string, bool) {
|
||||
for _, v := range in.Files {
|
||||
if v.MetaFile {
|
||||
_, file := filepath.Split(v.File)
|
||||
fileTrimmed := strings.TrimSuffix(file, ModExtension)
|
||||
fileTrimmed := strings.TrimSuffix(file, MetaExtension)
|
||||
if fileTrimmed == modName {
|
||||
return filepath.Join(filepath.Dir(in.indexFile), filepath.FromSlash(v.File)), true
|
||||
}
|
||||
|
@@ -72,9 +72,9 @@ func LoadMod(modFile string) (Mod, error) {
|
||||
return mod, nil
|
||||
}
|
||||
|
||||
// SetMetaName sets the mod metadata file from a given file name (to be put in the mods folder)
|
||||
func (m *Mod) SetMetaName(metaName string, index Index) string {
|
||||
m.metaFile = ResolveMod(metaName, index)
|
||||
// SetMetaPath sets the file path of a metadata file
|
||||
func (m *Mod) SetMetaPath(metaFile string) string {
|
||||
m.metaFile = metaFile
|
||||
return m.metaFile
|
||||
}
|
||||
|
||||
|
@@ -1,19 +1,5 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
// ModExtension is the file extension of the mod metadata files
|
||||
const ModExtension = ".toml"
|
||||
|
||||
// ResolveMod returns the path to a mod file from it's name
|
||||
func ResolveMod(modName string, index Index) string {
|
||||
// TODO: should this work for any metadata file?
|
||||
fileName := strings.ToLower(strings.TrimSuffix(modName, ModExtension)) + ModExtension
|
||||
modsDir := filepath.Join(index.GetPackRoot(), viper.GetString("mods-folder"))
|
||||
return filepath.Join(modsDir, fileName)
|
||||
}
|
||||
// MetaExtension is the file extension of the mod metadata files
|
||||
// Note that this is currently not required; it will only be used for new files.
|
||||
const MetaExtension = ".pw.toml"
|
||||
|
Reference in New Issue
Block a user