diff options
Diffstat (limited to 'core/helpers.cpp')
-rw-r--r-- | core/helpers.cpp | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/core/helpers.cpp b/core/helpers.cpp index 58cc74e5..f9de25cf 100644 --- a/core/helpers.cpp +++ b/core/helpers.cpp @@ -3,6 +3,11 @@ #include "helpers.h" +#if defined(_WIN32) +#define WIN32_LEAN_AND_MEAN +#include <windows.h> +#endif + #include <algorithm> #include <cerrno> #include <cstdarg> @@ -40,7 +45,7 @@ const PathNamePair &GetProcBinary() { static std::optional<PathNamePair> procbin; if(procbin) return *procbin; - +#if !defined(ALSOFT_UWP) auto fullpath = std::vector<WCHAR>(256); DWORD len{GetModuleFileNameW(nullptr, fullpath.data(), static_cast<DWORD>(fullpath.size()))}; while(len == fullpath.size()) @@ -58,7 +63,16 @@ const PathNamePair &GetProcBinary() fullpath.resize(len); if(fullpath.back() != 0) fullpath.push_back(0); - +#else + auto exePath = __wargv[0]; + if (!exePath) + { + ERR("Failed to get process name: error %lu\n", GetLastError()); + procbin.emplace(); + return *procbin; + } + std::vector<WCHAR> fullpath{exePath, exePath + wcslen(exePath) + 1}; +#endif std::replace(fullpath.begin(), fullpath.end(), '/', '\\'); auto sep = std::find(fullpath.rbegin()+1, fullpath.rend(), '\\'); if(sep != fullpath.rend()) @@ -84,7 +98,7 @@ void DirectorySearch(const char *path, const char *ext, std::vector<std::string> std::wstring wpath{utf8_to_wstr(pathstr.c_str())}; WIN32_FIND_DATAW fdata; - HANDLE hdl{FindFirstFileW(wpath.c_str(), &fdata)}; + HANDLE hdl{FindFirstFileExW(wpath.c_str(), FindExInfoStandard, &fdata, FindExSearchNameMatch, NULL, 0)}; if(hdl == INVALID_HANDLE_VALUE) return; const auto base = results->size(); @@ -97,7 +111,6 @@ void DirectorySearch(const char *path, const char *ext, std::vector<std::string> str += wstr_to_utf8(fdata.cFileName); } while(FindNextFileW(hdl, &fdata)); FindClose(hdl); - const al::span<std::string> newlist{results->data()+base, results->size()-base}; std::sort(newlist.begin(), newlist.end()); for(const auto &name : newlist) @@ -149,6 +162,7 @@ std::vector<std::string> SearchDataFiles(const char *ext, const char *subdir) std::replace(path.begin(), path.end(), '/', '\\'); DirectorySearch(path.c_str(), ext, &results); +#if !defined(ALSOFT_UWP) /* Search the local and global data dirs. */ static const int ids[2]{ CSIDL_APPDATA, CSIDL_COMMON_APPDATA }; for(int id : ids) @@ -165,17 +179,20 @@ std::vector<std::string> SearchDataFiles(const char *ext, const char *subdir) DirectorySearch(path.c_str(), ext, &results); } +#endif return results; } void SetRTPriority(void) { +#if !defined(ALSOFT_UWP) if(RTPrioLevel > 0) { if(!SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL)) ERR("Failed to set priority level for thread\n"); } +#endif } #else |