From 9bfa470581f537b3e5e3d657e98ed9c816746781 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Mon, 11 Feb 2019 21:36:23 +0100 Subject: [PATCH] [util] Implement createDirectory function --- src/util/util_env.cpp | 22 +++++++++------------- src/util/util_env.h | 8 ++++++++ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/util/util_env.cpp b/src/util/util_env.cpp index 42ab8b86..0a9ca60f 100644 --- a/src/util/util_env.cpp +++ b/src/util/util_env.cpp @@ -1,6 +1,4 @@ #include "util_env.h" -#include -#include #include "./com/com_include.h" @@ -33,16 +31,6 @@ namespace dxvk::env { void setThreadName(const std::string& name) { using SetThreadDescriptionProc = void (WINAPI *) (HANDLE, PCWSTR); - int nameLen = ::MultiByteToWideChar( - CP_ACP, 0, name.c_str(), name.length() + 1, - nullptr, 0); - - std::vector wideName(nameLen); - - ::MultiByteToWideChar( - CP_ACP, 0, name.c_str(), name.length() + 1, - wideName.data(), nameLen); - HMODULE module = ::GetModuleHandleW(L"kernel32.dll"); if (module == nullptr) @@ -51,8 +39,16 @@ namespace dxvk::env { auto proc = reinterpret_cast( ::GetProcAddress(module, "SetThreadDescription")); - if (proc != nullptr) + if (proc != nullptr) { + auto wideName = str::tows(name); (*proc)(::GetCurrentThread(), wideName.data()); + } + } + + + bool createDirectory(const std::string& path) { + auto widePath = str::tows(path); + return !!CreateDirectoryW(widePath.data(), nullptr); } } diff --git a/src/util/util_env.h b/src/util/util_env.h index bbbfa3a1..f327bf7a 100644 --- a/src/util/util_env.h +++ b/src/util/util_env.h @@ -30,5 +30,13 @@ namespace dxvk::env { * \param [in] name Thread name */ void setThreadName(const std::string& name); + + /** + * \brief Creates a directory + * + * \param [in] path Path to directory + * \returns \c true on success + */ + bool createDirectory(const std::string& path); }