-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.cpp
70 lines (57 loc) · 1.54 KB
/
utils.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "pch.h"
#include "utils.h"
#include <algorithm>
#include <Shlwapi.h>
using namespace std;
string WideCharToUtf8(const WCHAR* wcPath)
{
CHAR mbPath[TC_MAX_PATH];
WideCharToMultiByte(CP_UTF8, 0, wcPath, static_cast<int>(wcslen(wcPath)) + 1, mbPath, TC_MAX_PATH, nullptr, nullptr);
return string(mbPath);
}
string WideCharToUtf8(const wstring& wString)
{
return WideCharToUtf8(wString.c_str());
}
string GetUtf8FileNameFromPath(const WCHAR* wcPath)
{
WCHAR wcName[TC_MAX_PATH];
wcscpy_s(wcName, wcPath);
PathStripPath(wcName);
return WideCharToUtf8(wcName);
}
wstring GetStringResource(HINSTANCE hInst, UINT resourceId)
{
WCHAR wcString[MAX_STRING_RESOURCE];
LoadString(hInst, resourceId, wcString, MAX_STRING_RESOURCE);
return wstring(wcString);
}
std::wstring ConstCharToWstring(const char* path)
{
WCHAR wcString[MAX_STRING_RESOURCE];
MultiByteToWideChar(CP_ACP, 0, path, strlen(path) + 1, wcString, MAX_STRING_RESOURCE);
return std::wstring(wcString);
}
void OutputDebugFormat(LPCWSTR format, ...)
{
WCHAR logMessage[MAX_LOG_LENGTH];
va_list args;
va_start(args, format);
StringCchVPrintf(logMessage, MAX_LOG_LENGTH, format, args);
va_end(args);
OutputDebugString(logMessage);
}
string LocalPathToMegaPath(const WCHAR* wcLocalPath)
{
string str = WideCharToUtf8(wcLocalPath);
std::replace(str.begin(), str.end(), '\\', '/');
return str;
}
string GetFsMegaTempPath()
{
WCHAR tempPath[MAX_PATH];
GetTempPath(MAX_PATH, tempPath);
PathAppend(tempPath, _T("FsMega"));
CreateDirectory(tempPath, NULL);
return WideCharToUtf8(tempPath);
}