mirror of
https://github.com/packwiz/packwiz.git
synced 2025-04-19 13:06:30 +02:00
Switch to forward slashes, add metafile bool
This commit is contained in:
parent
2f3b80f251
commit
e2c772ee30
@ -22,6 +22,7 @@ type Index struct {
|
||||
|
||||
// IndexFile is a file in the index
|
||||
type IndexFile struct {
|
||||
// Files are stored in relative forward-slash format to the index file
|
||||
File string `toml:"file"`
|
||||
Hash string `toml:"hash"`
|
||||
HashFormat string `toml:"hash-format,omitempty"`
|
||||
@ -57,7 +58,7 @@ func (in *Index) RemoveFile(path string) error {
|
||||
|
||||
i := 0
|
||||
for _, file := range in.Files {
|
||||
if filepath.Clean(file.File) != relPath {
|
||||
if filepath.Clean(filepath.FromSlash(file.File)) != relPath {
|
||||
// Keep file, as it doesn't match
|
||||
in.Files[i] = file
|
||||
i++
|
||||
@ -76,8 +77,7 @@ func (in *Index) resortIndex() {
|
||||
})
|
||||
}
|
||||
|
||||
// updateFile calculates the hash for a given path relative to the pack folder,
|
||||
// and updates it in the index
|
||||
// updateFile calculates the hash for a given path and updates it in the index
|
||||
func (in *Index) updateFile(path string) error {
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
@ -101,7 +101,7 @@ func (in *Index) updateFile(path string) error {
|
||||
return err
|
||||
}
|
||||
for k, v := range in.Files {
|
||||
if filepath.Clean(v.File) == relPath {
|
||||
if filepath.Clean(filepath.FromSlash(v.File)) == relPath {
|
||||
found = true
|
||||
// Update hash
|
||||
in.Files[k].Hash = hashString
|
||||
@ -113,14 +113,14 @@ func (in *Index) updateFile(path string) error {
|
||||
// Mark this file as found
|
||||
in.Files[k].fileExistsTemp = true
|
||||
// Clean up path if it's untidy
|
||||
in.Files[k].File = relPath
|
||||
in.Files[k].File = filepath.ToSlash(relPath)
|
||||
// Don't break out of loop, as there may be aliased versions that
|
||||
// also need to be updated
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
newFile := IndexFile{
|
||||
File: relPath,
|
||||
File: filepath.ToSlash(relPath),
|
||||
Hash: hashString,
|
||||
fileExistsTemp: true,
|
||||
}
|
||||
@ -128,6 +128,20 @@ func (in *Index) updateFile(path string) error {
|
||||
if in.HashFormat != "sha256" {
|
||||
newFile.HashFormat = "sha256"
|
||||
}
|
||||
// If the file is in the mods folder, set MetaFile to true (mods are metafiles by default)
|
||||
// This is incredibly powerful: you can put a normal jar in the mods folder just by
|
||||
// setting MetaFile to false. Or you can use the "mod" metadata system for other types
|
||||
// of files, like CraftTweaker resources.
|
||||
absFileDir, err := filepath.Abs(filepath.Dir(path))
|
||||
if err == nil {
|
||||
absModsDir, err := filepath.Abs(in.flags.ModsFolder)
|
||||
if err == nil {
|
||||
if absFileDir == absModsDir {
|
||||
newFile.MetaFile = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
in.Files = append(in.Files, newFile)
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@ import (
|
||||
type Pack struct {
|
||||
Name string `toml:"name"`
|
||||
Index struct {
|
||||
// Path is stored in forward slash format relative to pack.toml
|
||||
File string `toml:"file"`
|
||||
HashFormat string `toml:"hash-format"`
|
||||
Hash string `toml:"hash"`
|
||||
@ -47,12 +48,14 @@ func (pack Pack) LoadIndex() (Index, error) {
|
||||
if filepath.IsAbs(pack.Index.File) {
|
||||
return LoadIndex(pack.Index.File, pack.flags)
|
||||
}
|
||||
return LoadIndex(filepath.Join(filepath.Dir(pack.flags.PackFile), pack.Index.File), pack.flags)
|
||||
fileNative := filepath.FromSlash(pack.Index.File)
|
||||
return LoadIndex(filepath.Join(filepath.Dir(pack.flags.PackFile), fileNative), pack.flags)
|
||||
}
|
||||
|
||||
// UpdateIndexHash recalculates the hash of the index file of this modpack
|
||||
func (pack *Pack) UpdateIndexHash() error {
|
||||
indexFile := filepath.Join(filepath.Dir(pack.flags.PackFile), pack.Index.File)
|
||||
fileNative := filepath.FromSlash(pack.Index.File)
|
||||
indexFile := filepath.Join(filepath.Dir(pack.flags.PackFile), fileNative)
|
||||
if filepath.IsAbs(pack.Index.File) {
|
||||
indexFile = pack.Index.File
|
||||
}
|
||||
|
@ -13,15 +13,3 @@ func ResolveMod(modName string, flags Flags) string {
|
||||
return filepath.Join(flags.ModsFolder, fileName)
|
||||
}
|
||||
|
||||
// ResolveIndex returns the path to the index file
|
||||
func ResolveIndex(flags Flags) (string, error) {
|
||||
pack, err := LoadPack(flags)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if filepath.IsAbs(pack.Index.File) {
|
||||
return pack.Index.File, nil
|
||||
}
|
||||
return filepath.Join(filepath.Dir(flags.PackFile), pack.Index.File), nil
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user