sharedutils/domain/structures.go

158 lines
3.4 KiB
Go
Raw Normal View History

2023-02-12 16:58:30 +00:00
package domain
2023-02-11 23:15:55 +00:00
import "strconv"
2023-02-11 23:15:55 +00:00
type JavaVersion struct {
VersionNums `json:"versionnums"`
Specifics []JavaVersionSpecifics `json:"specifics"`
}
type JavaVersionSpecifics struct {
Os string `json:"os"`
Arch string `json:"arch"`
URL string `json:"URL"`
Sha1 string `json:"SHA1"`
}
func (jv *JavaVersion) FindOs(os string, arch string) *JavaVersionSpecifics {
for _, s := range jv.Specifics {
if s.Os == os && s.Arch == arch {
return &s
}
}
return nil
2023-02-11 23:15:55 +00:00
}
2023-02-11 23:34:22 +00:00
type VersionNums struct {
2023-02-12 19:09:24 +00:00
Major int `json:"major"`
Minor int `json:"minor"`
Patch int `json:"patch"`
2023-02-11 23:15:55 +00:00
}
2023-02-11 23:34:22 +00:00
func (v *VersionNums) FillFromString(maj string, min string, patch string) error {
iMaj, err := strconv.Atoi(maj)
if err != nil {
return err
}
iMin := 0
iMin, err = strconv.Atoi(min)
if err != nil {
return err
}
iPatch := 0
iPatch, err = strconv.Atoi(patch)
if err != nil {
return err
}
v.Major = iMaj
v.Minor = iMin
v.Patch = iPatch
return nil
}
2023-02-11 23:34:22 +00:00
type Version struct {
AssetIndex AssetIndex `json:"assetIndex"`
Downloads struct {
Client Artifact `json:"client"`
Server Artifact `json:"server"`
Mods struct {
Required []ModArtifact `json:"required"`
} `json:"mods"`
} `json:"downloads"`
ID string `json:"id"`
Libraries []Lib `json:"libraries"`
//ClientLog LogCfg
MainClass string `json:"mainClass"`
GameArgs []Argument
JVMArgs []Argument
Type string `json:"type"`
JavaVersion JavaVersion `json:"javaVersion"`
2023-02-11 23:34:22 +00:00
}
type AssetIndex struct {
ID string `json:"id"`
TotalSize uint64 `json:"totalSize"`
Artifact
}
2023-02-12 16:58:30 +00:00
// type Argument struct {
// Value string `json:"value"`
// Rules []Rule `json:"rules"`
// }
2023-02-11 23:34:22 +00:00
type JavaVersionClientDistribution struct { //TODO Rename
Component string `json:"component"`
MajorVersion int `json:"majorVersion"`
}
2023-02-11 23:34:22 +00:00
type Rule struct {
Action RuleAct `json:"action" mapstructure:"action"`
// OS information. All fields are regexes.
OS struct {
Name string `json:"name" mapstructure:"name"`
Version string `json:"version" mapstructure:"version"`
Arch string `json:"arch" mapstructure:"arch"`
} `json:"os" mapstructure:"os"`
Features struct {
IsDemoUser *bool `json:"is_demo_user" mapstructure:"is_demo_user"`
HasCustomResolution *bool `json:"has_custom_resolution" mapstructure:"has_custom_resolution"`
} `json:"features" mapstructure:"features"`
}
type RuleAct string
const (
ActAllow RuleAct = "allow"
ActDisallow RuleAct = "disallow"
)
type LibClassifiers struct {
JavaDoc *Artifact `json:"javadoc"`
NativesLinux *Artifact `json:"natives-linux"`
NativesMacOS *Artifact `json:"natives-osx"`
NativesWin *Artifact `json:"natives-windows"`
Sources *Artifact `json:"sources"`
}
type Lib struct {
Downloads struct {
MainJar *Artifact `json:"artifact"`
LibClassifiers `json:"classifiers"`
} `json:"downloads"`
NativeSuffixes struct {
Linux string `json:"linux"`
MacOS string `json:"osx"`
Windows string `json:"windows"`
} `json:"natives"`
Name string `json:"name"`
Rules []Rule `json:"rules"`
ExtractRules struct {
Exclude []string `json:"exclude"`
} `json:"extract"`
}
type Artifact struct {
SHA1 string `json:"sha1"`
Size uint64 `json:"size"`
URL string `json:"url"`
}
type ModArtifact struct {
Artifact
File string
Name string
Version string
}
2023-02-12 16:58:30 +00:00
type VersionMeta struct {
2023-02-12 19:09:24 +00:00
ID string `json:"id"`
Type string `json:"type"`
URL string `json:"url"`
Installed bool
2023-02-12 16:58:30 +00:00
}