Made instances list global
This commit is contained in:
parent
9d23d503e2
commit
27c97010ae
@ -17,22 +17,22 @@ import (
|
||||
)
|
||||
|
||||
type Instance struct {
|
||||
InstanceName string
|
||||
ModpackId string
|
||||
ModpackVersion string
|
||||
InstanceName string
|
||||
ModpackId string
|
||||
ModpackVersion string
|
||||
MinecraftVersion string
|
||||
ForgeVersion string
|
||||
NeoForgeVersion string
|
||||
FabricVersion string
|
||||
QuiltVersion string
|
||||
JavaVersion int
|
||||
Libraries []string
|
||||
MainClass string
|
||||
ForgeVersion string
|
||||
NeoForgeVersion string
|
||||
FabricVersion string
|
||||
QuiltVersion string
|
||||
JavaVersion int
|
||||
Libraries []string
|
||||
MainClass string
|
||||
}
|
||||
|
||||
type InstanceManager struct {
|
||||
instances []Instance
|
||||
app *App
|
||||
app *App
|
||||
}
|
||||
|
||||
type mmcpack struct {
|
||||
@ -40,11 +40,11 @@ type mmcpack struct {
|
||||
}
|
||||
|
||||
type component struct {
|
||||
Uid string
|
||||
Uid string
|
||||
Version string
|
||||
}
|
||||
|
||||
func (i *InstanceManager)SearchInstances() {
|
||||
func (i *InstanceManager) SearchInstances() {
|
||||
i.instances = []Instance{}
|
||||
dir, _ := os.UserConfigDir()
|
||||
dir = filepath.Join(dir, "FCLauncher", "instances")
|
||||
@ -69,21 +69,21 @@ func (i *InstanceManager)SearchInstances() {
|
||||
}
|
||||
}
|
||||
|
||||
func (i *InstanceManager)checkJavaVersion(instance Instance){
|
||||
func (i *InstanceManager) checkJavaVersion(instance Instance) {
|
||||
infoPath := filepath.Join(i.app.PrismLauncher.GetInstanceDir(), instance.InstanceName, "mmc-pack.json")
|
||||
f, _ := os.OpenFile(infoPath, os.O_RDONLY, 0755)
|
||||
defer f.Close()
|
||||
dataStr,_ := io.ReadAll(f)
|
||||
dataStr, _ := io.ReadAll(f)
|
||||
var data mmcpack
|
||||
json.Unmarshal(dataStr, &data)
|
||||
mc_version := "0.0"
|
||||
for _, comp := range data.Components {
|
||||
if comp.Uid == "net.minecraft" {
|
||||
mc_version = comp.Version
|
||||
break;
|
||||
break
|
||||
}
|
||||
}
|
||||
fmt.Printf("MC Version: %s",mc_version)
|
||||
fmt.Printf("MC Version: %s", mc_version)
|
||||
tokensStr := strings.Split(mc_version, ".")
|
||||
tokens := []int{0, 0, 0}
|
||||
tokens[0], _ = strconv.Atoi(tokensStr[0])
|
||||
@ -103,7 +103,7 @@ func (i *InstanceManager)checkJavaVersion(instance Instance){
|
||||
javaVer = 21
|
||||
}
|
||||
}
|
||||
fmt.Printf("Req Java Version: %d",javaVer)
|
||||
fmt.Printf("Req Java Version: %d", javaVer)
|
||||
if !i.app.Java.CheckJavaVer(javaVer) {
|
||||
i.app.Java.InstallJavaVer(javaVer)
|
||||
}
|
||||
@ -129,23 +129,23 @@ func (i *InstanceManager)checkJavaVersion(instance Instance){
|
||||
line = fmt.Sprintf("JavaPath=%s/FCLauncher/java/java-%d-%s/bin/%s", strings.ReplaceAll(confDir, "\\", "/"), javaVer, plat, exe)
|
||||
found = true
|
||||
}
|
||||
f.WriteString(line+"\n")
|
||||
f.WriteString(line + "\n")
|
||||
}
|
||||
if !found {
|
||||
line := fmt.Sprintf("JavaPath=%s/FCLauncher/java/java-%d-%s/bin/%s", strings.ReplaceAll(confDir, "\\", "/"), javaVer, plat, exe)
|
||||
f.WriteString(line+"\n")
|
||||
f.WriteString(line + "\n")
|
||||
f.WriteString("OverrideJavaLocation=true\nOverrideJava=true\n")
|
||||
}
|
||||
f.Close()
|
||||
}
|
||||
|
||||
func (i *InstanceManager)InstallModpack(modpack Modpack, instanceName string){
|
||||
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)
|
||||
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)
|
||||
@ -157,7 +157,7 @@ func (i *InstanceManager)InstallModpack(modpack Modpack, instanceName string){
|
||||
|
||||
}
|
||||
|
||||
func (i *InstanceManager)InstallVanilla(version string, instanceName string) {
|
||||
func (i *InstanceManager) InstallVanilla(version string, instanceName string) {
|
||||
dir, _ := os.UserConfigDir()
|
||||
err := DownloadAssets(version, filepath.Join(dir, "FCLauncher", "assets"), *i.app)
|
||||
if err != nil {
|
||||
@ -216,11 +216,15 @@ func (i *InstanceManager)InstallVanilla(version string, instanceName string) {
|
||||
return
|
||||
}
|
||||
|
||||
func (i *InstanceManager)GetInstances() []Instance{
|
||||
return i.instances
|
||||
func (i *InstanceManager) GetInstances() []string {
|
||||
names := []string{}
|
||||
for _, inst := range i.instances {
|
||||
names = append(names, inst.InstanceName)
|
||||
}
|
||||
return names
|
||||
}
|
||||
|
||||
func (i *InstanceManager)CheckUpdate(instance Instance){
|
||||
func (i *InstanceManager) CheckUpdate(instance Instance) {
|
||||
return
|
||||
i.app.Status("Checking for Updates")
|
||||
i.app.Modpacks.QuerryModpacks()
|
||||
@ -233,7 +237,7 @@ func (i *InstanceManager)CheckUpdate(instance Instance){
|
||||
dname, _ := os.MkdirTemp("", "fclauncher-*")
|
||||
f, _ := os.OpenFile(filepath.Join(dname, instance.InstanceName+".mrpack"), os.O_CREATE|os.O_RDWR, 0755)
|
||||
defer f.Close()
|
||||
HttpDownload(pack.Id + "/" + version.File, f, i.app.Ctx)
|
||||
HttpDownload(pack.Id+"/"+version.File, f, i.app.Ctx)
|
||||
i.app.PrismLauncher.ImportModpack(f.Name())
|
||||
instance.ModpackVersion = version.Version
|
||||
f, _ = os.OpenFile(filepath.Join(i.app.PrismLauncher.GetInstanceDir(), instance.InstanceName, "instance.json"), os.O_CREATE|os.O_RDWR, 0755)
|
||||
@ -244,7 +248,7 @@ func (i *InstanceManager)CheckUpdate(instance Instance){
|
||||
i.SearchInstances()
|
||||
}
|
||||
|
||||
func (i *InstanceManager)GetInstance(instance string) (Instance, error) {
|
||||
func (i *InstanceManager) GetInstance(instance string) (Instance, error) {
|
||||
instanceObject := Instance{}
|
||||
found := false
|
||||
for _, inst := range i.instances {
|
||||
@ -260,7 +264,7 @@ func (i *InstanceManager)GetInstance(instance string) (Instance, error) {
|
||||
return instanceObject, nil
|
||||
}
|
||||
|
||||
func (i *InstanceManager)LaunchInstance(instance string) {
|
||||
func (i *InstanceManager) LaunchInstance(instance string) {
|
||||
dir, err := os.UserConfigDir()
|
||||
if err != nil {
|
||||
fmt.Printf("unable to get config directory\n")
|
||||
@ -294,9 +298,7 @@ func (i *InstanceManager)LaunchInstance(instance string) {
|
||||
fmt.Printf("Command Output: %s\n", data)
|
||||
}
|
||||
|
||||
|
||||
|
||||
func (i *InstanceManager)InstallFabric(instance string, fabricVersion string) {
|
||||
func (i *InstanceManager) InstallFabric(instance string, fabricVersion string) {
|
||||
i.app.Status("Installing Fabric")
|
||||
instanceObject, err := i.GetInstance(instance)
|
||||
if err != nil {
|
||||
@ -306,7 +308,7 @@ func (i *InstanceManager)InstallFabric(instance string, fabricVersion string) {
|
||||
if err != nil {
|
||||
fmt.Printf("unable to get version metadata\n")
|
||||
}
|
||||
client:
|
||||
client:
|
||||
for _, lib := range metadata.LauncherMeta.Libraries.Client {
|
||||
tokens := strings.Split(ProcessMavenPath(lib.Name), string(os.PathSeparator))
|
||||
pkg := tokens[len(tokens)-2]
|
||||
@ -320,7 +322,7 @@ func (i *InstanceManager)InstallFabric(instance string, fabricVersion string) {
|
||||
}
|
||||
}
|
||||
}
|
||||
common:
|
||||
common:
|
||||
for _, lib := range metadata.LauncherMeta.Libraries.Common {
|
||||
tokens := strings.Split(ProcessMavenPath(lib.Name), string(os.PathSeparator))
|
||||
pkg := tokens[len(tokens)-2]
|
||||
@ -354,7 +356,7 @@ func (i *InstanceManager)InstallFabric(instance string, fabricVersion string) {
|
||||
}
|
||||
}
|
||||
|
||||
func (i *InstanceManager)InstallQuilt(instance string, quiltVersion string) {
|
||||
func (i *InstanceManager) InstallQuilt(instance string, quiltVersion string) {
|
||||
i.app.Status("Installing Quilt")
|
||||
instanceObject, err := i.GetInstance(instance)
|
||||
if err != nil {
|
||||
@ -364,7 +366,7 @@ func (i *InstanceManager)InstallQuilt(instance string, quiltVersion string) {
|
||||
if err != nil {
|
||||
fmt.Printf("unable to get version metadata\n")
|
||||
}
|
||||
client:
|
||||
client:
|
||||
for _, lib := range metadata.LauncherMeta.Libraries.Client {
|
||||
tokens := strings.Split(ProcessMavenPath(lib.Name), string(os.PathSeparator))
|
||||
pkg := tokens[len(tokens)-2]
|
||||
@ -378,7 +380,7 @@ func (i *InstanceManager)InstallQuilt(instance string, quiltVersion string) {
|
||||
}
|
||||
}
|
||||
}
|
||||
common:
|
||||
common:
|
||||
for _, lib := range metadata.LauncherMeta.Libraries.Common {
|
||||
tokens := strings.Split(ProcessMavenPath(lib.Name), string(os.PathSeparator))
|
||||
pkg := tokens[len(tokens)-2]
|
||||
|
@ -5,12 +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} from './global'
|
||||
import {loading, addingInstance, instances} from './global'
|
||||
import {slide} from 'svelte/transition'
|
||||
|
||||
let modpacks: string[] = []
|
||||
let pack: string
|
||||
let instances: Instance[] = []
|
||||
//let instances: Instance[] = []
|
||||
let instance: string
|
||||
let name: string = "New Modpack"
|
||||
let loader: string = "none"
|
||||
@ -29,8 +29,8 @@
|
||||
updateLoaders()
|
||||
})
|
||||
GetInstances().then((result) => {
|
||||
instances = result
|
||||
instance = instances[0].InstanceName
|
||||
$instances = result
|
||||
instance = $instances[0]
|
||||
})
|
||||
}
|
||||
|
||||
@ -109,8 +109,8 @@
|
||||
|
||||
<main>
|
||||
<select bind:value={instance} name="pack">Select a Modpack:
|
||||
{#each instances as instance}
|
||||
<option value={instance.InstanceName}>{instance.InstanceName}</option>
|
||||
{#each $instances as instance}
|
||||
<option value={instance}>{instance}</option>
|
||||
{/each}
|
||||
</select>
|
||||
<button on:click={onclick}>Launch</button>
|
||||
|
@ -1,4 +1,5 @@
|
||||
<script lang="ts">
|
||||
import {instances} from './global'
|
||||
var testArray = ["test","test2","test3"];
|
||||
|
||||
</script>
|
||||
@ -6,8 +7,8 @@
|
||||
|
||||
<main>
|
||||
<div class="testLinks">
|
||||
{#each {length: testArray.length} as _, i}
|
||||
<li>{testArray[i]}</li>
|
||||
{#each $instances as i}
|
||||
<li>{i}</li>
|
||||
{/each}
|
||||
</div>
|
||||
</main>
|
||||
|
@ -2,3 +2,4 @@ import { writable } from "svelte/store"
|
||||
export const loading = writable(true)
|
||||
export const addingInstance = writable(false)
|
||||
export const testPage = writable(false)
|
||||
export const instances = writable([])
|
@ -6,7 +6,7 @@ export function CheckUpdate(arg1:main.Instance):Promise<void>;
|
||||
|
||||
export function GetInstance(arg1:string):Promise<main.Instance>;
|
||||
|
||||
export function GetInstances():Promise<Array<main.Instance>>;
|
||||
export function GetInstances():Promise<Array<string>>;
|
||||
|
||||
export function InstallFabric(arg1:string,arg2:string):Promise<void>;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user