Use Sprintf instead of encoding UUIDs to hex
parent
6816df3158
commit
75cf6f3ab1
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue