Core: Add EnvironmentVariables
This commit is contained in:
parent
ba7d2221d0
commit
5472514f4b
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_CORE_ENVIRONMENTVARIABLES_HPP
|
||||
#define NAZARA_CORE_ENVIRONMENTVARIABLES_HPP
|
||||
|
||||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
NAZARA_CORE_API const char* GetEnvironmentVariable(const char* envVar);
|
||||
NAZARA_CORE_API bool TestEnvironmentVariable(const char* envVar);
|
||||
}
|
||||
|
||||
#include <Nazara/Core/EnvironmentVariables.inl>
|
||||
|
||||
#endif // NAZARA_CORE_ENVIRONMENTVARIABLES_HPP
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/EnvironmentVariables.hpp>
|
||||
#include <cstdlib>
|
||||
#include <string_view>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
const char* GetEnvironmentVariable(const char* envVar)
|
||||
{
|
||||
return std::getenv(envVar);
|
||||
}
|
||||
|
||||
bool TestEnvironmentVariable(const char* envVar)
|
||||
{
|
||||
const char* value = GetEnvironmentVariable(envVar);
|
||||
if (!value)
|
||||
return false;
|
||||
|
||||
// Environment variable exists, recognize some values as disabling it
|
||||
using namespace std::string_view_literals;
|
||||
constexpr std::array disabledValues = {
|
||||
"0"sv,
|
||||
"n"sv,
|
||||
"false"sv,
|
||||
};
|
||||
|
||||
for (std::string_view disabledValue : disabledValues)
|
||||
{
|
||||
if (value == disabledValue)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include <Nazara/Core/PluginLoader.hpp>
|
||||
#include <Nazara/Core/DynLib.hpp>
|
||||
#include <Nazara/Core/EnvironmentVariables.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <NazaraUtils/Algorithm.hpp>
|
||||
#include <stdexcept>
|
||||
|
|
@ -15,7 +16,7 @@ namespace Nz
|
|||
{
|
||||
AddSearchDirectory(".");
|
||||
AddSearchDirectory("plugins");
|
||||
if (const char* path = getenv("NAZARA_PLUGIN_DIR"))
|
||||
if (const char* path = GetEnvironmentVariable("NAZARA_PLUGIN_DIR"))
|
||||
AddSearchDirectory(Utf8Path(path));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue