From f905d617a847fd15a8183e727188fc4107230611 Mon Sep 17 00:00:00 2001
From: = <=>
Date: Mon, 25 Nov 2024 13:23:06 -0700
Subject: [PATCH] Able to install correct version of minecraft + loader from
mrpack
---
fclauncher/InstanceManager.go | 58 +++++++++++++++++++
fclauncher/frontend/src/App.svelte | 2 +-
fclauncher/frontend/src/Modpacks.svelte | 11 +++-
.../wailsjs/go/main/InstanceManager.d.ts | 5 ++
.../wailsjs/go/main/InstanceManager.js | 8 +++
5 files changed, 82 insertions(+), 2 deletions(-)
diff --git a/fclauncher/InstanceManager.go b/fclauncher/InstanceManager.go
index c094658..19c8926 100644
--- a/fclauncher/InstanceManager.go
+++ b/fclauncher/InstanceManager.go
@@ -14,8 +14,27 @@ import (
"strings"
wruntime "github.com/wailsapp/wails/v2/pkg/runtime"
+ "github.com/zhyee/zipstream"
)
+type MrData struct {
+ FormatVersion int
+ Game string
+ VersionId string
+ Name string
+ Summary string
+ Files []MrFile
+ Dependencies map[string]string
+}
+
+type MrFile struct {
+ Path string
+ Hashes map[string]string
+ Env map[string]string
+ Downloads []string
+ FileSize int
+}
+
type Instance struct {
InstanceName string
ModpackId string
@@ -460,3 +479,42 @@ outer:
}
}
+
+func (i *InstanceManager) ImportModpack(modpack Modpack, name string) {
+ buff := new(bytes.Buffer)
+ HttpDownload(filepath.Join(modpack.Id, modpack.Versions[len(modpack.Versions)-1].File), buff, i.app.Ctx)
+ i.ImportMrpack(buff, name)
+
+}
+
+func (i *InstanceManager) ImportMrpack(data io.Reader, name string) {
+ zr := zipstream.NewReader(data)
+ mrdata := MrData{}
+ for {
+ entry, err := zr.GetNextEntry()
+ if err == io.EOF {
+ break
+ }
+ if entry.Name == "modrinth.index.json" {
+ file, _ := entry.Open()
+ data, _ := io.ReadAll(file)
+ json.Unmarshal(data, &mrdata)
+ break
+ }
+ }
+ fmt.Printf("Installing minecraft %s\n", mrdata.Dependencies["minecraft"])
+ i.InstallVanilla(mrdata.Dependencies["minecraft"], name)
+ if mrdata.Dependencies["forge"] != "" {
+ fmt.Printf("Forge not implemented!")
+ //implement forge
+ } else if mrdata.Dependencies["neoforge"] != "" {
+ 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"])
+ }
+}
diff --git a/fclauncher/frontend/src/App.svelte b/fclauncher/frontend/src/App.svelte
index 94a9a88..cf937bb 100644
--- a/fclauncher/frontend/src/App.svelte
+++ b/fclauncher/frontend/src/App.svelte
@@ -11,7 +11,7 @@
import Instancepage from './Instancepage.svelte'
import { set_attributes, set_style } from 'svelte/internal';
- let width: int = 10
+ let width: number = 10
let navMargin = document.getElementById("body") as HTMLElement;
let r
diff --git a/fclauncher/frontend/src/Modpacks.svelte b/fclauncher/frontend/src/Modpacks.svelte
index ba6223c..a9f5c1a 100644
--- a/fclauncher/frontend/src/Modpacks.svelte
+++ b/fclauncher/frontend/src/Modpacks.svelte
@@ -1,16 +1,24 @@
@@ -19,4 +27,5 @@
{/each}
+
\ No newline at end of file
diff --git a/fclauncher/frontend/wailsjs/go/main/InstanceManager.d.ts b/fclauncher/frontend/wailsjs/go/main/InstanceManager.d.ts
index adda89f..6217c65 100755
--- a/fclauncher/frontend/wailsjs/go/main/InstanceManager.d.ts
+++ b/fclauncher/frontend/wailsjs/go/main/InstanceManager.d.ts
@@ -1,6 +1,7 @@
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT
import {main} from '../models';
+import {io} from '../models';
export function CheckUpdate(arg1:main.Instance):Promise;
@@ -8,6 +9,10 @@ export function GetInstance(arg1:string):Promise;
export function GetInstances():Promise>;
+export function ImportModpack(arg1:main.Modpack,arg2:string):Promise;
+
+export function ImportMrpack(arg1:io.Reader,arg2:string):Promise;
+
export function InstallFabric(arg1:string,arg2:string):Promise;
export function InstallForge(arg1:string,arg2:string):Promise;
diff --git a/fclauncher/frontend/wailsjs/go/main/InstanceManager.js b/fclauncher/frontend/wailsjs/go/main/InstanceManager.js
index 1ae52ea..5ae31d4 100755
--- a/fclauncher/frontend/wailsjs/go/main/InstanceManager.js
+++ b/fclauncher/frontend/wailsjs/go/main/InstanceManager.js
@@ -14,6 +14,14 @@ export function GetInstances() {
return window['go']['main']['InstanceManager']['GetInstances']();
}
+export function ImportModpack(arg1, arg2) {
+ return window['go']['main']['InstanceManager']['ImportModpack'](arg1, arg2);
+}
+
+export function ImportMrpack(arg1, arg2) {
+ return window['go']['main']['InstanceManager']['ImportMrpack'](arg1, arg2);
+}
+
export function InstallFabric(arg1, arg2) {
return window['go']['main']['InstanceManager']['InstallFabric'](arg1, arg2);
}