diff options
| author | Mitchell Riedstra <mitch@riedstra.dev> | 2021-08-04 20:06:07 -0400 |
|---|---|---|
| committer | Mitchell Riedstra <mitch@riedstra.dev> | 2021-08-04 20:06:07 -0400 |
| commit | 742938b00222c7ad57ad11eb24850d9202c2503d (patch) | |
| tree | e0d1d033027d5dd553c213ed41bb8ae201d6a285 /steam/game.go | |
| parent | a5a49ff08056a67cc57435f219aa157342a0d9a0 (diff) | |
| download | steam-export-742938b00222c7ad57ad11eb24850d9202c2503d.tar.gz steam-export-742938b00222c7ad57ad11eb24850d9202c2503d.tar.xz | |
Pretty large structural changes. Non-building development snapshot
Diffstat (limited to 'steam/game.go')
| -rw-r--r-- | steam/game.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/steam/game.go b/steam/game.go new file mode 100644 index 0000000..0028257 --- /dev/null +++ b/steam/game.go @@ -0,0 +1,32 @@ +package steam + +import ( + "os" + "path/filepath" +) + +// GetSize returns the size of a game in a pretty format. If size is 0 +// it will call SetSizeInfo before returning +func (g *Game) GetSize() string { + if g.Size == 0 { + _ = g.SetSizeInfo() + } + return formatBytes(g.Size) +} + +// SetSizeInfo reads the size information for the game off of the disk +// and stores it in the Size struct element +func (g *Game) SetSizeInfo() error { + pth := filepath.Join(g.LibraryPath, "common", g.Name) + return filepath.Walk(pth, func(path string, info os.FileInfo, err error) error { + if err != nil { + return err + } + + if info.Mode().IsRegular() { + g.Size += info.Size() + } + + return nil + }) +} |
