forked from OpenEnroth/OpenEnroth
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
ebc36fa
commit 1f32572
Showing
8 changed files
with
128 additions
and
95 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
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
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 |
---|---|---|
@@ -1,81 +1,95 @@ | ||
#include <vector> | ||
|
||
#include "Application/GamePathResolver.h" | ||
#include "GamePathResolver.h" | ||
|
||
#include "Library/Logger/Logger.h" | ||
#include "Library/Environment/Interface/Environment.h" | ||
|
||
static std::string _resolvePath(Environment *environment, const char *envVarOverride, const std::vector<const char *> ®istryKeys); | ||
struct PathResolutionConfig { | ||
const char *overrideEnvKey = nullptr; | ||
std::initializer_list<const char *> registryKeys; | ||
}; | ||
|
||
std::string resolveMm6Path(Environment *environment) { | ||
return _resolvePath( | ||
environment, | ||
mm6PathOverrideKey, | ||
{ | ||
"HKEY_LOCAL_MACHINE/SOFTWARE/GOG.com/Games/1207661253/PATH", | ||
"HKEY_LOCAL_MACHINE/SOFTWARE/GOG.com/GOGMM6/PATH", | ||
"HKEY_LOCAL_MACHINE/SOFTWARE/New World Computing/Might and Magic\xC2\xAE VI/1.0/AppPath", // \xC2\xAE is (R) in utf-8. | ||
"HKEY_LOCAL_MACHINE/SOFTWARE/WOW6432Node/GOG.com/Games/1207661253/PATH", | ||
"HKEY_LOCAL_MACHINE/SOFTWARE/WOW6432Node/GOG.com/GOGMM6/PATH", | ||
"HKEY_LOCAL_MACHINE/SOFTWARE/WOW6432Node/New World Computing/Might and Magic\xC2\xAE VI/1.0/AppPath", | ||
} | ||
); | ||
} | ||
static constexpr PathResolutionConfig mm6Config = { | ||
mm6PathOverrideKey, | ||
{ | ||
"HKEY_LOCAL_MACHINE/SOFTWARE/GOG.com/Games/1207661253/PATH", | ||
"HKEY_LOCAL_MACHINE/SOFTWARE/GOG.com/GOGMM6/PATH", | ||
"HKEY_LOCAL_MACHINE/SOFTWARE/New World Computing/Might and Magic\xC2\xAE VI/1.0/AppPath", // \xC2\xAE is (R) in utf-8. | ||
"HKEY_LOCAL_MACHINE/SOFTWARE/WOW6432Node/GOG.com/Games/1207661253/PATH", | ||
"HKEY_LOCAL_MACHINE/SOFTWARE/WOW6432Node/GOG.com/GOGMM6/PATH", | ||
"HKEY_LOCAL_MACHINE/SOFTWARE/WOW6432Node/New World Computing/Might and Magic\xC2\xAE VI/1.0/AppPath", | ||
} | ||
}; | ||
|
||
static constexpr PathResolutionConfig mm7Config = { | ||
mm7PathOverrideKey, | ||
{ | ||
"HKEY_LOCAL_MACHINE/SOFTWARE/GOG.com/Games/1207658916/Path", | ||
"HKEY_LOCAL_MACHINE/SOFTWARE/GOG.com/GOGMM7/PATH", | ||
"HKEY_LOCAL_MACHINE/SOFTWARE/New World Computing/Might and Magic VII/1.0/AppPath", | ||
"HKEY_LOCAL_MACHINE/SOFTWARE/WOW6432Node/GOG.com/Games/1207658916/Path", | ||
"HKEY_LOCAL_MACHINE/SOFTWARE/WOW6432Node/GOG.com/GOGMM7/PATH", | ||
"HKEY_LOCAL_MACHINE/SOFTWARE/WOW6432Node/New World Computing/Might and Magic VII/1.0/AppPath", | ||
} | ||
}; | ||
|
||
std::string resolveMm7Path(Environment *environment) { | ||
return _resolvePath( | ||
environment, | ||
mm7PathOverrideKey, | ||
{ | ||
"HKEY_LOCAL_MACHINE/SOFTWARE/GOG.com/Games/1207658916/Path", | ||
"HKEY_LOCAL_MACHINE/SOFTWARE/GOG.com/GOGMM7/PATH", | ||
"HKEY_LOCAL_MACHINE/SOFTWARE/New World Computing/Might and Magic VII/1.0/AppPath", | ||
"HKEY_LOCAL_MACHINE/SOFTWARE/WOW6432Node/GOG.com/Games/1207658916/Path", | ||
"HKEY_LOCAL_MACHINE/SOFTWARE/WOW6432Node/GOG.com/GOGMM7/PATH", | ||
"HKEY_LOCAL_MACHINE/SOFTWARE/WOW6432Node/New World Computing/Might and Magic VII/1.0/AppPath", | ||
} | ||
); | ||
} | ||
static constexpr PathResolutionConfig mm8Config = { | ||
mm8PathOverrideKey, | ||
{ | ||
"HKEY_LOCAL_MACHINE/SOFTWARE/GOG.com/GOGMM8/PATH", | ||
"HKEY_LOCAL_MACHINE/SOFTWARE/New World Computing/Might and Magic Day of the Destroyer/1.0/AppPath", | ||
"HKEY_LOCAL_MACHINE/SOFTWARE/WOW6432Node/GOG.com/GOGMM8/PATH", | ||
"HKEY_LOCAL_MACHINE/SOFTWARE/WOW6432Node/New World Computing/Might and Magic Day of the Destroyer/1.0/AppPath", | ||
} | ||
}; | ||
|
||
static std::vector<std::string> resolvePaths(Environment *environment, const PathResolutionConfig &config) { | ||
std::string envPath = environment->getenv(config.overrideEnvKey); | ||
if (!envPath.empty()) { | ||
logger->info("Path override provided, '{}={}'.", config.overrideEnvKey, envPath); | ||
return {envPath}; // Have path override => this is the only one we'll try. | ||
} | ||
|
||
std::string resolveMm8Path(Environment *environment) { | ||
return _resolvePath( | ||
environment, | ||
mm8PathOverrideKey, | ||
{ | ||
"HKEY_LOCAL_MACHINE/SOFTWARE/GOG.com/GOGMM8/PATH", | ||
"HKEY_LOCAL_MACHINE/SOFTWARE/New World Computing/Might and Magic Day of the Destroyer/1.0/AppPath", | ||
"HKEY_LOCAL_MACHINE/SOFTWARE/WOW6432Node/GOG.com/GOGMM8/PATH", | ||
"HKEY_LOCAL_MACHINE/SOFTWARE/WOW6432Node/New World Computing/Might and Magic Day of the Destroyer/1.0/AppPath", | ||
} | ||
); | ||
} | ||
std::vector<std::string> result; | ||
|
||
static std::string _resolvePath(Environment *environment, const char *envVarOverride, const std::vector<const char *> ®istryKeys) { | ||
#ifdef __ANDROID__ | ||
// TODO: find a better way to deal with paths and remove this android specific block. | ||
std::string result = environment->path(PATH_ANDROID_STORAGE_EXTERNAL); | ||
if (result.empty()) | ||
result = environment->path(PATH_ANDROID_STORAGE_INTERNAL); | ||
// Windows-specific. | ||
for (const char *registryKey : config.registryKeys) { | ||
std::string registryPath = environment->queryRegistry(registryKey); | ||
if (!registryPath.empty()) | ||
result.push_back(registryPath); | ||
} | ||
|
||
// Android-specific. | ||
std::string externalPath = environment->path(PATH_ANDROID_STORAGE_EXTERNAL); | ||
if (!externalPath.empty()) | ||
result.push_back(externalPath); | ||
std::string internalPath = environment->path(PATH_ANDROID_STORAGE_INTERNAL); | ||
if (!internalPath.empty()) | ||
result.push_back(internalPath); | ||
// TODO(captainurist): need a mechanism to show user-visible errors. Commenting out for now. | ||
//if (result.empty()) | ||
//if (ANDROID && result.empty()) | ||
// platform->showMessageBox("Device currently unsupported", "Your device doesn't have any storage so it is unsupported!"); | ||
|
||
// Mac-specific. | ||
#ifdef __APPLE__ | ||
std::string home = environment->path(PATH_HOME); | ||
if (!home.empty()) | ||
result.push_back(home + "/Library/Application Support/OpenEnroth"); | ||
#endif | ||
|
||
// PWD. | ||
result.push_back("."); | ||
|
||
return result; | ||
#else | ||
std::string envPath = environment->getenv(envVarOverride); | ||
if (!envPath.empty()) { | ||
logger->info("Path override provided: {}={}", envVarOverride, envPath); | ||
return envPath; | ||
} | ||
} | ||
|
||
for (auto key : registryKeys) { | ||
envPath = environment->queryRegistry(key); | ||
if (!envPath.empty()) { | ||
return envPath; | ||
} | ||
} | ||
std::vector<std::string> resolveMm6Paths(Environment *environment) { | ||
return resolvePaths(environment, mm6Config); | ||
} | ||
|
||
return ""; | ||
#endif | ||
std::vector<std::string> resolveMm7Paths(Environment *environment) { | ||
return resolvePaths(environment, mm7Config); | ||
} | ||
|
||
std::vector<std::string> resolveMm8Paths(Environment *environment) { | ||
return resolvePaths(environment, mm8Config); | ||
} |
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 |
---|---|---|
@@ -1,11 +1,14 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
class Environment; | ||
|
||
constexpr char mm6PathOverrideKey[] = "OPENENROTH_MM6_PATH"; | ||
constexpr char mm7PathOverrideKey[] = "OPENENROTH_MM7_PATH"; | ||
constexpr char mm8PathOverrideKey[] = "OPENENROTH_MM8_PATH"; | ||
|
||
std::string resolveMm6Path(Environment *environment); | ||
std::string resolveMm7Path(Environment *environment); | ||
std::string resolveMm8Path(Environment *environment); | ||
std::vector<std::string> resolveMm6Paths(Environment *environment); | ||
std::vector<std::string> resolveMm7Paths(Environment *environment); | ||
std::vector<std::string> resolveMm8Paths(Environment *environment); |
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
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
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
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