diff --git a/README.md b/README.md index b439979..2f3c071 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,8 @@ For use on servers, add the `-g` flag to disable the GUI and `-s server` to down ## Options - 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 - `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 \ No newline at end of file + - `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) \ No newline at end of file diff --git a/core/index.go b/core/index.go index 968f035..47cfd04 100644 --- a/core/index.go +++ b/core/index.go @@ -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")) diff --git a/core/mod.go b/core/mod.go index d32bdf6..d3247e7 100644 --- a/core/mod.go +++ b/core/mod.go @@ -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 } diff --git a/core/resolve.go b/core/resolve.go index 093bd37..571d343 100644 --- a/core/resolve.go +++ b/core/resolve.go @@ -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) } diff --git a/curseforge/curseforge.go b/curseforge/curseforge.go index 7848fce..dc02b78 100644 --- a/curseforge/curseforge.go +++ b/curseforge/curseforge.go @@ -187,7 +187,7 @@ func createModFile(modInfo modInfo, fileInfo modFileInfo, index *core.Index) err }, Update: updateMap, } - path := modMeta.SetMetaName(modInfo.Slug) + path := modMeta.SetMetaName(modInfo.Slug, *index) // If the file already exists, this will overwrite it!!! // TODO: Should this be improved? diff --git a/curseforge/import.go b/curseforge/import.go index be52f4d..fc4c330 100644 --- a/curseforge/import.go +++ b/curseforge/import.go @@ -224,7 +224,8 @@ var importCmd = &cobra.Command{ } // 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 { referencedModPaths = append(referencedModPaths, ref) } @@ -243,9 +244,9 @@ var importCmd = &cobra.Command{ } 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 { - filePath := filepath.Join(indexFolder, filepath.FromSlash(v.Name())) + filePath := filepath.Join(packRoot, filepath.FromSlash(v.Name())) filePathAbs, err := filepath.Abs(filePath) if err == nil { found := false diff --git a/modrinth/install.go b/modrinth/install.go index 4c93cd2..98bbd66 100644 --- a/modrinth/install.go +++ b/modrinth/install.go @@ -205,9 +205,9 @@ func installVersion(mod Mod, version Version, pack core.Pack) error { } var path string if mod.Slug != "" { - path = modMeta.SetMetaName(mod.Slug) + path = modMeta.SetMetaName(mod.Slug, index) } else { - path = modMeta.SetMetaName(mod.Title) + path = modMeta.SetMetaName(mod.Title, index) } // If the file already exists, this will overwrite it!!!