From 4bcc2703d6575176c316d6254c9adde4d63a466b Mon Sep 17 00:00:00 2001 From: Samuel Walker Date: Sat, 26 Oct 2024 14:00:53 -0600 Subject: [PATCH] Working on division between modpack and instance --- fclauncher/2 | 34 ++++++++ fclauncher/InstanceManager.go | 67 +++++++++++++++ fclauncher/Java.go | 11 ++- fclauncher/Modpack.go | 62 +++++++++++++ fclauncher/Prism.go | 83 +++++++++++------- fclauncher/app.go | 86 +++++++------------ fclauncher/frontend/src/App.svelte | 4 +- fclauncher/frontend/src/Client.svelte | 32 ------- fclauncher/frontend/src/Instances.svelte | 74 ++++++++++++++++ fclauncher/frontend/wailsjs/go/main/App.d.ts | 7 +- fclauncher/frontend/wailsjs/go/main/App.js | 12 +-- .../wailsjs/go/main/InstanceManager.d.ts | 9 ++ .../wailsjs/go/main/InstanceManager.js | 15 ++++ .../frontend/wailsjs/go/main/JavaManager.d.ts | 6 ++ .../frontend/wailsjs/go/main/JavaManager.js | 11 +++ .../wailsjs/go/main/ModpackManager.d.ts | 9 ++ .../wailsjs/go/main/ModpackManager.js | 15 ++++ .../frontend/wailsjs/go/main/Prism.d.ts | 10 +++ fclauncher/frontend/wailsjs/go/main/Prism.js | 19 ++++ fclauncher/frontend/wailsjs/go/models.ts | 71 +++++++++++++++ fclauncher/main.go | 6 +- 21 files changed, 503 insertions(+), 140 deletions(-) create mode 100644 fclauncher/2 create mode 100644 fclauncher/InstanceManager.go create mode 100644 fclauncher/Modpack.go delete mode 100644 fclauncher/frontend/src/Client.svelte create mode 100644 fclauncher/frontend/src/Instances.svelte create mode 100755 fclauncher/frontend/wailsjs/go/main/InstanceManager.d.ts create mode 100755 fclauncher/frontend/wailsjs/go/main/InstanceManager.js create mode 100755 fclauncher/frontend/wailsjs/go/main/JavaManager.d.ts create mode 100755 fclauncher/frontend/wailsjs/go/main/JavaManager.js create mode 100755 fclauncher/frontend/wailsjs/go/main/ModpackManager.d.ts create mode 100755 fclauncher/frontend/wailsjs/go/main/ModpackManager.js create mode 100755 fclauncher/frontend/wailsjs/go/main/Prism.d.ts create mode 100755 fclauncher/frontend/wailsjs/go/main/Prism.js diff --git a/fclauncher/2 b/fclauncher/2 new file mode 100644 index 0000000..e8baf67 --- /dev/null +++ b/fclauncher/2 @@ -0,0 +1,34 @@ +package main + +import ( + "context" + "os" + "path/filepath" +) + +type Instance struct { + InstanceName string + ModpackId string + ModpackVersion string +} + +type InstanceManager struct { + instances []Instance + PrismLauncher Prism + ctx context.Context +} + +func (i *InstanceManager)SearchInstances() { + i.instances = []Instance{} + dir := i.PrismLauncher.GetInstanceDir() + subdirs, _ := os.ReadDir(dir) + for _, d := range subdirs { + if !d.IsDir() { + continue + } + if _, err := os.Stat(filepath.Join(dir, d.Name(), "instance.json")); err != nil { + continue + } + f, _ = os.OpenFile() + } +} diff --git a/fclauncher/InstanceManager.go b/fclauncher/InstanceManager.go new file mode 100644 index 0000000..b7e97ee --- /dev/null +++ b/fclauncher/InstanceManager.go @@ -0,0 +1,67 @@ +package main + +import ( + "bytes" + "encoding/json" + "fmt" + "io" + "os" + "path/filepath" +) + +type Instance struct { + InstanceName string + ModpackId string + ModpackVersion string +} + +type InstanceManager struct { + instances []Instance + app *App +} + +func (i *InstanceManager)SearchInstances() { + i.instances = []Instance{} + dir := i.app.PrismLauncher.GetInstanceDir() + if _, err := os.Stat(dir); err != nil { + return + } + subdirs, _ := os.ReadDir(dir) + for _, d := range subdirs { + if !d.IsDir() { + continue + } + if _, err := os.Stat(filepath.Join(dir, d.Name(), "instance.json")); err != nil { + continue + } + f, _ := os.OpenFile(filepath.Join(dir, d.Name(), "instance.json"), os.O_RDONLY, 0755) + defer f.Close() + buff := new(bytes.Buffer) + io.Copy(buff, f) + instance := Instance{} + json.Unmarshal(buff.Bytes(), &instance) + fmt.Printf("Found Instance: %+v\n", instance) + i.instances = append(i.instances, instance) + } +} + +func (i *InstanceManager)InstallModpack(modpack Modpack, instanceName string){ + i.app.Status(fmt.Sprintf("Installing %s", modpack.Name)) + version := modpack.Versions[len(modpack.Versions)-1] + dname, _ := os.MkdirTemp("", "fclauncher-*") + f, _ := os.OpenFile(filepath.Join(dname, instanceName+".mrpack"), os.O_CREATE|os.O_RDWR, 0755) + defer f.Close() + HttpDownload(modpack.Id + "/" + version.File, f, i.app.Ctx) + i.app.PrismLauncher.ImportModpack(f.Name()) + instance := Instance{InstanceName: instanceName, ModpackVersion: version.Version, ModpackId: modpack.Id} + i.instances = append(i.instances, instance) + f, _ = os.OpenFile(filepath.Join(i.app.PrismLauncher.GetInstanceDir(), instanceName, "instance.json"), os.O_CREATE|os.O_RDWR, 0755) + defer f.Close() + data, _ := json.Marshal(instance) + f.Write(data) +} + +func (i *InstanceManager)GetInstances() []Instance{ + return i.instances +} + diff --git a/fclauncher/Java.go b/fclauncher/Java.go index 98a5265..50a1c5e 100644 --- a/fclauncher/Java.go +++ b/fclauncher/Java.go @@ -4,7 +4,6 @@ import ( "archive/tar" "bytes" "compress/gzip" - "context" "fmt" "io" "os" @@ -15,11 +14,11 @@ import ( "github.com/zhyee/zipstream" ) -type Java struct { - ctx context.Context +type JavaManager struct { + app *App } -func (Java)CheckJavaVer(version int) bool{ +func (JavaManager)CheckJavaVer(version int) bool{ suffix := "lin" if runtime.GOOS == "windows" { suffix = "win" @@ -35,13 +34,13 @@ func (Java)CheckJavaVer(version int) bool{ } -func (j *Java)InstallJavaVer(version int) { +func (j *JavaManager)InstallJavaVer(version int) { suffix := "lin.tar.gz" if runtime.GOOS == "windows" { suffix = "win.zip" } buff := new(bytes.Buffer) - HttpDownload("java/"+fmt.Sprintf("java-%d-%s", version, suffix), buff, j.ctx) + HttpDownload("java/"+fmt.Sprintf("java-%d-%s", version, suffix), buff, j.app.Ctx) path, _ := os.UserConfigDir() suffix = "lin" if runtime.GOOS == "windows" { diff --git a/fclauncher/Modpack.go b/fclauncher/Modpack.go new file mode 100644 index 0000000..d82a0a0 --- /dev/null +++ b/fclauncher/Modpack.go @@ -0,0 +1,62 @@ +package main + +import ( + "bytes" + "encoding/json" + "time" +) + +type Modpack struct { + Name string + Id string + Last_updated string + Versions []Version +} + +type Version struct { + Version string + Data time.Time + File string +} + +type ModpackManager struct { + app *App + Modpacks []Modpack +} + + +func (m *ModpackManager) QuerryModpacks() { + buff := new(bytes.Buffer) + err := HttpDownload("modpacks.json", buff, nil) + if err != nil { + return + } + err = json.Unmarshal(buff.Bytes(), &m.Modpacks) + if err != nil { + return + } + + for ind, pack := range m.Modpacks { + buff = new(bytes.Buffer) + err = HttpDownload(pack.Id + "/versions.json", buff, nil) + if err != nil { + continue + } + json.Unmarshal(buff.Bytes(), &pack.Versions) + m.Modpacks[ind] = pack + } +} + + +func (m *ModpackManager) GetModpacks() []Modpack{ + return m.Modpacks +} + +func (m *ModpackManager) GetModpack(id string) Modpack { + for _, pack := range m.Modpacks { + if pack.Id == id { + return pack + } + } + return Modpack{} +} diff --git a/fclauncher/Prism.go b/fclauncher/Prism.go index 60e62a2..550e30f 100644 --- a/fclauncher/Prism.go +++ b/fclauncher/Prism.go @@ -2,36 +2,26 @@ package main import ( "archive/tar" + "bufio" "bytes" "compress/gzip" - "context" - "encoding/json" + "fmt" "io" "os" + "os/exec" "path/filepath" "runtime" + "strings" "time" "github.com/zhyee/zipstream" ) type Prism struct { - Instances []Instance - ctx context.Context + app *App } -type Instance struct { - Path string - Name string - MCVer string - JavaVer string -} -type Version struct { - Version string - Data time.Time - File string -} func (Prism) CheckInstalled() bool { path, _ := os.UserConfigDir() @@ -45,11 +35,13 @@ func (Prism) CheckInstalled() bool { func (p *Prism) Install() { suffix := "lin.tar.gz" + shortSuffix := "lin" if runtime.GOOS == "windows" { suffix = "win.zip" + shortSuffix = "win" } buff := new(bytes.Buffer) - HttpDownload("prism/prism-"+suffix, buff, p.ctx) + HttpDownload("prism/prism-"+suffix, buff, p.app.Ctx) path, _ := os.UserConfigDir() os.MkdirAll(filepath.Join(path, "FCLauncher", "prism"), 0755) if runtime.GOOS == "windows" { @@ -121,18 +113,51 @@ 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+".mrpack"), os.O_CREATE|os.O_RDWR, 0755) + dir, _ := os.UserConfigDir() + buff = new(bytes.Buffer) + HttpDownload("prism/prismlauncher.cfg", buff, nil) + scanner := bufio.NewScanner(buff) + f, _ := os.OpenFile(filepath.Join(dir, "FCLauncher", "prism", "prismlauncher.cfg"), os.O_CREATE|os.O_RDWR, 0755) defer f.Close() - HttpDownload(modpack.Id + "/" + version.File, f, p.ctx) - + for scanner.Scan() { + line := scanner.Text() + if strings.HasPrefix(line, "JavaPath") { + line = fmt.Sprintf("JavaPath=%s/FCLauncher/java/java-21-%s", dir, shortSuffix) + } + if strings.HasPrefix(line, "LastHostname") { + host, _ := os.Hostname() + line = fmt.Sprintf("LastHostname=%s", host) + } + f.WriteString(line + "\n") + } +} + + + +func (Prism)GetInstanceDir() string{ + dir, _ := os.UserConfigDir() + return filepath.Join(dir, "FCLauncher", "prism", "instances") +} + +func (Prism)getExecutableName() string { + execName := "PrismLauncher" + if runtime.GOOS == "windows" { + execName = "prismlauncher.exe" + } + return execName +} + +func (p *Prism)ImportModpack(path string) { + dir, _ := os.UserConfigDir() + child := exec.Command(filepath.Join(dir, "FCLauncher", "prism", p.getExecutableName()), "-I", path) + child.Start() + tokens := strings.Split(path, string(os.PathSeparator)) + versionPath := filepath.Join(dir, "FCLauncher", "prism", "instances",strings.Split(tokens[len(tokens)-1], ".")[0], ".minecraft", "version.txt") + for { + time.Sleep(time.Second * 3) + if _, err := os.Stat(versionPath); err == nil { + break + } + } + child.Process.Kill() } diff --git a/fclauncher/app.go b/fclauncher/app.go index 813f958..240b903 100644 --- a/fclauncher/app.go +++ b/fclauncher/app.go @@ -1,91 +1,69 @@ package main import ( - "bytes" "context" - "encoding/json" "fmt" - "io" "github.com/wailsapp/wails/v2/pkg/runtime" ) // App struct type App struct { - ctx context.Context - prism Prism - java Java + Ctx context.Context + PrismLauncher Prism + Java JavaManager + Instance InstanceManager + Modpacks ModpackManager } -type Modpack struct { - Name string - Id string - Last_updated string -} // NewApp creates a new App application struct func NewApp() *App { - return &App{} + a := &App{} + a.PrismLauncher = Prism{app: a} + a.Java = JavaManager{app: a} + a.Instance = InstanceManager{app: a} + a.Modpacks = ModpackManager{app: a} + return a } // startup is called when the app starts. The context is saved // so we can call the runtime methods func (a *App) startup(ctx context.Context) { - a.ctx = ctx + a.Ctx = ctx } // Greet returns a greeting for the given name -func (a *App) Greet(name string) string { - return fmt.Sprintf("Hello %s, It's show time!", name) -} -func (a *App) GetModpacks() []Modpack { - buff := new(bytes.Buffer) - err := HttpDownload("modpacks.json", buff, nil) - if err != nil { - fmt.Println(err) - } - body, err := io.ReadAll(buff) - var modpacks []Modpack - err = json.Unmarshal([]byte(body), &modpacks) - if err != nil { - fmt.Println(err.Error()) - return nil - } - return modpacks -} func (a *App) CheckPrerequisites() { - a.status("Checking Prism") - a.prism = Prism{ctx: a.ctx} - res := a.prism.CheckInstalled() + a.Status("Querrying Existing Instances") + a.Instance.SearchInstances() + a.Status("Pulling Modpacks") + a.Modpacks.QuerryModpacks() + a.Status("Checking Prism") + res := a.PrismLauncher.CheckInstalled() if res { - a.status("Prism OK") + a.Status("Prism OK") } else { - a.status("Prism MISSING") - a.status("Installing Prism") - a.prism.Install() - a.status("Prism Installed") + a.Status("Prism MISSING") + a.Status("Installing Prism") + a.PrismLauncher.Install() + a.Status("Prism Installed") } - a.status("Checking Java 21") - a.java = Java{ctx: a.ctx} - res = a.java.CheckJavaVer(21) + a.Status("Checking Java 21") + res = a.Java.CheckJavaVer(21) if res { - a.status("Java 21 OK") + a.Status("Java 21 OK") } else { - a.status("Java 21 MISSING") - a.status("Installing Java 21") - a.java.InstallJavaVer(21) - a.status("Java 21 Installed") + a.Status("Java 21 MISSING") + a.Status("Installing Java 21") + a.Java.InstallJavaVer(21) + a.Status("Java 21 Installed") } } -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) { +func (a *App) Status(status string) { fmt.Printf("LOG: %s\n", status) - runtime.EventsEmit(a.ctx, "status", status) + runtime.EventsEmit(a.Ctx, "status", status) } diff --git a/fclauncher/frontend/src/App.svelte b/fclauncher/frontend/src/App.svelte index 3538ebb..8fa51bd 100644 --- a/fclauncher/frontend/src/App.svelte +++ b/fclauncher/frontend/src/App.svelte @@ -1,6 +1,6 @@ - -
- - -
- - diff --git a/fclauncher/frontend/src/Instances.svelte b/fclauncher/frontend/src/Instances.svelte new file mode 100644 index 0000000..46ff915 --- /dev/null +++ b/fclauncher/frontend/src/Instances.svelte @@ -0,0 +1,74 @@ + + +
+ + +
+ {#if addingInstance} + +
+ +
+ + + {:else} + + {/if} +
+ + diff --git a/fclauncher/frontend/wailsjs/go/main/App.d.ts b/fclauncher/frontend/wailsjs/go/main/App.d.ts index 06d8607..5aa050a 100755 --- a/fclauncher/frontend/wailsjs/go/main/App.d.ts +++ b/fclauncher/frontend/wailsjs/go/main/App.d.ts @@ -1,11 +1,6 @@ // Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL // This file is automatically generated. DO NOT EDIT -import {main} from '../models'; export function CheckPrerequisites():Promise; -export function GetModpacks():Promise>; - -export function Greet(arg1:string):Promise; - -export function InstallModpack(arg1:main.Modpack):Promise; +export function Status(arg1:string):Promise; diff --git a/fclauncher/frontend/wailsjs/go/main/App.js b/fclauncher/frontend/wailsjs/go/main/App.js index f486275..d029a0b 100755 --- a/fclauncher/frontend/wailsjs/go/main/App.js +++ b/fclauncher/frontend/wailsjs/go/main/App.js @@ -6,14 +6,6 @@ export function CheckPrerequisites() { return window['go']['main']['App']['CheckPrerequisites'](); } -export function GetModpacks() { - return window['go']['main']['App']['GetModpacks'](); -} - -export function Greet(arg1) { - return window['go']['main']['App']['Greet'](arg1); -} - -export function InstallModpack(arg1) { - return window['go']['main']['App']['InstallModpack'](arg1); +export function Status(arg1) { + return window['go']['main']['App']['Status'](arg1); } diff --git a/fclauncher/frontend/wailsjs/go/main/InstanceManager.d.ts b/fclauncher/frontend/wailsjs/go/main/InstanceManager.d.ts new file mode 100755 index 0000000..82dd410 --- /dev/null +++ b/fclauncher/frontend/wailsjs/go/main/InstanceManager.d.ts @@ -0,0 +1,9 @@ +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT +import {main} from '../models'; + +export function GetInstances():Promise>; + +export function InstallModpack(arg1:main.Modpack,arg2:string):Promise; + +export function SearchInstances():Promise; diff --git a/fclauncher/frontend/wailsjs/go/main/InstanceManager.js b/fclauncher/frontend/wailsjs/go/main/InstanceManager.js new file mode 100755 index 0000000..a40f564 --- /dev/null +++ b/fclauncher/frontend/wailsjs/go/main/InstanceManager.js @@ -0,0 +1,15 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +export function GetInstances() { + return window['go']['main']['InstanceManager']['GetInstances'](); +} + +export function InstallModpack(arg1, arg2) { + return window['go']['main']['InstanceManager']['InstallModpack'](arg1, arg2); +} + +export function SearchInstances() { + return window['go']['main']['InstanceManager']['SearchInstances'](); +} diff --git a/fclauncher/frontend/wailsjs/go/main/JavaManager.d.ts b/fclauncher/frontend/wailsjs/go/main/JavaManager.d.ts new file mode 100755 index 0000000..44cafbf --- /dev/null +++ b/fclauncher/frontend/wailsjs/go/main/JavaManager.d.ts @@ -0,0 +1,6 @@ +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +export function CheckJavaVer(arg1:number):Promise; + +export function InstallJavaVer(arg1:number):Promise; diff --git a/fclauncher/frontend/wailsjs/go/main/JavaManager.js b/fclauncher/frontend/wailsjs/go/main/JavaManager.js new file mode 100755 index 0000000..4bb1bd4 --- /dev/null +++ b/fclauncher/frontend/wailsjs/go/main/JavaManager.js @@ -0,0 +1,11 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +export function CheckJavaVer(arg1) { + return window['go']['main']['JavaManager']['CheckJavaVer'](arg1); +} + +export function InstallJavaVer(arg1) { + return window['go']['main']['JavaManager']['InstallJavaVer'](arg1); +} diff --git a/fclauncher/frontend/wailsjs/go/main/ModpackManager.d.ts b/fclauncher/frontend/wailsjs/go/main/ModpackManager.d.ts new file mode 100755 index 0000000..272b4ef --- /dev/null +++ b/fclauncher/frontend/wailsjs/go/main/ModpackManager.d.ts @@ -0,0 +1,9 @@ +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT +import {main} from '../models'; + +export function GetModpack(arg1:string):Promise; + +export function GetModpacks():Promise>; + +export function QuerryModpacks():Promise; diff --git a/fclauncher/frontend/wailsjs/go/main/ModpackManager.js b/fclauncher/frontend/wailsjs/go/main/ModpackManager.js new file mode 100755 index 0000000..85fb9aa --- /dev/null +++ b/fclauncher/frontend/wailsjs/go/main/ModpackManager.js @@ -0,0 +1,15 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +export function GetModpack(arg1) { + return window['go']['main']['ModpackManager']['GetModpack'](arg1); +} + +export function GetModpacks() { + return window['go']['main']['ModpackManager']['GetModpacks'](); +} + +export function QuerryModpacks() { + return window['go']['main']['ModpackManager']['QuerryModpacks'](); +} diff --git a/fclauncher/frontend/wailsjs/go/main/Prism.d.ts b/fclauncher/frontend/wailsjs/go/main/Prism.d.ts new file mode 100755 index 0000000..d32bc0f --- /dev/null +++ b/fclauncher/frontend/wailsjs/go/main/Prism.d.ts @@ -0,0 +1,10 @@ +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +export function CheckInstalled():Promise; + +export function GetInstanceDir():Promise; + +export function ImportModpack(arg1:string):Promise; + +export function Install():Promise; diff --git a/fclauncher/frontend/wailsjs/go/main/Prism.js b/fclauncher/frontend/wailsjs/go/main/Prism.js new file mode 100755 index 0000000..da4f2d6 --- /dev/null +++ b/fclauncher/frontend/wailsjs/go/main/Prism.js @@ -0,0 +1,19 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +export function CheckInstalled() { + return window['go']['main']['Prism']['CheckInstalled'](); +} + +export function GetInstanceDir() { + return window['go']['main']['Prism']['GetInstanceDir'](); +} + +export function ImportModpack(arg1) { + return window['go']['main']['Prism']['ImportModpack'](arg1); +} + +export function Install() { + return window['go']['main']['Prism']['Install'](); +} diff --git a/fclauncher/frontend/wailsjs/go/models.ts b/fclauncher/frontend/wailsjs/go/models.ts index 11f4c23..11272e4 100755 --- a/fclauncher/frontend/wailsjs/go/models.ts +++ b/fclauncher/frontend/wailsjs/go/models.ts @@ -1,9 +1,61 @@ export namespace main { + export class Instance { + InstanceName: string; + ModpackId: string; + ModpackVersion: string; + + static createFrom(source: any = {}) { + return new Instance(source); + } + + constructor(source: any = {}) { + if ('string' === typeof source) source = JSON.parse(source); + this.InstanceName = source["InstanceName"]; + this.ModpackId = source["ModpackId"]; + this.ModpackVersion = source["ModpackVersion"]; + } + } + export class Version { + Version: string; + // Go type: time + Data: any; + File: string; + + static createFrom(source: any = {}) { + return new Version(source); + } + + constructor(source: any = {}) { + if ('string' === typeof source) source = JSON.parse(source); + this.Version = source["Version"]; + this.Data = this.convertValues(source["Data"], null); + this.File = source["File"]; + } + + convertValues(a: any, classs: any, asMap: boolean = false): any { + if (!a) { + return a; + } + if (a.slice && a.map) { + return (a as any[]).map(elem => this.convertValues(elem, classs)); + } else if ("object" === typeof a) { + if (asMap) { + for (const key of Object.keys(a)) { + a[key] = new classs(a[key]); + } + return a; + } + return new classs(a); + } + return a; + } + } export class Modpack { Name: string; Id: string; Last_updated: string; + Versions: Version[]; static createFrom(source: any = {}) { return new Modpack(source); @@ -14,7 +66,26 @@ export namespace main { this.Name = source["Name"]; this.Id = source["Id"]; this.Last_updated = source["Last_updated"]; + this.Versions = this.convertValues(source["Versions"], Version); } + + convertValues(a: any, classs: any, asMap: boolean = false): any { + if (!a) { + return a; + } + if (a.slice && a.map) { + return (a as any[]).map(elem => this.convertValues(elem, classs)); + } else if ("object" === typeof a) { + if (asMap) { + for (const key of Object.keys(a)) { + a[key] = new classs(a[key]); + } + return a; + } + return new classs(a); + } + return a; + } } } diff --git a/fclauncher/main.go b/fclauncher/main.go index d88a32e..75cc308 100644 --- a/fclauncher/main.go +++ b/fclauncher/main.go @@ -2,7 +2,7 @@ package main import ( "embed" - + "github.com/wailsapp/wails/v2" "github.com/wailsapp/wails/v2/pkg/options" "github.com/wailsapp/wails/v2/pkg/options/assetserver" @@ -27,6 +27,10 @@ func main() { OnStartup: app.startup, Bind: []interface{}{ app, + &app.Instance, + &app.PrismLauncher, + &app.Java, + &app.Modpacks, }, })