Implement game path manipulation

This commit is contained in:
2025-01-11 23:19:45 +01:00
parent c975aee3cb
commit 156c5770e8
3 changed files with 33 additions and 6 deletions

View File

@@ -111,7 +111,7 @@ func (a *Addon) Update(body []byte) (err error) {
}
}
localPath := filepath.Join(gamePath, "Interface", "AddOns", file.Name)
localPath := filepath.Join(settings.GamePath, "Interface", "AddOns", file.Name)
log.Printf("Updating file %s", localPath)
err = UpdateFile(localPath, fileData)
if err != nil {
@@ -124,7 +124,7 @@ func (a *Addon) Update(body []byte) (err error) {
return nil
}
func (a *Addon) GetLocalTocPath() string {
return filepath.Join(gamePath, "Interface", "AddOns", a.Name, a.Name+".toc")
return filepath.Join(settings.GamePath, "Interface", "AddOns", a.Name, a.Name+".toc")
}
func (a *Addon) GetRemoteVersion() (version string, err error) {
url := a.GetRemoteTocURL()

21
app.go
View File

@@ -37,6 +37,10 @@ type StringResponse struct {
Data string `json:"data"`
Error string `json:"error,omitempty"`
}
type BoolResponse struct {
Data bool `json:"data"`
Error string `json:"error,omitempty"`
}
func (a *App) GetAddons() (res AddonsResponse) {
res.Data = addonService.Addons
@@ -78,3 +82,20 @@ func (a *App) UpdateAddon(name string) (res AddonResponse) {
}
return res
}
func (a *App) GetGamePath() (res StringResponse) {
res.Data = settings.GamePath
return res
}
func (a *App) SetGamePath(path string) (res StringResponse) {
settings.GamePath = path
SaveSettings(*settings)
res.Data = path
return res
}
func (a *App) IsGamePathValid() (res BoolResponse) {
res.Data = settings.GamePath != ""
return res
}

14
main.go
View File

@@ -30,7 +30,7 @@ func init() {
//go:embed all:frontend/dist
var assets embed.FS
var settingsFilePath = "settings.json"
var gamePath string
var settings *Settings
var addonService *AddonService
type Settings struct {
@@ -55,11 +55,10 @@ func main() {
Error.Printf("error opening settings file: %s", err)
return
}
settings := Settings{}
err = json.NewDecoder(settingsFile).Decode(&settings)
if err != nil {
Warning.Printf("error decoding settings: %s", err)
settings = Settings{}
settings = &Settings{}
}
settingsFile.Close()
log.Printf("Loaded settings: %+v", settings)
@@ -70,6 +69,13 @@ func main() {
addonService = &AddonService{}
addonService.Addons = settings.Addons
for _, addon := range addonService.Addons {
version, err := addonService.GetLocalVersion(addon.Name)
if err != nil {
Warning.Printf("error getting local version: %s", err)
}
log.Printf("%s %#v", addon.Name, version)
}
app := NewApp()
@@ -90,5 +96,5 @@ func main() {
if err != nil {
println("Error:", err.Error())
}
SaveSettings(settings)
SaveSettings(*settings)
}