aboutsummaryrefslogtreecommitdiff
path: root/src/Cache.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Cache.cpp')
-rw-r--r--src/Cache.cpp25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/Cache.cpp b/src/Cache.cpp
index 8657371..cf9aa8a 100644
--- a/src/Cache.cpp
+++ b/src/Cache.cpp
@@ -12,8 +12,18 @@
#if OS_FAMILY == OS_FAMILY_POSIX
#include <pwd.h>
+#define toNativeString(str) str
#else
#include <string>
+#include <userenv.h>
+#include <locale>
+#include <codecvt>
+
+static std::wstring toNativeString(const std::string &str)
+{
+ std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
+ return converter.from_bytes(str);
+}
#endif
using namespace std;
@@ -41,12 +51,12 @@ namespace dchat
homeDir.resize(homeDirLen);
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_READ, &hToken))
- return Result<FileString>::Err("Failed to open process token");
+ throw std::runtime_error("Failed to open process token");
if (!GetUserProfileDirectory(hToken, &homeDir[0], &homeDirLen))
{
CloseHandle(hToken);
- return Result<FileString>::Err("Failed to get home directory");
+ throw std::runtime_error("Failed to get home directory");
}
CloseHandle(hToken);
@@ -143,7 +153,7 @@ namespace dchat
return false;
}
- bool success = (gdImageFile(newImgPtr, filepath.c_str()) == 0);
+ bool success = (gdImageFile(newImgPtr, filepath.string().c_str()) == 0);
gdImageDestroy(imgPtr);
gdImageDestroy(newImgPtr);
return success;
@@ -427,11 +437,12 @@ namespace dchat
string downloadLimitBytesStr = to_string(downloadLimitBytes);
- Process::string_type cmd = "curl -L --silent -o '";
- cmd += filepath.native();
- cmd += "' --max-filesize " + downloadLimitBytesStr + " --range 0-" + downloadLimitBytesStr + " --url '" + url + "'";
+ std::string cmdUtf8 = "curl -L --silent -o '";
+ cmdUtf8 += filepath.string();
+ cmdUtf8 += "' --max-filesize " + downloadLimitBytesStr + " --range 0-" + downloadLimitBytesStr + " --url '" + url + "'";
+ Process::string_type cmd = toNativeString(cmdUtf8);
// TODO: Use this instead of curl on windows: certutil.exe -urlcache -split -f "https://url/to/file" path/and/name/to/save/as/file
- Process *process = new Process(cmd, "", nullptr, nullptr, false);
+ Process *process = new Process(cmd, toNativeString(""), nullptr, nullptr, false);
ImageDownloadInfo imageDownloadInfo { process, url };
imageDownloadProcessesQueue.emplace_back(imageDownloadInfo);
return result;