Skip to content

Commit

Permalink
Standalone application for fixing play times (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
g026r authored Sep 27, 2024
1 parent 7e0444f commit 0452292
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions cmd/playfix/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package main

import (
"encoding/binary"
"log"
"os"

"github.com/g026r/pocket-toolkit/pkg/io"
)

// Simple application to fix played times & nothing else.

func main() {
entries, err := io.LoadEntries(os.DirFS("./"))
if err != nil {
log.Fatal(err)
}
p, err := io.LoadPlaytimes(os.DirFS("./"))
if err != nil {
log.Fatal(err)
}

complete := false
out, err := os.CreateTemp("", "playtimes_*.bin")
if err != nil {
log.Fatal(err)
}
defer func() {
_ = out.Close()
if complete { // Overwrite the original with the temp file if successful; delete it if not.
err = os.Rename(out.Name(), "System/Played Games/playtimes.bin")
} else {
err = os.Remove(out.Name())
}
}()

// Write header
if err := binary.Write(out, binary.BigEndian, io.PlaytimesHeader); err != nil {
log.Fatal(err)
}
if err := binary.Write(out, binary.LittleEndian, uint32(len(entries))); err != nil {
log.Fatal(err)
}

// Write entries in the same order as list.bin
for _, e := range entries {
tmp := p[e.Sig]
tmp.Played = tmp.Played &^ 0xFF000000 // Fix the time. System prefix will get written by WriteTo
if err := binary.Write(out, binary.LittleEndian, e.Sig); err != nil {
log.Fatal(err)
}
if _, err := tmp.WriteTo(out); err != nil {
log.Fatal(err)
}
}

complete = true
}

0 comments on commit 0452292

Please sign in to comment.