From 75cf6f3ab10f86f47f0b85a28f159fb6b6abb104 Mon Sep 17 00:00:00 2001 From: maru Date: Sat, 20 Apr 2024 17:10:48 -0400 Subject: [PATCH] Use Sprintf instead of encoding UUIDs to hex --- api/savedata/delete.go | 7 ++----- api/savedata/update.go | 11 ++++------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/api/savedata/delete.go b/api/savedata/delete.go index cdaa3b0..97b625b 100644 --- a/api/savedata/delete.go +++ b/api/savedata/delete.go @@ -1,7 +1,6 @@ package savedata import ( - "encoding/hex" "fmt" "log" "os" @@ -18,11 +17,9 @@ func Delete(uuid []byte, datatype, slot int) error { log.Print("failed to update account last activity") } - hexUUID := hex.EncodeToString(uuid) - switch datatype { case 0: // System - err := os.Remove("userdata/" + hexUUID + "/system.pzs") + err := os.Remove(fmt.Sprintf("userdata/%x/system.pzs", uuid)) if err != nil && !os.IsNotExist(err) { return fmt.Errorf("failed to delete save file: %s", err) } @@ -36,7 +33,7 @@ func Delete(uuid []byte, datatype, slot int) error { fileName += strconv.Itoa(slot) } - err = os.Remove(fmt.Sprintf("userdata/%s/%s.pzs", hexUUID, fileName)) + err = os.Remove(fmt.Sprintf("userdata/%x/%s.pzs", uuid, fileName)) if err != nil && !os.IsNotExist(err) { return fmt.Errorf("failed to delete save file: %s", err) } diff --git a/api/savedata/update.go b/api/savedata/update.go index 12a79a8..7b6edc6 100644 --- a/api/savedata/update.go +++ b/api/savedata/update.go @@ -2,7 +2,6 @@ package savedata import ( "encoding/gob" - "encoding/hex" "fmt" "log" "os" @@ -20,8 +19,6 @@ func Update(uuid []byte, slot int, save any) error { log.Print("failed to update account last activity") } - hexUUID := hex.EncodeToString(uuid) - switch save := save.(type) { case defs.SystemSaveData: // System if save.TrainerId == 0 && save.SecretId == 0 { @@ -37,12 +34,12 @@ func Update(uuid []byte, slot int, save any) error { return fmt.Errorf("failed to update account stats: %s", err) } - err = os.MkdirAll("userdata/"+hexUUID, 0755) + err = os.MkdirAll(fmt.Sprintf("userdata/%x", uuid), 0755) if err != nil && !os.IsExist(err) { return fmt.Errorf("failed to create userdata folder: %s", err) } - file, err := os.OpenFile("userdata/"+hexUUID+"/system.pzs", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644) + file, err := os.OpenFile(fmt.Sprintf("userdata/%x/system.pzs", uuid), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644) if err != nil { return fmt.Errorf("failed to open save file for writing: %s", err) } @@ -72,12 +69,12 @@ func Update(uuid []byte, slot int, save any) error { fileName += strconv.Itoa(slot) } - err = os.MkdirAll("userdata/"+hexUUID, 0755) + err = os.MkdirAll(fmt.Sprintf("userdata/%x", uuid), 0755) if err != nil && !os.IsExist(err) { return fmt.Errorf(fmt.Sprintf("failed to create userdata folder: %s", err)) } - file, err := os.OpenFile(fmt.Sprintf("userdata/%s/%s.pzs", hexUUID, fileName), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644) + file, err := os.OpenFile(fmt.Sprintf("userdata/%x/%s.pzs", uuid, fileName), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644) if err != nil { return fmt.Errorf("failed to open save file for writing: %s", err) }