C7-Game / Prototype

An early-stage, open-source 4X strategy game
https://c7-game.github.io/
MIT License
32 stars 9 forks source link

Steam Install Auto-Detect 2.0 #444

Open QuintillusCFC opened 2 months ago

QuintillusCFC commented 2 months ago

Spinning off of #442 ... (tagging @pcen , thanks for confirming how it works on Win11)

Based on our limited sample size, it appears that on Windows 11, the Civ III install path is not set in the registry upon installing the game via Steam. The PR listed above added a check for Civ III in the default Steam folder.

However, not everyone installs Steam to the default folder, and even for those who do, they may install games on a secondary drive. This issue is to handle those cases.

For the first part, it looks like the install path is stored in the registry at Computer\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Valve\Steam, with the InstallPath key; in my case it is C:\Games\Steam. This will let you know where Steam is installed, and Civ III can be checked for in that location.

If it isn't found there, the file /config/config.vdf lists the install folders. It's JSON-y but I haven't verified if it's really JSON, and we only need 1% of it, which conveniently is near the beginning:

"InstallConfigStore"
{
    "Software"
    {
        "valve"
        {
            "Steam"
            {
                "BaseInstallFolder_1"       "D:\\Games\\Steam Library"
                "BaseInstallFolder_2"       "G:\\Games\\Steam"

These BaseInstallFolder entries list other Steam directories. Game folders are within the steamapps/common sub-directories of those, just like within the main Steam folder.

The combination of these two steps should theoretically find Civ III reliably whenever it is installed by Steam. We already theoretically have the CD case covered (as in theory it should always set the registry, particularly as the CD implies Windows 8.1 or earlier due to SecuROM being removed in Win10), which leaves GOG detection (when it doesn't set the registry) as the remaining follow up once this one is done.

(@WildWeazel Any pointers on how to detect the Steam install location on Linux? I don't suppose Proton emulates the Windows registry for us? Depending on the complexity it may or may not warrant a spin-off ticket)

WildWeazel commented 1 month ago

I have no idea, but I have Steam installed as a flatpak in my home partition and Civ3 in a secondary library on another device, so it'll be a fun use case!

Edit: turns out it's easy. https://unix.stackexchange.com/questions/735211/how-to-get-steam-game-install-save-file-path-programmatically