core

package
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 23, 2025 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ModeURL string = "url"
	ModeCF  string = "metadata:curseforge"
)
View Source
const CurrentPackFormat = "packwiz:1.1.0"
View Source
const MetaExtension = ".pw.toml"

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.

View Source
const MetaExtensionOld = ".toml"
View Source
const UserAgent = "packwiz/packwiz"

Variables

View Source
var MetaDownloaders = make(map[string]MetaDownloader)

MetaDownloaders stores all the metadata-based installers that packwiz can use. Add your own downloaders to this map, keyed by the source name.

View Source
var ModLoaders = map[string]ModLoaderComponent{
	"fabric": {
		Name:         "fabric",
		FriendlyName: "Fabric loader",
		VersionListGetter: func(mcVersion string) ([]string, string, error) {
			return GetLoaderCache().GetVersions(mcVersion, "fabric")
		},
	},
	"forge": {
		Name:         "forge",
		FriendlyName: "Forge",
		VersionListGetter: func(mcVersion string) ([]string, string, error) {
			return GetLoaderCache().GetVersions(mcVersion, "forge")
		},
	},
	"liteloader": {
		Name:         "liteloader",
		FriendlyName: "LiteLoader",
		VersionListGetter: func(mcVersion string) ([]string, string, error) {
			return GetLoaderCache().GetVersions(mcVersion, "liteloader")
		},
	},
	"quilt": {
		Name:         "quilt",
		FriendlyName: "Quilt loader",
		VersionListGetter: func(mcVersion string) ([]string, string, error) {
			return GetLoaderCache().GetVersions(mcVersion, "quilt")
		},
	},
	"neoforge": {
		Name:         "neoforge",
		FriendlyName: "NeoForge",
		VersionListGetter: func(mcVersion string) ([]string, string, error) {
			return GetLoaderCache().GetVersions(mcVersion, "neoforge")
		},
	},
}
View Source
var PackFormatConstraintAccepted = mustParseConstraint("~1")
View Source
var PackFormatConstraintSuggestUpgrade = mustParseConstraint("~1.1")
View Source
var PreferredHashList = []string{
	"murmur2",
	"md5",
	"sha1",
	"sha256",
	"sha512",
}

Functions

func AddUpdater

func AddUpdater(updater Updater)

func CompareVersions added in v0.0.3

func CompareVersions(version1, version2 string) int

CompareVersions compares two version strings and returns:

-1 if version1 < version2
 0 if version1 == version2
 1 if version1 > version2

func ComponentToFriendlyName

func ComponentToFriendlyName(component string) string

func GetForgeRecommended

func GetForgeRecommended(mcVersion string) string

GetForgeRecommended gets the recommended version of Forge for the given Minecraft version

func GetWithUA

func GetWithUA(url string, contentType string) (resp *http.Response, err error)

func HighestSliceIndex

func HighestSliceIndex(slice []string, values []string) int

HighestSliceIndex returns the highest index of the given values in the slice (-1 if no value is found in the slice)

func ReEncodeURL

func ReEncodeURL(u string) (string, error)

ReEncodeURL re-encodes URLs for RFC3986 compliance; as CurseForge URLs aren't properly encoded

func SlugifyName

func SlugifyName(name string) string

func SortAndDedupeVersions

func SortAndDedupeVersions(versions []string)

func SortAscending added in v0.0.3

func SortAscending(versions []string) []string

func SortDescending added in v0.0.3

func SortDescending(versions []string) []string

func UpdateAllMods

func UpdateAllMods(pack Pack) error

func UpdateSingleMod

func UpdateSingleMod(pack Pack, mod *Mod) error

func ValidatePack

func ValidatePack(pack *PackToml) error

ValidatePack run some basic validation and migrate the pack if possible.

Types

type ForgeRecommended

type ForgeRecommended struct {
	Homepage string            `json:"homepage"`
	Versions map[string]string `json:"promos"`
}

type HashStringer

type HashStringer interface {
	hash.Hash
	String() string
}

func GetHashImpl

func GetHashImpl(hashType string) (HashStringer, error)

GetHashImpl gets an implementation of hash.Hash for the given hash type string

type HashableObject

type HashableObject interface {
	Marshal() (MarshalResult, error)
}

type IndexFS

type IndexFS struct {
	DefaultModHashFormat string
	Files                IndexFiles
	// contains filtered or unexported fields
}

IndexFS is a representation of the index.toml file for referencing all the files in a pack.

func NewIndexFromTomlRepr

func NewIndexFromTomlRepr(rep IndexTomlRepresentation) IndexFS

func (*IndexFS) FindMod

func (in *IndexFS) FindMod(modName string) (string, bool)

FindMod finds a mod in the index and returns its path and whether it has been found

func (*IndexFS) GetAllMods

func (in *IndexFS) GetAllMods() []string

GetAllMods finds paths to every metadata file (ModToml) in the index

func (*IndexFS) GetFilePath

func (in *IndexFS) GetFilePath() string

func (*IndexFS) GetHash

func (in *IndexFS) GetHash() string

func (*IndexFS) GetHashFormat

func (in *IndexFS) GetHashFormat() string

func (*IndexFS) GetPackRoot

func (in *IndexFS) GetPackRoot() string

func (*IndexFS) RelIndexPath

func (in *IndexFS) RelIndexPath(p string) (string, error)

RelIndexPath turns a file path on disk into a path from the index

func (*IndexFS) RemoveFile

func (in *IndexFS) RemoveFile(path string) error

RemoveFile removes a file from the index, given a file path

func (*IndexFS) ResolveIndexPath

func (in *IndexFS) ResolveIndexPath(p string) string

ResolveIndexPath turns a path from the index into a file path on disk

func (*IndexFS) ToWritable

func (in *IndexFS) ToWritable() IndexTomlRepresentation

func (*IndexFS) UpdateFileHashGiven

func (in *IndexFS) UpdateFileHashGiven(path, format, hash string, markAsMetaFile bool) error

type IndexFile

type IndexFile struct {
	// Files are stored in forward-slash format relative to the index file
	File       string `toml:"file"`
	Hash       string `toml:"hash,omitempty"`
	HashFormat string `toml:"hash-format,omitempty"`
	Alias      string `toml:"alias,omitempty"`
	MetaFile   bool   `toml:"metafile,omitempty"` // True when it is a .toml metadata file
	Preserve   bool   `toml:"preserve,omitempty"` // Don't overwrite the file when updating
	// contains filtered or unexported fields
}

IndexFile is a file in the index

func (*IndexFile) IsMetaFile

func (i *IndexFile) IsMetaFile() bool

func (*IndexFile) MarkedFound

func (i *IndexFile) MarkedFound() bool

type IndexFiles

type IndexFiles map[string]IndexPathHolder

IndexFiles are stored as a map of path -> (indexFile or alias -> indexFile) The latter is used for multiple copies with the same path but different alias

type IndexFilesTomlRepresentation

type IndexFilesTomlRepresentation []IndexFile

type IndexPathHolder

type IndexPathHolder interface {
	MarkedFound() bool
	IsMetaFile() bool
	// contains filtered or unexported methods
}

type IndexTomlRepresentation

type IndexTomlRepresentation struct {
	DefaultModHashFormat string                       `toml:"hash-format"`
	Files                IndexFilesTomlRepresentation `toml:"files"`
	// contains filtered or unexported fields
}

IndexTomlRepresentation is the TOML representation of IndexFS (Files must be converted)

func (*IndexTomlRepresentation) GetFilePath

func (it *IndexTomlRepresentation) GetFilePath() string

func (*IndexTomlRepresentation) GetHashFormat

func (it *IndexTomlRepresentation) GetHashFormat() string

func (*IndexTomlRepresentation) Marshal

func (it *IndexTomlRepresentation) Marshal() (MarshalResult, error)

func (*IndexTomlRepresentation) SetFilePath

func (it *IndexTomlRepresentation) SetFilePath(path string)

func (*IndexTomlRepresentation) UpdateHash

func (it *IndexTomlRepresentation) UpdateHash(format, hash string)

type LengthHasher

type LengthHasher struct {
	// contains filtered or unexported fields
}

func (*LengthHasher) BlockSize

func (h *LengthHasher) BlockSize() int

func (*LengthHasher) Reset

func (h *LengthHasher) Reset()

func (*LengthHasher) Size

func (h *LengthHasher) Size() int

func (*LengthHasher) Sum

func (h *LengthHasher) Sum(b []byte) []byte

func (*LengthHasher) Write

func (h *LengthHasher) Write(p []byte) (n int, err error)

type LoaderInfo

type LoaderInfo map[string]string

type LoaderVersionCache added in v0.0.3

type LoaderVersionCache struct {
	Fabric     []string
	Forge      VersionMap
	Liteloader []string
	Quilt      []string
	Neoforge   VersionMap
}

func GetLoaderCache added in v0.0.3

func GetLoaderCache() *LoaderVersionCache

func (*LoaderVersionCache) GetVersions added in v0.0.3

func (l *LoaderVersionCache) GetVersions(mcVersion string, loader string) ([]string, string, error)

func (*LoaderVersionCache) IsEmpty added in v0.0.3

func (l *LoaderVersionCache) IsEmpty() bool

func (*LoaderVersionCache) RefreshCache added in v0.0.3

func (l *LoaderVersionCache) RefreshCache() error

type ManualDownload

type ManualDownload struct {
	Name     string
	FileName string
	URL      string
}

type MarshalResult

type MarshalResult struct {
	Value      []byte
	HashFormat string
	Hash       string
}

func (MarshalResult) String

func (m MarshalResult) String() string

type McVersionInfo added in v0.0.3

type McVersionInfo struct {
	Latest         string
	LatestSnapshot string
	Versions       []string
}

func GetMinecraftVersions added in v0.0.3

func GetMinecraftVersions() (McVersionInfo, error)

func (McVersionInfo) CheckValid added in v0.0.3

func (m McVersionInfo) CheckValid(version string) bool

type MetaDownloader

type MetaDownloader interface {
	GetFilesMetadata([]*Mod) ([]MetaDownloaderData, error)
}

MetaDownloader specifies a downloader for a Mod using a "metadata:source" mode The calling code should handle caching and hash validation.

type MetaDownloaderData

type MetaDownloaderData interface {
	GetManualDownload() (bool, ManualDownload)
	DownloadFile() (io.ReadCloser, error)
}

MetaDownloaderData specifies the per-ModToml metadata retrieved for downloading

type Mod

type Mod struct {
	Name     string
	FileName string
	Side     ModSide
	Pin      bool
	Download ModDownload
	Update   ModUpdate
	Option   *ModOption

	// for index
	Slug       string
	ModType    string // mods, shaders, resourcepacks, etc.
	HashFormat string
	Alias      string
	Preserve   bool
}

func FromModMeta

func FromModMeta(modMeta ModToml) *Mod

func NewMod

func NewMod(
	slug,
	name,
	fileName string,
	side ModSide,
	modType,
	alias string,
	pin,
	preserve bool,
	update ModUpdate,
	download ModDownload,
	options *ModOption,
) *Mod

func (*Mod) AsModToml

func (m *Mod) AsModToml() (string, string, error)

func (*Mod) DecodeNamedModSourceData

func (m *Mod) DecodeNamedModSourceData(name string, target interface{}) error

func (*Mod) GetRelDownloadPath

func (m *Mod) GetRelDownloadPath() string

func (*Mod) GetRelMetaPath

func (m *Mod) GetRelMetaPath() string

func (*Mod) GetUpdater

func (m *Mod) GetUpdater() (Updater, error)

func (*Mod) ToModMeta

func (m *Mod) ToModMeta() ModToml

type ModDownload

type ModDownload struct {
	URL        string `toml:"url,omitempty"`
	HashFormat string `toml:"hash-format"`
	Hash       string `toml:"hash"`
	// Mode defaults to modeURL (i.e. use URL when omitted or empty)
	Mode string `toml:"mode,omitempty"`
}

ModDownload specifies how to download the mod file

type ModLoaderComponent

type ModLoaderComponent struct {
	Name              string
	FriendlyName      string
	VersionListGetter func(mcVersion string) ([]string, string, error)
}

type ModOption

type ModOption struct {
	Optional    bool   `toml:"optional"`
	Description string `toml:"description,omitempty"`
	Default     bool   `toml:"default,omitempty"`
}

ModOption specifies optional metadata for this mod file

type ModSide

type ModSide string
const (
	ServerSide    ModSide = "server"
	ClientSide    ModSide = "client"
	UniversalSide ModSide = "both"
	EmptySide     ModSide = ""
)

The four possible values of Side (the side that the mod is on) are "server", "client", "both", and "" (equivalent to "both")

type ModSourceData

type ModSourceData map[string]interface{}

type ModToml

type ModToml struct {
	Name     string      `toml:"name"`
	FileName string      `toml:"filename"`
	Side     ModSide     `toml:"side,omitempty"`
	Pin      bool        `toml:"pin,omitempty"`
	Download ModDownload `toml:"download"`
	// Update is a map of maps, of stuff, so you can store arbitrary values on
	// string keys to define updating
	Update ModUpdate `toml:"update"`

	Option *ModOption `toml:"option,omitempty"`
	// contains filtered or unexported fields
}

ModToml stores metadata about a mod. This is written to a TOML file for each mod.

func (*ModToml) AppendUpdateData

func (m *ModToml) AppendUpdateData(key string, value interface{})

func (*ModToml) GetDestFilePath

func (m *ModToml) GetDestFilePath() string

GetDestFilePath returns the path of the destination file of the mod

func (*ModToml) GetFilePath

func (m *ModToml) GetFilePath() string

GetFilePath is a clumsy hack that I made because ModToml already stores it's path anyway

func (*ModToml) GetHashFormat

func (m *ModToml) GetHashFormat() string

func (*ModToml) GetHashInfo

func (m *ModToml) GetHashInfo() (string, string)

func (*ModToml) GetMetaFolder

func (m *ModToml) GetMetaFolder() string

func (*ModToml) GetMetaRelativePath

func (m *ModToml) GetMetaRelativePath() string

func (*ModToml) GetParsedUpdateData

func (m *ModToml) GetParsedUpdateData(updaterName string) (interface{}, bool)

GetParsedUpdateData can be used to retrieve updater-specific information after parsing a mod file

func (*ModToml) GetSlug

func (m *ModToml) GetSlug() string

func (*ModToml) GetUpdater

func (m *ModToml) GetUpdater() (Updater, error)

func (*ModToml) IsMetaFile

func (m *ModToml) IsMetaFile() bool

func (*ModToml) Marshal

func (m *ModToml) Marshal() (MarshalResult, error)

func (*ModToml) ReflectUpdateData

func (m *ModToml) ReflectUpdateData() error

func (*ModToml) SetMetaFolder

func (m *ModToml) SetMetaFolder(value string)

func (*ModToml) SetMetaPath

func (m *ModToml) SetMetaPath(metaFile string) string

SetMetaPath sets the file path of a metadata file

func (*ModToml) SetSlug

func (m *ModToml) SetSlug(value string)

func (*ModToml) UpdateHash

func (m *ModToml) UpdateHash(_ string, hash string)

UpdateHash updates the hash of a mod file, used with ModWriter

type ModUpdate

type ModUpdate map[string]ModSourceData

type Pack

type Pack struct {
	Name        string
	Author      string
	Version     string
	Description string
	PackFormat  string
	Versions    map[string]string
	Export      map[string]map[string]interface{}
	Options     map[string]interface{}
	Mods        map[string]*Mod
}

func FromPackAndModsMeta

func FromPackAndModsMeta(packMeta PackToml, modMetas []*ModToml) *Pack

func NewPack

func NewPack(
	name string,
	author string,
	version string,
	description string,
	mcVersion string,
	loaderInfo LoaderInfo,
) *Pack

func (*Pack) AsIndexMeta

func (p *Pack) AsIndexMeta() (IndexFS, error)

func (*Pack) AsIndexToml

func (p *Pack) AsIndexToml() (string, string, error)

func (*Pack) AsModToml

func (p *Pack) AsModToml(modSlug string) (string, error)

func (*Pack) AsPackToml

func (p *Pack) AsPackToml() (string, error)

func (*Pack) GetAcceptableGameVersions

func (p *Pack) GetAcceptableGameVersions() []string

func (*Pack) GetCompatibleLoaders

func (p *Pack) GetCompatibleLoaders() (loaders []string)

func (*Pack) GetExportName

func (p *Pack) GetExportName() string

func (*Pack) GetMCVersion

func (p *Pack) GetMCVersion() (string, error)

GetMCVersion gets the version of Minecraft this pack uses, if it has been correctly specified

func (*Pack) GetModsList

func (p *Pack) GetModsList() []*Mod

func (*Pack) GetSupportedMCVersions

func (p *Pack) GetSupportedMCVersions() ([]string, error)

GetSupportedMCVersions gets the versions of Minecraft this pack allows in downloaded mods, ordered by preference (highest = most desirable)

func (*Pack) SetAcceptableGameVersions

func (p *Pack) SetAcceptableGameVersions(versions []string)

func (*Pack) SetMod

func (p *Pack) SetMod(mod *Mod)

func (*Pack) ToPackMeta

func (p *Pack) ToPackMeta() (PackToml, error)

func (*Pack) Update

func (p *Pack) Update(modSlug string) error

func (*Pack) UpdateAll

func (p *Pack) UpdateAll() error

type PackToml

type PackToml struct {
	Name        string                            `toml:"name"`
	Author      string                            `toml:"author,omitempty"`
	Version     string                            `toml:"version,omitempty"`
	Description string                            `toml:"description,omitempty"`
	PackFormat  string                            `toml:"pack-format"`
	Index       PackTomlIndex                     `toml:"index"`
	Versions    map[string]string                 `toml:"versions"`
	Export      map[string]map[string]interface{} `toml:"export"`
	Options     map[string]interface{}            `toml:"options"`
	// contains filtered or unexported fields
}

PackToml stores the modpack metadata, usually in pack.toml

func CreatePackToml

func CreatePackToml(name, author, version string, versions map[string]string) *PackToml

func (*PackToml) GetAcceptableGameVersions

func (pack *PackToml) GetAcceptableGameVersions() []string

func (*PackToml) GetCompatibleLoaders

func (pack *PackToml) GetCompatibleLoaders() (loaders []string)

func (*PackToml) GetFilePath

func (pack *PackToml) GetFilePath() string

func (*PackToml) GetLoaders

func (pack *PackToml) GetLoaders() (loaders []string)

func (*PackToml) GetMCVersion

func (pack *PackToml) GetMCVersion() (string, error)

GetMCVersion gets the version of Minecraft this pack uses, if it has been correctly specified

func (*PackToml) GetPackDir

func (pack *PackToml) GetPackDir() string

func (*PackToml) GetPackName

func (pack *PackToml) GetPackName() string

func (*PackToml) GetSupportedMCVersions

func (pack *PackToml) GetSupportedMCVersions() ([]string, error)

GetSupportedMCVersions gets the versions of Minecraft this pack allows in downloaded mods, ordered by preference (highest = most desirable)

func (*PackToml) Marshal

func (pack *PackToml) Marshal() (MarshalResult, error)

func (*PackToml) RefreshIndexHash

func (pack *PackToml) RefreshIndexHash(index IndexFS)

func (*PackToml) SetAcceptableGameVersions

func (pack *PackToml) SetAcceptableGameVersions(versions []string)

func (*PackToml) SetFilePath

func (pack *PackToml) SetFilePath(path string)

func (*PackToml) UpdateHash

func (pack *PackToml) UpdateHash(_, _ string)

type PackTomlIndex

type PackTomlIndex struct {
	File       string `toml:"file"`
	HashFormat string `toml:"hash-format"`
	Hash       string `toml:"hash,omitempty"`
}

type UpdateCheck

type UpdateCheck struct {
	// UpdateAvailable is true if an update is available for this mod
	UpdateAvailable bool
	// UpdateString is a string that details the update in some way to the user. Usually this will be in the form of
	// a version change (1.0.0 -> 1.0.1), or a file name change (thanos-skin-1.0.0.jar -> thanos-skin-1.0.1.jar).
	UpdateString string
	// CachedState can be used to preserve per-mod state between CheckUpdate and DoUpdate (e.g. file metadata)
	CachedState interface{}
	// Error stores an error for this specific mod
	// Errors can also be returned from CheckUpdate directly, if the whole operation failed completely (so only 1 error is printed)
	// If an error is returned for a mod, or from CheckUpdate, DoUpdate is not called on that mod / at all
	Error error
}

UpdateCheck represents the data returned from CheckUpdate for each mod

type UpdateData

type UpdateData struct {
	Mods        []*Mod
	CachedState []interface{}
}

type UpdateDataList

type UpdateDataList map[string]UpdateData

func GetUpdatableMods

func GetUpdatableMods(pack Pack) (UpdateDataList, error)

func (UpdateDataList) Append

func (ud UpdateDataList) Append(source string, mod *Mod, cachedState interface{})

type UpdateSourceMap

type UpdateSourceMap map[string][]*Mod

named update source to mod list

func BuildUpdateMap

func BuildUpdateMap(mods []*Mod) UpdateSourceMap

type Updater

type Updater interface {
	GetName() string
	// ParseUpdate takes an unparsed interface{} (as a map[string]interface{}), and returns an Updater for a mod file.
	// This can be done using the mapstructure library or your own parsing methods.
	ParseUpdate(map[string]interface{}) (interface{}, error)
	// CheckUpdate checks whether there is an update for each of the mods in the given slice,
	// called for all of the mods that this updater handles
	CheckUpdate([]*Mod, Pack) ([]UpdateCheck, error)
	// DoUpdate carries out the update previously queried in CheckUpdate, on each ModToml's metadata,
	// given pointers to Mods and the value of CachedState for each mod
	DoUpdate([]*Mod, []interface{}) error
}

Updater is used to process updates on mods

func GetUpdater

func GetUpdater(name string) (Updater, bool)

type VersionMap added in v0.0.3

type VersionMap map[string][]string

VersionMap keys are minecraft versions and value is list of valid loader versions for that minecraft version

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL