Skip to content

Commit

Permalink
SporeModManager: use GetEnvironmentVariableW() on win32
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosalie241 committed Jan 1, 2024
1 parent 67b372c commit 704e46b
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions SporeModManager/SporeModManagerHelpers/Path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#define _CRT_SECURE_NO_WARNINGS // TODO for getenv() for msvc
#include "SporeModManagerHelpers.hpp"

#include <filesystem>
Expand Down Expand Up @@ -200,12 +199,30 @@ std::filesystem::path Path::GetFullInstallPath(SporeMod::InstallLocation install

std::filesystem::path Path::GetConfigFilePath(void)
{
static const char* configFile = std::getenv("SPOREMODMANAGER_CONFIGFILE");
static std::filesystem::path cachedConfigFilePath;
if (!cachedConfigFilePath.empty())
{
return cachedConfigFilePath;
}

#ifdef _WIN32
wchar_t envBuffer[MAX_PATH] = {0};
if (GetEnvironmentVariableW(L"SPOREMODMANAGER_CONFIGFILE", envBuffer, MAX_PATH) != 0)
{
cachedConfigFilePath = envBuffer;
}
#else
const char* configFile = std::getenv("SPOREMODMANAGER_CONFIGFILE");
if (configFile != nullptr)
{
return configFile;
cachedConfigFilePath = configFile;
}
#endif
if (cachedConfigFilePath.empty())
{
cachedConfigFilePath = Path::Combine({ Path::GetCurrentExecutablePath(), "SporeModManager.xml" });
}
return Path::Combine({ Path::GetCurrentExecutablePath(), "SporeModManager.xml" });;
return cachedConfigFilePath;
}

std::filesystem::path Path::GetCoreLibsPath(void)
Expand Down

0 comments on commit 704e46b

Please sign in to comment.