mirror of
https://github.com/packwiz/packwiz.git
synced 2025-10-14 06:54:32 +02:00
Add pack-root option (fixes #27)
This commit is contained in:
@@ -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
|
||||
absFileDir, err := filepath.Abs(filepath.Dir(path))
|
||||
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 absFileDir == absModsDir && strings.HasSuffix(filepath.Base(path), ".toml") {
|
||||
mod = true
|
||||
@@ -164,6 +165,14 @@ func (in *Index) updateFile(path string) error {
|
||||
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
|
||||
func (in *Index) Refresh() error {
|
||||
// TODO: If needed, multithreaded hashing
|
||||
@@ -173,8 +182,7 @@ func (in *Index) Refresh() error {
|
||||
pathPF, _ := filepath.Abs(viper.GetString("pack-file"))
|
||||
pathIndex, _ := filepath.Abs(in.indexFile)
|
||||
|
||||
// TODO: A method of specifying pack root directory?
|
||||
packRoot := filepath.Dir(viper.GetString("pack-file"))
|
||||
packRoot := in.GetPackRoot()
|
||||
ignoreExists := true
|
||||
pathIgnore, _ := filepath.Abs(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)
|
||||
func (m *Mod) SetMetaName(metaName string) string {
|
||||
m.metaFile = ResolveMod(metaName)
|
||||
func (m *Mod) SetMetaName(metaName string, index Index) string {
|
||||
m.metaFile = ResolveMod(metaName, index)
|
||||
return m.metaFile
|
||||
}
|
||||
|
||||
|
@@ -11,8 +11,9 @@ import (
|
||||
const ModExtension = ".toml"
|
||||
|
||||
// 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?
|
||||
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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user