-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Standalone application for fixing play times (#16)
- Loading branch information
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |