some random ui polish changes

This commit is contained in:
= 2024-11-26 10:22:37 -07:00
parent ad736787e9
commit d4f9711699
8 changed files with 142 additions and 77 deletions

View File

@ -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")
}
}

View File

@ -1,6 +1,7 @@
package main
import (
"bytes"
"crypto/sha1"
"encoding/hex"
"encoding/json"
@ -10,13 +11,13 @@ import (
"os"
"path/filepath"
"strings"
wruntime "github.com/wailsapp/wails/v2/pkg/runtime"
)
type Fabric struct {
}
type FabricDefinition struct {
Separator string
Build int
@ -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
}
}
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(lib, libDir, a)
}
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(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 {

View File

@ -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 @@
</div>
{:else if $currentPage == 2}
<div transition:slide="{{duration:100}}" class="central">
<Instances />
<Instances UpdateInstances={UpdateInstances} />
</div>
{:else if $currentPage == 3}
<div transition:slide="{{duration:100}}" class="central">
<Modpacks />
<Modpacks UpdateInstances={UpdateInstances} />
</div>
{/if}
</body>

View File

@ -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 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,10 +27,7 @@
name = modpacks[0]
updateLoaders()
})
GetInstances().then((result) => {
$instances = result
instance = $instances[0]
})
UpdateInstances()
}
function updateLoaders(){
@ -64,13 +60,6 @@
updateLists()
})
function onclick(event) {
$loading = true
LaunchInstance(instance).then(() => {
$loading = false
})
}
function install(){
$loading = true
InstallVanilla(pack, name).then(() => {

View File

@ -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
}
</script>
<main>
<select id="pack" bind:value={pack} name="pack">Select a Modpack:
<select id="pack" bind:value={pack} on:change={onchange} name="pack">Select a Modpack:
{#each modpacks as pack}
<option value={pack}>{pack.Name}</option>
{/each}
</select>
<input bind:value={name} />
<button on:click={AddModpack}>Add Modpack</button>
</main>

View File

@ -1,6 +1,6 @@
<script lang="ts" src="https://kit.fontawesome.com/172593a6a5.js" crossorigin="anonymous">
import { main } from '../wailsjs/go/models';
import {addingInstance, testPage, navMargin, currentPage} from './global'
import {addingInstance, navMargin, currentPage} from './global'
function extend(){
$navMargin = 17;

View File

@ -1,7 +1,6 @@
import { writable } from "svelte/store"
export const loading = writable(true)
export const addingInstance = writable(false)
export const testPage = writable(false)
export const instances = writable([])
export const navMargin = writable(3)
export const currentPage = writable(1)

View File

@ -1,6 +1,7 @@
package main
import (
"bytes"
"crypto/sha1"
"encoding/hex"
"encoding/json"
@ -9,13 +10,13 @@ import (
"net/http"
"os"
"path/filepath"
wruntime "github.com/wailsapp/wails/v2/pkg/runtime"
)
type Quilt struct {
}
type QuiltDefinition struct {
Separator string
Build int
@ -74,7 +75,8 @@ func GetQuiltMetadata(mcVersion string, quiltVersion string) (QuiltVersion, erro
return QuiltVersion{}, fmt.Errorf("Unable to find requested version.\n")
}
func InstallQuiltLib(lib QuiltLibrary, libDir string) {
func InstallQuiltLib(lib QuiltLibrary, 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,6 +87,7 @@ func InstallQuiltLib(lib QuiltLibrary, libDir string) {
return
}
}
a.Status(fmt.Sprintf("Downloading %s\n", lib.Name))
resp, err := http.Get(lib.Url + path)
if err != nil {
fmt.Printf("unable to find library: %s\n", lib.Url+path)
@ -95,22 +98,37 @@ func InstallQuiltLib(lib QuiltLibrary, libDir string) {
fmt.Printf("unable to find library: %s\n", lib.Url+path)
return
}
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 InstallQuiltLibs(mcVersion string, quiltVersion string, libDir string) {
func InstallQuiltLibs(mcVersion string, quiltVersion string, libDir string, a *App) {
metadata, _ := GetQuiltMetadata(mcVersion, quiltVersion)
for _, lib := range metadata.LauncherMeta.Libraries.Client {
InstallQuiltLib(lib, libDir)
InstallQuiltLib(lib, libDir, a)
}
for _, lib := range metadata.LauncherMeta.Libraries.Common {
InstallQuiltLib(lib, libDir)
InstallQuiltLib(lib, libDir, a)
}
InstallQuiltLib(QuiltLibrary{Name: metadata.Loader.Maven, Sha1: "", Url: "https://maven.quiltmc.org/repository/release/"}, libDir)
InstallQuiltLib(QuiltLibrary{Name: metadata.Intermediary.Maven, Sha1: "", Url: "https://maven.fabricmc.net/"}, libDir)
InstallQuiltLib(QuiltLibrary{Name: metadata.Hashed.Maven, Sha1: "", Url: "https://maven.quiltmc.org/repository/release/"}, libDir)
InstallQuiltLib(QuiltLibrary{Name: metadata.Loader.Maven, Sha1: "", Url: "https://maven.quiltmc.org/repository/release/"}, libDir, a)
InstallQuiltLib(QuiltLibrary{Name: metadata.Intermediary.Maven, Sha1: "", Url: "https://maven.fabricmc.net/"}, libDir, a)
InstallQuiltLib(QuiltLibrary{Name: metadata.Hashed.Maven, Sha1: "", Url: "https://maven.quiltmc.org/repository/release/"}, libDir, a)
}