From 2bbb4b8cf00d1186ab4eb6a8a6540967ecb8ba6e Mon Sep 17 00:00:00 2001 From: Samuel Walker Date: Wed, 30 Oct 2024 15:39:11 -0600 Subject: [PATCH] installation and launching of vanilla minecraft working --- fclauncher/InstanceManager.go | 100 ++++- fclauncher/app.go | 3 + fclauncher/frontend/src/Instances.svelte | 17 +- .../wailsjs/go/main/InstanceManager.d.ts | 2 + .../wailsjs/go/main/InstanceManager.js | 4 + fclauncher/frontend/wailsjs/go/models.ts | 12 + fclauncher/logs/2024-10-30-1.log.gz | Bin 0 -> 3599 bytes fclauncher/logs/2024-10-30-2.log.gz | Bin 0 -> 2922 bytes fclauncher/logs/2024-10-30-3.log.gz | Bin 0 -> 2393 bytes fclauncher/logs/2024-10-30-4.log.gz | Bin 0 -> 2388 bytes fclauncher/logs/2024-10-30-5.log.gz | Bin 0 -> 839 bytes fclauncher/logs/latest.log | 77 ++++ fclauncher/minecraft.go | 386 +++++++++++++++++- 13 files changed, 584 insertions(+), 17 deletions(-) create mode 100644 fclauncher/logs/2024-10-30-1.log.gz create mode 100644 fclauncher/logs/2024-10-30-2.log.gz create mode 100644 fclauncher/logs/2024-10-30-3.log.gz create mode 100644 fclauncher/logs/2024-10-30-4.log.gz create mode 100644 fclauncher/logs/2024-10-30-5.log.gz create mode 100644 fclauncher/logs/latest.log diff --git a/fclauncher/InstanceManager.go b/fclauncher/InstanceManager.go index c3645cc..9c096e2 100644 --- a/fclauncher/InstanceManager.go +++ b/fclauncher/InstanceManager.go @@ -7,17 +7,23 @@ import ( "fmt" "io" "os" + "os/exec" "path/filepath" "runtime" "strconv" "strings" - "time" ) type Instance struct { InstanceName string ModpackId string ModpackVersion string + MinecraftVersion string + ForgeVersion string + NeoForgeVersion string + FabricVersion string + QuiltVersion string + JavaVersion int } type InstanceManager struct { @@ -36,7 +42,8 @@ type component struct { func (i *InstanceManager)SearchInstances() { i.instances = []Instance{} - dir := i.app.PrismLauncher.GetInstanceDir() + dir, _ := os.UserConfigDir() + dir = filepath.Join(dir, "FCLauncher", "instances") if _, err := os.Stat(dir); err != nil { return } @@ -148,13 +155,59 @@ func (i *InstanceManager)InstallModpack(modpack Modpack, 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 { + fmt.Printf("Unable to download assets: %s\n", err) + } else { + fmt.Printf("Assets Downloaded") + } + err = DownloadLibraries(version, filepath.Join(dir, "FCLauncher", "lib"), *i.app) + if err != nil { + fmt.Printf("Unable to download libs: %s\n", err) + } else { + fmt.Printf("Libs Downloaded") + } + InstallNatives(version, filepath.Join(dir, "FCLauncher", "instances", instanceName, "minecraft", "natives")) + err = DownloadExecutable(version, filepath.Join(dir, "FCLauncher", "bin"), *i.app) + if err != nil { + fmt.Printf("Unable to download binaries: %s\n", err) + } else { + fmt.Printf("Binaries Downloaded") + } metadata, err := GetVersionMetadata(version) if err != nil { - fmt.Printf("Unable to obtain metadata: %s\n", err) - } else { - fmt.Printf("Version Metadata: %+v", metadata) + fmt.Printf("unable to pull metadata: %s\n", err) } - time.Sleep(time.Second * 1) + + err = os.MkdirAll(filepath.Join(dir, "FCLauncher", "instances", instanceName, "minecraft"), 0755) + if err != nil { + fmt.Printf("unable to create directory: %s\n", err) + } + + + instance := Instance{InstanceName: instanceName, MinecraftVersion: version, JavaVersion: metadata.JavaVersion.MajorVersion} + data, err := json.Marshal(instance) + if err != nil { + fmt.Printf("unable to marshal json data: %s\n", err) + } + f, err := os.OpenFile(filepath.Join(dir, "FCLauncher", "instances", instanceName, "instance.json"), os.O_CREATE|os.O_RDWR, 0755) + if err != nil { + fmt.Printf("unable to open file: %s\n", err) + } + + defer f.Close() + _, err = f.Write(data) + if err != nil { + fmt.Printf("unable to write data: %s\n", err) + } + i.instances = append(i.instances, instance) + + if !i.app.Java.CheckJavaVer(instance.JavaVersion) { + i.app.Status(fmt.Sprintf("Installing Java Version %d", instance.JavaVersion)) + i.app.Java.InstallJavaVer(instance.JavaVersion) + } + return } @@ -163,6 +216,7 @@ func (i *InstanceManager)GetInstances() []Instance{ } func (i *InstanceManager)CheckUpdate(instance Instance){ + return i.app.Status("Checking for Updates") i.app.Modpacks.QuerryModpacks() pack := i.app.Modpacks.GetModpack(instance.ModpackId) @@ -185,3 +239,37 @@ func (i *InstanceManager)CheckUpdate(instance Instance){ i.SearchInstances() } +func (i *InstanceManager)LaunchInstance(instance string) { + dir, err := os.UserConfigDir() + if err != nil { + fmt.Printf("unable to get config directory\n") + } + instanceObject := Instance{} + found := false + for _, inst := range i.instances { + if inst.InstanceName == instance { + instanceObject = inst + found = true + break + } + } + if !found { + fmt.Printf("unable to find instance %s\n", instance) + } + execName := "java" + suffix := "lin" + if runtime.GOOS == "windows" { + execName = "Java.exe" + suffix = "win" + } + dir = filepath.Join(dir, "FCLauncher") + args, err := GetOfflineLaunchArgs(instanceObject.MinecraftVersion, filepath.Join(dir, "lib"), filepath.Join(dir, "bin"), filepath.Join(dir, "assets"), filepath.Join(dir, "instances", instance, "minecraft"), "Player") + if err != nil { + fmt.Printf("unable to get launch args: %s\n", err) + } + fmt.Printf("Args: %+v", args) + child := exec.Command(filepath.Join(dir, "java", fmt.Sprintf("java-%d-%s", instanceObject.JavaVersion, suffix), "bin", execName), args...) + data, err := child.CombinedOutput() + fmt.Printf("Command Output: %s\n", data) +} + diff --git a/fclauncher/app.go b/fclauncher/app.go index 8d77820..d4f6f05 100644 --- a/fclauncher/app.go +++ b/fclauncher/app.go @@ -7,6 +7,9 @@ import ( "github.com/wailsapp/wails/v2/pkg/runtime" ) + +const client_id string = "9305aeb8-5ecb-4e7a-b28f-c33aefcfbd8d" + // App struct type App struct { Ctx context.Context diff --git a/fclauncher/frontend/src/Instances.svelte b/fclauncher/frontend/src/Instances.svelte index 5ff508b..8c1238b 100644 --- a/fclauncher/frontend/src/Instances.svelte +++ b/fclauncher/frontend/src/Instances.svelte @@ -1,7 +1,6 @@