_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

View File

@ -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<uint32_t>(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

View File

@ -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;
}

View File

@ -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;

View File

@ -9,6 +9,7 @@
#include "xenia/vfs/entry.h"
#include "xenia/base/filesystem.h"
#include "xenia/base/string.h"
#include "xenia/vfs/device.h"

View File

@ -12,13 +12,16 @@
#include <memory>
#include <string>
#include <vector>
#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;