Skip to content

Commit

Permalink
Better invalid GameInfo structure handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Galaco committed Sep 19, 2019
1 parent 54ccb40 commit 4f11962
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
6 changes: 6 additions & 0 deletions errors.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package filesystem

import (
"errors"
"fmt"
"strings"
)

var (
// ErrorInvalidGameInfo
ErrorInvalidGameInfo = errors.New("gameinfo keyvalues do not match expected specification")
)

// FileNotFoundError
type FileNotFoundError struct {
fileName string
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/golang-source-engine/filesystem
go 1.12

require (
github.com/galaco/KeyValues v1.3.1
github.com/galaco/KeyValues v1.4.0
github.com/galaco/bsp v0.2.2
github.com/galaco/vpk2 v0.0.0-20181012095330-21e4d1f6c888
)
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
github.com/galaco/KeyValues v1.3.1 h1:Mka6aZcMSrFawDAGTk7Y0mKHTlGmqiqfz1zIaHs5jYc=
github.com/galaco/KeyValues v1.3.1/go.mod h1:EByNBjnai9BpKGMykvBD3G28R+L6OubVnRkvZrYxP2Y=
github.com/galaco/KeyValues v1.4.0/go.mod h1:00r0hZpLlOBIHehyWAgUngjKPoo3vCVP25BgWLwOP7E=
github.com/galaco/bsp v0.2.2 h1:BomFvMNrlG9AvtOLppfwoj1ToAYJukL0LEa8gRnjUxI=
github.com/galaco/bsp v0.2.2/go.mod h1:2T3tF0vzvY0NBPrLGe0B5EEQrbG2F0Ur+HWnaSy9YA4=
github.com/galaco/vpk2 v0.0.0-20181012095330-21e4d1f6c888 h1:QCMt6AZ5gwsJ3SNsvTULg/xjZIfmcbRWv6BBnkYNOWI=
Expand Down
10 changes: 9 additions & 1 deletion register.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@ import (
// will be returned will all paths that are invalid.
func CreateFilesystemFromGameInfoDefinitions(basePath string, gameInfo *keyvalues.KeyValue, allowInvalidLocations bool) (*FileSystem, error) {
fs := NewFileSystem()
gameInfoNode, _ := gameInfo.Find("GameInfo")
var gameInfoNode *keyvalues.KeyValue
if gameInfo.Key() != "GameInfo" {
gameInfoNode, _ = gameInfo.Find("GameInfo")
} else {
gameInfoNode = gameInfo
}
if gameInfoNode == nil {
return nil, ErrorInvalidGameInfo
}
fsNode, _ := gameInfoNode.Find("FileSystem")

searchPathsNode, _ := fsNode.Find("SearchPaths")
Expand Down

0 comments on commit 4f11962

Please sign in to comment.