mirror of
https://github.com/packwiz/packwiz.git
synced 2025-04-19 21:16:30 +02:00
Add pack-root option (fixes #27)
This commit is contained in:
parent
d6bed7ad4c
commit
8cbe7d4c61
@ -76,7 +76,8 @@ For use on servers, add the `-g` flag to disable the GUI and `-s server` to down
|
|||||||
|
|
||||||
## Options
|
## Options
|
||||||
- Additional options can be configured in the `[options]` section of `pack.toml`, as follows:
|
- Additional options can be configured in the `[options]` section of `pack.toml`, as follows:
|
||||||
- `mods-folder` The folder to save mod metadata files into, for the install commands
|
- `mods-folder` The folder to save mod metadata files into, for the install commands (relative to the pack root)
|
||||||
- `acceptable-game-versions` A list of additional Minecraft versions to accept when installing or updating mods
|
- `acceptable-game-versions` A list of additional Minecraft versions to accept when installing or updating mods
|
||||||
- `no-internal-hashes` If this is set to true, packwiz will not generate hashes of local files, to prevent merge conflicts and inconsistent hashes when using git/etc.
|
- `no-internal-hashes` If this is set to true, packwiz will not generate hashes of local files, to prevent merge conflicts and inconsistent hashes when using git/etc.
|
||||||
- `packwiz refresh --build` can be used in this mode to generate internal hashes for distributing the pack with packwiz-installer
|
- `packwiz refresh --build` can be used in this mode to generate internal hashes for distributing the pack with packwiz-installer
|
||||||
|
- `pack-root` A custom directory, containing the modpack files and optional .packwizignore file (defaults to the index file location)
|
@ -153,7 +153,8 @@ func (in *Index) updateFile(path string) error {
|
|||||||
// If the file has an extension of toml and is in the mods folder, set mod to true
|
// 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))
|
absFileDir, err := filepath.Abs(filepath.Dir(path))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
absModsDir, err := filepath.Abs(viper.GetString("mods-folder"))
|
modsDir := filepath.Join(in.GetPackRoot(), viper.GetString("mods-folder"))
|
||||||
|
absModsDir, err := filepath.Abs(modsDir)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if absFileDir == absModsDir && strings.HasSuffix(filepath.Base(path), ".toml") {
|
if absFileDir == absModsDir && strings.HasSuffix(filepath.Base(path), ".toml") {
|
||||||
mod = true
|
mod = true
|
||||||
@ -164,6 +165,14 @@ func (in *Index) updateFile(path string) error {
|
|||||||
return in.updateFileHashGiven(path, "sha256", hashString, mod)
|
return in.updateFileHashGiven(path, "sha256", hashString, mod)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (in Index) GetPackRoot() string {
|
||||||
|
packRoot := viper.GetString("pack-root")
|
||||||
|
if len(packRoot) == 0 {
|
||||||
|
packRoot = filepath.Dir(in.indexFile)
|
||||||
|
}
|
||||||
|
return packRoot
|
||||||
|
}
|
||||||
|
|
||||||
// Refresh updates the hashes of all the files in the index, and adds new files to the index
|
// Refresh updates the hashes of all the files in the index, and adds new files to the index
|
||||||
func (in *Index) Refresh() error {
|
func (in *Index) Refresh() error {
|
||||||
// TODO: If needed, multithreaded hashing
|
// TODO: If needed, multithreaded hashing
|
||||||
@ -173,8 +182,7 @@ func (in *Index) Refresh() error {
|
|||||||
pathPF, _ := filepath.Abs(viper.GetString("pack-file"))
|
pathPF, _ := filepath.Abs(viper.GetString("pack-file"))
|
||||||
pathIndex, _ := filepath.Abs(in.indexFile)
|
pathIndex, _ := filepath.Abs(in.indexFile)
|
||||||
|
|
||||||
// TODO: A method of specifying pack root directory?
|
packRoot := in.GetPackRoot()
|
||||||
packRoot := filepath.Dir(viper.GetString("pack-file"))
|
|
||||||
ignoreExists := true
|
ignoreExists := true
|
||||||
pathIgnore, _ := filepath.Abs(filepath.Join(packRoot, ".packwizignore"))
|
pathIgnore, _ := filepath.Abs(filepath.Join(packRoot, ".packwizignore"))
|
||||||
ignore, err := gitignore.NewFromFile(filepath.Join(packRoot, ".packwizignore"))
|
ignore, err := gitignore.NewFromFile(filepath.Join(packRoot, ".packwizignore"))
|
||||||
|
@ -71,8 +71,8 @@ func LoadMod(modFile string) (Mod, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetMetaName sets the mod metadata file from a given file name (to be put in the mods folder)
|
// SetMetaName sets the mod metadata file from a given file name (to be put in the mods folder)
|
||||||
func (m *Mod) SetMetaName(metaName string) string {
|
func (m *Mod) SetMetaName(metaName string, index Index) string {
|
||||||
m.metaFile = ResolveMod(metaName)
|
m.metaFile = ResolveMod(metaName, index)
|
||||||
return m.metaFile
|
return m.metaFile
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,8 +11,9 @@ import (
|
|||||||
const ModExtension = ".toml"
|
const ModExtension = ".toml"
|
||||||
|
|
||||||
// ResolveMod returns the path to a mod file from it's name
|
// ResolveMod returns the path to a mod file from it's name
|
||||||
func ResolveMod(modName string) string {
|
func ResolveMod(modName string, index Index) string {
|
||||||
// TODO: should this work for any metadata file?
|
// TODO: should this work for any metadata file?
|
||||||
fileName := strings.ToLower(strings.TrimSuffix(modName, ModExtension)) + ModExtension
|
fileName := strings.ToLower(strings.TrimSuffix(modName, ModExtension)) + ModExtension
|
||||||
return filepath.Join(viper.GetString("mods-folder"), fileName)
|
modsDir := filepath.Join(index.GetPackRoot(), viper.GetString("mods-folder"))
|
||||||
|
return filepath.Join(modsDir, fileName)
|
||||||
}
|
}
|
||||||
|
@ -187,7 +187,7 @@ func createModFile(modInfo modInfo, fileInfo modFileInfo, index *core.Index) err
|
|||||||
},
|
},
|
||||||
Update: updateMap,
|
Update: updateMap,
|
||||||
}
|
}
|
||||||
path := modMeta.SetMetaName(modInfo.Slug)
|
path := modMeta.SetMetaName(modInfo.Slug, *index)
|
||||||
|
|
||||||
// If the file already exists, this will overwrite it!!!
|
// If the file already exists, this will overwrite it!!!
|
||||||
// TODO: Should this be improved?
|
// TODO: Should this be improved?
|
||||||
|
@ -224,7 +224,8 @@ var importCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: just use mods-folder directly? does texture pack importing affect this?
|
// TODO: just use mods-folder directly? does texture pack importing affect this?
|
||||||
ref, err := filepath.Abs(filepath.Join(filepath.Dir(core.ResolveMod(modInfoValue.Slug)), fileInfo.FileName))
|
modFilePath := core.ResolveMod(modInfoValue.Slug, index)
|
||||||
|
ref, err := filepath.Abs(filepath.Join(filepath.Dir(modFilePath), fileInfo.FileName))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
referencedModPaths = append(referencedModPaths, ref)
|
referencedModPaths = append(referencedModPaths, ref)
|
||||||
}
|
}
|
||||||
@ -243,9 +244,9 @@ var importCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
successes = 0
|
successes = 0
|
||||||
indexFolder := filepath.Dir(filepath.Join(filepath.Dir(viper.GetString("pack-file")), filepath.FromSlash(pack.Index.File)))
|
packRoot := index.GetPackRoot()
|
||||||
for _, v := range filesList {
|
for _, v := range filesList {
|
||||||
filePath := filepath.Join(indexFolder, filepath.FromSlash(v.Name()))
|
filePath := filepath.Join(packRoot, filepath.FromSlash(v.Name()))
|
||||||
filePathAbs, err := filepath.Abs(filePath)
|
filePathAbs, err := filepath.Abs(filePath)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
found := false
|
found := false
|
||||||
|
@ -205,9 +205,9 @@ func installVersion(mod Mod, version Version, pack core.Pack) error {
|
|||||||
}
|
}
|
||||||
var path string
|
var path string
|
||||||
if mod.Slug != "" {
|
if mod.Slug != "" {
|
||||||
path = modMeta.SetMetaName(mod.Slug)
|
path = modMeta.SetMetaName(mod.Slug, index)
|
||||||
} else {
|
} else {
|
||||||
path = modMeta.SetMetaName(mod.Title)
|
path = modMeta.SetMetaName(mod.Title, index)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the file already exists, this will overwrite it!!!
|
// If the file already exists, this will overwrite it!!!
|
||||||
|
Loading…
x
Reference in New Issue
Block a user