commit c24fdfcb71f8a39f9f67943171e6ecf894bb6c33 Author: aomizu Date: Sat May 17 21:32:02 2025 +0900 init commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e43b0f9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store diff --git a/FyneApp.toml b/FyneApp.toml new file mode 100644 index 0000000..429aec3 --- /dev/null +++ b/FyneApp.toml @@ -0,0 +1,13 @@ +[Details] + Icon = "" + Name = "TurtleSilicon Patcher" + ID = "com.example.turtlesilicon" + Version = "0.1.0" + Build = 1 + +Resources = [ + "winerosetta/winerosetta.dll", + "winerosetta/d3d9.dll", + "rosettax87/rosettax87", + "rosettax87/libRuntimeRosettax87" +] diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..7cb4bef --- /dev/null +++ b/go.mod @@ -0,0 +1,40 @@ +module turtlesilicon + +go 1.24.3 + +require fyne.io/fyne/v2 v2.6.1 + +require ( + fyne.io/systray v1.11.0 // indirect + github.com/BurntSushi/toml v1.4.0 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/fredbi/uri v1.1.0 // indirect + github.com/fsnotify/fsnotify v1.7.0 // indirect + github.com/fyne-io/gl-js v0.1.0 // indirect + github.com/fyne-io/glfw-js v0.2.0 // indirect + github.com/fyne-io/image v0.1.1 // indirect + github.com/fyne-io/oksvg v0.1.0 // indirect + github.com/go-gl/gl v0.0.0-20231021071112-07e5d0ea2e71 // indirect + github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a // indirect + github.com/go-text/render v0.2.0 // indirect + github.com/go-text/typesetting v0.2.1 // indirect + github.com/godbus/dbus/v5 v5.1.0 // indirect + github.com/hack-pad/go-indexeddb v0.3.2 // indirect + github.com/hack-pad/safejs v0.1.0 // indirect + github.com/jeandeaual/go-locale v0.0.0-20241217141322-fcc2cadd6f08 // indirect + github.com/jsummers/gobmp v0.0.0-20230614200233-a9de23ed2e25 // indirect + github.com/kr/text v0.2.0 // indirect + github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect + github.com/nicksnyder/go-i18n/v2 v2.5.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/rymdport/portal v0.4.1 // indirect + github.com/srwiley/oksvg v0.0.0-20221011165216-be6e8873101c // indirect + github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef // indirect + github.com/stretchr/testify v1.10.0 // indirect + github.com/yuin/goldmark v1.7.8 // indirect + golang.org/x/image v0.24.0 // indirect + golang.org/x/net v0.35.0 // indirect + golang.org/x/sys v0.30.0 // indirect + golang.org/x/text v0.22.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..83677a5 --- /dev/null +++ b/go.sum @@ -0,0 +1,80 @@ +fyne.io/fyne/v2 v2.6.1 h1:kjPJD4/rBS9m2nHJp+npPSuaK79yj6ObMTuzR6VQ1Is= +fyne.io/fyne/v2 v2.6.1/go.mod h1:YZt7SksjvrSNJCwbWFV32WON3mE1Sr7L41D29qMZ/lU= +fyne.io/systray v1.11.0 h1:D9HISlxSkx+jHSniMBR6fCFOUjk1x/OOOJLa9lJYAKg= +fyne.io/systray v1.11.0/go.mod h1:RVwqP9nYMo7h5zViCBHri2FgjXF7H2cub7MAq4NSoLs= +github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0= +github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/felixge/fgprof v0.9.3 h1:VvyZxILNuCiUCSXtPtYmmtGvb65nqXh2QFWc0Wpf2/g= +github.com/felixge/fgprof v0.9.3/go.mod h1:RdbpDgzqYVh/T9fPELJyV7EYJuHB55UTEULNun8eiPw= +github.com/fredbi/uri v1.1.0 h1:OqLpTXtyRg9ABReqvDGdJPqZUxs8cyBDOMXBbskCaB8= +github.com/fredbi/uri v1.1.0/go.mod h1:aYTUoAXBOq7BLfVJ8GnKmfcuURosB1xyHDIfWeC/iW4= +github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= +github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= +github.com/fyne-io/gl-js v0.1.0 h1:8luJzNs0ntEAJo+8x8kfUOXujUlP8gB3QMOxO2mUdpM= +github.com/fyne-io/gl-js v0.1.0/go.mod h1:ZcepK8vmOYLu96JoxbCKJy2ybr+g1pTnaBDdl7c3ajI= +github.com/fyne-io/glfw-js v0.2.0 h1:8GUZtN2aCoTPNqgRDxK5+kn9OURINhBEBc7M4O1KrmM= +github.com/fyne-io/glfw-js v0.2.0/go.mod h1:Ri6te7rdZtBgBpxLW19uBpp3Dl6K9K/bRaYdJ22G8Jk= +github.com/fyne-io/image v0.1.1 h1:WH0z4H7qfvNUw5l4p3bC1q70sa5+YWVt6HCj7y4VNyA= +github.com/fyne-io/image v0.1.1/go.mod h1:xrfYBh6yspc+KjkgdZU/ifUC9sPA5Iv7WYUBzQKK7JM= +github.com/fyne-io/oksvg v0.1.0 h1:7EUKk3HV3Y2E+qypp3nWqMXD7mum0hCw2KEGhI1fnBw= +github.com/fyne-io/oksvg v0.1.0/go.mod h1:dJ9oEkPiWhnTFNCmRgEze+YNprJF7YRbpjgpWS4kzoI= +github.com/go-gl/gl v0.0.0-20231021071112-07e5d0ea2e71 h1:5BVwOaUSBTlVZowGO6VZGw2H/zl9nrd3eCZfYV+NfQA= +github.com/go-gl/gl v0.0.0-20231021071112-07e5d0ea2e71/go.mod h1:9YTyiznxEY1fVinfM7RvRcjRHbw2xLBJ3AAGIT0I4Nw= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a h1:vxnBhFDDT+xzxf1jTJKMKZw3H0swfWk9RpWbBbDK5+0= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/go-text/render v0.2.0 h1:LBYoTmp5jYiJ4NPqDc2pz17MLmA3wHw1dZSVGcOdeAc= +github.com/go-text/render v0.2.0/go.mod h1:CkiqfukRGKJA5vZZISkjSYrcdtgKQWRa2HIzvwNN5SU= +github.com/go-text/typesetting v0.2.1 h1:x0jMOGyO3d1qFAPI0j4GSsh7M0Q3Ypjzr4+CEVg82V8= +github.com/go-text/typesetting v0.2.1/go.mod h1:mTOxEwasOFpAMBjEQDhdWRckoLLeI/+qrQeBCTGEt6M= +github.com/go-text/typesetting-utils v0.0.0-20241103174707-87a29e9e6066 h1:qCuYC+94v2xrb1PoS4NIDe7DGYtLnU2wWiQe9a1B1c0= +github.com/go-text/typesetting-utils v0.0.0-20241103174707-87a29e9e6066/go.mod h1:DDxDdQEnB70R8owOx3LVpEFvpMK9eeH1o2r0yZhFI9o= +github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk= +github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= +github.com/google/pprof v0.0.0-20211214055906-6f57359322fd h1:1FjCyPC+syAzJ5/2S8fqdZK1R22vvA0J7JZKcuOIQ7Y= +github.com/google/pprof v0.0.0-20211214055906-6f57359322fd/go.mod h1:KgnwoLYCZ8IQu3XUZ8Nc/bM9CCZFOyjUNOSygVozoDg= +github.com/hack-pad/go-indexeddb v0.3.2 h1:DTqeJJYc1usa45Q5r52t01KhvlSN02+Oq+tQbSBI91A= +github.com/hack-pad/go-indexeddb v0.3.2/go.mod h1:QvfTevpDVlkfomY498LhstjwbPW6QC4VC/lxYb0Kom0= +github.com/hack-pad/safejs v0.1.0 h1:qPS6vjreAqh2amUqj4WNG1zIw7qlRQJ9K10eDKMCnE8= +github.com/hack-pad/safejs v0.1.0/go.mod h1:HdS+bKF1NrE72VoXZeWzxFOVQVUSqZJAG0xNCnb+Tio= +github.com/jeandeaual/go-locale v0.0.0-20241217141322-fcc2cadd6f08 h1:wMeVzrPO3mfHIWLZtDcSaGAe2I4PW9B/P5nMkRSwCAc= +github.com/jeandeaual/go-locale v0.0.0-20241217141322-fcc2cadd6f08/go.mod h1:ZDXo8KHryOWSIqnsb/CiDq7hQUYryCgdVnxbj8tDG7o= +github.com/jsummers/gobmp v0.0.0-20230614200233-a9de23ed2e25 h1:YLvr1eE6cdCqjOe972w/cYF+FjW34v27+9Vo5106B4M= +github.com/jsummers/gobmp v0.0.0-20230614200233-a9de23ed2e25/go.mod h1:kLgvv7o6UM+0QSf0QjAse3wReFDsb9qbZJdfexWlrQw= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ= +github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8= +github.com/nicksnyder/go-i18n/v2 v2.5.1 h1:IxtPxYsR9Gp60cGXjfuR/llTqV8aYMsC472zD0D1vHk= +github.com/nicksnyder/go-i18n/v2 v2.5.1/go.mod h1:DrhgsSDZxoAfvVrBVLXoxZn/pN5TXqaDbq7ju94viiQ= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= +github.com/pkg/profile v1.7.0 h1:hnbDkaNWPCLMO9wGLdBFTIZvzDrDfBM2072E1S9gJkA= +github.com/pkg/profile v1.7.0/go.mod h1:8Uer0jas47ZQMJ7VD+OHknK4YDY07LPUC6dEvqDjvNo= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rymdport/portal v0.4.1 h1:2dnZhjf5uEaeDjeF/yBIeeRo6pNI2QAKm7kq1w/kbnA= +github.com/rymdport/portal v0.4.1/go.mod h1:kFF4jslnJ8pD5uCi17brj/ODlfIidOxlgUDTO5ncnC4= +github.com/srwiley/oksvg v0.0.0-20221011165216-be6e8873101c h1:km8GpoQut05eY3GiYWEedbTT0qnSxrCjsVbb7yKY1KE= +github.com/srwiley/oksvg v0.0.0-20221011165216-be6e8873101c/go.mod h1:cNQ3dwVJtS5Hmnjxy6AgTPd0Inb3pW05ftPSX7NZO7Q= +github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef h1:Ch6Q+AZUxDBCVqdkI8FSpFyZDtCVBc2VmejdNrm5rRQ= +github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef/go.mod h1:nXTWP6+gD5+LUJ8krVhhoeHjvHTutPxMYl5SvkcnJNE= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/yuin/goldmark v1.7.8 h1:iERMLn0/QJeHFhxSt3p6PeN9mGnvIKSpG9YYorDMnic= +github.com/yuin/goldmark v1.7.8/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E= +golang.org/x/image v0.24.0 h1:AN7zRgVsbvmTfNyqIbbOraYL8mSwcKncEj8ofjgzcMQ= +golang.org/x/image v0.24.0/go.mod h1:4b/ITuLfqYq1hqZcjofwctIhi7sZh2WaCjvsBNjjya8= +golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8= +golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk= +golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= +golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM= +golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/main.go b/main.go new file mode 100644 index 0000000..4a48acc --- /dev/null +++ b/main.go @@ -0,0 +1,627 @@ +package main + +import ( + "bytes" // Added import + "fmt" + "io" + "log" + "os" + "os/exec" + "path/filepath" + "strings" + + "fyne.io/fyne/v2" + "fyne.io/fyne/v2/app" + "fyne.io/fyne/v2/container" + "fyne.io/fyne/v2/dialog" + "fyne.io/fyne/v2/widget" +) + +const defaultCrossOverPath = "/Applications/CrossOver.app" + +var ( + crossoverPath string + turtlewowPath string + patchesAppliedTurtleWoW = false + patchesAppliedCrossOver = false + +) + +// Helper function to check if a path exists +func pathExists(path string) bool { + _, err := os.Stat(path) + return err == nil +} + +// Helper function to check 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() +} + +// Helper function to copy a file +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 +} + +// Helper function to copy a directory recursively +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 +} + +// Helper function to run 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() // Changed variable name to avoid conflict if 'output' is used later + 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 to be safely embedded in an AppleScript double-quoted string. +func escapeStringForAppleScript(s string) string { + s = strings.ReplaceAll(s, "\\", "\\\\") // Escape backslashes first: \ -> \\ + s = strings.ReplaceAll(s, "\"", "\\\"") // Escape double quotes: " -> \" + return s +} + +func main() { + myApp := app.NewWithID("com.example.turtlesilicon") + myWindow := myApp.NewWindow("TurtleSilicon Patcher") + myWindow.Resize(fyne.NewSize(650, 450)) // Slightly wider for clarity + + // --- Path Labels --- + crossoverPathLabel := widget.NewLabel("CrossOver Path: Not set") + turtlewowPathLabel := widget.NewLabel("TurtleWoW Path: Not set") + + // --- Status Labels --- + turtlewowStatusLabel := widget.NewLabel("TurtleWoW Patch Status: Not Applied") + crossoverStatusLabel := widget.NewLabel("CrossOver Patch Status: Not Applied") + + // --- Buttons (declared here to be accessible in updateAllStatuses) --- + var launchButton *widget.Button + var patchTurtleWoWButton *widget.Button + var patchCrossOverButton *widget.Button + + // --- Helper to update all statuses and button states --- + updateAllStatuses := func() { + // Update Crossover Path and Status + if crossoverPath == "" { + crossoverPathLabel.SetText("CrossOver Path: Not set") + patchesAppliedCrossOver = false // Reset if path is cleared + } else { + crossoverPathLabel.SetText("CrossOver Path: " + crossoverPath) + wineloader2Path := filepath.Join(crossoverPath, "Contents", "SharedSupport", "CrossOver", "CrossOver-Hosted Application", "wineloader2") + if pathExists(wineloader2Path) { + patchesAppliedCrossOver = true + } else { + // patchesAppliedCrossOver = false // Only set to false if not already true from a patch action this session + // This will be set to true by the patch function upon success + } + } + if patchesAppliedCrossOver { + crossoverStatusLabel.SetText("CrossOver Patch Status: Applied") + if patchCrossOverButton != nil { + patchCrossOverButton.Disable() + } + } else { + crossoverStatusLabel.SetText("CrossOver Patch Status: Not Applied") + if patchCrossOverButton != nil { + if crossoverPath != "" { + patchCrossOverButton.Enable() + } else { + patchCrossOverButton.Disable() + } + } + } + + // Update TurtleWoW Path and Status + if turtlewowPath == "" { + turtlewowPathLabel.SetText("TurtleWoW Path: Not set") + patchesAppliedTurtleWoW = false // Reset if path is cleared + } else { + turtlewowPathLabel.SetText("TurtleWoW Path: " + turtlewowPath) + winerosettaDllPath := filepath.Join(turtlewowPath, "winerosetta.dll") + d3d9DllPath := filepath.Join(turtlewowPath, "d3d9.dll") + rosettaX87DirPath := filepath.Join(turtlewowPath, "rosettax87") + if pathExists(winerosettaDllPath) && pathExists(d3d9DllPath) && dirExists(rosettaX87DirPath) { + patchesAppliedTurtleWoW = true + } else { + // patchesAppliedTurtleWoW = false // Similar to crossover, only set by patch success or initial check + } + } + if patchesAppliedTurtleWoW { + turtlewowStatusLabel.SetText("TurtleWoW Patch Status: Applied") + if patchTurtleWoWButton != nil { + patchTurtleWoWButton.Disable() + } + } else { + turtlewowStatusLabel.SetText("TurtleWoW Patch Status: Not Applied") + if patchTurtleWoWButton != nil { + if turtlewowPath != "" { + patchTurtleWoWButton.Enable() + } else { + patchTurtleWoWButton.Disable() + } + } + } + + // Update Launch Button State + if launchButton != nil { + if patchesAppliedTurtleWoW && patchesAppliedCrossOver && turtlewowPath != "" && crossoverPath != "" { + launchButton.Enable() + } else { + launchButton.Disable() + } + } + } + + // --- Path Selection Functions --- + selectCrossOverPath := func() { + dialog.ShowFolderOpen(func(uri fyne.ListableURI, err error) { + if err != nil { + dialog.ShowError(err, myWindow) + return + } + if uri == nil { // User cancelled + log.Println("CrossOver path selection cancelled.") + // Do not reset crossoverPath if user cancels, keep previous valid path + updateAllStatuses() // Re-evaluate with existing path + return + } + selectedPath := uri.Path() + if filepath.Ext(selectedPath) == ".app" && dirExists(selectedPath) { // Check if it's a directory too + crossoverPath = selectedPath + patchesAppliedCrossOver = false // Reset patch status on new path, updateAllStatuses will re-check + log.Println("CrossOver path set to:", crossoverPath) + } else { + // Don't reset crossoverPath, show error and keep old one if any + dialog.ShowError(fmt.Errorf("invalid selection: '%s'. Please select a valid .app bundle", selectedPath), myWindow) + log.Println("Invalid CrossOver path selected:", selectedPath) + } + updateAllStatuses() + }, myWindow) + } + + selectTurtleWoWPath := func() { + dialog.ShowFolderOpen(func(uri fyne.ListableURI, err error) { + if err != nil { + dialog.ShowError(err, myWindow) + return + } + if uri == nil { // User cancelled + log.Println("TurtleWoW path selection cancelled.") + updateAllStatuses() // Re-evaluate + return + } + selectedPath := uri.Path() + if dirExists(selectedPath) { // Basic check for directory + turtlewowPath = selectedPath + patchesAppliedTurtleWoW = false // Reset patch status on new path, updateAllStatuses will re-check + 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) + } + + // --- Patching Functions --- + patchTurtleWoWFunc := func() { + log.Println("Patch TurtleWoW clicked") + if turtlewowPath == "" { + dialog.ShowError(fmt.Errorf("TurtleWoW path not set. Please set it first."), myWindow) + return + } + + // Target paths + targetWinerosettaDll := filepath.Join(turtlewowPath, "winerosetta.dll") + targetD3d9Dll := filepath.Join(turtlewowPath, "d3d9.dll") + targetRosettaX87Dir := filepath.Join(turtlewowPath, "rosettax87") + + // Files to copy directly into turtlewowPath + filesToCopy := map[string]string{ + "winerosetta/winerosetta.dll": targetWinerosettaDll, // Adjusted path + "winerosetta/d3d9.dll": targetD3d9Dll, // Adjusted path + } + + 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) + 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) + patchesAppliedTurtleWoW = false + updateAllStatuses() + return + } + defer destinationFile.Close() + + _, err = io.Copy(destinationFile, bytes.NewReader(resource.Content())) // Changed to use 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) + patchesAppliedTurtleWoW = false + updateAllStatuses() + return + } + log.Printf("Successfully copied %s to %s", resourceName, destPath) + } + + // Handle rosettax87 folder and its contents + 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) + // Not necessarily fatal, MkdirAll will handle creation. + } + 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) + patchesAppliedTurtleWoW = false + updateAllStatuses() + return + } + + rosettaFilesToCopy := map[string]string{ + "rosettax87/rosettax87": filepath.Join(targetRosettaX87Dir, "rosettax87"), // Adjusted path + "rosettax87/libRuntimeRosettax87": filepath.Join(targetRosettaX87Dir, "libRuntimeRosettax87"), // Added 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) + 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) + patchesAppliedTurtleWoW = false + updateAllStatuses() + return + } + // No defer destinationFile.Close() here, because we chmod after copy and then it can be closed. + + _, err = io.Copy(destinationFile, bytes.NewReader(resource.Content())) // Changed to use bytes.NewReader(resource.Content()) + if err != nil { + destinationFile.Close() // Close before erroring out + errMsg := fmt.Sprintf("failed to copy bundled resource %s to %s: %v", resourceName, destPath, err) + dialog.ShowError(fmt.Errorf(errMsg), myWindow) + log.Println(errMsg) + patchesAppliedTurtleWoW = false + updateAllStatuses() + return + } + destinationFile.Close() // Close after successful copy + + // Set execute permissions for the rosettax87 executable + if filepath.Base(destPath) == "rosettax87" { // Corrected condition + 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) + // Decide if this is fatal or a warning. For now, treat as fatal for patching. + patchesAppliedTurtleWoW = false + updateAllStatuses() + return + } + } + log.Printf("Successfully copied %s to %s", resourceName, destPath) + } + + log.Println("TurtleWoW patching with bundled resources completed successfully.") + patchesAppliedTurtleWoW = true + dialog.ShowInformation("Success", "TurtleWoW patching process completed using bundled resources.", myWindow) + updateAllStatuses() + } + + patchCrossOverFunc := func() { + log.Println("Patch CrossOver clicked") + if crossoverPath == "" { + dialog.ShowError(fmt.Errorf("CrossOver path not set. Please set it first."), myWindow) + return + } + + wineloaderBasePath := filepath.Join(crossoverPath, "Contents", "SharedSupport", "CrossOver", "CrossOver-Hosted Application") + wineloaderOrig := filepath.Join(wineloaderBasePath, "wineloader") + wineloaderCopy := filepath.Join(wineloaderBasePath, "wineloader2") + + if !pathExists(wineloaderOrig) { + dialog.ShowError(fmt.Errorf("original wineloader not found at %s", wineloaderOrig), myWindow) + patchesAppliedCrossOver = false + updateAllStatuses() + return + } + + // 1. Make a copy of wineloader + log.Printf("Copying %s to %s", wineloaderOrig, wineloaderCopy) + if err := copyFile(wineloaderOrig, wineloaderCopy); err != nil { + dialog.ShowError(fmt.Errorf("failed to copy wineloader: %w", err), myWindow) + patchesAppliedCrossOver = false + updateAllStatuses() + return + } + + // Set execute permissions for the wineloader2 copy + log.Printf("Setting execute permission for %s", wineloaderCopy) + if err := os.Chmod(wineloaderCopy, 0755); err != nil { + errMsg := fmt.Sprintf("failed to set execute permission for %s: %v", wineloaderCopy, err) + dialog.ShowError(fmt.Errorf(errMsg), myWindow) + log.Println(errMsg) + patchesAppliedCrossOver = false + // Attempt to clean up the copied file if chmod fails + if err := os.Remove(wineloaderCopy); err != nil { + log.Printf("Warning: failed to cleanup wineloader2 after chmod failure: %v", err) + } + updateAllStatuses() + return + } + + // 2. Execute codesign --remove-signature + log.Printf("Executing: codesign --remove-signature %s", wineloaderCopy) + cmd := exec.Command("codesign", "--remove-signature", wineloaderCopy) + combinedOutput, err := cmd.CombinedOutput() // Store result in a new variable + if err != nil { + // Corrected variable name for error message and use combinedOutput + 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) + patchesAppliedCrossOver = false + // Attempt to clean up the copied file if codesign fails + 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)) // Use combinedOutput here + + log.Println("CrossOver patching completed successfully.") + patchesAppliedCrossOver = true + dialog.ShowInformation("Success", "CrossOver patching process completed.", myWindow) + updateAllStatuses() + } + + // --- Launch Function --- + launchGameFunc := func(myWindow fyne.Window) { + log.Println("Launch Game button clicked") + + // crossoverBinPath := filepath.Join(crossoverPath, "Contents", "MacOS", "CrossOver") // No longer used + turtlewowExePath := filepath.Join(turtlewowPath, "WoW.exe") + + // Pre-launch checks + if crossoverPath == "" { + dialog.ShowError(fmt.Errorf("CrossOver path not set. Please set it in the patcher."), myWindow) + return + } + if turtlewowPath == "" { + dialog.ShowError(fmt.Errorf("TurtleWoW path not set. Please set it in the patcher."), myWindow) + return + } + if !patchesAppliedTurtleWoW || !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(turtlewowPath, "rosettax87") + rosettaExecutable := filepath.Join(rosettaInTurtlePath, "rosettax87") + wineloader2Path := filepath.Join(crossoverPath, "Contents", "SharedSupport", "CrossOver", "CrossOver-Hosted Application", "wineloader2") + wowExePath := filepath.Join(turtlewowPath, "wow.exe") + + if !pathExists(rosettaExecutable) { + dialog.ShowError(fmt.Errorf("rosetta executable not found at %s. Ensure TurtleWoW patching was successful", rosettaExecutable), myWindow) + return + } + if !pathExists(wineloader2Path) { + dialog.ShowError(fmt.Errorf("patched wineloader2 not found at %s. Ensure CrossOver patching was successful", wineloader2Path), myWindow) + return + } + if !pathExists(wowExePath) { + dialog.ShowError(fmt.Errorf("wow.exe not found at %s. Ensure your TurtleWoW directory is correct", wowExePath), myWindow) + return + } + + // Command 1: Launch rosettax87 + // The path itself needs to be an AppleScript string literal, so we use escapeStringForAppleScript. + // Corrected: cd into the rosettax87 directory itself. + appleScriptSafeRosettaDir := escapeStringForAppleScript(rosettaInTurtlePath) + // Construct the AppleScript command using a regular Go string literal for the format string. + // This ensures that \" correctly escapes double quotes for Go, producing literal quotes in the AppleScript command. + 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 !runOsascript(cmd1Script, myWindow) { + // Error already shown by runOsascript + return + } + + dialog.ShowConfirm("Action Required", // Changed from ShowInformation to ShowConfirm + "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 OK here once rosetta x87 is running and you have entered the password.\n"+ + "Click Cancel to abort launching WoW.", + func(confirmed bool) { + if confirmed { + log.Println("User confirmed rosetta x87 is running. Proceeding to launch WoW.") + // Command 2: Launch WoW.exe via rosettax87 + if crossoverPath == "" || turtlewowPath == "" { + dialog.ShowError(fmt.Errorf("CrossOver path or TurtleWoW path is not set. Cannot launch WoW."), myWindow) + return + } + + // Paths required for the new command (already defined in launchGameFunc scope): + // rosettaExecutable := filepath.Join(turtlewowPath, "rosettax87", "rosettax87") + // wineloader2Path := filepath.Join(crossoverPath, "Contents", "SharedSupport", "CrossOver", "CrossOver-Hosted Application", "wineloader2") + // turtlewowExePath := filepath.Join(turtlewowPath, "WoW.exe") + + // Construct the new shell command + shellCmd := fmt.Sprintf(`cd %s && WINEDLLOVERRIDES="d3d9=n,b" MTL_HUD_ENABLED=1 %s %s %s`, + quotePathForShell(turtlewowPath), // Added cd to turtlewowPath + quotePathForShell(rosettaExecutable), + quotePathForShell(wineloader2Path), + quotePathForShell(turtlewowExePath)) // turtlewowExePath is defined at the start of launchGameFunc + + // Escape the entire shell command for AppleScript + escapedShellCmd := escapeStringForAppleScript(shellCmd) + + cmd2Script := fmt.Sprintf("tell application \"Terminal\" to do script \"%s\"", escapedShellCmd) + + log.Println("Executing updated WoW launch command via AppleScript...") + if !runOsascript(cmd2Script, myWindow) { + // Error already shown by runOsascript + return + } + + log.Println("Launch commands executed. Check the new terminal windows.") + dialog.ShowInformation("Launched", "World of Warcraft launch sequence initiated. Check the new terminal windows.", myWindow) + } else { + log.Println("User cancelled WoW launch after rosetta x87 initiation.") + dialog.ShowInformation("Cancelled", "WoW launch was cancelled.", myWindow) + } + }, myWindow) + + // The following lines are now moved inside the dialog.ShowConfirm callback + // // Command 2: Launch WoW.exe via CrossOver + // ... (rest of the original cmd2 logic was here) + } + + // --- Button Definitions --- + patchTurtleWoWButton = widget.NewButton("Patch TurtleWoW", patchTurtleWoWFunc) + patchCrossOverButton = widget.NewButton("Patch CrossOver", patchCrossOverFunc) + launchButton = widget.NewButton("Launch Game", func() { // Wrap the call in an anonymous function + launchGameFunc(myWindow) // Pass myWindow to the actual handler + }) + + // --- Initial Check for Default CrossOver Path --- + if info, err := os.Stat(defaultCrossOverPath); err == nil && info.IsDir() { + crossoverPath = defaultCrossOverPath + log.Println("Pre-set CrossOver to default:", defaultCrossOverPath) + // No need to reset patchesAppliedCrossOver here, updateAllStatuses will check + } + + // --- UI Layout --- + // Using Form layout for better alignment of labels and controls + pathSelectionForm := widget.NewForm( + widget.NewFormItem("CrossOver Path:", container.NewBorder(nil, nil, nil, widget.NewButton("Set/Change", selectCrossOverPath), crossoverPathLabel)), + widget.NewFormItem("TurtleWoW Path:", container.NewBorder(nil, nil, nil, widget.NewButton("Set/Change", selectTurtleWoWPath), turtlewowPathLabel)), + ) + + patchOperationsLayout := container.NewVBox( + widget.NewSeparator(), + container.NewGridWithColumns(3, // Label, Status, Button + widget.NewLabel("TurtleWoW Patch:"), turtlewowStatusLabel, patchTurtleWoWButton, + ), + container.NewGridWithColumns(3, + widget.NewLabel("CrossOver Patch:"), crossoverStatusLabel, patchCrossOverButton, + ), + widget.NewSeparator(), + ) + + myWindow.SetContent(container.NewVBox( + pathSelectionForm, + patchOperationsLayout, + launchButton, + )) + + updateAllStatuses() // Initial UI state update, including button states + myWindow.ShowAndRun() +} + +// Helper to quote paths for shell commands if they contain spaces or special chars +func quotePathForShell(path string) string { + // A simple approach: always quote. More robust parsing might be needed for complex paths. + return fmt.Sprintf(`"%s"`, path) +} diff --git a/rosettax87/libRuntimeRosettax87 b/rosettax87/libRuntimeRosettax87 new file mode 100755 index 0000000..4c0dca9 Binary files /dev/null and b/rosettax87/libRuntimeRosettax87 differ diff --git a/rosettax87/rosettax87 b/rosettax87/rosettax87 new file mode 100755 index 0000000..f33a776 Binary files /dev/null and b/rosettax87/rosettax87 differ diff --git a/winerosetta/d3d9.dll b/winerosetta/d3d9.dll new file mode 100755 index 0000000..13e32b3 Binary files /dev/null and b/winerosetta/d3d9.dll differ diff --git a/winerosetta/winerosetta.dll b/winerosetta/winerosetta.dll new file mode 100644 index 0000000..879cb8d Binary files /dev/null and b/winerosetta/winerosetta.dll differ