Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standalone application for fixing play times #16

Merged
merged 3 commits into from
Sep 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading