131 {
132#ifdef WIN32
133 std::wstring wide_path;
134 try { wide_path = string_tools::utf8_to_utf16(path_to_file); } catch (...) { return false; }
135 HANDLE file_handle = CreateFileW(wide_path.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
136 if (file_handle == INVALID_HANDLE_VALUE)
137 return false;
138 DWORD file_size = GetFileSize(file_handle, NULL);
139 if ((file_size == INVALID_FILE_SIZE) || (
uint64_t)file_size > (
uint64_t)max_size) {
140 CloseHandle(file_handle);
141 return false;
142 }
143 target_str.resize(file_size);
144 DWORD bytes_read;
145 BOOL result = ReadFile(file_handle, &target_str[0], file_size, &bytes_read, NULL);
146 CloseHandle(file_handle);
147 if (bytes_read != file_size)
148 result = FALSE;
149 return result;
150#else
151 try
152 {
153 std::ifstream fstream;
154 fstream.exceptions(std::ifstream::failbit | std::ifstream::badbit);
155 fstream.open(path_to_file, std::ios_base::binary | std::ios_base::in | std::ios::ate);
156
157 std::ifstream::pos_type file_size = fstream.tellg();
158
160 return false;
161 size_t file_size_t = static_cast<size_t>(file_size);
162
163 target_str.resize(file_size_t);
164
165 fstream.seekg (0, std::ios::beg);
166 fstream.read((char*)target_str.data(), target_str.size());
167 fstream.close();
168 return true;
169 }
170
171 catch(...)
172 {
173 return false;
174 }
175#endif
176 }
unsigned __int64 uint64_t