mirror of
https://github.com/xmrig/xmrig.git
synced 2024-11-18 10:01:06 +00:00
Add extra variables.
This commit is contained in:
parent
2d15c10e0f
commit
f9d07229b4
2 changed files with 29 additions and 2 deletions
|
@ -24,6 +24,8 @@
|
|||
|
||||
|
||||
#include "base/kernel/Env.h"
|
||||
#include "base/kernel/Process.h"
|
||||
#include "version.h"
|
||||
|
||||
|
||||
#include <regex>
|
||||
|
@ -44,6 +46,23 @@
|
|||
#endif
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
static std::map<String, String> variables;
|
||||
|
||||
|
||||
static void createVariables()
|
||||
{
|
||||
variables.insert({ "XMRIG_VERSION", APP_VERSION });
|
||||
variables.insert({ "XMRIG_EXE_DIR", Process::location(Process::ExeLocation, "") });
|
||||
variables.insert({ "XMRIG_CWD", Process::location(Process::CwdLocation, "") });
|
||||
}
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
xmrig::String xmrig::Env::expand(const char *in)
|
||||
{
|
||||
if (in == nullptr) {
|
||||
|
@ -86,8 +105,16 @@ xmrig::String xmrig::Env::expand(const char *in)
|
|||
}
|
||||
|
||||
|
||||
xmrig::String xmrig::Env::get(const char *name)
|
||||
xmrig::String xmrig::Env::get(const String &name)
|
||||
{
|
||||
if (variables.empty()) {
|
||||
createVariables();
|
||||
}
|
||||
|
||||
if (variables.count(name)) {
|
||||
return variables.at(name);
|
||||
}
|
||||
|
||||
return static_cast<const char *>(getenv(name));
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ class Env
|
|||
{
|
||||
public:
|
||||
static String expand(const char *in);
|
||||
static String get(const char *name);
|
||||
static String get(const String &name);
|
||||
static String hostname();
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue