diff --git a/fclauncher/Prism.go b/fclauncher/Prism.go new file mode 100644 index 0000000..ab748f8 --- /dev/null +++ b/fclauncher/Prism.go @@ -0,0 +1,31 @@ +package main + +import ( + "os" + "path/filepath" +) + +type Prism struct { + Instances []Instance +} + +type Instance struct { + Path string + Name string + MCVer string + JavaVer string +} + +func (Prism) CheckInstalled() bool { + path, _ := os.UserConfigDir() + _, err := os.Stat(filepath.Join(path, "FCLauncher", "prism")) + if err == nil { + return true + } else { + return false + } +} + +func (Prism) Install() { + +} diff --git a/fclauncher/app.go b/fclauncher/app.go index d78c485..d429130 100644 --- a/fclauncher/app.go +++ b/fclauncher/app.go @@ -1,16 +1,17 @@ package main import ( + "bytes" "context" "encoding/json" "fmt" "io" - "net/http" ) // App struct type App struct { - ctx context.Context + ctx context.Context + prism Prism } type Modpack struct { @@ -36,12 +37,12 @@ func (a *App) Greet(name string) string { } func (a *App) GetModpacks() []string { - res, err := http.Get("https://gitea.piwalker.net/fclauncher/modpacks.json") + buff := new(bytes.Buffer) + err := HttpDownload("modpacks.json", buff) if err != nil { - fmt.Println(err.Error()) + fmt.Println(err) } - defer res.Body.Close() - body, err := io.ReadAll(res.Body) + body, err := io.ReadAll(buff) var modpacks []Modpack err = json.Unmarshal([]byte(body), &modpacks) if err != nil { @@ -56,5 +57,14 @@ func (a *App) GetModpacks() []string { } func (a *App) CheckPrerequisites() { - + a.prism = Prism{} + res := a.prism.CheckInstalled() + fmt.Printf("Checking if prism is installed: ") + if res { + fmt.Println("Yes") + } else { + fmt.Println("No") + fmt.Println("Installing Prism") + a.prism.Install() + } } diff --git a/fclauncher/https.go b/fclauncher/https.go new file mode 100644 index 0000000..9360166 --- /dev/null +++ b/fclauncher/https.go @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "io" + "net/http" +) + +const BlockSize = 1024 + +func HttpDownload(path string, out io.Writer) error { + res, err := http.Get("https://gitea.piwalker.net/fclauncher/" + path) + if err != nil { + return err + } + defer res.Body.Close() + var read int64 = 0 + for read < res.ContentLength { + count, err := io.CopyN(out, res.Body, BlockSize) + read += count + fmt.Printf("Downloaded %dMB / %dMB\n", read/(1024*1024), res.ContentLength/(1024*1024)) + if err != nil { + break + } + } + return nil +}