Started https download code
This commit is contained in:
parent
0a6b37ccab
commit
7ad769ff96
31
fclauncher/Prism.go
Normal file
31
fclauncher/Prism.go
Normal file
@ -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() {
|
||||
|
||||
}
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
27
fclauncher/https.go
Normal file
27
fclauncher/https.go
Normal file
@ -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
|
||||
}
|
Loading…
Reference in New Issue
Block a user