Compare commits

..

No commits in common. "4cf354733ca692ab16b8a9d086d6bdeaa3975ad9" and "6f1cc3cc7c6bfb28cdd58b359629a8d4b2060dad" have entirely different histories.

3 changed files with 66 additions and 111 deletions

View File

@ -56,6 +56,5 @@ func ListDir(path string) ([]fs.FileInfo, error) {
func GetParentDir(filePath string) (string, error) { func GetParentDir(filePath string) (string, error) {
cuttedPath := strings.Split(filePath, "/") cuttedPath := strings.Split(filePath, "/")
cuttedPath = cuttedPath[:len(cuttedPath)-1] cuttedPath = cuttedPath[:len(cuttedPath)-1]
finalPath := path.Join("/", path.Join(cuttedPath...)) return path.Join(cuttedPath...), nil
return finalPath, nil
} }

View File

@ -1,47 +0,0 @@
package osutils
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
)
func WriteStructAsJSON(data interface{}, versionJsonPath string) error {
file, _ := json.MarshalIndent(data, "", " ")
directory, err := GetParentDir(versionJsonPath)
if err != nil {
return err
}
err = os.MkdirAll(directory+"/", os.ModePerm)
if err != nil {
return err
}
err = ioutil.WriteFile(versionJsonPath, file, 0644)
if err != nil {
return err
}
return nil
}
func ReadJsonFromDisk(target interface{}, filePath string) error {
// Open our jsonFile
jsonFile, err := os.Open(filePath)
// if we os.Open returns an error then handle it
if err != nil {
fmt.Println(err)
}
// fmt.Println("Successfully Opened users.json")
// defer the closing of our jsonFile so that we can parse it later on
defer jsonFile.Close()
// read our opened xmlFile as a byte array.
byteValue, _ := ioutil.ReadAll(jsonFile)
// we unmarshal our byteArray which contains our
// jsonFile's content into 'users' which we defined above
json.Unmarshal(byteValue, &target)
return nil
}

View File

@ -1,75 +1,78 @@
package javaentities package javaentities
// type JavaVersion struct { import (
// Component string "errors"
// Type string "os"
// Name string "path"
// Major int "runtime"
// Minor int "strconv"
// Patch int "strings"
// } )
// type JavaMetas struct { type JavaVersion struct {
// JavaVersions []JavaMeta `json:"javaVersions"` Major int
// } Minor int
Patch int
}
// func (jm JavaMetas) FindSpecificJavaOsByMajor(version JavaVersion) (SpecificJavaVersion, error) { type JavaMetas struct {
// for _, v := range jm.JavaVersions { JavaVersions []JavaMeta `json:"javaVersions"`
// if version.Major == v.Version.Major { }
// jv, err := v.getOsJava()
// if err != nil {
// continue
// }
// return jv, nil
// }
// }
// return SpecificJavaVersion{}, errors.New("cant find os url")
// }
// func (jm JavaMetas) FindSpecificJava(MajorVersion string) func (jm JavaMetas) FindOsURL(MajorVersion string) (SpecificJavaVersion, error) {
for _, v := range jm.JavaVersions {
if MajorVersion == v.Version.Major {
jv, err := v.getOsJava()
if err != nil {
continue
}
return jv, nil
}
}
return SpecificJavaVersion{}, errors.New("cant find os url")
}
// type JavaMeta struct { type JavaMeta struct {
// Version struct { Version struct {
// Major int `json:"major"` Major string `json:"major"`
// Minor int `json:"minor"` Minor string `json:"minor"`
// Patch int `json:"patch"` Patch string `json:"patch"`
// } `json:"version"` } `json:"version"`
// Name string Specifics `json:"specifics"`
// Specifics `json:"specifics"` }
// }
// type SpecificJavaVersion struct { type SpecificJavaVersion struct {
// Os string `json:"os"` Os string `json:"os"`
// Arch string `json:"arch"` Arch string `json:"arch"`
// URL string `json:"URL"` URL string `json:"URL"`
// Sha1 string `json:"SHA1"` Sha1 string `json:"SHA1"`
// } }
// type Specifics []SpecificJavaVersion type Specifics []SpecificJavaVersion
// func (s Specifics) getOsJava() (SpecificJavaVersion, error) { func (s Specifics) getOsJava() (SpecificJavaVersion, error) {
// for _, v := range s { for _, v := range s {
// if v.Os == runtime.GOOS { if v.Os == runtime.GOOS {
// return v, nil return v, nil
// } }
// } }
// return SpecificJavaVersion{}, errors.New("not java for current os") return SpecificJavaVersion{}, errors.New("not java for current os")
// } }
// func (v *JavaVersion) CheckNotExists(launcherPath string) bool { func (v *JavaVersion) CheckNotExists(launcherPath string) bool {
// javaBinPath := path.Join(launcherPath, ".redist", "java", v.GetString()) javaBinPath := path.Join(launcherPath, ".redist", "java", v.GetString())
// _, err := os.Stat(javaBinPath) _, err := os.Stat(javaBinPath)
// return err != nil return err != nil
// } }
// func (v *JavaVersion) GetString() string { func (v *JavaVersion) GetString() string {
// var stringBuilder strings.Builder var stringBuilder strings.Builder
// stringBuilder.WriteString(strconv.Itoa(v.Major)) stringBuilder.WriteString(strconv.Itoa(v.Major))
// stringBuilder.WriteRune('.') stringBuilder.WriteRune('.')
// stringBuilder.WriteString(strconv.Itoa(v.Minor)) stringBuilder.WriteString(strconv.Itoa(v.Minor))
// stringBuilder.WriteRune('.') stringBuilder.WriteRune('.')
// stringBuilder.WriteString(strconv.Itoa(v.Patch)) stringBuilder.WriteString(strconv.Itoa(v.Patch))
// return stringBuilder.String() return stringBuilder.String()
// } }