From e08b265ae8524c852cf9b92d1c6332b395fd4855 Mon Sep 17 00:00:00 2001 From: AzenKain Date: Wed, 5 Nov 2025 23:33:34 +0700 Subject: [PATCH] FIX: Fail to start game --- .../internal/fs-service/fsservice.js | 4 ++-- frontend/src/pages/launcher/index.tsx | 22 +++++++++++-------- internal/fs-service/fs.go | 21 +++++++++--------- pkg/constant/constant.go | 2 +- 4 files changed, 26 insertions(+), 23 deletions(-) diff --git a/frontend/bindings/firefly-launcher/internal/fs-service/fsservice.js b/frontend/bindings/firefly-launcher/internal/fs-service/fsservice.js index 034f241..5d44711 100644 --- a/frontend/bindings/firefly-launcher/internal/fs-service/fsservice.js +++ b/frontend/bindings/firefly-launcher/internal/fs-service/fsservice.js @@ -80,7 +80,7 @@ export function RemoveFile(path) { /** * @param {string} path - * @returns {$CancellablePromise} + * @returns {$CancellablePromise<[boolean, string]>} */ export function StartApp(path) { return $Call.ByID(1267568402, path); @@ -88,7 +88,7 @@ export function StartApp(path) { /** * @param {string} path - * @returns {$CancellablePromise} + * @returns {$CancellablePromise<[boolean, string]>} */ export function StartWithConsole(path) { return $Call.ByID(3249271428, path); diff --git a/frontend/src/pages/launcher/index.tsx b/frontend/src/pages/launcher/index.tsx index f71350f..8ea4d89 100644 --- a/frontend/src/pages/launcher/index.tsx +++ b/frontend/src/pages/launcher/index.tsx @@ -190,18 +190,18 @@ export default function LauncherPage() { try { setIsLoading(true) if (!proxyRunning && !gamePath.endsWith("launcher.exe")) { - const resultProxy = await FSService.StartWithConsole(proxyPath) + const [resultProxy, error] = await FSService.StartWithConsole(proxyPath) if (!resultProxy) { - toast.error('Failed to start proxy') + toast.error('Failed to start proxy: ' + error) return } setProxyRunning(true) } await sleep(500) if (!serverRunning) { - const resultServer = await FSService.StartWithConsole(serverPath) + const [resultServer, error] = await FSService.StartWithConsole(serverPath) if (!resultServer) { - toast.error('Failed to start server') + toast.error('Failed to start server: ' + error) return } setServerRunning(true) @@ -209,23 +209,27 @@ export default function LauncherPage() { await sleep(1000) const gameFolder = await FSService.GetDir(gamePath) const fileNeedRemove = await FSService.Join(gameFolder, "StarRail_Data", "Plugins", "x86_64", "AccountPlatNative.dll") - await FSService.RemoveFile(fileNeedRemove) + const fileExists = await FSService.FileExists(fileNeedRemove) + if (fileExists) { + await FSService.RemoveFile(fileNeedRemove) + } if (gamePath.endsWith("launcher.exe")) { - const resultGame = await FSService.StartWithConsole(gamePath) + const [resultGame, error] = await FSService.StartWithConsole(gamePath) if (!resultGame) { - toast.error('Failed to start game') + toast.error('Failed to start game: ' + error) return } } else { - const resultGame = await FSService.StartApp(gamePath) + const [resultGame, error] = await FSService.StartApp(gamePath) if (!resultGame) { - toast.error('Failed to start game') + toast.error('Failed to start game: ' + error) return } } setGameRunning(true) } catch (err: any) { + console.log(err) toast.error('StartGame error:', err) } finally { setIsLoading(false) diff --git a/internal/fs-service/fs.go b/internal/fs-service/fs.go index 1f96f5e..5cb54de 100644 --- a/internal/fs-service/fs.go +++ b/internal/fs-service/fs.go @@ -2,12 +2,12 @@ package fsService import ( "firefly-launcher/pkg/sevenzip" - "fmt" "os" "os/exec" "path/filepath" "runtime" "strings" + "github.com/wailsapp/wails/v3/pkg/application" "golang.org/x/sys/windows" ) @@ -75,13 +75,13 @@ func (f *FSService) RemoveFile(path string) error { return os.Remove(path) } - -func (f *FSService) StartApp(path string) (bool, error) { +func (f *FSService) StartApp(path string) (bool, string) { cmd := exec.Command(path) err := cmd.Start() if err != nil { - return false, err + return false, err.Error() } + if strings.HasSuffix(path, "StarRail.exe") { go func() { _ = cmd.Wait() @@ -89,17 +89,17 @@ func (f *FSService) StartApp(path string) (bool, error) { }() } - return true, nil + return true, "" } -func (f *FSService) StartWithConsole(path string) (bool, error) { +func (f *FSService) StartWithConsole(path string) (bool, string) { absPath, err := filepath.Abs(path) if err != nil { - return false, err + return false, err.Error() } if _, err := os.Stat(absPath); os.IsNotExist(err) { - return false, fmt.Errorf("file not found: %s", absPath) + return false, "file not found: " + absPath } cmd := exec.Command(absPath) cmd.Dir = filepath.Dir(absPath) @@ -116,7 +116,7 @@ func (f *FSService) StartWithConsole(path string) (bool, error) { err = cmd.Start() if err != nil { - return false, err + return false, err.Error() } go func() { @@ -129,7 +129,7 @@ func (f *FSService) StartWithConsole(path string) (bool, error) { application.Get().Event.Emit("proxy:exit") } }() - return true, nil + return true, "" } func (f *FSService) OpenFolder(path string) (bool, string) { @@ -155,4 +155,3 @@ func (f *FSService) FileExistsInZip(archivePath, fileInside string) (bool, strin } return exists, "" } - diff --git a/pkg/constant/constant.go b/pkg/constant/constant.go index 49d923d..5dd9ee9 100644 --- a/pkg/constant/constant.go +++ b/pkg/constant/constant.go @@ -10,7 +10,7 @@ const ProxyZipFile = "64bit.zip" const LauncherFile = "firefly-launcher.exe" const TempUrl = "./temp" -const CurrentLauncherVersion = "2.3.0" +const CurrentLauncherVersion = "2.3.1" type ToolFile string