diff --git a/fclauncher/InstanceManager.go b/fclauncher/InstanceManager.go index 98a5e4f..781d28a 100644 --- a/fclauncher/InstanceManager.go +++ b/fclauncher/InstanceManager.go @@ -285,6 +285,7 @@ func (i *InstanceManager) GetInstance(instance string) (Instance, error) { } func (i *InstanceManager) LaunchInstance(instance string) { + i.app.Status(fmt.Sprintf("Launching %s", instance)) dir, err := os.UserConfigDir() if err != nil { fmt.Printf("unable to get config directory\n") @@ -367,7 +368,7 @@ common: instanceObject.MainClass = metadata.LauncherMeta.MainClass["client"] instanceObject.FabricVersion = fabricVersion dir, _ := os.UserConfigDir() - InstallFabricLibs(instanceObject.MinecraftVersion, fabricVersion, filepath.Join(dir, "FCLauncher", "lib")) + InstallFabricLibs(instanceObject.MinecraftVersion, fabricVersion, filepath.Join(dir, "FCLauncher", "lib"), i.app) f, _ := os.OpenFile(filepath.Join(dir, "FCLauncher", "instances", instance, "instance.json"), os.O_CREATE|os.O_RDWR, 0755) data, _ := json.Marshal(instanceObject) defer f.Close() @@ -427,7 +428,7 @@ common: instanceObject.MainClass = metadata.LauncherMeta.MainClass["client"] instanceObject.QuiltVersion = quiltVersion dir, _ := os.UserConfigDir() - InstallQuiltLibs(instanceObject.MinecraftVersion, quiltVersion, filepath.Join(dir, "FCLauncher", "lib")) + InstallQuiltLibs(instanceObject.MinecraftVersion, quiltVersion, filepath.Join(dir, "FCLauncher", "lib"), i.app) f, _ := os.OpenFile(filepath.Join(dir, "FCLauncher", "instances", instance, "instance.json"), os.O_CREATE|os.O_RDWR, 0755) data, _ := json.Marshal(instanceObject) defer f.Close() @@ -482,6 +483,7 @@ outer: } func (i *InstanceManager) ImportModpack(modpack Modpack, name string) { + i.app.Status(fmt.Sprintf("Downloading %s", modpack.Name)) buff := new(bytes.Buffer) HttpDownload(filepath.Join(modpack.Id, modpack.Versions[len(modpack.Versions)-1].File), buff, i.app.Ctx) i.ImportMrpack(buff, name) @@ -493,16 +495,19 @@ func (i *InstanceManager) ImportMrpack(data io.Reader, name string) { InstancePath := filepath.Join(dir, "FCLauncher", "instances", name, "minecraft") zr := zipstream.NewReader(data) mrdata := MrData{} + i.app.Status("Unpacking modpack File") for { entry, err := zr.GetNextEntry() if err == io.EOF { break } if entry.Name == "modrinth.index.json" { + i.app.Status("Loading metadata") file, _ := entry.Open() data, _ := io.ReadAll(file) json.Unmarshal(data, &mrdata) } else { + i.app.Status(fmt.Sprintf("Unpacking %s", entry.Name)) prefix := strings.Split(entry.Name, "/")[0] if prefix == "overrides" || prefix == "client-overrides" { path := strings.SplitN(entry.Name, "/", 2)[1] @@ -532,7 +537,6 @@ func (i *InstanceManager) ImportMrpack(data io.Reader, name string) { } } } - fmt.Printf("Installing minecraft %s\n", mrdata.Dependencies["minecraft"]) i.InstallVanilla(mrdata.Dependencies["minecraft"], name) if mrdata.Dependencies["forge"] != "" { fmt.Printf("Forge not implemented!") @@ -541,21 +545,35 @@ func (i *InstanceManager) ImportMrpack(data io.Reader, name string) { fmt.Printf("Neoforge not implemented!") //implement neoforge } else if mrdata.Dependencies["fabric-loader"] != "" { - fmt.Printf("Installing fabric %s\n", mrdata.Dependencies["fabric-loader"]) i.InstallFabric(name, mrdata.Dependencies["fabric-loader"]) } else if mrdata.Dependencies["quilt-loader"] != "" { - fmt.Printf("Installing quilt %s\n", mrdata.Dependencies["quilt-loader"]) i.InstallQuilt(name, mrdata.Dependencies["quilt-loader"]) } - + i.app.Status("Downloading Mods") for _, f := range mrdata.Files { fmt.Printf("Downloading %s\n", f.Path) + i.app.Status(fmt.Sprintf("Downloading %s", f.Path)) resp, err := http.Get(f.Downloads[0]) if err != nil { fmt.Printf("Unable to download file %s\n", err) continue } defer resp.Body.Close() + buff := new(bytes.Buffer) + downloaded := 0 + for { + count, err := io.CopyN(buff, resp.Body, BlockSize) + if err == io.EOF { + downloaded += int(count) + break + } + if err != nil { + fmt.Printf("Error Downloading libs: %e\n", err) + return + } + downloaded += int(count) + wruntime.EventsEmit(i.app.Ctx, "download", downloaded, f.FileSize) + } fileDir := "" tokens := strings.Split(f.Path, "/") for ind, token := range tokens { @@ -568,6 +586,7 @@ func (i *InstanceManager) ImportMrpack(data io.Reader, name string) { } file, _ := os.OpenFile(filepath.Join(InstancePath, f.Path), os.O_CREATE|os.O_RDWR, 0755) defer file.Close() - io.Copy(file, resp.Body) + io.Copy(file, buff) + wruntime.EventsEmit(i.app.Ctx, "download_complete") } } diff --git a/fclauncher/fabric.go b/fclauncher/fabric.go index bf601fd..668b940 100644 --- a/fclauncher/fabric.go +++ b/fclauncher/fabric.go @@ -1,6 +1,7 @@ package main import ( + "bytes" "crypto/sha1" "encoding/hex" "encoding/json" @@ -10,24 +11,24 @@ import ( "os" "path/filepath" "strings" + + wruntime "github.com/wailsapp/wails/v2/pkg/runtime" ) type Fabric struct { - } - type FabricDefinition struct { Separator string - Build int - Maven string - Version string - Stable bool + Build int + Maven string + Version string + Stable bool } type FabricLibrary struct { Name string - Url string + Url string Sha1 string } @@ -38,19 +39,19 @@ type FabricLibraries struct { } type FabricMeta struct { - Version int + Version int Libraries FabricLibraries MainClass map[string]string } type FabricVersion struct { - Loader FabricDefinition + Loader FabricDefinition Intermediary FabricDefinition LauncherMeta FabricMeta } -func (Fabric)GetFabricVersions(mcVersion string) ([]FabricVersion, error) { - resp, err := http.Get("https://meta.fabricmc.net/v2/versions/loader/"+mcVersion) +func (Fabric) GetFabricVersions(mcVersion string) ([]FabricVersion, error) { + resp, err := http.Get("https://meta.fabricmc.net/v2/versions/loader/" + mcVersion) if err != nil { return []FabricVersion{}, fmt.Errorf("Unable to pull fabric version manifest: %s\n", err) } @@ -74,7 +75,8 @@ func GetFabricMetadata(mcVersion string, fabricVersion string) (FabricVersion, e return FabricVersion{}, fmt.Errorf("Unable to find requested version.\n") } -func InstallLib(lib FabricLibrary, libDir string) { +func InstallLib(lib FabricLibrary, libDir string, a *App) { + a.Status(fmt.Sprintf("Checking %s\n", lib.Name)) path := filepath.Join(ProcessMavenPath(lib.Name), ProcessMavenFilename(lib.Name)) if _, err := os.Stat(filepath.Join(libDir, path)); err == nil { f, _ := os.OpenFile(filepath.Join(libDir, path), os.O_RDONLY, 0755) @@ -85,27 +87,44 @@ func InstallLib(lib FabricLibrary, libDir string) { return } } - resp, err := http.Get(lib.Url+path) + a.Status(fmt.Sprintf("Downloading %s\n", lib.Name)) + resp, err := http.Get(lib.Url + path) if err != nil { return } defer resp.Body.Close() + buff := new(bytes.Buffer) + downloaded := 0 + for { + count, err := io.CopyN(buff, resp.Body, BlockSize) + if err == io.EOF { + downloaded += int(count) + break + } + if err != nil { + fmt.Printf("Error Downloading libs: %e\n", err) + return + } + downloaded += int(count) + wruntime.EventsEmit(a.Ctx, "download", downloaded, resp.ContentLength) + } os.MkdirAll(filepath.Join(libDir, ProcessMavenPath(lib.Name)), 0755) f, _ := os.OpenFile(filepath.Join(libDir, path), os.O_CREATE|os.O_RDWR, 0755) defer f.Close() - io.Copy(f, resp.Body) + io.Copy(f, buff) + wruntime.EventsEmit(a.Ctx, "download_complete") } -func InstallFabricLibs(mcVersion string, fabricVersion string, libDir string) { +func InstallFabricLibs(mcVersion string, fabricVersion string, libDir string, a *App) { metadata, _ := GetFabricMetadata(mcVersion, fabricVersion) for _, lib := range metadata.LauncherMeta.Libraries.Client { - InstallLib(lib, libDir) - } + InstallLib(lib, libDir, a) + } for _, lib := range metadata.LauncherMeta.Libraries.Common { - InstallLib(lib, libDir) - } - InstallLib(FabricLibrary{Name: metadata.Loader.Maven, Sha1: "", Url: "https://maven.fabricmc.net/"}, libDir) - InstallLib(FabricLibrary{Name: metadata.Intermediary.Maven, Sha1: "", Url: "https://maven.fabricmc.net/"}, libDir) + InstallLib(lib, libDir, a) + } + InstallLib(FabricLibrary{Name: metadata.Loader.Maven, Sha1: "", Url: "https://maven.fabricmc.net/"}, libDir, a) + InstallLib(FabricLibrary{Name: metadata.Intermediary.Maven, Sha1: "", Url: "https://maven.fabricmc.net/"}, libDir, a) } func ProcessMavenPath(maven string) string { @@ -121,5 +140,5 @@ func ProcessMavenFilename(maven string) string { tokens := strings.Split(maven, ":") pack := tokens[1] version := tokens[2] - return pack+"-"+version+".jar" + return pack + "-" + version + ".jar" } diff --git a/fclauncher/frontend/src/App.svelte b/fclauncher/frontend/src/App.svelte index cf937bb..e9ad329 100644 --- a/fclauncher/frontend/src/App.svelte +++ b/fclauncher/frontend/src/App.svelte @@ -5,18 +5,29 @@ import Modpacks from './Modpacks.svelte' import {CheckPrerequisites} from '../wailsjs/go/main/App.js' import { onMount } from 'svelte' - import { loading, testPage, currentPage } from './global' + import { loading, currentPage, instances } from './global' import { slide } from 'svelte/transition' import Navbar from './Navbar.svelte' import Instancepage from './Instancepage.svelte' import { set_attributes, set_style } from 'svelte/internal'; + import {GetInstances} from '../wailsjs/go/main/InstanceManager.js' let width: number = 10 let navMargin = document.getElementById("body") as HTMLElement; let r + + function UpdateInstances() { + $loading = true + GetInstances().then((result) => { + $instances = result + $loading = false + }) + } onMount(() => { - CheckPrerequisites().then(() => $loading = false) + CheckPrerequisites().then(() => { + UpdateInstances() + }) r = document.getElementById('wrapper'); }) function setMargin(){ @@ -57,11 +68,11 @@ {:else if $currentPage == 2}
- +
{:else if $currentPage == 3}
- +
{/if} diff --git a/fclauncher/frontend/src/Instances.svelte b/fclauncher/frontend/src/Instances.svelte index a122250..47e702e 100644 --- a/fclauncher/frontend/src/Instances.svelte +++ b/fclauncher/frontend/src/Instances.svelte @@ -5,13 +5,12 @@ import {GetQuiltVersions} from '../wailsjs/go/main/Quilt.js' import {GetForgeVersions} from '../wailsjs/go/main/Forge.js' import {onMount} from 'svelte' - import {loading, addingInstance, instances, currentPage} from './global' + import {loading, addingInstance} from './global' import {slide} from 'svelte/transition' - - let modpacks: string[] = [] + let modpacks: string[] = [] let pack: string //let instances: Instance[] = [] - let instance: string + export let UpdateInstances let name: string = "New Modpack" let loader: string = "none" let fabric_ver: string = "" @@ -28,11 +27,8 @@ name = modpacks[0] updateLoaders() }) - GetInstances().then((result) => { - $instances = result - instance = $instances[0] - }) - } + UpdateInstances() + } function updateLoaders(){ GetFabricVersions(pack).then((result) => { @@ -64,13 +60,6 @@ updateLists() }) - function onclick(event) { - $loading = true - LaunchInstance(instance).then(() => { - $loading = false - }) - } - function install(){ $loading = true InstallVanilla(pack, name).then(() => { diff --git a/fclauncher/frontend/src/Modpacks.svelte b/fclauncher/frontend/src/Modpacks.svelte index a9f5c1a..2275de1 100644 --- a/fclauncher/frontend/src/Modpacks.svelte +++ b/fclauncher/frontend/src/Modpacks.svelte @@ -6,26 +6,36 @@ import {loading} from './global.js' let modpacks: main.Modpack[] = [] let pack: main.Modpack + export let UpdateInstances + let name: string = "New Modpack" onMount(() => { GetModpacks().then((result) => { modpacks = result pack = result[0] + name = pack.Name }) }) function AddModpack(){ $loading = true - ImportModpack(pack, pack.Name).then(() => $loading = false) + ImportModpack(pack, name).then(() => { + UpdateInstances() + }) } + function onchange(event){ + name = pack.Name + } +
- Select a Modpack: {#each modpacks as pack} {/each} +
\ No newline at end of file diff --git a/fclauncher/frontend/src/Navbar.svelte b/fclauncher/frontend/src/Navbar.svelte index 4352bb0..a096f86 100644 --- a/fclauncher/frontend/src/Navbar.svelte +++ b/fclauncher/frontend/src/Navbar.svelte @@ -1,6 +1,6 @@