UTF-8 everywhere
This commit is contained in:
parent
31dda85504
commit
d155b0ffc1
@ -28,9 +28,14 @@ ByteString ExecutableName()
|
|||||||
{
|
{
|
||||||
ByteString ret;
|
ByteString ret;
|
||||||
#if defined(WIN)
|
#if defined(WIN)
|
||||||
char *name = (char *)malloc(64);
|
using Char = wchar_t;
|
||||||
|
#else
|
||||||
|
using Char = char;
|
||||||
|
#endif
|
||||||
|
#if defined(WIN)
|
||||||
|
wchar_t *name = (wchar_t *)malloc(sizeof(wchar_t) * 64);
|
||||||
DWORD max = 64, res;
|
DWORD max = 64, res;
|
||||||
while ((res = GetModuleFileName(NULL, name, max)) >= max)
|
while ((res = GetModuleFileNameW(NULL, name, max)) >= max)
|
||||||
{
|
{
|
||||||
#elif defined MACOSX
|
#elif defined MACOSX
|
||||||
char *fn = (char*)malloc(64),*name = (char*)malloc(PATH_MAX);
|
char *fn = (char*)malloc(64),*name = (char*)malloc(PATH_MAX);
|
||||||
@ -59,10 +64,10 @@ ByteString ExecutableName()
|
|||||||
#endif
|
#endif
|
||||||
#ifndef MACOSX
|
#ifndef MACOSX
|
||||||
max *= 2;
|
max *= 2;
|
||||||
char* realloced_name = (char *)realloc(name, max);
|
Char* realloced_name = (Char *)realloc(name, sizeof(Char) * max);
|
||||||
assert(realloced_name != NULL);
|
assert(realloced_name != NULL);
|
||||||
name = realloced_name;
|
name = realloced_name;
|
||||||
memset(name, 0, max);
|
memset(name, 0, sizeof(Char) * max);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (res <= 0)
|
if (res <= 0)
|
||||||
@ -70,7 +75,11 @@ ByteString ExecutableName()
|
|||||||
free(name);
|
free(name);
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
#if defined(WIN)
|
||||||
|
ret = WinNarrow(name);
|
||||||
|
#else
|
||||||
ret = name;
|
ret = name;
|
||||||
|
#endif
|
||||||
free(name);
|
free(name);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -81,7 +90,7 @@ void DoRestart()
|
|||||||
if (exename.length())
|
if (exename.length())
|
||||||
{
|
{
|
||||||
#ifdef WIN
|
#ifdef WIN
|
||||||
int ret = int(INT_PTR(ShellExecute(NULL, NULL, exename.c_str(), NULL, NULL, SW_SHOWNORMAL)));
|
int ret = int(INT_PTR(ShellExecuteW(NULL, NULL, WinWiden(exename).c_str(), NULL, NULL, SW_SHOWNORMAL)));
|
||||||
if (ret <= 32)
|
if (ret <= 32)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "cannot restart: ShellExecute(...) failed: code %i\n", ret);
|
fprintf(stderr, "cannot restart: ShellExecute(...) failed: code %i\n", ret);
|
||||||
@ -109,7 +118,7 @@ void DoRestart()
|
|||||||
void OpenURI(ByteString uri)
|
void OpenURI(ByteString uri)
|
||||||
{
|
{
|
||||||
#if defined(WIN)
|
#if defined(WIN)
|
||||||
if (int(INT_PTR(ShellExecute(NULL, NULL, uri.c_str(), NULL, NULL, SW_SHOWNORMAL))) <= 32)
|
if (int(INT_PTR(ShellExecuteW(NULL, NULL, WinWiden(uri).c_str(), NULL, NULL, SW_SHOWNORMAL))) <= 32)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "cannot open URI: ShellExecute(...) failed\n");
|
fprintf(stderr, "cannot open URI: ShellExecute(...) failed\n");
|
||||||
}
|
}
|
||||||
@ -167,4 +176,36 @@ void LoadFileInResource(int name, int type, unsigned int& size, const char*& dat
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef WIN
|
||||||
|
ByteString WinNarrow(const std::wstring &source)
|
||||||
|
{
|
||||||
|
int buffer_size = WideCharToMultiByte(CP_UTF8, 0, source.c_str(), source.size(), nullptr, 0, NULL, NULL);
|
||||||
|
if (!buffer_size)
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
std::string output(buffer_size, 0);
|
||||||
|
if (!WideCharToMultiByte(CP_UTF8, 0, source.c_str(), source.size(), &output[0], buffer_size, NULL, NULL))
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::wstring WinWiden(const ByteString &source)
|
||||||
|
{
|
||||||
|
int buffer_size = MultiByteToWideChar(CP_UTF8, 0, source.c_str(), source.size(), nullptr, 0);
|
||||||
|
if (!buffer_size)
|
||||||
|
{
|
||||||
|
return L"";
|
||||||
|
}
|
||||||
|
std::wstring output(buffer_size, 0);
|
||||||
|
if (!MultiByteToWideChar(CP_UTF8, 0, source.c_str(), source.size(), &output[0], buffer_size))
|
||||||
|
{
|
||||||
|
return L"";
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,10 @@
|
|||||||
|
|
||||||
#include "common/String.h"
|
#include "common/String.h"
|
||||||
|
|
||||||
|
#ifdef WIN
|
||||||
|
# include <string>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace Platform
|
namespace Platform
|
||||||
{
|
{
|
||||||
ByteString ExecutableName();
|
ByteString ExecutableName();
|
||||||
@ -15,6 +19,11 @@ namespace Platform
|
|||||||
long unsigned int GetTime();
|
long unsigned int GetTime();
|
||||||
|
|
||||||
void LoadFileInResource(int name, int type, unsigned int& size, const char*& data);
|
void LoadFileInResource(int name, int type, unsigned int& size, const char*& data);
|
||||||
|
|
||||||
|
#ifdef WIN
|
||||||
|
ByteString WinNarrow(const std::wstring &source);
|
||||||
|
std::wstring WinWiden(const ByteString &source);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -162,57 +162,33 @@ bool Client::DoInstallation()
|
|||||||
int returnval;
|
int returnval;
|
||||||
LONG rresult;
|
LONG rresult;
|
||||||
HKEY newkey;
|
HKEY newkey;
|
||||||
ByteString currentfilename2 = Platform::ExecutableName();
|
ByteString currentfilename = Platform::ExecutableName();
|
||||||
// this isn't necessary but I don't feel like c++ifying this code right now
|
ByteString iconname = currentfilename + ",-102";
|
||||||
const char *currentfilename = currentfilename2.c_str();
|
ByteString AppDataPath = Platform::WinNarrow(_wgetcwd(NULL, 0));
|
||||||
char *iconname = NULL;
|
ByteString opencommand = "\"" + currentfilename + "\" open \"%%1\" ddir \"" + AppDataPath + "\"";
|
||||||
char *opencommand = NULL;
|
ByteString protocolcommand = "\"" + currentfilename + "\" ddir \"" + AppDataPath + "\" ptsave \"%%1\"";
|
||||||
char *protocolcommand = NULL;
|
|
||||||
//char AppDataPath[MAX_PATH];
|
|
||||||
char *AppDataPath = NULL;
|
|
||||||
iconname = (char*)malloc(strlen(currentfilename)+6);
|
|
||||||
sprintf(iconname, "%s,-102", currentfilename);
|
|
||||||
|
|
||||||
//Create Roaming application data folder
|
auto createKey = [](ByteString s, HKEY &k) {
|
||||||
/*if(!SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA|CSIDL_FLAG_CREATE, NULL, 0, AppDataPath)))
|
return RegCreateKeyExW(HKEY_CURRENT_USER, Platform::WinWiden(s).c_str(), 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &k, NULL);
|
||||||
{
|
};
|
||||||
returnval = 0;
|
auto setValue = [](HKEY k, ByteString s) {
|
||||||
goto finalise;
|
auto w = Platform::WinWiden(s);
|
||||||
}*/
|
return RegSetValueExW(k, NULL, 0, REG_SZ, (LPBYTE)&w[0], w.size() + 1);
|
||||||
|
};
|
||||||
AppDataPath = _getcwd(NULL, 0);
|
|
||||||
|
|
||||||
//Move Game executable into application data folder
|
|
||||||
//TODO: Implement
|
|
||||||
|
|
||||||
opencommand = (char*)malloc(strlen(currentfilename)+53+strlen(AppDataPath));
|
|
||||||
protocolcommand = (char*)malloc(strlen(currentfilename)+53+strlen(AppDataPath));
|
|
||||||
/*if((strlen(AppDataPath)+strlen(APPDATA_SUBDIR "\\Powder Toy"))<MAX_PATH)
|
|
||||||
{
|
|
||||||
strappend(AppDataPath, APPDATA_SUBDIR);
|
|
||||||
_mkdir(AppDataPath);
|
|
||||||
strappend(AppDataPath, "\\Powder Toy");
|
|
||||||
_mkdir(AppDataPath);
|
|
||||||
} else {
|
|
||||||
returnval = 0;
|
|
||||||
goto finalise;
|
|
||||||
}*/
|
|
||||||
sprintf(opencommand, "\"%s\" open \"%%1\" ddir \"%s\"", currentfilename, AppDataPath);
|
|
||||||
sprintf(protocolcommand, "\"%s\" ddir \"%s\" ptsave \"%%1\"", currentfilename, AppDataPath);
|
|
||||||
|
|
||||||
//Create protocol entry
|
//Create protocol entry
|
||||||
rresult = RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Classes\\ptsave", 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &newkey, NULL);
|
rresult = createKey("Software\\Classes\\ptsave", newkey);
|
||||||
if (rresult != ERROR_SUCCESS) {
|
if (rresult != ERROR_SUCCESS) {
|
||||||
returnval = 0;
|
returnval = 0;
|
||||||
goto finalise;
|
goto finalise;
|
||||||
}
|
}
|
||||||
rresult = RegSetValueEx(newkey, 0, 0, REG_SZ, (LPBYTE)"Powder Toy Save", strlen("Powder Toy Save")+1);
|
rresult = setValue(newkey, "Powder Toy Save");
|
||||||
if (rresult != ERROR_SUCCESS) {
|
if (rresult != ERROR_SUCCESS) {
|
||||||
RegCloseKey(newkey);
|
RegCloseKey(newkey);
|
||||||
returnval = 0;
|
returnval = 0;
|
||||||
goto finalise;
|
goto finalise;
|
||||||
}
|
}
|
||||||
rresult = RegSetValueEx(newkey, (LPCSTR)"URL Protocol", 0, REG_SZ, (LPBYTE)"", strlen("")+1);
|
rresult = RegSetValueExW(newkey, (LPWSTR)L"URL Protocol", 0, REG_SZ, (LPBYTE)L"", 1);
|
||||||
if (rresult != ERROR_SUCCESS) {
|
if (rresult != ERROR_SUCCESS) {
|
||||||
RegCloseKey(newkey);
|
RegCloseKey(newkey);
|
||||||
returnval = 0;
|
returnval = 0;
|
||||||
@ -221,12 +197,12 @@ bool Client::DoInstallation()
|
|||||||
RegCloseKey(newkey);
|
RegCloseKey(newkey);
|
||||||
|
|
||||||
//Set Protocol DefaultIcon
|
//Set Protocol DefaultIcon
|
||||||
rresult = RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Classes\\ptsave\\DefaultIcon", 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &newkey, NULL);
|
rresult = createKey("Software\\Classes\\ptsave\\DefaultIcon", newkey);
|
||||||
if (rresult != ERROR_SUCCESS) {
|
if (rresult != ERROR_SUCCESS) {
|
||||||
returnval = 0;
|
returnval = 0;
|
||||||
goto finalise;
|
goto finalise;
|
||||||
}
|
}
|
||||||
rresult = RegSetValueEx(newkey, 0, 0, REG_SZ, (LPBYTE)iconname, strlen(iconname)+1);
|
rresult = setValue(newkey, iconname);
|
||||||
if (rresult != ERROR_SUCCESS) {
|
if (rresult != ERROR_SUCCESS) {
|
||||||
RegCloseKey(newkey);
|
RegCloseKey(newkey);
|
||||||
returnval = 0;
|
returnval = 0;
|
||||||
@ -235,12 +211,12 @@ bool Client::DoInstallation()
|
|||||||
RegCloseKey(newkey);
|
RegCloseKey(newkey);
|
||||||
|
|
||||||
//Set Protocol Launch command
|
//Set Protocol Launch command
|
||||||
rresult = RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Classes\\ptsave\\shell\\open\\command", 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &newkey, NULL);
|
rresult = createKey("Software\\Classes\\ptsave\\shell\\open\\command", newkey);
|
||||||
if (rresult != ERROR_SUCCESS) {
|
if (rresult != ERROR_SUCCESS) {
|
||||||
returnval = 0;
|
returnval = 0;
|
||||||
goto finalise;
|
goto finalise;
|
||||||
}
|
}
|
||||||
rresult = RegSetValueEx(newkey, 0, 0, REG_SZ, (LPBYTE)protocolcommand, strlen(protocolcommand)+1);
|
rresult = setValue(newkey, protocolcommand);
|
||||||
if (rresult != ERROR_SUCCESS) {
|
if (rresult != ERROR_SUCCESS) {
|
||||||
RegCloseKey(newkey);
|
RegCloseKey(newkey);
|
||||||
returnval = 0;
|
returnval = 0;
|
||||||
@ -249,12 +225,12 @@ bool Client::DoInstallation()
|
|||||||
RegCloseKey(newkey);
|
RegCloseKey(newkey);
|
||||||
|
|
||||||
//Create extension entry
|
//Create extension entry
|
||||||
rresult = RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Classes\\.cps", 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &newkey, NULL);
|
rresult = createKey("Software\\Classes\\.cps", newkey);
|
||||||
if (rresult != ERROR_SUCCESS) {
|
if (rresult != ERROR_SUCCESS) {
|
||||||
returnval = 0;
|
returnval = 0;
|
||||||
goto finalise;
|
goto finalise;
|
||||||
}
|
}
|
||||||
rresult = RegSetValueEx(newkey, 0, 0, REG_SZ, (LPBYTE)"PowderToySave", strlen("PowderToySave")+1);
|
rresult = setValue(newkey, "PowderToySave");
|
||||||
if (rresult != ERROR_SUCCESS) {
|
if (rresult != ERROR_SUCCESS) {
|
||||||
RegCloseKey(newkey);
|
RegCloseKey(newkey);
|
||||||
returnval = 0;
|
returnval = 0;
|
||||||
@ -262,12 +238,12 @@ bool Client::DoInstallation()
|
|||||||
}
|
}
|
||||||
RegCloseKey(newkey);
|
RegCloseKey(newkey);
|
||||||
|
|
||||||
rresult = RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Classes\\.stm", 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &newkey, NULL);
|
rresult = createKey("Software\\Classes\\.stm", newkey);
|
||||||
if (rresult != ERROR_SUCCESS) {
|
if (rresult != ERROR_SUCCESS) {
|
||||||
returnval = 0;
|
returnval = 0;
|
||||||
goto finalise;
|
goto finalise;
|
||||||
}
|
}
|
||||||
rresult = RegSetValueEx(newkey, 0, 0, REG_SZ, (LPBYTE)"PowderToySave", strlen("PowderToySave")+1);
|
rresult = setValue(newkey, "PowderToySave");
|
||||||
if (rresult != ERROR_SUCCESS) {
|
if (rresult != ERROR_SUCCESS) {
|
||||||
RegCloseKey(newkey);
|
RegCloseKey(newkey);
|
||||||
returnval = 0;
|
returnval = 0;
|
||||||
@ -276,12 +252,12 @@ bool Client::DoInstallation()
|
|||||||
RegCloseKey(newkey);
|
RegCloseKey(newkey);
|
||||||
|
|
||||||
//Create program entry
|
//Create program entry
|
||||||
rresult = RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Classes\\PowderToySave", 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &newkey, NULL);
|
rresult = createKey("Software\\Classes\\PowderToySave", newkey);
|
||||||
if (rresult != ERROR_SUCCESS) {
|
if (rresult != ERROR_SUCCESS) {
|
||||||
returnval = 0;
|
returnval = 0;
|
||||||
goto finalise;
|
goto finalise;
|
||||||
}
|
}
|
||||||
rresult = RegSetValueEx(newkey, 0, 0, REG_SZ, (LPBYTE)"Powder Toy Save", strlen("Powder Toy Save")+1);
|
rresult = setValue(newkey, "Powder Toy Save");
|
||||||
if (rresult != ERROR_SUCCESS) {
|
if (rresult != ERROR_SUCCESS) {
|
||||||
RegCloseKey(newkey);
|
RegCloseKey(newkey);
|
||||||
returnval = 0;
|
returnval = 0;
|
||||||
@ -290,12 +266,12 @@ bool Client::DoInstallation()
|
|||||||
RegCloseKey(newkey);
|
RegCloseKey(newkey);
|
||||||
|
|
||||||
//Set DefaultIcon
|
//Set DefaultIcon
|
||||||
rresult = RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Classes\\PowderToySave\\DefaultIcon", 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &newkey, NULL);
|
rresult = createKey("Software\\Classes\\PowderToySave\\DefaultIcon", newkey);
|
||||||
if (rresult != ERROR_SUCCESS) {
|
if (rresult != ERROR_SUCCESS) {
|
||||||
returnval = 0;
|
returnval = 0;
|
||||||
goto finalise;
|
goto finalise;
|
||||||
}
|
}
|
||||||
rresult = RegSetValueEx(newkey, 0, 0, REG_SZ, (LPBYTE)iconname, strlen(iconname)+1);
|
rresult = setValue(newkey, iconname);
|
||||||
if (rresult != ERROR_SUCCESS) {
|
if (rresult != ERROR_SUCCESS) {
|
||||||
RegCloseKey(newkey);
|
RegCloseKey(newkey);
|
||||||
returnval = 0;
|
returnval = 0;
|
||||||
@ -304,12 +280,12 @@ bool Client::DoInstallation()
|
|||||||
RegCloseKey(newkey);
|
RegCloseKey(newkey);
|
||||||
|
|
||||||
//Set Launch command
|
//Set Launch command
|
||||||
rresult = RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Classes\\PowderToySave\\shell\\open\\command", 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &newkey, NULL);
|
rresult = createKey("Software\\Classes\\PowderToySave\\shell\\open\\command", newkey);
|
||||||
if (rresult != ERROR_SUCCESS) {
|
if (rresult != ERROR_SUCCESS) {
|
||||||
returnval = 0;
|
returnval = 0;
|
||||||
goto finalise;
|
goto finalise;
|
||||||
}
|
}
|
||||||
rresult = RegSetValueEx(newkey, 0, 0, REG_SZ, (LPBYTE)opencommand, strlen(opencommand)+1);
|
rresult = setValue(newkey, opencommand);
|
||||||
if (rresult != ERROR_SUCCESS) {
|
if (rresult != ERROR_SUCCESS) {
|
||||||
RegCloseKey(newkey);
|
RegCloseKey(newkey);
|
||||||
returnval = 0;
|
returnval = 0;
|
||||||
@ -320,10 +296,6 @@ bool Client::DoInstallation()
|
|||||||
returnval = 1;
|
returnval = 1;
|
||||||
finalise:
|
finalise:
|
||||||
|
|
||||||
free(iconname);
|
|
||||||
free(opencommand);
|
|
||||||
free(protocolcommand);
|
|
||||||
|
|
||||||
return returnval;
|
return returnval;
|
||||||
#elif defined(LIN)
|
#elif defined(LIN)
|
||||||
#include "icondoc.h"
|
#include "icondoc.h"
|
||||||
@ -451,10 +423,10 @@ std::vector<ByteString> Client::DirectorySearch(ByteString directory, ByteString
|
|||||||
std::vector<ByteString> directoryList;
|
std::vector<ByteString> directoryList;
|
||||||
#if defined(WIN) && !defined(__GNUC__)
|
#if defined(WIN) && !defined(__GNUC__)
|
||||||
//Windows
|
//Windows
|
||||||
struct _finddata_t currentFile;
|
struct _wfinddata_t currentFile;
|
||||||
intptr_t findFileHandle;
|
intptr_t findFileHandle;
|
||||||
ByteString fileMatch = directory + "*.*";
|
ByteString fileMatch = directory + "*.*";
|
||||||
findFileHandle = _findfirst(fileMatch.c_str(), ¤tFile);
|
findFileHandle = _wfindfirst(Platform::WinWiden(fileMatch).c_str(), ¤tFile);
|
||||||
if (findFileHandle == -1L)
|
if (findFileHandle == -1L)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
@ -464,11 +436,11 @@ std::vector<ByteString> Client::DirectorySearch(ByteString directory, ByteString
|
|||||||
}
|
}
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
ByteString currentFileName = ByteString(currentFile.name);
|
ByteString currentFileName = Platform::WinNarrow(currentFile.name);
|
||||||
if(currentFileName.length()>4)
|
if(currentFileName.length()>4)
|
||||||
directoryList.push_back(directory+currentFileName);
|
directoryList.push_back(directory+currentFileName);
|
||||||
}
|
}
|
||||||
while (_findnext(findFileHandle, ¤tFile) == 0);
|
while (_wfindnext(findFileHandle, ¤tFile) == 0);
|
||||||
_findclose(findFileHandle);
|
_findclose(findFileHandle);
|
||||||
#else
|
#else
|
||||||
//Linux or MinGW
|
//Linux or MinGW
|
||||||
@ -519,7 +491,7 @@ std::vector<ByteString> Client::DirectorySearch(ByteString directory, ByteString
|
|||||||
int Client::MakeDirectory(const char * dirName)
|
int Client::MakeDirectory(const char * dirName)
|
||||||
{
|
{
|
||||||
#ifdef WIN
|
#ifdef WIN
|
||||||
return _mkdir(dirName);
|
return _wmkdir(Platform::WinWiden(dirName).c_str());
|
||||||
#else
|
#else
|
||||||
return mkdir(dirName, 0755);
|
return mkdir(dirName, 0755);
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user