summaryrefslogtreecommitdiff
path: root/src/shared/gameinfo.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/gameinfo.cpp')
-rw-r--r--src/shared/gameinfo.cpp114
1 files changed, 34 insertions, 80 deletions
diff --git a/src/shared/gameinfo.cpp b/src/shared/gameinfo.cpp
index 6a6e6c22..6d8957ad 100644
--- a/src/shared/gameinfo.cpp
+++ b/src/shared/gameinfo.cpp
@@ -27,19 +27,21 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include "skyriminfo.h"
#include "util.h"
+#include <boost/assign.hpp>
+#include <boost/format.hpp>
+
#include <shlobj.h>
#include <sstream>
#include <cassert>
-#include <boost/assign.hpp>
namespace MOShared {
-GameInfo* GameInfo::s_Instance = NULL;
+GameInfo* GameInfo::s_Instance = nullptr;
-GameInfo::GameInfo(const std::wstring &omoDirectory, const std::wstring &gameDirectory)
- : m_GameDirectory(gameDirectory), m_OrganizerDirectory(omoDirectory)
+GameInfo::GameInfo(const std::wstring &moDirectory, const std::wstring &moDataDirectory, const std::wstring &gameDirectory)
+ : m_GameDirectory(gameDirectory), m_OrganizerDirectory(moDirectory), m_OrganizerDataDirectory(moDataDirectory)
{
atexit(&cleanup);
}
@@ -47,7 +49,7 @@ GameInfo::GameInfo(const std::wstring &omoDirectory, const std::wstring &gameDir
void GameInfo::cleanup() {
delete GameInfo::s_Instance;
- GameInfo::s_Instance = NULL;
+ GameInfo::s_Instance = nullptr;
}
@@ -60,56 +62,61 @@ void GameInfo::identifyMyGamesDirectory(const std::wstring &file)
m_MyGamesDirectory.clear();
// a) this is the way it should work. get the configured My Documents\My Games directory
- if (::SHGetFolderPathW(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, myDocuments) == S_OK) {
+ if (::SHGetFolderPathW(nullptr, CSIDL_PERSONAL, nullptr, SHGFP_TYPE_CURRENT, myDocuments) == S_OK) {
m_MyGamesDirectory = std::wstring(myDocuments) + L"\\My Games";
}
// b) if there is no <game> directory there, look in the default directory
if (m_MyGamesDirectory.empty()
|| !FileExists(m_MyGamesDirectory + L"\\" + file)) {
- if (::SHGetFolderPathW(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_DEFAULT, myDocuments) == S_OK) {
+ if (::SHGetFolderPathW(nullptr, CSIDL_PERSONAL, nullptr, SHGFP_TYPE_DEFAULT, myDocuments) == S_OK) {
std::wstring fromDefault = std::wstring(myDocuments) + L"\\My Games";
if (FileExists(fromDefault + L"\\" + file)) {
m_MyGamesDirectory = fromDefault;
}
}
}
- if (!FileExists(m_MyGamesDirectory.substr().append(L"/").append(file))) {
- m_MyGamesDirectory.assign(getSpecialPath(L"Personal")).append(L"\\My Games");
+ // c) finally, look in the registry. This is discouraged
+ if (m_MyGamesDirectory.empty()
+ || !FileExists(m_MyGamesDirectory + L"\\" + file)) {
+ std::wstring fromRegistry = getSpecialPath(L"Personal") + L"\\My Games";
+ if (FileExists(fromRegistry + L"\\" + file)) {
+ m_MyGamesDirectory = fromRegistry;
+ }
}
}
-bool GameInfo::identifyGame(const std::wstring &moDirectory, const std::wstring &searchPath)
+bool GameInfo::identifyGame(const std::wstring &moDirectory, const std::wstring &moDataDirectory, const std::wstring &searchPath)
{
if (OblivionInfo::identifyGame(searchPath)) {
- s_Instance = new OblivionInfo(moDirectory, searchPath);
+ s_Instance = new OblivionInfo(moDirectory, moDataDirectory, searchPath);
} else if (Fallout3Info::identifyGame(searchPath)) {
- s_Instance = new Fallout3Info(moDirectory, searchPath);
+ s_Instance = new Fallout3Info(moDirectory, moDataDirectory, searchPath);
} else if (FalloutNVInfo::identifyGame(searchPath)) {
- s_Instance = new FalloutNVInfo(moDirectory, searchPath);
+ s_Instance = new FalloutNVInfo(moDirectory, moDataDirectory, searchPath);
} else if (SkyrimInfo::identifyGame(searchPath)) {
- s_Instance = new SkyrimInfo(moDirectory, searchPath);
+ s_Instance = new SkyrimInfo(moDirectory, moDataDirectory, searchPath);
}
- return s_Instance != NULL;
+ return s_Instance != nullptr;
}
-bool GameInfo::init(const std::wstring &moDirectory, const std::wstring &gamePath)
+bool GameInfo::init(const std::wstring &moDirectory, const std::wstring &moDataDirectory, const std::wstring &gamePath)
{
- if (s_Instance == NULL) {
+ if (s_Instance == nullptr) {
if (gamePath.length() == 0) {
// search upward in the directory until a recognized game-binary is found
std::wstring searchPath(moDirectory);
- while (!identifyGame(moDirectory, searchPath)) {
+ while (!identifyGame(moDirectory, moDataDirectory, searchPath)) {
size_t lastSep = searchPath.find_last_of(L"/\\");
if (lastSep == std::string::npos) {
return false;
}
searchPath.erase(lastSep);
}
- } else if (!identifyGame(moDirectory, gamePath)) {
+ } else if (!identifyGame(moDirectory, moDataDirectory, gamePath)) {
return false;
}
}
@@ -119,7 +126,7 @@ bool GameInfo::init(const std::wstring &moDirectory, const std::wstring &gamePat
GameInfo &GameInfo::instance()
{
- assert(s_Instance != NULL);
+ assert(s_Instance != nullptr && "gameinfo not yet initialized");
return *s_Instance;
}
@@ -128,61 +135,9 @@ std::wstring GameInfo::getGameDirectory() const
return m_GameDirectory;
}
-std::wstring GameInfo::getModsDir() const
-{
- return m_OrganizerDirectory + L"\\mods";
-}
-
-std::wstring GameInfo::getProfilesDir() const
-{
- return m_OrganizerDirectory + L"\\profiles";
-}
-
-std::wstring GameInfo::getIniFilename() const
-{
- return m_OrganizerDirectory + L"\\ModOrganizer.ini";
-}
-
-
-std::wstring GameInfo::getDownloadDir() const
-{
- return m_OrganizerDirectory + L"\\downloads";
-}
-
-
-std::wstring GameInfo::getCacheDir() const
-{
- return m_OrganizerDirectory + L"\\webcache";
-}
-
-
-std::wstring GameInfo::getOverwriteDir() const
-{
- return m_OrganizerDirectory + L"\\overwrite";
-}
-
-
-std::wstring GameInfo::getLogDir() const
-{
- return m_OrganizerDirectory + L"\\logs";
-}
-
-
-std::wstring GameInfo::getLootDir() const
-{
- return m_OrganizerDirectory + L"\\loot";
-}
-
-
-std::wstring GameInfo::getTutorialDir() const
-{
- return m_OrganizerDirectory + L"\\tutorials";
-}
-
-
bool GameInfo::requiresSteam() const
{
- return FileExists(getGameDirectory().append(L"\\steam_api.dll"));
+ return FileExists(getGameDirectory() + L"\\steam_api.dll");
}
std::vector<std::wstring> GameInfo::getSteamVariants() const
@@ -190,13 +145,12 @@ std::vector<std::wstring> GameInfo::getSteamVariants() const
return boost::assign::list_of(L"Regular");
}
-
std::wstring GameInfo::getLocalAppFolder() const
{
wchar_t localAppFolder[MAX_PATH];
memset(localAppFolder, '\0', MAX_PATH * sizeof(wchar_t));
- if (::SHGetFolderPathW(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, localAppFolder) == S_OK) {
+ if (::SHGetFolderPathW(nullptr, CSIDL_LOCAL_APPDATA, nullptr, SHGFP_TYPE_CURRENT, localAppFolder) == S_OK) {
return localAppFolder;
} else {
// fallback: try the registry
@@ -207,19 +161,19 @@ std::wstring GameInfo::getLocalAppFolder() const
std::wstring GameInfo::getSpecialPath(LPCWSTR name) const
{
HKEY key;
- LONG errorcode = ::RegOpenKeyEx(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders",
- 0, KEY_QUERY_VALUE, &key);
+ LONG errorcode = ::RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders",
+ 0, KEY_QUERY_VALUE, &key);
if (errorcode != ERROR_SUCCESS) {
- throw windows_error("failed to look up special folder", errorcode);
+ throw windows_error("failed to look up special folder (path)", errorcode);
}
WCHAR temp[MAX_PATH];
DWORD bufferSize = MAX_PATH;
- errorcode = ::RegQueryValueExW(key, name, NULL, NULL, (LPBYTE)temp, &bufferSize);
+ errorcode = ::RegQueryValueExW(key, name, nullptr, nullptr, (LPBYTE)temp, &bufferSize);
if (errorcode != ERROR_SUCCESS) {
- throw windows_error("failed to look up special folder", errorcode);
+ throw windows_error((boost::format("failed to look up special folder (%1%)") % ToString(name, true)).str(), errorcode);
}
WCHAR temp2[MAX_PATH];