Improve logging (#2)

Reviewed-on: #2
This commit is contained in:
2025-07-24 15:30:33 +00:00
parent 71f044e6e0
commit bc80ca2c9c
22 changed files with 411 additions and 307 deletions

View File

@@ -2,13 +2,13 @@ package launcher
import (
"bufio"
"epochsilicon/pkg/log"
"fmt"
"os"
"os/exec"
"path/filepath"
"sync"
"epochsilicon/pkg/debug"
"epochsilicon/pkg/paths" // Corrected import path
"epochsilicon/pkg/utils" // Corrected import path
@@ -16,10 +16,9 @@ import (
"fyne.io/fyne/v2/dialog"
)
var EnableMetalHud = false // Default to disabled
var CustomEnvVars = "" // Custom environment variables
var EnableVanillaTweaks = false // Default to disabled
var AutoDeleteWdb = false // Default to disabled
var EnableMetalHud = false // Default to disabled
var CustomEnvVars = "" // Custom environment variables
var AutoDeleteWdb = false // Default to disabled
// Terminal state management
var (
@@ -41,7 +40,7 @@ func runGameIntegrated(parentWindow fyne.Window, shellCmd string) error {
// Parse the shell command to extract components
// The shellCmd format is: cd <path> && <envVars> <rosettaExec> <wineloader> <wowExe>
debug.Printf("Parsing shell command: %s", shellCmd)
log.Debugf("Parsing shell command: %s", shellCmd)
// Create the command without context cancellation
cmd := exec.Command("sh", "-c", shellCmd)
@@ -71,7 +70,7 @@ func runGameIntegrated(parentWindow fyne.Window, shellCmd string) error {
scanner := bufio.NewScanner(stdout)
for scanner.Scan() {
line := scanner.Text()
debug.Printf("GAME STDOUT: %s", line)
log.WineLoggerStdout(line)
}
}()
@@ -79,7 +78,7 @@ func runGameIntegrated(parentWindow fyne.Window, shellCmd string) error {
scanner := bufio.NewScanner(stderr)
for scanner.Scan() {
line := scanner.Text()
debug.Printf("GAME STDERR: %s", line)
log.WineLoggerStderr(line)
}
}()
@@ -93,9 +92,9 @@ func runGameIntegrated(parentWindow fyne.Window, shellCmd string) error {
}()
if err := cmd.Wait(); err != nil {
debug.Printf("Game process ended with error: %v", err)
log.Debugf("Game process ended with error: %v", err)
} else {
debug.Println("Game process ended successfully")
log.Debug("Game process ended successfully")
}
}()
@@ -103,7 +102,7 @@ func runGameIntegrated(parentWindow fyne.Window, shellCmd string) error {
}
func LaunchGame(myWindow fyne.Window) {
debug.Println("Launch Game button clicked")
log.Debug("Launch Game button clicked")
if paths.CrossoverPath == "" {
dialog.ShowError(fmt.Errorf("CrossOver path not set. Please set it in the patcher."), myWindow)
@@ -132,7 +131,7 @@ func LaunchGame(myWindow fyne.Window) {
}
gameMutex.Unlock()
debug.Println("Preparing to launch EpochSilicon...")
log.Debug("Preparing to launch EpochSilicon...")
wowExePath := filepath.Join(paths.EpochPath, "Project-Epoch.exe")
@@ -163,20 +162,20 @@ func continueLaunch(myWindow fyne.Window, wowExePath string) {
if AutoDeleteWdb {
wdbPath := filepath.Join(paths.EpochPath, "WDB")
if utils.DirExists(wdbPath) {
debug.Printf("Auto-deleting WDB directory: %s", wdbPath)
log.Debugf("Auto-deleting WDB directory: %s", wdbPath)
if err := os.RemoveAll(wdbPath); err != nil {
debug.Printf("Warning: failed to auto-delete WDB directory: %v", err)
log.Debugf("Warning: failed to auto-delete WDB directory: %v", err)
// Don't block the launch, just log the error
} else {
debug.Printf("Successfully auto-deleted WDB directory")
log.Debugf("Successfully auto-deleted WDB directory")
}
} else {
debug.Printf("WDB directory not found, nothing to delete")
log.Debugf("WDB directory not found, nothing to delete")
}
}
// Since RosettaX87 service is already running, we can directly launch WoW
debug.Println("RosettaX87 service is running. Proceeding to launch WoW.")
log.Debug("RosettaX87 service is running. Proceeding to launch WoW.")
if paths.CrossoverPath == "" || paths.EpochPath == "" {
dialog.ShowError(fmt.Errorf("CrossOver path or Epoch path is not set. Cannot launch WoW."), myWindow)
@@ -201,29 +200,12 @@ func continueLaunch(myWindow fyne.Window, wowExePath string) {
utils.QuotePathForShell(wineloader2Path),
utils.QuotePathForShell(wowExePath))
// Check user preference for terminal display
prefs, _ := utils.LoadPrefs()
if prefs.ShowTerminalNormally {
// Use the old method with external Terminal.app
escapedShellCmd := utils.EscapeStringForAppleScript(shellCmd)
cmd2Script := fmt.Sprintf("tell application \"Terminal\" to do script \"%s\"", escapedShellCmd)
debug.Println("Executing WoW launch command via AppleScript...")
if !utils.RunOsascript(cmd2Script, myWindow) {
return
}
debug.Println("Launch command executed. Check the new terminal window.")
} else {
// Use integrated terminal
debug.Printf("Shell command for integrated terminal: %s", shellCmd)
debug.Println("Executing WoW launch command with integrated terminal...")
if err := runGameIntegrated(myWindow, shellCmd); err != nil {
dialog.ShowError(fmt.Errorf("failed to launch game: %v", err), myWindow)
return
}
debug.Println("Game launched with integrated terminal. Check the application logs for output.")
// Use integrated terminal
log.Debugf("Shell command for integrated terminal: %s", shellCmd)
log.Debug("Executing WoW launch command with integrated terminal...")
if err := runGameIntegrated(myWindow, shellCmd); err != nil {
dialog.ShowError(fmt.Errorf("failed to launch game: %v", err), myWindow)
return
}
}

View File

@@ -1,13 +1,13 @@
package launcher
import (
"epochsilicon/pkg/log"
"fmt"
"os"
"path/filepath"
"regexp"
"strings"
"epochsilicon/pkg/debug"
"epochsilicon/pkg/paths"
)
@@ -25,20 +25,20 @@ var RecommendedSettings = map[string]string{
// Returns true if all settings are correctly applied, false otherwise
func CheckRecommendedSettings() bool {
if paths.EpochPath == "" {
debug.Printf("Epoch path not set, cannot check Config.wtf")
log.Debugf("Epoch path not set, cannot check Config.wtf")
return false
}
configPath := filepath.Join(paths.EpochPath, "WTF", "Config.wtf")
if _, err := os.Stat(configPath); os.IsNotExist(err) {
debug.Printf("Config.wtf not found at %s", configPath)
log.Debugf("Config.wtf not found at %s", configPath)
return false
}
content, err := os.ReadFile(configPath)
if err != nil {
debug.Printf("Failed to read Config.wtf: %v", err)
log.Debugf("Failed to read Config.wtf: %v", err)
return false
}
@@ -47,12 +47,12 @@ func CheckRecommendedSettings() bool {
// Check each recommended setting
for setting, expectedValue := range RecommendedSettings {
if !isSettingCorrect(configText, setting, expectedValue) {
debug.Printf("Setting %s not found or incorrect in Config.wtf", setting)
log.Debugf("Setting %s not found or incorrect in Config.wtf", setting)
return false
}
}
debug.Printf("All recommended settings are correctly applied")
log.Debugf("All recommended settings are correctly applied")
return true
}
@@ -91,7 +91,7 @@ func ApplyRecommendedSettings() error {
if content, err := os.ReadFile(configPath); err == nil {
configText = string(content)
} else {
debug.Printf("Config.wtf not found, creating new file")
log.Debugf("Config.wtf not found, creating new file")
configText = ""
}
@@ -105,7 +105,7 @@ func ApplyRecommendedSettings() error {
return fmt.Errorf("failed to write Config.wtf: %v", err)
}
debug.Printf("Successfully applied recommended settings to Config.wtf")
log.Debugf("Successfully applied recommended settings to Config.wtf")
return nil
}
@@ -120,14 +120,14 @@ func updateOrAddSetting(configText, setting, value string) string {
if re.MatchString(configText) {
// Replace existing setting
configText = re.ReplaceAllString(configText, newSetting)
debug.Printf("Updated setting %s to %s", setting, value)
log.Debugf("Updated setting %s to %s", setting, value)
} else {
// Add new setting
if configText != "" && !strings.HasSuffix(configText, "\n") {
configText += "\n"
}
configText += newSetting + "\n"
debug.Printf("Added new setting %s with value %s", setting, value)
log.Debugf("Added new setting %s with value %s", setting, value)
}
return configText