Skip to content

Commit

Permalink
- Added Steam detection for Stife: Veteran Edition.
Browse files Browse the repository at this point in the history
- Added Steam install scanning for Linux and OS X. (OS X and Win32 not yet tested.)
  • Loading branch information
Blzut3 committed Dec 12, 2014
1 parent 372f7e7 commit 86372fc
Show file tree
Hide file tree
Showing 7 changed files with 257 additions and 27 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ set( PLAT_SDL_SYSTEM_SOURCES
sdl/i_cd.cpp
sdl/i_main.cpp
sdl/i_movie.cpp
sdl/i_steam.cpp
sdl/i_system.cpp
sdl/sdlvideo.cpp
sdl/st_start.cpp )
Expand Down
8 changes: 8 additions & 0 deletions src/cocoa/i_backend_cocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1619,6 +1619,14 @@ bool I_SetCursor(FTexture* cursorpic)
}


FString OSX_FindApplicationSupport()
{
NSURL *url = [[NSFileManager defaultManager] URLForDirectory:NSApplicationSupportDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:nil];
if(url == nil)
return FString();
return [[url path] UTF8String];
}

// ---------------------------------------------------------------------------


Expand Down
22 changes: 3 additions & 19 deletions src/d_iwad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,27 +430,11 @@ int FIWadManager::IdentifyVersion (TArray<FString> &wadfiles, const char *iwad,
}
}
}
#ifdef _WIN32
FString steam_path = I_GetSteamPath();
if (steam_path.IsNotEmpty())
TArray<FString> steam_path = I_GetSteamPath();
for (i = 0; i < steam_path.Size(); ++i)
{
static const char *const steam_dirs[] =
{
"doom 2/base",
"final doom/base",
"heretic shadow of the serpent riders/base",
"hexen/base",
"hexen deathkings of the dark citadel/base",
"ultimate doom/base",
"DOOM 3 BFG Edition/base/wads"
};
steam_path += "/SteamApps/common/";
for (i = 0; i < countof(steam_dirs); ++i)
{
CheckIWAD (steam_path + steam_dirs[i], &wads[0]);
}
CheckIWAD (steam_path[i], &wads[0]);
}
#endif
}

if (iwadparm != NULL && !wads[0].Path.IsEmpty())
Expand Down
217 changes: 217 additions & 0 deletions src/sdl/i_steam.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
/*
** i_steam.cpp
**
**---------------------------------------------------------------------------
** Copyright 2013 Braden Obrzut
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
** are met:
**
** 1. Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** 2. Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in the
** documentation and/or other materials provided with the distribution.
** 3. The name of the author may not be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**---------------------------------------------------------------------------
**
**
*/

#include <sys/stat.h>

#include "doomerrors.h"
#include "d_main.h"
#include "zstring.h"
#include "sc_man.h"

static void PSR_FindEndBlock(FScanner &sc)
{
int depth = 1;
do
{
if(sc.CheckToken('}'))
--depth;
else if(sc.CheckToken('{'))
++depth;
else
sc.MustGetAnyToken();
}
while(depth);
}
static void PSR_SkipBlock(FScanner &sc)
{
sc.MustGetToken('{');
PSR_FindEndBlock(sc);
}
static bool PSR_FindAndEnterBlock(FScanner &sc, const char* keyword)
{
// Finds a block with a given keyword and then enter it (opening brace)
// Should be closed with PSR_FindEndBlock
while(sc.GetToken())
{
if(sc.TokenType == '}')
{
sc.UnGet();
return false;
}

sc.TokenMustBe(TK_StringConst);
if(!sc.Compare(keyword))
{
if(!sc.CheckToken(TK_StringConst))
PSR_SkipBlock(sc);
}
else
{
sc.MustGetToken('{');
return true;
}
}
return false;
}
static TArray<FString> PSR_ReadBaseInstalls(FScanner &sc)
{
TArray<FString> result;

// Get a list of possible install directories.
while(sc.GetToken())
{
if(sc.TokenType == '}')
break;

sc.TokenMustBe(TK_StringConst);
FString key(sc.String);
if(key.Left(18).CompareNoCase("BaseInstallFolder_") == 0)
{
sc.MustGetToken(TK_StringConst);
result.Push(sc.String);
}
else
{
if(sc.CheckToken('{'))
PSR_FindEndBlock(sc);
else
sc.MustGetToken(TK_StringConst);
}
}

return result;
}
static TArray<FString> ParseSteamRegistry(const char* path)
{
TArray<FString> dirs;

// Read registry data
FScanner sc;
sc.OpenFile(path);
sc.SetCMode(true);

// Find the SteamApps listing
if(PSR_FindAndEnterBlock(sc, "InstallConfigStore"))
{
if(PSR_FindAndEnterBlock(sc, "Software"))
{
if(PSR_FindAndEnterBlock(sc, "Valve"))
{
if(PSR_FindAndEnterBlock(sc, "Steam"))
{
dirs = PSR_ReadBaseInstalls(sc);
}
PSR_FindEndBlock(sc);
}
PSR_FindEndBlock(sc);
}
PSR_FindEndBlock(sc);
}

return dirs;
}

static struct SteamAppInfo
{
const char* const BasePath;
const int AppID;
} AppInfo[] =
{
/*{"doom 2/base", 2300},
{"final doom/base", 2290},
{"heretic shadow of the serpent riders/base", 2390},
{"hexen/base", 2360},
{"hexen deathkings of the dark citadel/base", 2370},
{"ultimate doom/base", 2280},
{"DOOM 3 BFG Edition/base/wads", 208200},*/
{"Strife", 317040}
};

TArray<FString> I_GetSteamPath()
{
TArray<FString> result;
TArray<FString> SteamInstallFolders;

// Linux and OS X actually allow the user to install to any location, so
// we need to figure out on an app-by-app basis where the game is installed.
// To do so, we read the virtual registry.
#ifdef __APPLE__
FString OSX_FindApplicationSupport();

FString regPath = OSX_FindApplicationSupport() + "/Steam/config/config.vdf";
try
{
SteamInstallFolders = ParseSteamRegistry(regPath);
}
catch(class CDoomError &error)
{
// If we can't parse for some reason just pretend we can't find anything.
return result;
}

SteamInstallFolders.Push(OSX_FindApplicationSupport() + "/Steam/SteamApps/common");
#else
char* home = getenv("HOME");
if(home != NULL && *home != '\0')
{
FString regPath;
regPath.Format("%s/.local/share/Steam/config/config.vdf", home);
try
{
SteamInstallFolders = ParseSteamRegistry(regPath);
}
catch(class CDoomError &error)
{
// If we can't parse for some reason just pretend we can't find anything.
return result;
}

regPath.Format("%s/.local/share/Steam/SteamApps/common", home);
SteamInstallFolders.Push(regPath);
}
#endif

for(unsigned int i = 0;i < SteamInstallFolders.Size();++i)
{
for(unsigned int app = 0;app < countof(AppInfo);++app)
{
struct stat st;
FString candidate(SteamInstallFolders[i] + "/" + AppInfo[app].BasePath);
if(stat(candidate, &st) == 0 && S_ISDIR(st.st_mode))
result.Push(candidate);
}
}

return result;
}
4 changes: 4 additions & 0 deletions src/sdl/i_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ void I_SetIWADInfo ();
// Pick from multiple IWADs to use
int I_PickIWad (WadStuff *wads, int numwads, bool queryiwad, int defaultiwad);

// [RH] Checks the registry for Steam's install path, so we can scan its
// directories for IWADs if the user purchased any through Steam.
TArray<FString> I_GetSteamPath();

// The ini could not be saved at exit
bool I_WriteIniFailed ();

Expand Down
30 changes: 23 additions & 7 deletions src/win32/i_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1524,20 +1524,36 @@ static bool QueryPathKey(HKEY key, const char *keypath, const char *valname, FSt
//
//==========================================================================

FString I_GetSteamPath()
TArray<FString> I_GetSteamPath()
{
TArray<FString> result;
static const char *const steam_dirs[] =
{
"doom 2/base",
"final doom/base",
"heretic shadow of the serpent riders/base",
"hexen/base",
"hexen deathkings of the dark citadel/base",
"ultimate doom/base",
"DOOM 3 BFG Edition/base/wads",
"Strife"
};

FString path;

if (QueryPathKey(HKEY_CURRENT_USER, "Software\\Valve\\Steam", "SteamPath", path))
if (!QueryPathKey(HKEY_CURRENT_USER, "Software\\Valve\\Steam", "SteamPath", path))
{
return path;
if (!QueryPathKey(HKEY_LOCAL_MACHINE, "Software\\Valve\\Steam", "InstallPath", path))
return result;
}
if (QueryPathKey(HKEY_LOCAL_MACHINE, "Software\\Valve\\Steam", "InstallPath", path))
path += "/SteamApps/common/";

for(unsigned int i = 0; i < countof(steam_dirs); ++i)
{
return path;
result.Push(path + steam_dirs[i]);
}
path = "";
return path;

return result;
}

//==========================================================================
Expand Down
2 changes: 1 addition & 1 deletion src/win32/i_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void I_SetWndProc();

// [RH] Checks the registry for Steam's install path, so we can scan its
// directories for IWADs if the user purchased any through Steam.
FString I_GetSteamPath();
TArray<FString> I_GetSteamPath();

// Damn Microsoft for doing Get/SetWindowLongPtr half-assed. Instead of
// giving them proper prototypes under Win32, they are just macros for
Expand Down

0 comments on commit 86372fc

Please sign in to comment.