-
Notifications
You must be signed in to change notification settings - Fork 540
/
Copy pathFileUtil.cpp
48 lines (35 loc) · 1.16 KB
/
FileUtil.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
#include "FileUtil.h"
#include "StringUtil.h"
#include <fstream>
#include <ShlObj.h>
template <typename Container>
bool read_helper(const std::wstring& path, Container& container)
{
std::basic_ifstream<typename Container::value_type> f(path, std::ios_base::binary);
if (!f.good())
return false;
container.assign((std::istreambuf_iterator<typename Container::value_type>(f)),
std::istreambuf_iterator<typename Container::value_type>());
container.push_back(acut::ensure_tchar<typename Container::value_type>('\0'));
return true;
}
bool acut::read_file(const std::wstring& path, std::string& buffer)
{
return read_helper(path, buffer);
}
bool acut::read_file(const std::wstring& path, std::vector<char>& buffer)
{
return read_helper(path, buffer);
}
bool acut::read_file(const std::wstring& path, std::wstring& buffer)
{
return read_helper(path, buffer);
}
bool acut::read_file(const std::wstring& path, std::vector<wchar_t>& buffer)
{
return read_helper(path, buffer);
}
bool acut::file_exists( const std::wstring& filename )
{
return (GetFileAttributesW( filename.c_str() ) != INVALID_FILE_ATTRIBUTES);
}