Skip to content

Commit

Permalink
Remove unused images and backups
Browse files Browse the repository at this point in the history
  • Loading branch information
boppreh committed May 17, 2017
1 parent bcbc949 commit ac4a72f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
22 changes: 22 additions & 0 deletions backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,28 @@ func getBackupPath(gridDir string, game *Game) string {
return filepath.Join(gridDir, "originals", game.ID+" "+hexHash+game.ImageExt)
}

func RemoveExisting(gridDir string, gameId string) error {
images, err := filepath.Glob(filepath.Join(gridDir, gameId+".*"))
if err != nil {
return err
}

backups, err := filepath.Glob(filepath.Join(gridDir, "originals", gameId+" *.*"))
if err != nil {
return err
}

all := append(images, backups...)
for _, path := range all {
err = os.Remove(path)
if err != nil {
return err
}
}

return nil
}

func loadImage(game *Game, sourceName string, imagePath string) error {
imageBytes, err := ioutil.ReadFile(imagePath)
if err == nil {
Expand Down
8 changes: 5 additions & 3 deletions steamgrid.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,17 @@ func startApplication() {

fmt.Println("Loading existing images and backups...")

// From this point onward we could delete the entire grid/ dir, because all relevant data is loaded in 'games'.
// We don't, and this builds up useless files (TODO), but is better than accidentally deleting data.

i := 0
for _, game := range games {
i++

overridePath := filepath.Join(filepath.Dir(os.Args[0]), "games")
LoadExisting(overridePath, gridDir, game)
// This cleans up unused backups and images for the same game but with different extensions.
err = RemoveExisting(gridDir, game.ID)
if err != nil {
fmt.Println(err.Error())
}

var name string
if game.Name != "" {
Expand Down

0 comments on commit ac4a72f

Please sign in to comment.