Compare commits
2 Commits
de188c1b8f
...
b02c858b38
Author | SHA1 | Date | |
---|---|---|---|
b02c858b38 | |||
010a8becd7 |
128
redistruable/javaentities/java.go
Normal file
128
redistruable/javaentities/java.go
Normal file
@ -0,0 +1,128 @@
|
||||
package javaentities
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"path"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
|
||||
"git.gregbrzezinski.com/Skirda/skirdaGoLauncher/api"
|
||||
"git.gregbrzezinski.com/Skirda/skirdaGoLauncher/downloader"
|
||||
>>>>>>> 7b3396a (Add java entities)
|
||||
=======
|
||||
>>>>>>> 368286c (Add javaentities)
|
||||
)
|
||||
|
||||
type JavaVersion struct {
|
||||
Major int
|
||||
Minor int
|
||||
Patch int
|
||||
}
|
||||
|
||||
type JavaMetas struct {
|
||||
JavaVersions []JavaMeta `json:"javaVersions"`
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
>>>>>>> 368286c (Add javaentities)
|
||||
func (jm JavaMetas) GetOsURL() (string, error) {
|
||||
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
>>>>>>> 7b3396a (Add java entities)
|
||||
=======
|
||||
>>>>>>> 368286c (Add javaentities)
|
||||
type JavaMeta struct {
|
||||
Version struct {
|
||||
Major string `json:"major"`
|
||||
Minor string `json:"minor"`
|
||||
Patch string `json:"patch"`
|
||||
} `json:"version"`
|
||||
Specifics `json:"specifics"`
|
||||
}
|
||||
|
||||
type SpecificJavaVersion struct {
|
||||
Os string `json:"os"`
|
||||
Arch string `json:"arch"`
|
||||
URL string `json:"URL"`
|
||||
Sha1 string `json:"SHA1"`
|
||||
}
|
||||
|
||||
type Specifics []SpecificJavaVersion
|
||||
|
||||
func (s Specifics) getOsJava() (SpecificJavaVersion, error) {
|
||||
for _, v := range s {
|
||||
if v.Os == runtime.GOOS {
|
||||
return v, nil
|
||||
}
|
||||
}
|
||||
return SpecificJavaVersion{}, errors.New("not java for current os")
|
||||
}
|
||||
|
||||
func (v *JavaVersion) CheckNotExists(launcherPath string) bool {
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
|
||||
>>>>>>> 7b3396a (Add java entities)
|
||||
=======
|
||||
>>>>>>> 368286c (Add javaentities)
|
||||
javaBinPath := path.Join(launcherPath, ".redist", "java", v.GetString())
|
||||
_, err := os.Stat(javaBinPath)
|
||||
|
||||
return err != nil
|
||||
}
|
||||
|
||||
func (v *JavaVersion) GetString() string {
|
||||
var stringBuilder strings.Builder
|
||||
stringBuilder.WriteString(strconv.Itoa(v.Major))
|
||||
stringBuilder.WriteRune('.')
|
||||
stringBuilder.WriteString(strconv.Itoa(v.Minor))
|
||||
stringBuilder.WriteRune('.')
|
||||
stringBuilder.WriteString(strconv.Itoa(v.Patch))
|
||||
|
||||
return stringBuilder.String()
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
|
||||
func (v *JavaVersion) DownloadLatest(downloadDir string) (downloader.DownloadFile, error) {
|
||||
javaVersionMeta := JavaMetas{}
|
||||
task := downloader.DownloadFile{
|
||||
Url: "",
|
||||
Path: "",
|
||||
}
|
||||
|
||||
javaVersionMeta, err := api.GetJavaVersionMetas()
|
||||
|
||||
// if err := downloadJson("https://skirda.gregbrzezinski.com/java_version_manifest.json", &javaVersionMeta); err != nil {
|
||||
// return task, errors.New("error in download json")
|
||||
// }
|
||||
|
||||
// javaSpecific := SpecificJavaVersion{}
|
||||
|
||||
javaSpecific, err := javaVersionMeta.getOsJava()
|
||||
if err != nil {
|
||||
return task, err
|
||||
}
|
||||
|
||||
task = downloader.DownloadFile{
|
||||
Url: javaSpecific.URL,
|
||||
Path: path.Join(downloadDir, v.GetString()),
|
||||
}
|
||||
|
||||
return task, nil
|
||||
}
|
||||
>>>>>>> 7b3396a (Add java entities)
|
||||
=======
|
||||
>>>>>>> 368286c (Add javaentities)
|
Loading…
Reference in New Issue
Block a user