generated from dave/wails-template
Implement picking game dir
This commit is contained in:
32
app.go
32
app.go
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user