Common.hpp: Refactor to remove <Windows.h> include

This commit is contained in:
Luke Street 2022-02-22 00:46:15 -05:00
parent 89986bdd65
commit 101746f268
2 changed files with 18 additions and 10 deletions

View File

@ -18,10 +18,6 @@
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#else #else
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN 1
#endif
#include <Windows.h>
#include <nowide/stackstring.hpp> #include <nowide/stackstring.hpp>
#endif #endif
@ -344,15 +340,11 @@ typedef struct stat Sstat;
static inline int Stat(const char* path, Sstat* statout) { return stat(path, statout); } static inline int Stat(const char* path, Sstat* statout) { return stat(path, statout); }
#endif #endif
inline int Rename(const char* oldpath, const char* newpath) {
#if _WIN32 #if _WIN32
const nowide::wstackstring woldpath(oldpath); int Rename(const char* oldpath, const char* newpath);
const nowide::wstackstring wnewpath(newpath);
return MoveFileExW(woldpath.get(), wnewpath.get(), MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH) == 0;
#else #else
return rename(oldpath, newpath); inline int Rename(const char* oldpath, const char* newpath) { return rename(oldpath, newpath); }
#endif #endif
}
inline int CompareCaseInsensitive(const char* a, const char* b) { inline int CompareCaseInsensitive(const char* a, const char* b) {
#if _WIN32 #if _WIN32

View File

@ -3,6 +3,14 @@
#ifndef _WIN32 #ifndef _WIN32
#include <cstdio> #include <cstdio>
#include <memory> #include <memory>
#else
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN 1
#endif
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <Windows.h>
#endif #endif
#include <logvisor/logvisor.hpp> #include <logvisor/logvisor.hpp>
@ -47,6 +55,14 @@ bool Copy(const char* from, const char* to) {
#endif #endif
} }
#if _WIN32
int Rename(const char* oldpath, const char* newpath) {
const nowide::wstackstring woldpath(oldpath);
const nowide::wstackstring wnewpath(newpath);
return MoveFileExW(woldpath.get(), wnewpath.get(), MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH) == 0;
}
#endif
#define DEFINE_ID_TYPE(type, typeName) \ #define DEFINE_ID_TYPE(type, typeName) \
thread_local NameDB* type::CurNameDB = nullptr; \ thread_local NameDB* type::CurNameDB = nullptr; \
template <> \ template <> \