_wfopen -> xe::filesystem::OpenFile.

Progress on #305.
This commit is contained in:
Ben Vanik
2015-06-28 17:16:44 -07:00
parent 1d7606097a
commit 1106029afc
9 changed files with 28 additions and 14 deletions

View File

@@ -15,7 +15,7 @@ namespace xe {
namespace filesystem {
std::string CanonicalizePath(const std::string& original_path) {
char path_sep('\\');
char path_sep(xe::path_separator);
std::string path(xe::fix_path_separators(original_path, path_sep));
std::vector<std::string::size_type> path_breaks;

View File

@@ -19,12 +19,16 @@
namespace xe {
namespace filesystem {
std::string CanonicalizePath(const std::string& original_path);
bool PathExists(const std::wstring& path);
bool CreateFolder(const std::wstring& path);
bool DeleteFolder(const std::wstring& path);
bool IsFolder(const std::wstring& path);
FILE* OpenFile(const std::wstring& path, const char* mode);
struct FileInfo {
enum class Type {
kFile,
@@ -39,8 +43,6 @@ struct FileInfo {
};
std::vector<FileInfo> ListFiles(const std::wstring& path);
std::string CanonicalizePath(const std::string& original_path);
class WildcardFlags {
public:
bool FromStart : 1, ToEnd : 1;

View File

@@ -25,11 +25,11 @@ bool PathExists(const std::wstring& path) {
bool CreateFolder(const std::wstring& path) {
wchar_t folder[MAX_PATH] = {0};
auto end = std::wcschr(path.c_str(), L'\\');
auto end = std::wcschr(path.c_str(), xe::wpath_separator);
while (end) {
wcsncpy(folder, path.c_str(), end - path.c_str() + 1);
CreateDirectory(folder, NULL);
end = wcschr(++end, L'\\');
end = wcschr(++end, xe::wpath_separator);
}
return PathExists(path);
}
@@ -49,6 +49,11 @@ bool IsFolder(const std::wstring& path) {
(attrib & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY;
}
FILE* OpenFile(const std::wstring& path, const char* mode) {
auto fixed_path = xe::fix_path_separators(path);
return _wfopen(fixed_path.c_str(), xe::to_wstring(mode).c_str());
}
#define COMBINE_TIME(t) (((uint64_t)t.dwHighDateTime << 32) | t.dwLowDateTime)
std::vector<FileInfo> ListFiles(const std::wstring& path) {

View File

@@ -65,9 +65,11 @@ namespace xe {
#if XE_PLATFORM_WIN32
const char path_separator = '\\';
const wchar_t wpath_separator = L'\\';
const size_t max_path = _MAX_PATH;
#else
const char path_separator = '/';
const wchar_t wpath_separator = L'/';
const size_t max_path = 1024; // PATH_MAX
#endif // XE_PLATFORM_WIN32