Files
EpochSilicon/pkg/paths/paths.go
Evan Burkey 9b04ad7fd0
Some checks failed
Build Go/Fyne App for macOS ARM64 / build (push) Has been cancelled
rip out turtle specific options
2025-07-20 14:54:38 -07:00

108 lines
3.3 KiB
Go

package paths
import (
"fmt"
"log"
"os"
"path/filepath"
"turtlesilicon/pkg/utils"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
)
const DefaultCrossOverPath = "/Applications/CrossOver.app"
var (
CrossoverPath string
EpochPath string
PatchesAppliedEpoch = false
PatchesAppliedCrossOver = false
RosettaX87ServiceRunning = false
ServiceStarting = 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)
// Save to prefs
prefs, _ := utils.LoadPrefs()
prefs.CrossOverPath = selectedPath
utils.SavePrefs(prefs)
} 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) {
EpochPath = selectedPath
PatchesAppliedEpoch = false
log.Println("TurtleWoW path set to:", EpochPath)
// Save to prefs
prefs, _ := utils.LoadPrefs()
prefs.EpochPath = selectedPath
utils.SavePrefs(prefs)
} 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 EpochPath == "" {
turtlewowPathLabel.Segments = []widget.RichTextSegment{&widget.TextSegment{Text: "Not set", Style: widget.RichTextStyle{ColorName: theme.ColorNameError}}}
} else {
turtlewowPathLabel.Segments = []widget.RichTextSegment{&widget.TextSegment{Text: EpochPath, Style: widget.RichTextStyle{ColorName: theme.ColorNameSuccess}}}
}
turtlewowPathLabel.Refresh()
}
func CheckDefaultCrossOverPath() {
if CrossoverPath == "" {
if info, err := os.Stat(DefaultCrossOverPath); err == nil && info.IsDir() {
CrossoverPath = DefaultCrossOverPath
log.Println("Pre-set CrossOver to default:", DefaultCrossOverPath)
}
}
}