From 3c8fb9a89f66bbb00ed908ebe06038410f928b34 Mon Sep 17 00:00:00 2001 From: Samuel Walker Date: Fri, 25 Oct 2024 22:56:22 -0600 Subject: [PATCH] added basic support for downloading (not installing) modpack files --- fclauncher/Prism.go | 22 ++++++++++++++++++++ fclauncher/app.go | 15 ++++++------- fclauncher/frontend/src/App.svelte | 6 +++--- fclauncher/frontend/src/Client.svelte | 15 ++++++++++--- fclauncher/frontend/src/Loading.svelte | 4 ++-- fclauncher/frontend/src/global.ts | 2 ++ fclauncher/frontend/wailsjs/go/main/App.d.ts | 5 ++++- fclauncher/frontend/wailsjs/go/main/App.js | 4 ++++ fclauncher/frontend/wailsjs/go/models.ts | 21 +++++++++++++++++++ fclauncher/https.go | 2 +- 10 files changed, 79 insertions(+), 17 deletions(-) create mode 100644 fclauncher/frontend/src/global.ts create mode 100755 fclauncher/frontend/wailsjs/go/models.ts diff --git a/fclauncher/Prism.go b/fclauncher/Prism.go index 4918834..2bfcd8c 100644 --- a/fclauncher/Prism.go +++ b/fclauncher/Prism.go @@ -5,10 +5,12 @@ import ( "bytes" "compress/gzip" "context" + "encoding/json" "io" "os" "path/filepath" "runtime" + "time" "github.com/zhyee/zipstream" ) @@ -25,6 +27,12 @@ type Instance struct { JavaVer string } +type Version struct { + Version string + Data time.Time + File string +} + func (Prism) CheckInstalled() bool { path, _ := os.UserConfigDir() _, err := os.Stat(filepath.Join(path, "FCLauncher", "prism")) @@ -114,3 +122,17 @@ func (p *Prism) Install() { } } + + +func (p *Prism)InstallModpack(modpack Modpack){ + buff := new(bytes.Buffer) + HttpDownload(modpack.Id + "/versions.json", buff, nil) + var versions []Version + json.Unmarshal(buff.Bytes(), &versions) + version := versions[len(versions)-1] + dname, _ := os.MkdirTemp("", "fclauncher-*") + f, _ := os.OpenFile(filepath.Join(dname, modpack.Name), os.O_CREATE|os.O_RDWR, 0755) + defer f.Close() + HttpDownload(modpack.Id + "/" + version.File, f, p.ctx) + +} diff --git a/fclauncher/app.go b/fclauncher/app.go index a5d4c0b..813f958 100644 --- a/fclauncher/app.go +++ b/fclauncher/app.go @@ -19,7 +19,7 @@ type App struct { type Modpack struct { Name string - Nd string + Id string Last_updated string } @@ -39,7 +39,7 @@ func (a *App) Greet(name string) string { return fmt.Sprintf("Hello %s, It's show time!", name) } -func (a *App) GetModpacks() []string { +func (a *App) GetModpacks() []Modpack { buff := new(bytes.Buffer) err := HttpDownload("modpacks.json", buff, nil) if err != nil { @@ -52,11 +52,7 @@ func (a *App) GetModpacks() []string { fmt.Println(err.Error()) return nil } - var names []string - for _, pack := range modpacks { - names = append(names, pack.Name) - } - return names + return modpacks } func (a *App) CheckPrerequisites() { @@ -84,6 +80,11 @@ func (a *App) CheckPrerequisites() { } } +func (a *App) InstallModpack(pack Modpack) { + a.status(fmt.Sprintf("Installing %s\n", pack.Name)) + a.prism.InstallModpack(pack) +} + func (a *App) status(status string) { fmt.Printf("LOG: %s\n", status) runtime.EventsEmit(a.ctx, "status", status) diff --git a/fclauncher/frontend/src/App.svelte b/fclauncher/frontend/src/App.svelte index 97c1458..3538ebb 100644 --- a/fclauncher/frontend/src/App.svelte +++ b/fclauncher/frontend/src/App.svelte @@ -4,12 +4,12 @@ import Loading from './Loading.svelte' import {CheckPrerequisites} from '../wailsjs/go/main/App.js' import { onMount } from 'svelte' + import { loading } from './global.ts' - let loading: boolean = true let width: int = 10 onMount(() => { - CheckPrerequisites().then(() => loading = false) + CheckPrerequisites().then(() => $loading = false) }) @@ -17,7 +17,7 @@
- {#if loading} + {#if $loading} {:else} diff --git a/fclauncher/frontend/src/Client.svelte b/fclauncher/frontend/src/Client.svelte index 5cb4bcc..316c74e 100644 --- a/fclauncher/frontend/src/Client.svelte +++ b/fclauncher/frontend/src/Client.svelte @@ -1,22 +1,31 @@
- Select a Modpack: {#each modpacks as pack} - + {/each} +