diff --git a/src/xenia/base/filesystem.cc b/src/xenia/base/filesystem.cc index 16dc1eb9e..0362a6f15 100644 --- a/src/xenia/base/filesystem.cc +++ b/src/xenia/base/filesystem.cc @@ -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 path_breaks; diff --git a/src/xenia/base/filesystem.h b/src/xenia/base/filesystem.h index 91304d273..1d6c2d914 100644 --- a/src/xenia/base/filesystem.h +++ b/src/xenia/base/filesystem.h @@ -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 ListFiles(const std::wstring& path); -std::string CanonicalizePath(const std::string& original_path); - class WildcardFlags { public: bool FromStart : 1, ToEnd : 1; diff --git a/src/xenia/base/filesystem_win.cc b/src/xenia/base/filesystem_win.cc index ecf694144..568d9f4eb 100644 --- a/src/xenia/base/filesystem_win.cc +++ b/src/xenia/base/filesystem_win.cc @@ -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 ListFiles(const std::wstring& path) { diff --git a/src/xenia/base/platform.h b/src/xenia/base/platform.h index f43fb4ff8..ee75d72c9 100644 --- a/src/xenia/base/platform.h +++ b/src/xenia/base/platform.h @@ -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 diff --git a/src/xenia/cpu/raw_module.cc b/src/xenia/cpu/raw_module.cc index 3142958f2..e36ce2fb7 100644 --- a/src/xenia/cpu/raw_module.cc +++ b/src/xenia/cpu/raw_module.cc @@ -9,6 +9,7 @@ #include "xenia/cpu/raw_module.h" +#include "xenia/base/filesystem.h" #include "xenia/base/platform.h" #include "xenia/base/string.h" @@ -21,8 +22,8 @@ RawModule::RawModule(Processor* processor) RawModule::~RawModule() {} bool RawModule::LoadFile(uint32_t base_address, const std::wstring& path) { - auto fixed_path = xe::to_string(xe::fix_path_separators(path)); - FILE* file = fopen(fixed_path.c_str(), "rb"); + auto fixed_path = xe::fix_path_separators(path); + FILE* file = xe::filesystem::OpenFile(fixed_path, "rb"); fseek(file, 0, SEEK_END); uint32_t file_length = static_cast(ftell(file)); fseek(file, 0, SEEK_SET); @@ -44,9 +45,9 @@ bool RawModule::LoadFile(uint32_t base_address, const std::wstring& path) { // Setup debug info. auto last_slash = fixed_path.find_last_of(xe::path_separator); if (last_slash != std::string::npos) { - name_ = fixed_path.substr(last_slash + 1); + name_ = xe::to_string(fixed_path.substr(last_slash + 1)); } else { - name_ = fixed_path; + name_ = xe::to_string(fixed_path); } // TODO(benvanik): debug info diff --git a/src/xenia/gpu/tracing.cc b/src/xenia/gpu/tracing.cc index 460799015..a387337ea 100644 --- a/src/xenia/gpu/tracing.cc +++ b/src/xenia/gpu/tracing.cc @@ -27,7 +27,7 @@ bool TraceWriter::Open(const std::wstring& path) { auto base_path = xe::find_base_path(canonical_path); xe::filesystem::CreateFolder(base_path); - file_ = _wfopen(canonical_path.c_str(), L"wb"); + file_ = xe::filesystem::OpenFile(canonical_path, "wb"); return file_ != nullptr; } diff --git a/src/xenia/kernel/content_manager.cc b/src/xenia/kernel/content_manager.cc index 0e65b9430..9fca09e7f 100644 --- a/src/xenia/kernel/content_manager.cc +++ b/src/xenia/kernel/content_manager.cc @@ -79,7 +79,7 @@ std::wstring ContentManager::ResolvePackageRoot(uint32_t content_type) { // content_root/title_id/type_name/ auto package_root = xe::join_paths(root_path_, xe::join_paths(title_id, type_name)); - return package_root + L"\\"; + return package_root + xe::wpath_separator; } std::wstring ContentManager::ResolvePackagePath(const XCONTENT_DATA& data) { @@ -207,7 +207,7 @@ X_RESULT ContentManager::GetContentThumbnail(const XCONTENT_DATA& data, auto package_path = ResolvePackagePath(data); auto thumb_path = xe::join_paths(package_path, kThumbnailFileName); if (xe::filesystem::PathExists(thumb_path)) { - auto file = _wfopen(thumb_path.c_str(), L"rb"); + auto file = xe::filesystem::OpenFile(thumb_path, "rb"); fseek(file, 0, SEEK_END); size_t file_len = ftell(file); fseek(file, 0, SEEK_SET); @@ -227,7 +227,7 @@ X_RESULT ContentManager::SetContentThumbnail(const XCONTENT_DATA& data, xe::filesystem::CreateFolder(package_path); if (xe::filesystem::PathExists(package_path)) { auto thumb_path = xe::join_paths(package_path, kThumbnailFileName); - auto file = _wfopen(thumb_path.c_str(), L"wb"); + auto file = xe::filesystem::OpenFile(thumb_path, "wb"); fwrite(buffer.data(), 1, buffer.size(), file); fclose(file); return X_ERROR_SUCCESS; diff --git a/src/xenia/vfs/entry.cc b/src/xenia/vfs/entry.cc index 61895e90d..97dd79f6b 100644 --- a/src/xenia/vfs/entry.cc +++ b/src/xenia/vfs/entry.cc @@ -9,6 +9,7 @@ #include "xenia/vfs/entry.h" +#include "xenia/base/filesystem.h" #include "xenia/base/string.h" #include "xenia/vfs/device.h" diff --git a/src/xenia/vfs/entry.h b/src/xenia/vfs/entry.h index 1eaf03d75..6027e8479 100644 --- a/src/xenia/vfs/entry.h +++ b/src/xenia/vfs/entry.h @@ -12,13 +12,16 @@ #include #include +#include -#include "xenia/base/filesystem.h" #include "xenia/base/mapped_memory.h" #include "xenia/base/string_buffer.h" #include "xenia/xbox.h" namespace xe { +namespace filesystem { +class WildcardEngine; +} // namespace filesystem namespace kernel { class KernelState; class XFile;