Skip to content

Commit

Permalink
feat: Make registry key configurable via software finder config
Browse files Browse the repository at this point in the history
  • Loading branch information
cetteup committed Jan 16, 2023
1 parent acfb7cd commit d473ea7
Show file tree
Hide file tree
Showing 18 changed files with 120 additions and 20 deletions.
3 changes: 3 additions & 0 deletions internal/domain/game_title_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func TestGameTitle_AddCustomConfig(t *testing.T) {
FinderConfigs: []software_finder.Config{
{
ForType: software_finder.RegistryFinder,
RegistryKey: software_finder.RegistryKeyLocalMachine,
RegistryPath: "default",
RegistryValueName: "default",
},
Expand Down Expand Up @@ -322,6 +323,7 @@ func TestGameMod_ComputeFinderConfigs(t *testing.T) {
finderConfigs: []software_finder.Config{
{
ForType: software_finder.RegistryFinder,
RegistryKey: software_finder.RegistryKeyLocalMachine,
RegistryPath: "some-game\\some-mod",
RegistryValueName: "InstallPath",
},
Expand All @@ -331,6 +333,7 @@ func TestGameMod_ComputeFinderConfigs(t *testing.T) {
expectedFinderConfigs: []software_finder.Config{
{
ForType: software_finder.RegistryFinder,
RegistryKey: software_finder.RegistryKeyLocalMachine,
RegistryPath: "some-game\\some-mod",
RegistryValueName: "InstallPath",
},
Expand Down
1 change: 1 addition & 0 deletions internal/platforms/origin.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var OriginClient = domain.PlatformClient{
Platform: domain.PlatformOrigin,
FinderConfig: software_finder.Config{
ForType: software_finder.RegistryFinder,
RegistryKey: software_finder.RegistryKeyLocalMachine,
RegistryPath: "SOFTWARE\\WOW6432Node\\Origin",
RegistryValueName: "ClientPath",
},
Expand Down
13 changes: 13 additions & 0 deletions internal/router/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func TestGameRouter_RegisterHandlers(t *testing.T) {
FinderConfigs: []software_finder.Config{
{
ForType: software_finder.RegistryFinder,
RegistryKey: software_finder.RegistryKeyLocalMachine,
RegistryPath: "SOFTWARE\\some-game",
RegistryValueName: "some-value-name",
},
Expand Down Expand Up @@ -128,6 +129,7 @@ func TestGameRouter_RegisterHandlers(t *testing.T) {
FinderConfigs: []software_finder.Config{
{
ForType: software_finder.RegistryFinder,
RegistryKey: software_finder.RegistryKeyLocalMachine,
RegistryPath: "SOFTWARE\\some-game",
RegistryValueName: "some-value-name",
},
Expand Down Expand Up @@ -174,13 +176,15 @@ func TestGameRouter_RegisterHandlers(t *testing.T) {
Platform: "some-platform",
FinderConfig: software_finder.Config{
ForType: software_finder.RegistryFinder,
RegistryKey: software_finder.RegistryKeyLocalMachine,
RegistryPath: "SOFTWARE\\some-client",
RegistryValueName: "some-value-name",
},
},
FinderConfigs: []software_finder.Config{
{
ForType: software_finder.RegistryFinder,
RegistryKey: software_finder.RegistryKeyLocalMachine,
RegistryPath: "SOFTWARE\\some-game",
RegistryValueName: "some-value-name",
},
Expand Down Expand Up @@ -220,6 +224,7 @@ func TestGameRouter_RegisterHandlers(t *testing.T) {
FinderConfigs: []software_finder.Config{
{
ForType: software_finder.RegistryFinder,
RegistryKey: software_finder.RegistryKeyLocalMachine,
RegistryPath: "SOFTWARE\\some-game",
RegistryValueName: "some-value-name",
},
Expand Down Expand Up @@ -258,6 +263,7 @@ func TestGameRouter_RegisterHandlers(t *testing.T) {
FinderConfigs: []software_finder.Config{
{
ForType: software_finder.RegistryFinder,
RegistryKey: software_finder.RegistryKeyLocalMachine,
RegistryPath: "SOFTWARE\\some-game",
RegistryValueName: "some-value-name",
},
Expand Down Expand Up @@ -293,13 +299,15 @@ func TestGameRouter_RegisterHandlers(t *testing.T) {
Platform: "some-platform",
FinderConfig: software_finder.Config{
ForType: software_finder.RegistryFinder,
RegistryKey: software_finder.RegistryKeyLocalMachine,
RegistryPath: "SOFTWARE\\some-client",
RegistryValueName: "some-value-name",
},
},
FinderConfigs: []software_finder.Config{
{
ForType: software_finder.RegistryFinder,
RegistryKey: software_finder.RegistryKeyLocalMachine,
RegistryPath: "SOFTWARE\\some-game",
RegistryValueName: "some-value-name",
},
Expand Down Expand Up @@ -335,6 +343,7 @@ func TestGameRouter_RegisterHandlers(t *testing.T) {
FinderConfigs: []software_finder.Config{
{
ForType: software_finder.RegistryFinder,
RegistryKey: software_finder.RegistryKeyLocalMachine,
RegistryPath: "SOFTWARE\\some-game",
RegistryValueName: "some-value-name",
},
Expand Down Expand Up @@ -364,13 +373,15 @@ func TestGameRouter_RegisterHandlers(t *testing.T) {
Platform: "some-platform",
FinderConfig: software_finder.Config{
ForType: software_finder.RegistryFinder,
RegistryKey: software_finder.RegistryKeyLocalMachine,
RegistryPath: "SOFTWARE\\some-client",
RegistryValueName: "some-value-name",
},
},
FinderConfigs: []software_finder.Config{
{
ForType: software_finder.RegistryFinder,
RegistryKey: software_finder.RegistryKeyLocalMachine,
RegistryPath: "SOFTWARE\\some-game",
RegistryValueName: "some-value-name",
},
Expand Down Expand Up @@ -400,6 +411,7 @@ func TestGameRouter_RegisterHandlers(t *testing.T) {
FinderConfigs: []software_finder.Config{
{
ForType: software_finder.RegistryFinder,
RegistryKey: software_finder.RegistryKeyLocalMachine,
RegistryPath: "SOFTWARE\\some-game",
RegistryValueName: "some-value-name",
},
Expand Down Expand Up @@ -429,6 +441,7 @@ func TestGameRouter_RegisterHandlers(t *testing.T) {
FinderConfigs: []software_finder.Config{
{
ForType: software_finder.RegistryFinder,
RegistryKey: software_finder.RegistryKeyLocalMachine,
RegistryPath: "SOFTWARE\\some-game",
RegistryValueName: "some-value-name",
},
Expand Down
1 change: 1 addition & 0 deletions internal/titles/bf1.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var Bf1 = domain.GameTitle{
FinderConfigs: []software_finder.Config{
{
ForType: software_finder.RegistryFinder,
RegistryKey: software_finder.RegistryKeyLocalMachine,
RegistryPath: "SOFTWARE\\WOW6432Node\\EA Games\\Battlefield 1",
RegistryValueName: "Install Dir",
},
Expand Down
3 changes: 3 additions & 0 deletions internal/titles/bf1942.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var Bf1942 = domain.GameTitle{
FinderConfigs: []software_finder.Config{
{
ForType: software_finder.RegistryFinder,
RegistryKey: software_finder.RegistryKeyLocalMachine,
RegistryPath: "SOFTWARE\\WOW6432Node\\EA Games\\Battlefield 1942",
RegistryValueName: "GAMEDIR",
},
Expand All @@ -38,6 +39,7 @@ var Bf1942 = domain.GameTitle{
[]software_finder.Config{
{
ForType: software_finder.RegistryFinder,
RegistryKey: software_finder.RegistryKeyLocalMachine,
RegistryPath: "SOFTWARE\\WOW6432Node\\EA Games\\Battlefield 1942 Xpack1",
RegistryValueName: "GAMEDIR",
},
Expand All @@ -54,6 +56,7 @@ var Bf1942 = domain.GameTitle{
[]software_finder.Config{
{
ForType: software_finder.RegistryFinder,
RegistryKey: software_finder.RegistryKeyLocalMachine,
RegistryPath: "SOFTWARE\\WOW6432Node\\EA Games\\Battlefield 1942 Xpack2",
RegistryValueName: "GAMEDIR",
},
Expand Down
2 changes: 2 additions & 0 deletions internal/titles/bf2.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var Bf2 = domain.GameTitle{
FinderConfigs: []software_finder.Config{
{
ForType: software_finder.RegistryFinder,
RegistryKey: software_finder.RegistryKeyLocalMachine,
RegistryPath: "SOFTWARE\\WOW6432Node\\Electronic Arts\\EA Games\\Battlefield 2",
RegistryValueName: "InstallDir",
},
Expand All @@ -39,6 +40,7 @@ var Bf2 = domain.GameTitle{
[]software_finder.Config{
{
ForType: software_finder.RegistryFinder,
RegistryKey: software_finder.RegistryKeyLocalMachine,
RegistryPath: "SOFTWARE\\WOW6432Node\\Electronic Arts\\EA Games\\Battlefield 2 Special Forces",
RegistryValueName: "InstallDir",
},
Expand Down
1 change: 1 addition & 0 deletions internal/titles/bf4.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var Bf4 = domain.GameTitle{
FinderConfigs: []software_finder.Config{
{
ForType: software_finder.RegistryFinder,
RegistryKey: software_finder.RegistryKeyLocalMachine,
RegistryPath: "SOFTWARE\\WOW6432Node\\EA Games\\Battlefield 4",
RegistryValueName: "Install Dir",
},
Expand Down
1 change: 1 addition & 0 deletions internal/titles/bfvietnam.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var BfVietnam = domain.GameTitle{
FinderConfigs: []software_finder.Config{
{
ForType: software_finder.RegistryFinder,
RegistryKey: software_finder.RegistryKeyLocalMachine,
RegistryPath: "SOFTWARE\\WOW6432Node\\EA Games\\Battlefield Vietnam",
RegistryValueName: "GAMEDIR",
},
Expand Down
2 changes: 2 additions & 0 deletions internal/titles/cod.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var Cod = domain.GameTitle{
FinderConfigs: []software_finder.Config{
{
ForType: software_finder.RegistryFinder,
RegistryKey: software_finder.RegistryKeyLocalMachine,
RegistryPath: "SOFTWARE\\WOW6432Node\\Activision\\Call of Duty",
RegistryValueName: "InstallPath",
},
Expand All @@ -31,6 +32,7 @@ var CodUO = domain.GameTitle{
FinderConfigs: []software_finder.Config{
{
ForType: software_finder.RegistryFinder,
RegistryKey: software_finder.RegistryKeyLocalMachine,
RegistryPath: "SOFTWARE\\WOW6432Node\\Activision\\Call of Duty United Offensive",
RegistryValueName: "InstallPath",
},
Expand Down
1 change: 1 addition & 0 deletions internal/titles/cod2.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var Cod2 = domain.GameTitle{
FinderConfigs: []software_finder.Config{
{
ForType: software_finder.RegistryFinder,
RegistryKey: software_finder.RegistryKeyLocalMachine,
RegistryPath: "SOFTWARE\\WOW6432Node\\Activision\\Call of Duty 2",
RegistryValueName: "InstallPath",
},
Expand Down
1 change: 1 addition & 0 deletions internal/titles/cod4.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var Cod4 = domain.GameTitle{
FinderConfigs: []software_finder.Config{
{
ForType: software_finder.RegistryFinder,
RegistryKey: software_finder.RegistryKeyLocalMachine,
RegistryPath: "SOFTWARE\\WOW6432Node\\Activision\\Call of Duty 4",
RegistryValueName: "InstallPath",
},
Expand Down
1 change: 1 addition & 0 deletions internal/titles/codwaw.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var CodWaw = domain.GameTitle{
FinderConfigs: []software_finder.Config{
{
ForType: software_finder.RegistryFinder,
RegistryKey: software_finder.RegistryKeyLocalMachine,
RegistryPath: "SOFTWARE\\WOW6432Node\\Activision\\Call of Duty WAW",
RegistryValueName: "InstallPath",
},
Expand Down
1 change: 1 addition & 0 deletions internal/titles/fear_sec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var FearSec2 = domain.GameTitle{
FinderConfigs: []software_finder.Config{
{
ForType: software_finder.RegistryFinder,
RegistryKey: software_finder.RegistryKeyLocalMachine,
RegistryPath: "SOFTWARE\\WOW6432Node\\FEAR-Community.org\\FEAR Combat (SEC2)",
RegistryValueName: "Path",
},
Expand Down
1 change: 1 addition & 0 deletions internal/titles/paraworld.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var Paraworld = domain.GameTitle{
FinderConfigs: []software_finder.Config{
{
ForType: software_finder.RegistryFinder,
RegistryKey: software_finder.RegistryKeyLocalMachine,
RegistryPath: "SOFTWARE\\WOW6432Node\\Sunflowers\\ParaWorld",
RegistryValueName: "InstallDir",
},
Expand Down
4 changes: 4 additions & 0 deletions internal/titles/swat4.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ var Swat4 = domain.GameTitle{
FinderConfigs: []software_finder.Config{
{
ForType: software_finder.RegistryFinder,
RegistryKey: software_finder.RegistryKeyLocalMachine,
RegistryPath: "SOFTWARE\\WOW6432Node\\Sierra\\SWAT 4",
RegistryValueName: "InstallPath",
},
{
ForType: software_finder.RegistryFinder,
RegistryKey: software_finder.RegistryKeyLocalMachine,
RegistryPath: "SOFTWARE\\WOW6432Node\\GOG.com\\Games\\1409964317",
RegistryValueName: "PATH",
},
Expand Down Expand Up @@ -48,11 +50,13 @@ var Swat4X = domain.GameTitle{
FinderConfigs: []software_finder.Config{
{
ForType: software_finder.RegistryFinder,
RegistryKey: software_finder.RegistryKeyLocalMachine,
RegistryPath: "SOFTWARE\\WOW6432Node\\Sierra\\SWAT 4 - THE STETCHKOV SYNDICATE",
RegistryValueName: "InstallPath",
},
{
ForType: software_finder.RegistryFinder,
RegistryKey: software_finder.RegistryKeyLocalMachine,
RegistryPath: "SOFTWARE\\WOW6432Node\\GOG.com\\Games\\1409964317",
RegistryValueName: "PATH",
},
Expand Down
1 change: 1 addition & 0 deletions internal/titles/vietcong.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var Vietcong = domain.GameTitle{
FinderConfigs: []software_finder.Config{
{
ForType: software_finder.RegistryFinder,
RegistryKey: software_finder.RegistryKeyLocalMachine,
RegistryPath: "SOFTWARE\\WOW6432Node\\Pterodon\\Vietcong",
RegistryValueName: "InstallDir",
},
Expand Down
7 changes: 6 additions & 1 deletion pkg/software_finder/software_finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ import (
)

type FinderType string
type RegistryKey registry.Key
type PathType int

const (
RegistryFinder FinderType = "RegistryFinder"
PathFinder FinderType = "PathFinder"

RegistryKeyCurrentUser = RegistryKey(registry.CURRENT_USER)
RegistryKeyLocalMachine = RegistryKey(registry.LOCAL_MACHINE)

PathTypeFile = iota
PathTypeDir
)
Expand All @@ -32,6 +36,7 @@ type FileRepository interface {

type Config struct {
ForType FinderType
RegistryKey RegistryKey
RegistryPath string
RegistryValueName string
InstallPath string
Expand Down Expand Up @@ -159,5 +164,5 @@ func (f *SoftwareFinder) getInstallDirFromPath(config Config) (string, error) {
}

func (f *SoftwareFinder) getInstallDirFromRegistry(config Config) (string, error) {
return f.registryRepository.GetStringValue(registry.LOCAL_MACHINE, config.RegistryPath, config.RegistryValueName)
return f.registryRepository.GetStringValue(registry.Key(config.RegistryKey), config.RegistryPath, config.RegistryValueName)
}
Loading

0 comments on commit d473ea7

Please sign in to comment.