Fix new save reader/writer functions

pull/4/head
maru 9 months ago
parent 9a0d4a2698
commit 72151d9c01
No known key found for this signature in database
GPG Key ID: 37689350E9CD0F0D

@ -16,7 +16,7 @@ func readSystemSaveData(uuid []byte) (defs.SystemSaveData, error) {
file, err := os.Open("userdata/" + hex.EncodeToString(uuid) + "/system.pzs") file, err := os.Open("userdata/" + hex.EncodeToString(uuid) + "/system.pzs")
if err != nil { if err != nil {
return system, fmt.Errorf("failed to open save file: %s", err) return system, fmt.Errorf("failed to open save file for reading: %s", err)
} }
defer file.Close() defer file.Close()
@ -46,7 +46,7 @@ func readSessionSaveData(uuid []byte, slotID int) (defs.SessionSaveData, error)
file, err := os.Open(fmt.Sprintf("userdata/%s/%s.pzs", hex.EncodeToString(uuid), fileName)) file, err := os.Open(fmt.Sprintf("userdata/%s/%s.pzs", hex.EncodeToString(uuid), fileName))
if err != nil { if err != nil {
return session, fmt.Errorf("failed to open save file: %s", err) return session, fmt.Errorf("failed to open save file for reading: %s", err)
} }
defer file.Close() defer file.Close()

@ -76,16 +76,20 @@ func handleSavedataUpdate(uuid []byte, slot int, save any) error {
return fmt.Errorf("failed to create userdata folder: %s", err) return fmt.Errorf("failed to create userdata folder: %s", err)
} }
file, err := os.OpenFile("userdata/"+hexUUID+"/system.pzs", os.O_WRONLY | os.O_TRUNC, 0644) file, err := os.OpenFile("userdata/"+hexUUID+"/system.pzs", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil { if err != nil {
return fmt.Errorf("failed to open save file for writing: %s", err) return fmt.Errorf("failed to open save file for writing: %s", err)
} }
defer file.Close()
zstdEncoder, err := zstd.NewWriter(file) zstdEncoder, err := zstd.NewWriter(file)
if err != nil { if err != nil {
return fmt.Errorf("failed to create zstd encoder: %s", err) return fmt.Errorf("failed to create zstd encoder: %s", err)
} }
defer zstdEncoder.Close()
err = gob.NewEncoder(zstdEncoder).Encode(save) err = gob.NewEncoder(zstdEncoder).Encode(save)
if err != nil { if err != nil {
return fmt.Errorf("failed to serialize save: %s", err) return fmt.Errorf("failed to serialize save: %s", err)
@ -105,16 +109,20 @@ func handleSavedataUpdate(uuid []byte, slot int, save any) error {
return fmt.Errorf(fmt.Sprintf("failed to create userdata folder: %s", 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_WRONLY | os.O_TRUNC, 0644) file, err := os.OpenFile(fmt.Sprintf("userdata/%s/%s.pzs", hexUUID, fileName), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil { if err != nil {
return fmt.Errorf("failed to open save file for writing: %s", err) return fmt.Errorf("failed to open save file for writing: %s", err)
} }
defer file.Close()
zstdEncoder, err := zstd.NewWriter(file) zstdEncoder, err := zstd.NewWriter(file)
if err != nil { if err != nil {
return fmt.Errorf("failed to create zstd encoder: %s", err) return fmt.Errorf("failed to create zstd encoder: %s", err)
} }
defer zstdEncoder.Close()
err = gob.NewEncoder(zstdEncoder).Encode(save) err = gob.NewEncoder(zstdEncoder).Encode(save)
if err != nil { if err != nil {
return fmt.Errorf("failed to serialize save: %s", err) return fmt.Errorf("failed to serialize save: %s", err)

Loading…
Cancel
Save