Skip to content

Commit

Permalink
Fix SS behavior for empty and missing hashes.
Browse files Browse the repository at this point in the history
Fixes: #214
  • Loading branch information
sselph committed Feb 13, 2018
1 parent f351309 commit cf56be9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
10 changes: 9 additions & 1 deletion ds/ss.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ func (s *SS) GetGame(ctx context.Context, path string) (*Game, error) {
if err != nil {
return nil, err
}
// Empty File, SS still returns a result.
if id == "da39a3ee5e6b4b0d3255bfef95601890afd80709" {
return nil, ErrNotFound
}
req := ss.GameInfoReq{SHA1: id}
resp, err := ss.GameInfo(ctx, s.Dev, s.User, req)
if err != nil {
Expand All @@ -215,7 +219,11 @@ func (s *SS) GetGame(ctx context.Context, path string) (*Game, error) {
}
game := resp.Response.Game
var regions []string
for _, r := range game.ROM(req).Regions() {
rom, ok := game.ROM(req)
if !ok {
return nil, ErrNotFound
}
for _, r := range rom.Regions() {
regions = append(regions, r)
}
regions = append(regions, s.Region...)
Expand Down
6 changes: 5 additions & 1 deletion ds/ss_mame.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ func (s *SSMAME) GetGame(ctx context.Context, path string) (*Game, error) {
}
game := resp.Response.Game
var regions []string
for _, r := range game.ROM(req).Regions() {
rom, ok := game.ROM(req)
if !ok {
return nil, ErrNotFound
}
for _, r := range rom.Regions() {
regions = append(regions, r)
}
regions = append(regions, s.Region...)
Expand Down
8 changes: 4 additions & 4 deletions ss/ss.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,18 +224,18 @@ func (g Game) Desc(l []string) (string, bool) {
return getSuffix(g.Synopsis.Map, preSynopsis, l)
}

func (g Game) ROM(req GameInfoReq) ROM {
func (g Game) ROM(req GameInfoReq) (ROM, bool) {
for _, x := range g.ROMs {
if strings.ToLower(x.SHA1) == strings.ToLower(req.SHA1) {
return x
return x, true
}
}
for _, x := range g.ROMs {
if x.FileName == req.Name {
return x
return x, true
}
}
return ROM{}
return ROM{}, false
}

type Response struct {
Expand Down

0 comments on commit cf56be9

Please sign in to comment.