Implement picking game dir

This commit is contained in:
2025-01-11 23:28:25 +01:00
parent 156c5770e8
commit e0f3361efe
8 changed files with 147 additions and 20 deletions

32
app.go
View File

@@ -2,6 +2,8 @@ package main
import (
"context"
"os"
"path/filepath"
"github.com/wailsapp/wails/v2/pkg/runtime"
)
@@ -90,12 +92,36 @@ func (a *App) GetGamePath() (res StringResponse) {
func (a *App) SetGamePath(path string) (res StringResponse) {
settings.GamePath = path
SaveSettings(*settings)
res.Data = path
err := SaveSettings(*settings)
if err != nil {
res.Error = err.Error()
}
return res
}
func (a *App) IsGamePathValid() (res BoolResponse) {
res.Data = settings.GamePath != ""
if settings.GamePath == "" {
res.Data = false
return res
}
// Check if the path exists and contains the Interface/AddOns directory
addonPath := filepath.Join(settings.GamePath, "Interface", "AddOns")
if _, err := os.Stat(addonPath); os.IsNotExist(err) {
res.Data = false
return res
}
res.Data = true
return res
}
func (a *App) SelectDirectory() (res StringResponse) {
path, err := runtime.OpenDirectoryDialog(a.ctx, runtime.OpenDialogOptions{
Title: "Select World of Warcraft Directory",
})
if err != nil {
res.Error = err.Error()
return
}
res.Data = path
return
}