Skip to content

Commit

Permalink
Remove charset converter dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
phunkyfish committed May 9, 2021
1 parent 4cac93a commit 69abb53
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/windows/FileUtils.cpp
Expand Up @@ -6,24 +6,36 @@
*/

#include "../FileUtils.h"
#include "p8-platform/windows/CharsetConverter.h"
#include <string>
#include "../utils.h"
#ifdef TARGET_WINDOWS_DESKTOP
#include <Shlobj.h>
#endif

#ifdef TARGET_WINDOWS
#include <windows.h>
#include <fileapi.h>
#endif

std::wstring ToW(const char* str, size_t length)
{
int result = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, str, length, nullptr, 0);
if (result == 0)
return std::wstring();

auto newStr = std::make_unique<wchar_t[]>(result);
result = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, str, length, newStr.get(), result);

if (result == 0)
return std::wstring();

return std::wstring(newStr.get(), result);
}

namespace OS
{
bool CFile::Exists(const std::string& strFileName, long* errCode)
{
std::string strWinFile = ToWindowsPath(strFileName);
std::wstring strWFile = p8::windows::ToW(strWinFile.c_str());
std::wstring strWFile = ToW(strWinFile.c_str(), 0);
DWORD dwAttr = GetFileAttributesW(strWFile.c_str());

if(dwAttr != 0xffffffff)
Expand Down

0 comments on commit 69abb53

Please sign in to comment.