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