diff --git a/core/gimx.c b/core/gimx.c index 8d4c60e2..c5328632 100755 --- a/core/gimx.c +++ b/core/gimx.c @@ -620,15 +620,17 @@ int main(int argc, char *argv[]) #ifndef WIN32 char * file = "/tmp/gimx.status"; #else - char file[MAX_PATH]; - int ret = GetTempPath(sizeof(file), file); - if (ret > 0 && (unsigned int) ret < MAX_PATH - sizeof("/gimx.status")) + char file[MAX_PATH + 1] = {}; + wchar_t wtmp[MAX_PATH + 1]; + int ret = GetTempPathW(MAX_PATH, wtmp); + if (ret > 0) { - strcat(file, "/gimx.status"); - } - else - { - file[0] = '\0'; + char * tmp = utf16le_to_utf8(wtmp); + if (strlen(tmp) + sizeof("/gimx.status") <= sizeof(file)) + { + sprintf(file, "%s/gimx.status", tmp); + } + free(tmp); } #endif if (file != NULL && file[0] != '\0') @@ -652,9 +654,9 @@ int main(int argc, char *argv[]) if(gimx_params.logfile) { fclose(gimx_params.logfile); +#ifndef WIN32 char file_path[PATH_MAX]; snprintf(file_path, sizeof(file_path), "%s%s%s%s", gimx_params.homedir, GIMX_DIR, LOG_DIR, gimx_params.logfilename); -#ifndef WIN32 int ret = chown(file_path, getpwuid(getuid())->pw_uid, getpwuid(getuid())->pw_gid); if (ret < 0) { diff --git a/launcher/gimx-launcher.cpp b/launcher/gimx-launcher.cpp index 2859790d..7bd66854 100644 --- a/launcher/gimx-launcher.cpp +++ b/launcher/gimx-launcher.cpp @@ -1658,7 +1658,7 @@ void launcherFrame::OnProcessTerminated(wxProcess *process __attribute__((unused stringstream ss(line); ss >> status; } - remove(statusFile.mb_str(wxConvUTF8)); + wxRemoveFile(statusFile); } switch(status) @@ -1752,7 +1752,7 @@ void launcherFrame::OnProcessTerminated(wxProcess *process __attribute__((unused if (answer == wxYES) { wxString logfile = gimxLogDir + wxT(LOG_FILE); - remove(logfile.mb_str(wxConvUTF8)); + wxRemoveFile(logfile); ProcessOutputChoice->SetSelection(ProcessOutputChoice->FindString(_("log file"))); wxCommandEvent event; OnButtonStartClick(event); diff --git a/shared/gimxconfigupdater/configupdater.cpp b/shared/gimxconfigupdater/configupdater.cpp index 15e7a647..5282935c 100644 --- a/shared/gimxconfigupdater/configupdater.cpp +++ b/shared/gimxconfigupdater/configupdater.cpp @@ -52,6 +52,19 @@ static wchar_t * utf8_to_utf16le(const char * inbuf) IFBUF(path) \ std::istream name (&fb); +#ifndef WIN32 +static int remove2(const char *path) { + return remove(path); +} +#else +static int remove2(const char *path) { + wchar_t * wpath = utf8_to_utf16le(path); + int result = _wremove(wpath); + free(wpath); + return result; +} +#endif + #ifdef WIN32 const char * configupdater::configs_url = "https://api.github.com/repos/matlo/GIMX-configurations/contents/Windows"; const char * configupdater::configs_download_url = "https://raw.githubusercontent.com/matlo/GIMX-configurations/master/Windows/"; @@ -108,28 +121,29 @@ configupdater::ConfigUpdaterStatus configupdater::getconfiglist(std::listprogress(convertDowloadStatus(status), progress, total); } +#ifdef WIN32 +static wchar_t * utf8_to_utf16le(const char * inbuf) +{ + wchar_t * outbuf = NULL; + int outsize = MultiByteToWideChar(CP_UTF8, 0, inbuf, -1, NULL, 0); + if (outsize != 0) { + outbuf = (wchar_t*) malloc(outsize * sizeof(*outbuf)); + if (outbuf != NULL) { + int res = MultiByteToWideChar(CP_UTF8, 0, inbuf, -1, outbuf, outsize); + if (res == 0) { + free(outbuf); + outbuf = NULL; + } + } + } + + return outbuf; +} +#endif + Updater::UpdaterStatus Updater::update(std::string url, ProgressCallback callback, void *clientp, bool wait) { clientCallback = callback; @@ -122,18 +142,21 @@ Updater::UpdaterStatus Updater::update(std::string url, ProgressCallback callbac UpdaterStatus status = UpdaterStatusOk; #ifdef WIN32 - SHELLEXECUTEINFO shExInfo = SHELLEXECUTEINFO(); + wchar_t * utf16 = utf8_to_utf16le(tempFile.c_str()); + + SHELLEXECUTEINFOW shExInfo = SHELLEXECUTEINFOW(); shExInfo.cbSize = sizeof(shExInfo); shExInfo.fMask = wait ? (SEE_MASK_NOCLOSEPROCESS | SEE_MASK_NOASYNC) : SEE_MASK_DEFAULT; shExInfo.hwnd = 0; - shExInfo.lpVerb = "runas"; - shExInfo.lpFile = tempFile.c_str(); - shExInfo.lpParameters = ""; + shExInfo.lpVerb = L"runas"; + shExInfo.lpFile = utf16; + shExInfo.lpParameters = L""; shExInfo.lpDirectory = 0; shExInfo.nShow = SW_SHOW; shExInfo.hInstApp = 0; - if (!ShellExecuteEx(&shExInfo)) { + if (!ShellExecuteExW(&shExInfo)) { + free(utf16); if (GetLastError() == ERROR_CANCELLED) { return UpdaterStatusCancelled; } @@ -148,6 +171,7 @@ Updater::UpdaterStatus Updater::update(std::string url, ProgressCallback callbac } CloseHandle(shExInfo.hProcess); + free(utf16); #else (void)wait; std::string cmd = "";