|
|
@ -33,6 +33,7 @@
|
|
|
|
#include <boost/filesystem/operations.hpp>
|
|
|
|
#include <boost/filesystem/operations.hpp>
|
|
|
|
#ifdef WIN32
|
|
|
|
#ifdef WIN32
|
|
|
|
#include <windows.h>
|
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
#include "string_tools.h"
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// On Windows there is a problem with non-ASCII characters in path and file names
|
|
|
|
// On Windows there is a problem with non-ASCII characters in path and file names
|
|
|
@ -72,11 +73,9 @@ namespace file_io_utils
|
|
|
|
bool save_string_to_file(const std::string& path_to_file, const std::string& str)
|
|
|
|
bool save_string_to_file(const std::string& path_to_file, const std::string& str)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
#ifdef WIN32
|
|
|
|
#ifdef WIN32
|
|
|
|
WCHAR wide_path[1000];
|
|
|
|
std::wstring wide_path;
|
|
|
|
int chars = MultiByteToWideChar(CP_UTF8, 0, path_to_file.c_str(), path_to_file.size() + 1, wide_path, 1000);
|
|
|
|
try { wide_path = string_tools::utf8_to_utf16(path_to_file); } catch (...) { return false; }
|
|
|
|
if (chars == 0)
|
|
|
|
HANDLE file_handle = CreateFileW(wide_path.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
return false;
|
|
|
|
|
|
|
|
HANDLE file_handle = CreateFileW(wide_path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
|
|
|
|
if (file_handle == INVALID_HANDLE_VALUE)
|
|
|
|
if (file_handle == INVALID_HANDLE_VALUE)
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
DWORD bytes_written;
|
|
|
|
DWORD bytes_written;
|
|
|
@ -131,11 +130,9 @@ namespace file_io_utils
|
|
|
|
bool load_file_to_string(const std::string& path_to_file, std::string& target_str, size_t max_size = 1000000000)
|
|
|
|
bool load_file_to_string(const std::string& path_to_file, std::string& target_str, size_t max_size = 1000000000)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
#ifdef WIN32
|
|
|
|
#ifdef WIN32
|
|
|
|
WCHAR wide_path[1000];
|
|
|
|
std::wstring wide_path;
|
|
|
|
int chars = MultiByteToWideChar(CP_UTF8, 0, path_to_file.c_str(), path_to_file.size() + 1, wide_path, 1000);
|
|
|
|
try { wide_path = string_tools::utf8_to_utf16(path_to_file); } catch (...) { return false; }
|
|
|
|
if (chars == 0)
|
|
|
|
HANDLE file_handle = CreateFileW(wide_path.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
return false;
|
|
|
|
|
|
|
|
HANDLE file_handle = CreateFileW(wide_path, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
|
|
|
|
if (file_handle == INVALID_HANDLE_VALUE)
|
|
|
|
if (file_handle == INVALID_HANDLE_VALUE)
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
DWORD file_size = GetFileSize(file_handle, NULL);
|
|
|
|
DWORD file_size = GetFileSize(file_handle, NULL);
|
|
|
@ -202,11 +199,9 @@ namespace file_io_utils
|
|
|
|
bool get_file_size(const std::string& path_to_file, uint64_t &size)
|
|
|
|
bool get_file_size(const std::string& path_to_file, uint64_t &size)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
#ifdef WIN32
|
|
|
|
#ifdef WIN32
|
|
|
|
WCHAR wide_path[1000];
|
|
|
|
std::wstring wide_path;
|
|
|
|
int chars = MultiByteToWideChar(CP_UTF8, 0, path_to_file.c_str(), path_to_file.size() + 1, wide_path, 1000);
|
|
|
|
try { wide_path = string_tools::utf8_to_utf16(path_to_file); } catch (...) { return false; }
|
|
|
|
if (chars == 0)
|
|
|
|
HANDLE file_handle = CreateFileW(wide_path.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
return false;
|
|
|
|
|
|
|
|
HANDLE file_handle = CreateFileW(wide_path, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
|
|
|
|
if (file_handle == INVALID_HANDLE_VALUE)
|
|
|
|
if (file_handle == INVALID_HANDLE_VALUE)
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
LARGE_INTEGER file_size;
|
|
|
|
LARGE_INTEGER file_size;
|
|
|
|