summaryrefslogtreecommitdiffstats
path: root/src/libs/dxvk-native-1.9.2a/src/util/util_env.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs/dxvk-native-1.9.2a/src/util/util_env.cpp')
-rw-r--r--src/libs/dxvk-native-1.9.2a/src/util/util_env.cpp71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/libs/dxvk-native-1.9.2a/src/util/util_env.cpp b/src/libs/dxvk-native-1.9.2a/src/util/util_env.cpp
new file mode 100644
index 00000000..3993ea65
--- /dev/null
+++ b/src/libs/dxvk-native-1.9.2a/src/util/util_env.cpp
@@ -0,0 +1,71 @@
+#include <numeric>
+
+#include "util_env.h"
+
+namespace dxvk::env {
+
+#ifndef DXVK_NATIVE
+ constexpr char dirSlash = '\\';
+#else
+ constexpr char dirSlash = '/';
+#endif
+
+
+ std::string getEnvVar(const char* name) {
+#ifdef DXVK_NATIVE
+ char* result = std::getenv(name);
+ return (result)
+ ? result
+ : "";
+#else
+ std::vector<WCHAR> result;
+ result.resize(MAX_PATH + 1);
+
+ DWORD len = ::GetEnvironmentVariableW(str::tows(name).c_str(), result.data(), MAX_PATH);
+ result.resize(len);
+
+ return str::fromws(result.data());
+#endif
+ }
+
+
+ size_t matchFileExtension(const std::string& name, const char* ext) {
+ auto pos = name.find_last_of('.');
+
+ if (pos == std::string::npos)
+ return pos;
+
+ bool matches = std::accumulate(name.begin() + pos + 1, name.end(), true,
+ [&ext] (bool current, char a) {
+ if (a >= 'A' && a <= 'Z')
+ a += 'a' - 'A';
+ return current && *ext && a == *(ext++);
+ });
+
+ return matches ? pos : std::string::npos;
+ }
+
+
+ std::string getExeName() {
+ std::string fullPath = getExePath();
+ auto n = fullPath.find_last_of(dirSlash);
+
+ return (n != std::string::npos)
+ ? fullPath.substr(n + 1)
+ : fullPath;
+ }
+
+
+ std::string getExeBaseName() {
+ auto exeName = getExeName();
+#ifndef DXVK_NATIVE
+ auto extp = matchFileExtension(exeName, "exe");
+
+ if (extp != std::string::npos)
+ exeName.erase(extp);
+#endif
+
+ return exeName;
+ }
+
+}