feat: add comprehensive diagnostic logging subsystem and UI controls
This commit is contained in:
1 parent
517436321b
commit
5f45841936
15 files changed
+495
-23
No files matched your search
+100
-13
@@ -2,6 +2,7 @@ package fsService
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"g-launcher/pkg/logger"
|
||||
"g-launcher/pkg/sevenzip"
|
||||
"os"
|
||||
"os/exec"
|
||||
@@ -25,7 +26,13 @@ func (f *FSService) PickFolder() (string, error) {
|
||||
} else {
|
||||
dialog.SetTitle("Select a folder")
|
||||
}
|
||||
return dialog.PromptForSingleSelection()
|
||||
res, err := dialog.PromptForSingleSelection()
|
||||
if err != nil {
|
||||
logger.Error("PickFolder error: %v", err)
|
||||
} else {
|
||||
logger.Info("PickFolder selected: %s", res)
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (f *FSService) PickFile(filter string) (string, error) {
|
||||
@@ -45,6 +52,7 @@ func (f *FSService) PickFile(filter string) (string, error) {
|
||||
dialog.AddFilter("Patch files (*.zip;*.7z;*.ziff)", "*.zip;*.7z;*.ziff")
|
||||
}
|
||||
if path, err := dialog.PromptForSingleSelection(); err == nil {
|
||||
logger.Info("PickFile (%s) selected: %s", filter, path)
|
||||
return path, nil
|
||||
}
|
||||
return "", nil
|
||||
@@ -74,40 +82,72 @@ func (f *FSService) Join(paths ...string) string {
|
||||
}
|
||||
|
||||
func (f *FSService) RemoveFile(path string) error {
|
||||
logger.Info("RemoveFile: %s", path)
|
||||
return os.Remove(path)
|
||||
}
|
||||
|
||||
func (f *FSService) StartApp(path string) (bool, string) {
|
||||
dir := filepath.Dir(path)
|
||||
cmd := exec.Command(path)
|
||||
cmd.Dir = dir
|
||||
|
||||
err := cmd.Start()
|
||||
absPath, err := filepath.Abs(path)
|
||||
if err != nil {
|
||||
logger.Error("StartApp: failed to resolve absolute path for %s: %v", path, err)
|
||||
return false, err.Error()
|
||||
}
|
||||
|
||||
if strings.HasSuffix(path, "StarRail.exe") || strings.HasSuffix(path, "ZenlessZoneZeroBeta.exe") {
|
||||
go func() {
|
||||
_ = cmd.Wait()
|
||||
application.Get().Event.Emit("game:exit")
|
||||
}()
|
||||
if _, err := os.Stat(absPath); os.IsNotExist(err) {
|
||||
logger.Error("StartApp: executable file not found: %s", absPath)
|
||||
return false, "file not found: " + absPath
|
||||
}
|
||||
|
||||
dir := filepath.Dir(absPath)
|
||||
cmd := exec.Command(absPath)
|
||||
cmd.Dir = dir
|
||||
cmd.SysProcAttr = &windows.SysProcAttr{
|
||||
CreationFlags: windows.CREATE_NEW_CONSOLE | windows.CREATE_BREAKAWAY_FROM_JOB,
|
||||
NoInheritHandles: true,
|
||||
}
|
||||
|
||||
logger.Info("StartApp: launching process %s in directory %s", absPath, dir)
|
||||
err = cmd.Start()
|
||||
if err != nil {
|
||||
logger.Error("StartApp: failed to start process %s: %v", absPath, err)
|
||||
return false, err.Error()
|
||||
}
|
||||
|
||||
pid := cmd.Process.Pid
|
||||
logger.Info("StartApp: process started successfully, PID: %d", pid)
|
||||
|
||||
go func() {
|
||||
waitErr := cmd.Wait()
|
||||
base := strings.ToLower(filepath.Base(path))
|
||||
if waitErr != nil {
|
||||
logger.Warn("StartApp: process PID %d (%s) exited with error: %v", pid, base, waitErr)
|
||||
} else {
|
||||
logger.Info("StartApp: process PID %d (%s) exited cleanly", pid, base)
|
||||
}
|
||||
|
||||
if strings.HasSuffix(base, "starrail.exe") || strings.HasSuffix(base, "zenlesszonezerobeta.exe") || strings.HasSuffix(base, "launcher.exe") {
|
||||
application.Get().Event.Emit("game:exit")
|
||||
}
|
||||
}()
|
||||
|
||||
return true, ""
|
||||
}
|
||||
|
||||
func (f *FSService) StartWithConsole(path string) (bool, string) {
|
||||
absPath, err := filepath.Abs(path)
|
||||
if err != nil {
|
||||
logger.Error("StartWithConsole: failed to resolve absolute path for %s: %v", path, err)
|
||||
return false, err.Error()
|
||||
}
|
||||
|
||||
if _, err := os.Stat(absPath); os.IsNotExist(err) {
|
||||
logger.Error("StartWithConsole: file not found: %s", absPath)
|
||||
return false, "file not found: " + absPath
|
||||
}
|
||||
|
||||
dir := filepath.Dir(absPath)
|
||||
cmd := exec.Command(absPath)
|
||||
cmd.Dir = filepath.Dir(absPath)
|
||||
cmd.Dir = dir
|
||||
cmd.Stdin = nil
|
||||
cmd.Stdout = nil
|
||||
cmd.Stderr = nil
|
||||
@@ -118,14 +158,25 @@ func (f *FSService) StartWithConsole(path string) (bool, string) {
|
||||
NoInheritHandles: true,
|
||||
}
|
||||
|
||||
logger.Info("StartWithConsole: starting process %s (WorkingDir: %s)", absPath, dir)
|
||||
err = cmd.Start()
|
||||
if err != nil {
|
||||
logger.Error("StartWithConsole: failed to start %s: %v", absPath, err)
|
||||
return false, err.Error()
|
||||
}
|
||||
|
||||
pid := cmd.Process.Pid
|
||||
logger.Info("StartWithConsole: process started successfully, PID: %d", pid)
|
||||
|
||||
go func() {
|
||||
_ = cmd.Wait()
|
||||
waitErr := cmd.Wait()
|
||||
base := strings.ToLower(filepath.Base(path))
|
||||
if waitErr != nil {
|
||||
logger.Warn("StartWithConsole: process PID %d (%s) exited with error: %v", pid, base, waitErr)
|
||||
} else {
|
||||
logger.Info("StartWithConsole: process PID %d (%s) exited cleanly", pid, base)
|
||||
}
|
||||
|
||||
if base == "launcher.exe" || base == "starrail.exe" {
|
||||
application.Get().Event.Emit("game:exit")
|
||||
} else if base == "firefly-go_win.exe" || base == "gameserver.exe" || base == "gameserver-go.exe" || base == "server.exe" || base == "sdkserver-go.exe" || base == "sdkserver.exe" {
|
||||
@@ -140,14 +191,17 @@ func (f *FSService) StartWithConsole(path string) (bool, string) {
|
||||
func (f *FSService) OpenFolder(path string) (bool, string) {
|
||||
absPath, err := filepath.Abs(path)
|
||||
if err != nil {
|
||||
logger.Error("OpenFolder: resolve path failed for %s: %v", path, err)
|
||||
return false, "failed to resolve absolute path: " + err.Error()
|
||||
}
|
||||
|
||||
if !f.DirExists(absPath) {
|
||||
logger.Warn("OpenFolder: directory not found: %s", absPath)
|
||||
return false, "directory not found: " + absPath
|
||||
}
|
||||
|
||||
url := "file:///" + filepath.ToSlash(absPath)
|
||||
logger.Info("OpenFolder: opening %s", url)
|
||||
application.Get().Browser.OpenURL(url)
|
||||
|
||||
return true, ""
|
||||
@@ -156,6 +210,7 @@ func (f *FSService) OpenFolder(path string) (bool, string) {
|
||||
func (f *FSService) FileExistsInZip(archivePath, fileInside string) (bool, string) {
|
||||
exists, err := sevenzip.IsFileIn7z(archivePath, fileInside)
|
||||
if err != nil {
|
||||
logger.Error("FileExistsInZip error: %v", err)
|
||||
return false, err.Error()
|
||||
}
|
||||
return exists, ""
|
||||
@@ -181,5 +236,37 @@ func (f *FSService) WriteConfigFile(gameDir, fileName, content string) error {
|
||||
return fmt.Errorf("select the game folder first")
|
||||
}
|
||||
target := filepath.Join(gameDir, fileName)
|
||||
logger.Info("WriteConfigFile: saving %s", target)
|
||||
return os.WriteFile(target, []byte(content), 0644)
|
||||
}
|
||||
|
||||
// LogMessage receives log entries from the frontend and appends them to launcher.log
|
||||
func (f *FSService) LogMessage(level string, message string) {
|
||||
logger.GetInstance().Log(level, "[UI] "+message)
|
||||
}
|
||||
|
||||
// GetLogFilePath returns the absolute path of launcher.log
|
||||
func (f *FSService) GetLogFilePath() (string, error) {
|
||||
p := logger.GetLogPath()
|
||||
if p == "" {
|
||||
return "", fmt.Errorf("log path not initialized")
|
||||
}
|
||||
return p, nil
|
||||
}
|
||||
|
||||
// OpenLogsFolder opens the folder containing launcher.log in Windows File Explorer
|
||||
func (f *FSService) OpenLogsFolder() (bool, string) {
|
||||
dir := logger.GetLogDir()
|
||||
if dir == "" {
|
||||
return false, "log directory not found"
|
||||
}
|
||||
return f.OpenFolder(dir)
|
||||
}
|
||||
|
||||
// ReadLogs returns the last maxLines of the log file
|
||||
func (f *FSService) ReadLogs(maxLines int) (string, error) {
|
||||
if maxLines <= 0 {
|
||||
maxLines = 200
|
||||
}
|
||||
return logger.ReadRecentLogs(maxLines)
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"g-launcher/pkg/logger"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
@@ -43,10 +44,12 @@ func (f *FSService) GetSavedGameSelection() (string, string, error) {
|
||||
return "", "", fmt.Errorf("parse saved game selection: %w", err)
|
||||
}
|
||||
|
||||
logger.Info("GetSavedGameSelection: loaded GamePath=%s, GameDir=%s", selection.GamePath, selection.GameDir)
|
||||
return selection.GamePath, selection.GameDir, nil
|
||||
}
|
||||
|
||||
func (f *FSService) SaveGameSelection(gamePath, gameDir string) error {
|
||||
logger.Info("SaveGameSelection: saving GamePath=%s, GameDir=%s", gamePath, gameDir)
|
||||
path, err := gameSelectionPath()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"g-launcher/pkg/constant"
|
||||
"g-launcher/pkg/logger"
|
||||
"g-launcher/pkg/models"
|
||||
"io"
|
||||
"net/http"
|
||||
@@ -203,5 +204,6 @@ func (g *GitService) FindServerExecutables() (string, string) {
|
||||
}
|
||||
}
|
||||
|
||||
logger.Info("FindServerExecutables: serverDir=%s, found gameServer=%s, sdkServer=%s", serverDir, gameServer, sdkServer)
|
||||
return gameServer, sdkServer
|
||||
}
|
||||
Reference in new issue
Block a user