@@ -179,6 +179,9 @@ extern const std::string API_VERSION; | |||||
#if defined ARCH_WIN | #if defined ARCH_WIN | ||||
// wchar_t on Windows should be 2 bytes | |||||
static_assert(sizeof(char16_t) == sizeof(wchar_t)); | |||||
// Windows C standard functions are ASCII-8 instead of UTF-8, so redirect these functions to wrappers which convert to UTF-8 | // Windows C standard functions are ASCII-8 instead of UTF-8, so redirect these functions to wrappers which convert to UTF-8 | ||||
#define fopen fopen_utf8 | #define fopen fopen_utf8 | ||||
#define remove remove_utf8 | #define remove remove_utf8 | ||||
@@ -61,11 +61,11 @@ static void initSystemDir() { | |||||
#endif | #endif | ||||
#if defined ARCH_WIN | #if defined ARCH_WIN | ||||
// Get path to executable | // Get path to executable | ||||
char16_t moduleBufU16[MAX_PATH]; | |||||
DWORD length = GetModuleFileNameW(NULL, moduleBufU16, LENGTHOF(moduleBufU16)); | |||||
char16_t moduleBufU16[MAX_PATH] = u""; | |||||
DWORD length = GetModuleFileNameW(NULL, (wchar_t*) moduleBufU16, LENGTHOF(moduleBufU16)); | |||||
assert(length > 0); | assert(length > 0); | ||||
// Get folder of executable | // Get folder of executable | ||||
PathRemoveFileSpecW(moduleBufU16); | |||||
PathRemoveFileSpecW((wchar_t*) moduleBufU16); | |||||
systemDir = string::UTF16toUTF8(moduleBufU16); | systemDir = string::UTF16toUTF8(moduleBufU16); | ||||
#endif | #endif | ||||
#if defined ARCH_LIN | #if defined ARCH_LIN | ||||
@@ -86,8 +86,8 @@ static void initUserDir() { | |||||
#if defined ARCH_WIN | #if defined ARCH_WIN | ||||
// Get "My Documents" folder | // Get "My Documents" folder | ||||
char16_t documentsBufU16[MAX_PATH] = L"."; | |||||
HRESULT result = SHGetFolderPathW(NULL, CSIDL_MYDOCUMENTS, NULL, SHGFP_TYPE_CURRENT, documentsBufU16); | |||||
char16_t documentsBufU16[MAX_PATH] = u"."; | |||||
HRESULT result = SHGetFolderPathW(NULL, CSIDL_MYDOCUMENTS, NULL, SHGFP_TYPE_CURRENT, (wchar_t*) documentsBufU16); | |||||
assert(result == S_OK); | assert(result == S_OK); | ||||
userDir = string::UTF16toUTF8(documentsBufU16); | userDir = string::UTF16toUTF8(documentsBufU16); | ||||
userDir += "/Rack"; | userDir += "/Rack"; | ||||
@@ -28,15 +28,15 @@ const std::string API_VERSION = "2"; | |||||
#include <windows.h> | #include <windows.h> | ||||
FILE* fopen_utf8(const char* filename, const char* mode) { | FILE* fopen_utf8(const char* filename, const char* mode) { | ||||
return _wfopen(rack::string::UTF8toUTF16(filename).c_str(), rack::string::UTF8toUTF16(mode).c_str()); | |||||
return _wfopen((wchar_t*) rack::string::UTF8toUTF16(filename).c_str(), (wchar_t*) rack::string::UTF8toUTF16(mode).c_str()); | |||||
} | } | ||||
int remove_utf8(const char* path) { | int remove_utf8(const char* path) { | ||||
return _wremove(rack::string::UTF8toUTF16(path).c_str()); | |||||
return _wremove((wchar_t*) rack::string::UTF8toUTF16(path).c_str()); | |||||
} | } | ||||
int rename_utf8(const char* oldname, const char* newname) { | int rename_utf8(const char* oldname, const char* newname) { | ||||
return _wrename(rack::string::UTF8toUTF16(oldname).c_str(), rack::string::UTF8toUTF16(newname).c_str()); | |||||
return _wrename((wchar_t*) rack::string::UTF8toUTF16(oldname).c_str(), (wchar_t*) rack::string::UTF8toUTF16(newname).c_str()); | |||||
} | } | ||||
#endif | #endif |
@@ -47,7 +47,7 @@ static void* loadLibrary(std::string libraryPath) { | |||||
#if defined ARCH_WIN | #if defined ARCH_WIN | ||||
SetErrorMode(SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS); | SetErrorMode(SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS); | ||||
std::u16string libraryFilenameU16 = string::UTF8toUTF16(libraryPath); | std::u16string libraryFilenameU16 = string::UTF8toUTF16(libraryPath); | ||||
HINSTANCE handle = LoadLibraryW(libraryFilenameU16.c_str()); | |||||
HINSTANCE handle = LoadLibraryW((wchar_t*) libraryFilenameU16.c_str()); | |||||
SetErrorMode(0); | SetErrorMode(0); | ||||
if (!handle) { | if (!handle) { | ||||
int error = GetLastError(); | int error = GetLastError(); | ||||
@@ -139,7 +139,7 @@ std::string absolutePath(const std::string& path) { | |||||
#elif defined ARCH_WIN | #elif defined ARCH_WIN | ||||
std::u16string pathU16 = UTF8toUTF16(path); | std::u16string pathU16 = UTF8toUTF16(path); | ||||
char16_t buf[PATH_MAX]; | char16_t buf[PATH_MAX]; | ||||
char16_t* absPathC = _wfullpath(buf, pathU16.c_str(), PATH_MAX); | |||||
char16_t* absPathC = (char16_t*) _wfullpath((wchar_t*) buf, (wchar_t*) pathU16.c_str(), PATH_MAX); | |||||
if (absPathC) | if (absPathC) | ||||
return UTF16toUTF8(absPathC); | return UTF16toUTF8(absPathC); | ||||
#endif | #endif | ||||
@@ -131,7 +131,7 @@ void copyFile(const std::string& srcPath, const std::string& destPath) { | |||||
void createDirectory(const std::string& path) { | void createDirectory(const std::string& path) { | ||||
#if defined ARCH_WIN | #if defined ARCH_WIN | ||||
std::u16string pathU16 = string::UTF8toUTF16(path); | std::u16string pathU16 = string::UTF8toUTF16(path); | ||||
_wmkdir(pathU16.c_str()); | |||||
_wmkdir((wchar_t*) pathU16.c_str()); | |||||
#else | #else | ||||
mkdir(path.c_str(), 0755); | mkdir(path.c_str(), 0755); | ||||
#endif | #endif | ||||
@@ -151,7 +151,7 @@ void createDirectories(const std::string& path) { | |||||
void removeDirectory(const std::string& path) { | void removeDirectory(const std::string& path) { | ||||
#if defined ARCH_WIN | #if defined ARCH_WIN | ||||
std::u16string pathU16 = string::UTF8toUTF16(path); | std::u16string pathU16 = string::UTF8toUTF16(path); | ||||
_wrmdir(pathU16.c_str()); | |||||
_wrmdir((wchar_t*) pathU16.c_str()); | |||||
#else | #else | ||||
rmdir(path.c_str()); | rmdir(path.c_str()); | ||||
#endif | #endif | ||||
@@ -170,8 +170,8 @@ void removeDirectories(const std::string& path) { | |||||
std::string getWorkingDirectory() { | std::string getWorkingDirectory() { | ||||
#if defined ARCH_WIN | #if defined ARCH_WIN | ||||
char16_t buf[4096] = L""; | |||||
GetCurrentDirectory(sizeof(buf), buf); | |||||
char16_t buf[4096] = u""; | |||||
GetCurrentDirectory(sizeof(buf), (wchar_t*) buf); | |||||
return string::UTF16toUTF8(buf); | return string::UTF16toUTF8(buf); | ||||
#else | #else | ||||
char buf[4096] = ""; | char buf[4096] = ""; | ||||
@@ -184,7 +184,7 @@ std::string getWorkingDirectory() { | |||||
void setWorkingDirectory(const std::string& path) { | void setWorkingDirectory(const std::string& path) { | ||||
#if defined ARCH_WIN | #if defined ARCH_WIN | ||||
std::u16string pathU16 = string::UTF8toUTF16(path); | std::u16string pathU16 = string::UTF8toUTF16(path); | ||||
SetCurrentDirectory(pathU16.c_str()); | |||||
SetCurrentDirectory((wchar_t*) pathU16.c_str()); | |||||
#else | #else | ||||
chdir(path.c_str()); | chdir(path.c_str()); | ||||
#endif | #endif | ||||
@@ -302,7 +302,7 @@ void openBrowser(const std::string& url) { | |||||
#endif | #endif | ||||
#if defined ARCH_WIN | #if defined ARCH_WIN | ||||
std::u16string urlW = string::UTF8toUTF16(url); | std::u16string urlW = string::UTF8toUTF16(url); | ||||
ShellExecuteW(NULL, L"open", urlW.c_str(), NULL, NULL, SW_SHOWDEFAULT); | |||||
ShellExecuteW(NULL, L"open", (wchar_t*) urlW.c_str(), NULL, NULL, SW_SHOWDEFAULT); | |||||
#endif | #endif | ||||
} | } | ||||
@@ -318,7 +318,7 @@ void openFolder(const std::string& path) { | |||||
#endif | #endif | ||||
#if defined ARCH_WIN | #if defined ARCH_WIN | ||||
std::u16string pathU16 = string::UTF8toUTF16(path); | std::u16string pathU16 = string::UTF8toUTF16(path); | ||||
ShellExecuteW(NULL, L"explore", pathU16.c_str(), NULL, NULL, SW_SHOWDEFAULT); | |||||
ShellExecuteW(NULL, L"explore", (wchar_t*) pathU16.c_str(), NULL, NULL, SW_SHOWDEFAULT); | |||||
#endif | #endif | ||||
} | } | ||||
@@ -331,7 +331,7 @@ void runProcessDetached(const std::string& path) { | |||||
shExInfo.lpVerb = L"runas"; | shExInfo.lpVerb = L"runas"; | ||||
std::u16string pathU16 = string::UTF8toUTF16(path); | std::u16string pathU16 = string::UTF8toUTF16(path); | ||||
shExInfo.lpFile = pathU16.c_str(); | |||||
shExInfo.lpFile = (wchar_t*) pathU16.c_str(); | |||||
shExInfo.nShow = SW_SHOW; | shExInfo.nShow = SW_SHOW; | ||||
if (ShellExecuteExW(&shExInfo)) { | if (ShellExecuteExW(&shExInfo)) { | ||||
@@ -60,7 +60,7 @@ int main(int argc, char* argv[]) { | |||||
#if defined ARCH_WIN | #if defined ARCH_WIN | ||||
// Windows global mutex to prevent multiple instances | // Windows global mutex to prevent multiple instances | ||||
// Handle will be closed by Windows when the process ends | // Handle will be closed by Windows when the process ends | ||||
HANDLE instanceMutex = CreateMutexW(NULL, true, string::toWstring(APP_NAME).c_str()); | |||||
HANDLE instanceMutex = CreateMutexW(NULL, true, (wchar_t*) string::UTF8toUTF16(APP_NAME).c_str()); | |||||
if (GetLastError() == ERROR_ALREADY_EXISTS) { | if (GetLastError() == ERROR_ALREADY_EXISTS) { | ||||
osdialog_message(OSDIALOG_ERROR, OSDIALOG_OK, "Rack is already running. Multiple Rack instances are not supported."); | osdialog_message(OSDIALOG_ERROR, OSDIALOG_OK, "Rack is already running. Multiple Rack instances are not supported."); | ||||
exit(1); | exit(1); | ||||