refactored project, added makefile

This commit is contained in:
aomizu
2025-05-18 21:46:58 +09:00
parent c9bb2786f7
commit 1f9e3891ac
9 changed files with 806 additions and 725 deletions

106
pkg/launcher/launcher.go Normal file
View File

@@ -0,0 +1,106 @@
package launcher
import (
"fmt"
"log"
"path/filepath"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/dialog"
"turtlesilicon/pkg/paths" // Corrected import path
"turtlesilicon/pkg/utils" // Corrected import path
)
var EnableMetalHud = true // Default to enabled
func LaunchGame(myWindow fyne.Window) {
log.Println("Launch Game button clicked")
if paths.CrossoverPath == "" {
dialog.ShowError(fmt.Errorf("CrossOver path not set. Please set it in the patcher."), myWindow)
return
}
if paths.TurtlewowPath == "" {
dialog.ShowError(fmt.Errorf("TurtleWoW path not set. Please set it in the patcher."), myWindow)
return
}
if !paths.PatchesAppliedTurtleWoW || !paths.PatchesAppliedCrossOver {
confirmed := false
dialog.ShowConfirm("Warning", "Not all patches confirmed applied. Continue with launch?", func(c bool) {
confirmed = c
}, myWindow)
if !confirmed {
return
}
}
log.Println("Preparing to launch TurtleSilicon...")
rosettaInTurtlePath := filepath.Join(paths.TurtlewowPath, "rosettax87")
rosettaExecutable := filepath.Join(rosettaInTurtlePath, "rosettax87")
wineloader2Path := filepath.Join(paths.CrossoverPath, "Contents", "SharedSupport", "CrossOver", "CrossOver-Hosted Application", "wineloader2")
wowExePath := filepath.Join(paths.TurtlewowPath, "wow.exe") // Corrected to wow.exe
if !utils.PathExists(rosettaExecutable) {
dialog.ShowError(fmt.Errorf("rosetta executable not found at %s. Ensure TurtleWoW patching was successful", rosettaExecutable), myWindow)
return
}
if !utils.PathExists(wineloader2Path) {
dialog.ShowError(fmt.Errorf("patched wineloader2 not found at %s. Ensure CrossOver patching was successful", wineloader2Path), myWindow)
return
}
if !utils.PathExists(wowExePath) {
dialog.ShowError(fmt.Errorf("wow.exe not found at %s. Ensure your TurtleWoW directory is correct", wowExePath), myWindow)
return
}
appleScriptSafeRosettaDir := utils.EscapeStringForAppleScript(rosettaInTurtlePath)
cmd1Script := fmt.Sprintf("tell application \"Terminal\" to do script \"cd \" & quoted form of \"%s\" & \" && sudo ./rosettax87\"", appleScriptSafeRosettaDir)
log.Println("Launching rosettax87 (requires sudo password in new terminal)...")
if !utils.RunOsascript(cmd1Script, myWindow) {
return
}
dialog.ShowConfirm("Action Required",
"The rosetta x87 terminal has been initiated.\n\n"+
"1. Please enter your sudo password in that new terminal window.\n"+
"2. Wait for rosetta x87 to fully start.\n\n"+
"Click Yes once rosetta x87 is running and you have entered the password.\n"+
"Click No to abort launching WoW.",
func(confirmed bool) {
if confirmed {
log.Println("User confirmed rosetta x87 is running. Proceeding to launch WoW.")
if paths.CrossoverPath == "" || paths.TurtlewowPath == "" {
dialog.ShowError(fmt.Errorf("CrossOver path or TurtleWoW path is not set. Cannot launch WoW."), myWindow)
return
}
mtlHudValue := "0"
if EnableMetalHud {
mtlHudValue = "1"
}
shellCmd := fmt.Sprintf(`cd %s && WINEDLLOVERRIDES="d3d9=n,b" MTL_HUD_ENABLED=%s %s %s %s`,
utils.QuotePathForShell(paths.TurtlewowPath),
mtlHudValue,
utils.QuotePathForShell(rosettaExecutable),
utils.QuotePathForShell(wineloader2Path),
utils.QuotePathForShell(wowExePath))
escapedShellCmd := utils.EscapeStringForAppleScript(shellCmd)
cmd2Script := fmt.Sprintf("tell application \"Terminal\" to do script \"%s\"", escapedShellCmd)
log.Println("Executing updated WoW launch command via AppleScript...")
if !utils.RunOsascript(cmd2Script, myWindow) {
return
}
log.Println("Launch commands executed. Check the new terminal windows.")
dialog.ShowInformation("Launched", "World of Warcraft is starting. Enjoy.", myWindow)
} else {
log.Println("User cancelled WoW launch after rosetta x87 initiation.")
dialog.ShowInformation("Cancelled", "WoW launch was cancelled.", myWindow)
}
}, myWindow)
}

259
pkg/patching/patching.go Normal file
View File

@@ -0,0 +1,259 @@
package patching
import (
"bytes"
"fmt"
"io"
"log"
"os"
"os/exec"
"path/filepath"
"strings"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/dialog"
"turtlesilicon/pkg/paths" // Corrected import path
"turtlesilicon/pkg/utils" // Corrected import path
)
func PatchTurtleWoW(myWindow fyne.Window, updateAllStatuses func()) {
log.Println("Patch TurtleWoW clicked")
if paths.TurtlewowPath == "" {
dialog.ShowError(fmt.Errorf("TurtleWoW path not set. Please set it first."), myWindow)
return
}
targetWinerosettaDll := filepath.Join(paths.TurtlewowPath, "winerosetta.dll")
targetD3d9Dll := filepath.Join(paths.TurtlewowPath, "d3d9.dll")
targetRosettaX87Dir := filepath.Join(paths.TurtlewowPath, "rosettax87")
dllsTextFile := filepath.Join(paths.TurtlewowPath, "dlls.txt")
filesToCopy := map[string]string{
"winerosetta/winerosetta.dll": targetWinerosettaDll,
"winerosetta/d3d9.dll": targetD3d9Dll,
}
for resourceName, destPath := range filesToCopy {
log.Printf("Processing resource: %s to %s", resourceName, destPath)
resource, err := fyne.LoadResourceFromPath(resourceName)
if err != nil {
errMsg := fmt.Sprintf("failed to open bundled resource %s: %v", resourceName, err)
dialog.ShowError(fmt.Errorf(errMsg), myWindow)
log.Println(errMsg)
paths.PatchesAppliedTurtleWoW = false
updateAllStatuses()
return
}
destinationFile, err := os.Create(destPath)
if err != nil {
errMsg := fmt.Sprintf("failed to create destination file %s: %v", destPath, err)
dialog.ShowError(fmt.Errorf(errMsg), myWindow)
log.Println(errMsg)
paths.PatchesAppliedTurtleWoW = false
updateAllStatuses()
return
}
defer destinationFile.Close()
_, err = io.Copy(destinationFile, bytes.NewReader(resource.Content()))
if err != nil {
errMsg := fmt.Sprintf("failed to copy bundled resource %s to %s: %v", resourceName, destPath, err)
dialog.ShowError(fmt.Errorf(errMsg), myWindow)
log.Println(errMsg)
paths.PatchesAppliedTurtleWoW = false
updateAllStatuses()
return
}
log.Printf("Successfully copied %s to %s", resourceName, destPath)
}
log.Printf("Preparing rosettax87 directory at: %s", targetRosettaX87Dir)
if err := os.RemoveAll(targetRosettaX87Dir); err != nil {
log.Printf("Warning: could not remove existing rosettax87 folder '%s': %v", targetRosettaX87Dir, err)
}
if err := os.MkdirAll(targetRosettaX87Dir, 0755); err != nil {
errMsg := fmt.Sprintf("failed to create directory %s: %v", targetRosettaX87Dir, err)
dialog.ShowError(fmt.Errorf(errMsg), myWindow)
log.Println(errMsg)
paths.PatchesAppliedTurtleWoW = false
updateAllStatuses()
return
}
rosettaFilesToCopy := map[string]string{
"rosettax87/rosettax87": filepath.Join(targetRosettaX87Dir, "rosettax87"),
"rosettax87/libRuntimeRosettax87": filepath.Join(targetRosettaX87Dir, "libRuntimeRosettax87"),
}
for resourceName, destPath := range rosettaFilesToCopy {
log.Printf("Processing rosetta resource: %s to %s", resourceName, destPath)
resource, err := fyne.LoadResourceFromPath(resourceName)
if err != nil {
errMsg := fmt.Sprintf("failed to open bundled resource %s: %v", resourceName, err)
dialog.ShowError(fmt.Errorf(errMsg), myWindow)
log.Println(errMsg)
paths.PatchesAppliedTurtleWoW = false
updateAllStatuses()
return
}
destinationFile, err := os.Create(destPath)
if err != nil {
errMsg := fmt.Sprintf("failed to create destination file %s: %v", destPath, err)
dialog.ShowError(fmt.Errorf(errMsg), myWindow)
log.Println(errMsg)
paths.PatchesAppliedTurtleWoW = false
updateAllStatuses()
return
}
_, err = io.Copy(destinationFile, bytes.NewReader(resource.Content()))
if err != nil {
destinationFile.Close()
errMsg := fmt.Sprintf("failed to copy bundled resource %s to %s: %v", resourceName, destPath, err)
dialog.ShowError(fmt.Errorf(errMsg), myWindow)
log.Println(errMsg)
paths.PatchesAppliedTurtleWoW = false
updateAllStatuses()
return
}
destinationFile.Close()
if filepath.Base(destPath) == "rosettax87" {
log.Printf("Setting execute permission for %s", destPath)
if err := os.Chmod(destPath, 0755); err != nil {
errMsg := fmt.Sprintf("failed to set execute permission for %s: %v", destPath, err)
dialog.ShowError(fmt.Errorf(errMsg), myWindow)
log.Println(errMsg)
paths.PatchesAppliedTurtleWoW = false
updateAllStatuses()
return
}
}
log.Printf("Successfully copied %s to %s", resourceName, destPath)
}
log.Printf("Checking dlls.txt file at: %s", dllsTextFile)
winerosettaEntry := "winerosetta.dll"
libSiliconPatchEntry := "libSiliconPatch.dll"
needsWinerosettaUpdate := true
needsLibSiliconPatchUpdate := true
if fileContentBytes, err := os.ReadFile(dllsTextFile); err == nil {
fileContent := string(fileContentBytes)
if strings.Contains(fileContent, winerosettaEntry) {
log.Printf("dlls.txt already contains %s", winerosettaEntry)
needsWinerosettaUpdate = false
}
if strings.Contains(fileContent, libSiliconPatchEntry) {
log.Printf("dlls.txt already contains %s", libSiliconPatchEntry)
needsLibSiliconPatchUpdate = false
}
} else {
log.Printf("dlls.txt not found, will create a new one with both entries")
}
if needsWinerosettaUpdate || needsLibSiliconPatchUpdate {
var fileContentBytes []byte
var err error
if utils.PathExists(dllsTextFile) {
fileContentBytes, err = os.ReadFile(dllsTextFile)
if err != nil {
errMsg := fmt.Sprintf("failed to read dlls.txt for update: %v", err)
dialog.ShowError(fmt.Errorf(errMsg), myWindow)
log.Println(errMsg)
}
}
currentContent := string(fileContentBytes)
updatedContent := currentContent
if len(updatedContent) > 0 && !strings.HasSuffix(updatedContent, "\n") {
updatedContent += "\n"
}
if needsWinerosettaUpdate {
if !strings.Contains(updatedContent, winerosettaEntry+"\n") {
updatedContent += winerosettaEntry + "\n"
log.Printf("Adding %s to dlls.txt", winerosettaEntry)
}
}
if needsLibSiliconPatchUpdate {
if !strings.Contains(updatedContent, libSiliconPatchEntry+"\n") {
updatedContent += libSiliconPatchEntry + "\n"
log.Printf("Adding %s to dlls.txt", libSiliconPatchEntry)
}
}
if err := os.WriteFile(dllsTextFile, []byte(updatedContent), 0644); err != nil {
errMsg := fmt.Sprintf("failed to update dlls.txt: %v", err)
dialog.ShowError(fmt.Errorf(errMsg), myWindow)
log.Println(errMsg)
} else {
log.Printf("Successfully updated dlls.txt")
}
}
log.Println("TurtleWoW patching with bundled resources completed successfully.")
dialog.ShowInformation("Success", "TurtleWoW patching process completed using bundled resources.", myWindow)
updateAllStatuses()
}
func PatchCrossOver(myWindow fyne.Window, updateAllStatuses func()) {
log.Println("Patch CrossOver clicked")
if paths.CrossoverPath == "" {
dialog.ShowError(fmt.Errorf("CrossOver path not set. Please set it first."), myWindow)
return
}
wineloaderBasePath := filepath.Join(paths.CrossoverPath, "Contents", "SharedSupport", "CrossOver", "CrossOver-Hosted Application")
wineloaderOrig := filepath.Join(wineloaderBasePath, "wineloader")
wineloaderCopy := filepath.Join(wineloaderBasePath, "wineloader2")
if !utils.PathExists(wineloaderOrig) {
dialog.ShowError(fmt.Errorf("original wineloader not found at %s", wineloaderOrig), myWindow)
paths.PatchesAppliedCrossOver = false
updateAllStatuses()
return
}
log.Printf("Copying %s to %s", wineloaderOrig, wineloaderCopy)
if err := utils.CopyFile(wineloaderOrig, wineloaderCopy); err != nil {
dialog.ShowError(fmt.Errorf("failed to copy wineloader: %w", err), myWindow)
paths.PatchesAppliedCrossOver = false
updateAllStatuses()
return
}
log.Printf("Executing: codesign --remove-signature %s", wineloaderCopy)
cmd := exec.Command("codesign", "--remove-signature", wineloaderCopy)
combinedOutput, err := cmd.CombinedOutput()
if err != nil {
derrMsg := fmt.Sprintf("failed to remove signature from %s: %v\nOutput: %s", wineloaderCopy, err, string(combinedOutput))
dialog.ShowError(fmt.Errorf(derrMsg), myWindow)
log.Println(derrMsg)
paths.PatchesAppliedCrossOver = false
if err := os.Remove(wineloaderCopy); err != nil {
log.Printf("Warning: failed to cleanup wineloader2 after codesign failure: %v", err)
}
updateAllStatuses()
return
}
log.Printf("codesign output: %s", string(combinedOutput))
log.Printf("Setting execute permissions for %s", wineloaderCopy)
if err := os.Chmod(wineloaderCopy, 0755); err != nil {
errMsg := fmt.Sprintf("failed to set executable permissions for %s: %v", wineloaderCopy, err)
dialog.ShowError(fmt.Errorf(errMsg), myWindow)
log.Println(errMsg)
paths.PatchesAppliedCrossOver = false
updateAllStatuses()
return
}
log.Println("CrossOver patching completed successfully.")
paths.PatchesAppliedCrossOver = true
dialog.ShowInformation("Success", "CrossOver patching process completed.", myWindow)
updateAllStatuses()
}

94
pkg/paths/paths.go Normal file
View File

@@ -0,0 +1,94 @@
package paths
import (
"fmt"
"log"
"os"
"path/filepath"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
"turtlesilicon/pkg/utils"
)
const DefaultCrossOverPath = "/Applications/CrossOver.app"
var (
CrossoverPath string
TurtlewowPath string
PatchesAppliedTurtleWoW = false
PatchesAppliedCrossOver = false
)
func SelectCrossOverPath(myWindow fyne.Window, crossoverPathLabel *widget.RichText, updateAllStatuses func()) {
dialog.ShowFolderOpen(func(uri fyne.ListableURI, err error) {
if err != nil {
dialog.ShowError(err, myWindow)
return
}
if uri == nil {
log.Println("CrossOver path selection cancelled.")
updateAllStatuses()
return
}
selectedPath := uri.Path()
if filepath.Ext(selectedPath) == ".app" && utils.DirExists(selectedPath) {
CrossoverPath = selectedPath
PatchesAppliedCrossOver = false
log.Println("CrossOver path set to:", CrossoverPath)
} else {
dialog.ShowError(fmt.Errorf("invalid selection: '%s'. Please select a valid .app bundle", selectedPath), myWindow)
log.Println("Invalid CrossOver path selected:", selectedPath)
}
updateAllStatuses()
}, myWindow)
}
func SelectTurtleWoWPath(myWindow fyne.Window, turtlewowPathLabel *widget.RichText, updateAllStatuses func()) {
dialog.ShowFolderOpen(func(uri fyne.ListableURI, err error) {
if err != nil {
dialog.ShowError(err, myWindow)
return
}
if uri == nil {
log.Println("TurtleWoW path selection cancelled.")
updateAllStatuses()
return
}
selectedPath := uri.Path()
if utils.DirExists(selectedPath) {
TurtlewowPath = selectedPath
PatchesAppliedTurtleWoW = false
log.Println("TurtleWoW path set to:", TurtlewowPath)
} else {
dialog.ShowError(fmt.Errorf("invalid selection: '%s' is not a valid directory", selectedPath), myWindow)
log.Println("Invalid TurtleWoW path selected:", selectedPath)
}
updateAllStatuses()
}, myWindow)
}
func UpdatePathLabels(crossoverPathLabel, turtlewowPathLabel *widget.RichText) {
if CrossoverPath == "" {
crossoverPathLabel.Segments = []widget.RichTextSegment{&widget.TextSegment{Text: "Not set", Style: widget.RichTextStyle{ColorName: theme.ColorNameError}}}
} else {
crossoverPathLabel.Segments = []widget.RichTextSegment{&widget.TextSegment{Text: CrossoverPath, Style: widget.RichTextStyle{ColorName: theme.ColorNameSuccess}}}
}
crossoverPathLabel.Refresh()
if TurtlewowPath == "" {
turtlewowPathLabel.Segments = []widget.RichTextSegment{&widget.TextSegment{Text: "Not set", Style: widget.RichTextStyle{ColorName: theme.ColorNameError}}}
} else {
turtlewowPathLabel.Segments = []widget.RichTextSegment{&widget.TextSegment{Text: TurtlewowPath, Style: widget.RichTextStyle{ColorName: theme.ColorNameSuccess}}}
}
turtlewowPathLabel.Refresh()
}
func CheckDefaultCrossOverPath() {
if info, err := os.Stat(DefaultCrossOverPath); err == nil && info.IsDir() {
CrossoverPath = DefaultCrossOverPath
log.Println("Pre-set CrossOver to default:", DefaultCrossOverPath)
}
}

173
pkg/ui/ui.go Normal file
View File

@@ -0,0 +1,173 @@
package ui
import (
"log"
"os" // Added import for os.ReadFile
"path/filepath"
"strings"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
"turtlesilicon/pkg/launcher" // Corrected import path
"turtlesilicon/pkg/patching" // Corrected import path
"turtlesilicon/pkg/paths" // Corrected import path
"turtlesilicon/pkg/utils" // Corrected import path
)
var (
crossoverPathLabel *widget.RichText
turtlewowPathLabel *widget.RichText
turtlewowStatusLabel *widget.RichText
crossoverStatusLabel *widget.RichText
launchButton *widget.Button
patchTurtleWoWButton *widget.Button
patchCrossOverButton *widget.Button
metalHudCheckbox *widget.Check
)
func UpdateAllStatuses() {
// Update Crossover Path and Status
if paths.CrossoverPath == "" {
crossoverPathLabel.Segments = []widget.RichTextSegment{&widget.TextSegment{Text: "Not set", Style: widget.RichTextStyle{ColorName: theme.ColorNameError}}}
paths.PatchesAppliedCrossOver = false // Reset if path is cleared
} else {
crossoverPathLabel.Segments = []widget.RichTextSegment{&widget.TextSegment{Text: paths.CrossoverPath, Style: widget.RichTextStyle{ColorName: theme.ColorNameSuccess}}}
wineloader2Path := filepath.Join(paths.CrossoverPath, "Contents", "SharedSupport", "CrossOver", "CrossOver-Hosted Application", "wineloader2")
if utils.PathExists(wineloader2Path) {
paths.PatchesAppliedCrossOver = true
} else {
// paths.PatchesAppliedCrossOver = false // Only set to false if not already true from a patch action this session
}
}
crossoverPathLabel.Refresh()
if paths.PatchesAppliedCrossOver {
crossoverStatusLabel.Segments = []widget.RichTextSegment{&widget.TextSegment{Text: "Patched", Style: widget.RichTextStyle{ColorName: theme.ColorNameSuccess}}}
if patchCrossOverButton != nil {
patchCrossOverButton.Disable()
}
} else {
crossoverStatusLabel.Segments = []widget.RichTextSegment{&widget.TextSegment{Text: "Not patched", Style: widget.RichTextStyle{ColorName: theme.ColorNameError}}}
if patchCrossOverButton != nil {
if paths.CrossoverPath != "" {
patchCrossOverButton.Enable()
} else {
patchCrossOverButton.Disable()
}
}
}
crossoverStatusLabel.Refresh()
// Update TurtleWoW Path and Status
if paths.TurtlewowPath == "" {
turtlewowPathLabel.Segments = []widget.RichTextSegment{&widget.TextSegment{Text: "Not set", Style: widget.RichTextStyle{ColorName: theme.ColorNameError}}}
paths.PatchesAppliedTurtleWoW = false // Reset if path is cleared
} else {
turtlewowPathLabel.Segments = []widget.RichTextSegment{&widget.TextSegment{Text: paths.TurtlewowPath, Style: widget.RichTextStyle{ColorName: theme.ColorNameSuccess}}}
winerosettaDllPath := filepath.Join(paths.TurtlewowPath, "winerosetta.dll")
d3d9DllPath := filepath.Join(paths.TurtlewowPath, "d3d9.dll")
rosettaX87DirPath := filepath.Join(paths.TurtlewowPath, "rosettax87")
dllsTextFile := filepath.Join(paths.TurtlewowPath, "dlls.txt")
rosettaX87ExePath := filepath.Join(rosettaX87DirPath, "rosettax87")
libRuntimeRosettaX87Path := filepath.Join(rosettaX87DirPath, "libRuntimeRosettax87")
dllsFileValid := false
if utils.PathExists(dllsTextFile) {
if fileContent, err := os.ReadFile(dllsTextFile); err == nil {
if strings.Contains(string(fileContent), "winerosetta.dll") {
dllsFileValid = true
}
}
}
if utils.PathExists(winerosettaDllPath) && utils.PathExists(d3d9DllPath) && utils.DirExists(rosettaX87DirPath) &&
utils.PathExists(rosettaX87ExePath) && utils.PathExists(libRuntimeRosettaX87Path) && dllsFileValid {
paths.PatchesAppliedTurtleWoW = true
} else {
// paths.PatchesAppliedTurtleWoW = false
}
}
turtlewowPathLabel.Refresh()
if paths.PatchesAppliedTurtleWoW {
turtlewowStatusLabel.Segments = []widget.RichTextSegment{&widget.TextSegment{Text: "Patched", Style: widget.RichTextStyle{ColorName: theme.ColorNameSuccess}}}
if patchTurtleWoWButton != nil {
patchTurtleWoWButton.Disable()
}
} else {
turtlewowStatusLabel.Segments = []widget.RichTextSegment{&widget.TextSegment{Text: "Not patched", Style: widget.RichTextStyle{ColorName: theme.ColorNameError}}}
if patchTurtleWoWButton != nil {
if paths.TurtlewowPath != "" {
patchTurtleWoWButton.Enable()
} else {
patchTurtleWoWButton.Disable()
}
}
}
turtlewowStatusLabel.Refresh()
// Update Launch Button State
if launchButton != nil {
if paths.PatchesAppliedTurtleWoW && paths.PatchesAppliedCrossOver && paths.TurtlewowPath != "" && paths.CrossoverPath != "" {
launchButton.Enable()
} else {
launchButton.Disable()
}
}
}
func CreateUI(myWindow fyne.Window) fyne.CanvasObject {
crossoverPathLabel = widget.NewRichText()
turtlewowPathLabel = widget.NewRichText()
turtlewowStatusLabel = widget.NewRichText()
crossoverStatusLabel = widget.NewRichText()
metalHudCheckbox = widget.NewCheck("Enable Metal Hud (show FPS)", func(checked bool) {
launcher.EnableMetalHud = checked
log.Printf("Metal HUD enabled: %v", launcher.EnableMetalHud)
})
metalHudCheckbox.SetChecked(launcher.EnableMetalHud)
patchTurtleWoWButton = widget.NewButton("Patch TurtleWoW", func() {
patching.PatchTurtleWoW(myWindow, UpdateAllStatuses)
})
patchCrossOverButton = widget.NewButton("Patch CrossOver", func() {
patching.PatchCrossOver(myWindow, UpdateAllStatuses)
})
launchButton = widget.NewButton("Launch Game", func() {
launcher.LaunchGame(myWindow)
})
paths.CheckDefaultCrossOverPath()
pathSelectionForm := widget.NewForm(
widget.NewFormItem("CrossOver Path:", container.NewBorder(nil, nil, nil, widget.NewButton("Set/Change", func() {
paths.SelectCrossOverPath(myWindow, crossoverPathLabel, UpdateAllStatuses)
}), crossoverPathLabel)),
widget.NewFormItem("TurtleWoW Path:", container.NewBorder(nil, nil, nil, widget.NewButton("Set/Change", func() {
paths.SelectTurtleWoWPath(myWindow, turtlewowPathLabel, UpdateAllStatuses)
}), turtlewowPathLabel)),
)
patchOperationsLayout := container.NewVBox(
widget.NewSeparator(),
container.NewGridWithColumns(3,
widget.NewLabel("TurtleWoW Patch:"), turtlewowStatusLabel, patchTurtleWoWButton,
),
container.NewGridWithColumns(3,
widget.NewLabel("CrossOver Patch:"), crossoverStatusLabel, patchCrossOverButton,
),
widget.NewSeparator(),
)
UpdateAllStatuses() // Initial UI state update
return container.NewVBox(
pathSelectionForm,
patchOperationsLayout,
metalHudCheckbox,
container.NewPadded(launchButton),
)
}

119
pkg/utils/utils.go Normal file
View File

@@ -0,0 +1,119 @@
package utils
import (
"fmt"
"io"
"log"
"os"
"os/exec"
"path/filepath"
"strings"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/dialog"
)
// PathExists checks if a path exists.
func PathExists(path string) bool {
_, err := os.Stat(path)
return err == nil
}
// DirExists checks if a path exists and is a directory.
func DirExists(path string) bool {
info, err := os.Stat(path)
if err != nil {
return false
}
return info.IsDir()
}
// CopyFile copies a single file from src to dst.
func CopyFile(src, dst string) error {
sourceFileStat, err := os.Stat(src)
if err != nil {
return err
}
if !sourceFileStat.Mode().IsRegular() {
return fmt.Errorf("%s is not a regular file", src)
}
source, err := os.Open(src)
if err != nil {
return err
}
defer source.Close()
destination, err := os.Create(dst)
if err != nil {
return err
}
defer destination.Close()
_, err = io.Copy(destination, source)
return err
}
// CopyDir copies a directory recursively from src to dst.
func CopyDir(src string, dst string) error {
srcInfo, err := os.Stat(src)
if err != nil {
return err
}
err = os.MkdirAll(dst, srcInfo.Mode())
if err != nil {
return err
}
dir, err := os.ReadDir(src)
if err != nil {
return err
}
for _, entry := range dir {
srcPath := filepath.Join(src, entry.Name())
dstPath := filepath.Join(dst, entry.Name())
if entry.IsDir() {
err = CopyDir(srcPath, dstPath)
if err != nil {
return err
}
} else {
err = CopyFile(srcPath, dstPath)
if err != nil {
return err
}
}
}
return nil
}
// RunOsascript runs an AppleScript command using osascript.
func RunOsascript(scriptString string, myWindow fyne.Window) bool {
log.Printf("Executing AppleScript: %s", scriptString)
cmd := exec.Command("osascript", "-e", scriptString)
output, err := cmd.CombinedOutput()
if err != nil {
errMsg := fmt.Sprintf("AppleScript failed: %v\nOutput: %s", err, string(output))
dialog.ShowError(fmt.Errorf(errMsg), myWindow)
log.Println(errMsg)
return false
}
log.Printf("osascript output: %s", string(output))
return true
}
// EscapeStringForAppleScript escapes a string for AppleScript.
func EscapeStringForAppleScript(s string) string {
s = strings.ReplaceAll(s, "\\", "\\\\")
s = strings.ReplaceAll(s, "\"", "\\\"")
return s
}
// QuotePathForShell quotes paths for shell commands.
func QuotePathForShell(path string) string {
return fmt.Sprintf(`"%s"`, path)
}