filesystem: use std for CreateFolder

Remove custom platform implementation of `CreateFolder` and replace uses
with `std::filesystem::create_directories` which creates paths
recursively.
This commit is contained in:
Sandy Carter 2020-04-09 10:17:13 -04:00 committed by Rick Gibbed
parent c8e64da4eb
commit 69bcf59c79
13 changed files with 11 additions and 28 deletions

View File

@ -352,7 +352,7 @@ void EmulatorWindow::ShowContentDirectory() {
}
if (!std::filesystem::exists(target_path)) {
xe::filesystem::CreateFolder(target_path);
std::filesystem::create_directories(target_path);
}
LaunchFileExplorer(target_path);

View File

@ -18,7 +18,7 @@ bool CreateParentFolder(const std::filesystem::path& path) {
if (path.has_parent_path()) {
auto parent_path = path.parent_path();
if (!std::filesystem::exists(parent_path)) {
return CreateFolder(parent_path);
return std::filesystem::create_directories(parent_path);
}
}
return true;

View File

@ -41,10 +41,6 @@ std::filesystem::path GetUserFolder();
// attempting to create it.
bool CreateParentFolder(const std::filesystem::path& path);
// Creates a folder at the specified path.
// Returns true if the path was created.
bool CreateFolder(const std::filesystem::path& path);
// Recursively deletes the files and folders at the specified path.
// Returns true if the path was found and removed.
bool DeleteFolder(const std::filesystem::path& path);

View File

@ -106,10 +106,6 @@ bool TruncateStdioFile(FILE* file, uint64_t length) {
return true;
}
bool CreateFolder(const std::filesystem::path& path) {
return mkdir(path.c_str(), 0774);
}
static int removeCallback(const char* fpath, const struct stat* sb,
int typeflag, struct FTW* ftwbuf) {
int rv = remove(fpath);

View File

@ -61,15 +61,6 @@ std::filesystem::path GetUserFolder() {
return result;
}
bool CreateFolder(const std::filesystem::path& path) {
std::filesystem::path create_path;
for (auto it = path.begin(); it != path.end(); ++it) {
create_path /= *it;
CreateDirectoryW(create_path.c_str(), nullptr);
}
return std::filesystem::exists(path);
}
bool DeleteFolder(const std::filesystem::path& path) {
auto double_null_path = path.wstring() + std::wstring(L"\0", 1);
SHFILEOPSTRUCT op = {0};

View File

@ -202,7 +202,7 @@ void PipelineCache::InitializeShaderStorage(
// cost - though D3D's internal validation would possibly be enough to ensure
// they are up to date).
auto shader_storage_shareable_root = shader_storage_root / "shareable";
if (!xe::filesystem::CreateFolder(shader_storage_shareable_root)) {
if (!std::filesystem::create_directories(shader_storage_shareable_root)) {
return;
}

View File

@ -47,7 +47,7 @@ std::pair<std::filesystem::path, std::filesystem::path> Shader::Dump(
auto target_path = base_path;
if (!target_path.empty()) {
target_path = std::filesystem::absolute(target_path);
xe::filesystem::CreateFolder(target_path);
std::filesystem::create_directories(target_path);
}
auto base_name =

View File

@ -33,7 +33,7 @@ bool TraceWriter::Open(const std::filesystem::path& path, uint32_t title_id) {
auto canonical_path = std::filesystem::absolute(path);
if (canonical_path.has_parent_path()) {
auto base_path = canonical_path.parent_path();
xe::filesystem::CreateFolder(base_path);
std::filesystem::create_directories(base_path);
}
file_ = xe::filesystem::OpenFile(canonical_path, "wb");

View File

@ -153,7 +153,7 @@ X_RESULT ContentManager::CreateContent(const std::string_view root_name,
return X_ERROR_ALREADY_EXISTS;
}
if (!xe::filesystem::CreateFolder(package_path)) {
if (!std::filesystem::create_directories(package_path)) {
return X_ERROR_ACCESS_DENIED;
}
@ -227,7 +227,7 @@ X_RESULT ContentManager::SetContentThumbnail(const XCONTENT_DATA& data,
std::vector<uint8_t> buffer) {
auto global_lock = global_critical_region_.Acquire();
auto package_path = ResolvePackagePath(data);
xe::filesystem::CreateFolder(package_path);
std::filesystem::create_directories(package_path);
if (std::filesystem::exists(package_path)) {
auto thumb_path = package_path / kThumbnailFileName;
auto file = xe::filesystem::OpenFile(thumb_path, "wb");

View File

@ -158,7 +158,7 @@ void UserProfile::SaveSetting(UserProfile::Setting* setting) {
auto serialized_setting = setting->Serialize();
auto content_dir =
kernel_state()->content_manager()->ResolveGameUserContentPath();
xe::filesystem::CreateFolder(content_dir);
std::filesystem::create_directories(content_dir);
auto setting_id = fmt::format("{:08X}", setting->setting_id);
auto file_path = content_dir / setting_id;
auto file = xe::filesystem::OpenFile(file_path, "wb");

View File

@ -29,7 +29,7 @@ bool HostPathDevice::Initialize() {
if (!std::filesystem::exists(host_path_)) {
if (!read_only_) {
// Create the path.
xe::filesystem::CreateFolder(host_path_);
std::filesystem::create_directories(host_path_);
} else {
XELOGE("Host path does not exist");
return false;

View File

@ -77,7 +77,7 @@ std::unique_ptr<Entry> HostPathEntry::CreateEntryInternal(
const std::string_view name, uint32_t attributes) {
auto full_path = host_path_ / xe::to_path(name);
if (attributes & kFileAttributeDirectory) {
if (!xe::filesystem::CreateFolder(full_path)) {
if (!std::filesystem::create_directories(full_path)) {
return nullptr;
}
} else {

View File

@ -62,7 +62,7 @@ int vfs_dump_main(const std::vector<std::string>& args) {
XELOGI("{}", entry->path());
auto dest_name = base_path / xe::to_path(entry->path());
if (entry->attributes() & kFileAttributeDirectory) {
xe::filesystem::CreateFolder(dest_name);
std::filesystem::create_directories(dest_name);
continue;
}