parent
1d7606097a
commit
1106029afc
|
@ -15,7 +15,7 @@ namespace xe {
|
||||||
namespace filesystem {
|
namespace filesystem {
|
||||||
|
|
||||||
std::string CanonicalizePath(const std::string& original_path) {
|
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::string path(xe::fix_path_separators(original_path, path_sep));
|
||||||
|
|
||||||
std::vector<std::string::size_type> path_breaks;
|
std::vector<std::string::size_type> path_breaks;
|
||||||
|
|
|
@ -19,12 +19,16 @@
|
||||||
namespace xe {
|
namespace xe {
|
||||||
namespace filesystem {
|
namespace filesystem {
|
||||||
|
|
||||||
|
std::string CanonicalizePath(const std::string& original_path);
|
||||||
|
|
||||||
bool PathExists(const std::wstring& path);
|
bool PathExists(const std::wstring& path);
|
||||||
|
|
||||||
bool CreateFolder(const std::wstring& path);
|
bool CreateFolder(const std::wstring& path);
|
||||||
bool DeleteFolder(const std::wstring& path);
|
bool DeleteFolder(const std::wstring& path);
|
||||||
bool IsFolder(const std::wstring& path);
|
bool IsFolder(const std::wstring& path);
|
||||||
|
|
||||||
|
FILE* OpenFile(const std::wstring& path, const char* mode);
|
||||||
|
|
||||||
struct FileInfo {
|
struct FileInfo {
|
||||||
enum class Type {
|
enum class Type {
|
||||||
kFile,
|
kFile,
|
||||||
|
@ -39,8 +43,6 @@ struct FileInfo {
|
||||||
};
|
};
|
||||||
std::vector<FileInfo> ListFiles(const std::wstring& path);
|
std::vector<FileInfo> ListFiles(const std::wstring& path);
|
||||||
|
|
||||||
std::string CanonicalizePath(const std::string& original_path);
|
|
||||||
|
|
||||||
class WildcardFlags {
|
class WildcardFlags {
|
||||||
public:
|
public:
|
||||||
bool FromStart : 1, ToEnd : 1;
|
bool FromStart : 1, ToEnd : 1;
|
||||||
|
|
|
@ -25,11 +25,11 @@ bool PathExists(const std::wstring& path) {
|
||||||
|
|
||||||
bool CreateFolder(const std::wstring& path) {
|
bool CreateFolder(const std::wstring& path) {
|
||||||
wchar_t folder[MAX_PATH] = {0};
|
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) {
|
while (end) {
|
||||||
wcsncpy(folder, path.c_str(), end - path.c_str() + 1);
|
wcsncpy(folder, path.c_str(), end - path.c_str() + 1);
|
||||||
CreateDirectory(folder, NULL);
|
CreateDirectory(folder, NULL);
|
||||||
end = wcschr(++end, L'\\');
|
end = wcschr(++end, xe::wpath_separator);
|
||||||
}
|
}
|
||||||
return PathExists(path);
|
return PathExists(path);
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,11 @@ bool IsFolder(const std::wstring& path) {
|
||||||
(attrib & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY;
|
(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)
|
#define COMBINE_TIME(t) (((uint64_t)t.dwHighDateTime << 32) | t.dwLowDateTime)
|
||||||
|
|
||||||
std::vector<FileInfo> ListFiles(const std::wstring& path) {
|
std::vector<FileInfo> ListFiles(const std::wstring& path) {
|
||||||
|
|
|
@ -65,9 +65,11 @@ namespace xe {
|
||||||
|
|
||||||
#if XE_PLATFORM_WIN32
|
#if XE_PLATFORM_WIN32
|
||||||
const char path_separator = '\\';
|
const char path_separator = '\\';
|
||||||
|
const wchar_t wpath_separator = L'\\';
|
||||||
const size_t max_path = _MAX_PATH;
|
const size_t max_path = _MAX_PATH;
|
||||||
#else
|
#else
|
||||||
const char path_separator = '/';
|
const char path_separator = '/';
|
||||||
|
const wchar_t wpath_separator = L'/';
|
||||||
const size_t max_path = 1024; // PATH_MAX
|
const size_t max_path = 1024; // PATH_MAX
|
||||||
#endif // XE_PLATFORM_WIN32
|
#endif // XE_PLATFORM_WIN32
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
#include "xenia/cpu/raw_module.h"
|
#include "xenia/cpu/raw_module.h"
|
||||||
|
|
||||||
|
#include "xenia/base/filesystem.h"
|
||||||
#include "xenia/base/platform.h"
|
#include "xenia/base/platform.h"
|
||||||
#include "xenia/base/string.h"
|
#include "xenia/base/string.h"
|
||||||
|
|
||||||
|
@ -21,8 +22,8 @@ RawModule::RawModule(Processor* processor)
|
||||||
RawModule::~RawModule() {}
|
RawModule::~RawModule() {}
|
||||||
|
|
||||||
bool RawModule::LoadFile(uint32_t base_address, const std::wstring& path) {
|
bool RawModule::LoadFile(uint32_t base_address, const std::wstring& path) {
|
||||||
auto fixed_path = xe::to_string(xe::fix_path_separators(path));
|
auto fixed_path = xe::fix_path_separators(path);
|
||||||
FILE* file = fopen(fixed_path.c_str(), "rb");
|
FILE* file = xe::filesystem::OpenFile(fixed_path, "rb");
|
||||||
fseek(file, 0, SEEK_END);
|
fseek(file, 0, SEEK_END);
|
||||||
uint32_t file_length = static_cast<uint32_t>(ftell(file));
|
uint32_t file_length = static_cast<uint32_t>(ftell(file));
|
||||||
fseek(file, 0, SEEK_SET);
|
fseek(file, 0, SEEK_SET);
|
||||||
|
@ -44,9 +45,9 @@ bool RawModule::LoadFile(uint32_t base_address, const std::wstring& path) {
|
||||||
// Setup debug info.
|
// Setup debug info.
|
||||||
auto last_slash = fixed_path.find_last_of(xe::path_separator);
|
auto last_slash = fixed_path.find_last_of(xe::path_separator);
|
||||||
if (last_slash != std::string::npos) {
|
if (last_slash != std::string::npos) {
|
||||||
name_ = fixed_path.substr(last_slash + 1);
|
name_ = xe::to_string(fixed_path.substr(last_slash + 1));
|
||||||
} else {
|
} else {
|
||||||
name_ = fixed_path;
|
name_ = xe::to_string(fixed_path);
|
||||||
}
|
}
|
||||||
// TODO(benvanik): debug info
|
// TODO(benvanik): debug info
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ bool TraceWriter::Open(const std::wstring& path) {
|
||||||
auto base_path = xe::find_base_path(canonical_path);
|
auto base_path = xe::find_base_path(canonical_path);
|
||||||
xe::filesystem::CreateFolder(base_path);
|
xe::filesystem::CreateFolder(base_path);
|
||||||
|
|
||||||
file_ = _wfopen(canonical_path.c_str(), L"wb");
|
file_ = xe::filesystem::OpenFile(canonical_path, "wb");
|
||||||
return file_ != nullptr;
|
return file_ != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -79,7 +79,7 @@ std::wstring ContentManager::ResolvePackageRoot(uint32_t content_type) {
|
||||||
// content_root/title_id/type_name/
|
// content_root/title_id/type_name/
|
||||||
auto package_root =
|
auto package_root =
|
||||||
xe::join_paths(root_path_, xe::join_paths(title_id, type_name));
|
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) {
|
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 package_path = ResolvePackagePath(data);
|
||||||
auto thumb_path = xe::join_paths(package_path, kThumbnailFileName);
|
auto thumb_path = xe::join_paths(package_path, kThumbnailFileName);
|
||||||
if (xe::filesystem::PathExists(thumb_path)) {
|
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);
|
fseek(file, 0, SEEK_END);
|
||||||
size_t file_len = ftell(file);
|
size_t file_len = ftell(file);
|
||||||
fseek(file, 0, SEEK_SET);
|
fseek(file, 0, SEEK_SET);
|
||||||
|
@ -227,7 +227,7 @@ X_RESULT ContentManager::SetContentThumbnail(const XCONTENT_DATA& data,
|
||||||
xe::filesystem::CreateFolder(package_path);
|
xe::filesystem::CreateFolder(package_path);
|
||||||
if (xe::filesystem::PathExists(package_path)) {
|
if (xe::filesystem::PathExists(package_path)) {
|
||||||
auto thumb_path = xe::join_paths(package_path, kThumbnailFileName);
|
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);
|
fwrite(buffer.data(), 1, buffer.size(), file);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
return X_ERROR_SUCCESS;
|
return X_ERROR_SUCCESS;
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
#include "xenia/vfs/entry.h"
|
#include "xenia/vfs/entry.h"
|
||||||
|
|
||||||
|
#include "xenia/base/filesystem.h"
|
||||||
#include "xenia/base/string.h"
|
#include "xenia/base/string.h"
|
||||||
#include "xenia/vfs/device.h"
|
#include "xenia/vfs/device.h"
|
||||||
|
|
||||||
|
|
|
@ -12,13 +12,16 @@
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "xenia/base/filesystem.h"
|
|
||||||
#include "xenia/base/mapped_memory.h"
|
#include "xenia/base/mapped_memory.h"
|
||||||
#include "xenia/base/string_buffer.h"
|
#include "xenia/base/string_buffer.h"
|
||||||
#include "xenia/xbox.h"
|
#include "xenia/xbox.h"
|
||||||
|
|
||||||
namespace xe {
|
namespace xe {
|
||||||
|
namespace filesystem {
|
||||||
|
class WildcardEngine;
|
||||||
|
} // namespace filesystem
|
||||||
namespace kernel {
|
namespace kernel {
|
||||||
class KernelState;
|
class KernelState;
|
||||||
class XFile;
|
class XFile;
|
||||||
|
|
Loading…
Reference in New Issue