-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
93 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include <Client/System/GameDirectoryGuesser.hpp> | ||
#include <Shared/Utils/OSDetect.hpp> | ||
|
||
#ifdef WOS_WINDOWS | ||
# include <windows.h> | ||
# include <shlobj.h> | ||
#elif defined WOS_LINUX | ||
# include <pwd.h> | ||
# include <unistd.h> | ||
# include <cstdlib> | ||
#endif | ||
|
||
std::vector<std::string> GameDirectoryGuesser::getDirectoryList() | ||
{ | ||
std::vector<std::string> directories; | ||
|
||
#ifdef WOS_WINDOWS | ||
|
||
// TODO: Handle non-ASCII paths better. | ||
TCHAR programFilesDirectory[MAX_PATH]; | ||
TCHAR programFilesX86Directory[MAX_PATH]; | ||
SHGetFolderPath(nullptr, CSIDL_PROGRAM_FILES, nullptr, 0, programFilesDirectory); | ||
SHGetFolderPath(nullptr, CSIDL_PROGRAM_FILESX86, nullptr, 0, programFilesX86Directory); | ||
|
||
std::wstring programFilesW(programFilesDirectory); | ||
std::wstring programFilesX86W(programFilesX86Directory); | ||
|
||
std::string programFilesA(programFilesW.begin(), programFilesW.end()); | ||
std::string programFilesX86A(programFilesX86W.begin(), programFilesX86W.end()); | ||
|
||
directories.push_back(programFilesA + "\\Steam\\SteamApps\\common\\Crypt of the NecroDancer"); | ||
directories.push_back(programFilesX86A + "\\Steam\\SteamApps\\common\\Crypt of the NecroDancer"); | ||
|
||
#elif defined WOS_LINUX | ||
|
||
// Get user's home directory, if set through $HOME. | ||
const char * homeDirectoryPtr = std::getenv("HOME"); | ||
|
||
if (homeDirectoryPtr == nullptr) | ||
{ | ||
// Get user's home directory, if not set through $HOME. | ||
homeDirectoryPtr = getpwuid(getuid())->pw_dir; | ||
} | ||
|
||
if (homeDirectoryPtr != nullptr) | ||
{ | ||
std::string homeDirectory(homeDirectoryPtr); | ||
|
||
// Try all capitalization variants. The exact capitalization depends on when Steam was installed/cleaned. | ||
directories.push_back(homeDirectory + "/.local/share/steam/steamapps/common/Crypt of the NecroDancer"); | ||
directories.push_back(homeDirectory + "/.local/share/Steam/steamapps/common/Crypt of the NecroDancer"); | ||
directories.push_back(homeDirectory + "/.local/share/steam/SteamApps/common/Crypt of the NecroDancer"); | ||
directories.push_back(homeDirectory + "/.local/share/Steam/SteamApps/common/Crypt of the NecroDancer"); | ||
} | ||
|
||
#endif | ||
|
||
// TODO: Detect game path for Mac OS X. | ||
|
||
return directories; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#ifndef SRC_CLIENT_SYSTEM_GAMEDIRECTORYGUESSER_HPP_ | ||
#define SRC_CLIENT_SYSTEM_GAMEDIRECTORYGUESSER_HPP_ | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
class GameDirectoryGuesser | ||
{ | ||
public: | ||
|
||
static std::vector<std::string> getDirectoryList(); | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters