Skip to content

Commit

Permalink
Find case-insensitive VDF keys
Browse files Browse the repository at this point in the history
  • Loading branch information
leighmacdonald committed Mar 13, 2023
1 parent 0672324 commit b0b38e1
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions internal/detector/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func getUserLaunchArgs(logger *zap.Logger, steamRoot string, steamID steamid.SID
if errConfigPath != nil {
return nil, errors.Wrap(errConfigPath, "Failed to locate localconfig.vdf")
}
logger.Info("Reading userdata", zap.String("path", localConfigPath))
openVDF, errOpen := os.Open(localConfigPath)
if errOpen != nil {
return nil, errors.Wrap(errOpen, "failed to open vdf")
Expand All @@ -36,19 +37,33 @@ func getUserLaunchArgs(logger *zap.Logger, steamRoot string, steamID steamid.SID
}
var (
ok bool
found bool
launchOpts []string
pathKeys = []string{"UserLocalConfigStore", "Software", "Valve", "Steam", "apps", "440"}
pathKeys = []string{"UserLocalConfigStore", "Software", "Valve", "sTeam", "apps", "440"}
)
for i, key := range pathKeys {
result, ok = result[key].(map[string]any)
// Find a matching existing key using case-insensitive match since casing can vary
csKey := key
for k := range result {
if strings.EqualFold(k, key) {
csKey = k
break
}
}
result, ok = result[csKey].(map[string]any)
if !ok {
return nil, errors.Wrapf(errOpen, "failed to find child key %s", key)
}

if i == len(pathKeys)-1 {
logger.Info("Raw args via userdata", zap.String("args", result["LaunchOptions"].(string)))
launchOpts = strings.Split(result["LaunchOptions"].(string), " ")
found = true
}
}
if !found {
return nil, errors.New("Failed to read LaunchOptions key")
}
return launchOpts, nil
}

Expand All @@ -73,6 +88,7 @@ func getLaunchArgs(logger *zap.Logger, rconPass string, rconPort uint16, steamRo
"-condebug",
"-conclearlog",
}

var full []string
for _, arg := range append(bdArgs, userArgs...) {
arg = strings.Trim(arg, " ")
Expand Down

0 comments on commit b0b38e1

Please sign in to comment.