Use experimental/filesystem or filesystem depending on compiler
This commit is contained in:
@@ -60,6 +60,7 @@ add_library(common STATIC
|
||||
scm_rev.cpp
|
||||
scm_rev.h
|
||||
scope_exit.h
|
||||
std_filesystem.h
|
||||
string_util.cpp
|
||||
string_util.h
|
||||
swap.h
|
||||
|
||||
13
src/common/std_filesystem.h
Normal file
13
src/common/std_filesystem.h
Normal file
@@ -0,0 +1,13 @@
|
||||
// Copyright 2018 yuzu Emulator Project
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include <filesystem>
|
||||
namespace filesystem = std::filesystem;
|
||||
#else
|
||||
#include <experimental/filesystem>
|
||||
namespace filesystem = std::experimental::filesystem;
|
||||
#endif
|
||||
@@ -40,7 +40,7 @@ size_t VfsFile::WriteBytes(std::vector<u8> data, size_t offset) {
|
||||
return Write(data.data(), data.size(), offset);
|
||||
}
|
||||
|
||||
std::shared_ptr<VfsFile> VfsDirectory::GetFileRelative(const std::filesystem::path& path) const {
|
||||
std::shared_ptr<VfsFile> VfsDirectory::GetFileRelative(const filesystem::path& path) const {
|
||||
if (path.parent_path() == path.root_path())
|
||||
return GetFile(path.filename().string());
|
||||
|
||||
@@ -54,7 +54,7 @@ std::shared_ptr<VfsFile> VfsDirectory::GetFileRelative(const std::filesystem::pa
|
||||
return sub->GetFileRelative(path.root_path().string() + rest);
|
||||
}
|
||||
|
||||
std::shared_ptr<VfsFile> VfsDirectory::GetFileAbsolute(const std::filesystem::path& path) const {
|
||||
std::shared_ptr<VfsFile> VfsDirectory::GetFileAbsolute(const filesystem::path& path) const {
|
||||
if (IsRoot())
|
||||
return GetFileRelative(path);
|
||||
|
||||
|
||||
@@ -4,12 +4,13 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
#include "boost/optional.hpp"
|
||||
#include "common/common_types.h"
|
||||
#include "common/file_util.h"
|
||||
#include "common/std_filesystem.h"
|
||||
|
||||
namespace FileSys {
|
||||
struct VfsDirectory;
|
||||
@@ -85,8 +86,8 @@ struct VfsFile : NonCopyable {
|
||||
struct VfsDirectory : NonCopyable {
|
||||
virtual ~VfsDirectory();
|
||||
|
||||
virtual std::shared_ptr<VfsFile> GetFileRelative(const std::filesystem::path& path) const;
|
||||
virtual std::shared_ptr<VfsFile> GetFileAbsolute(const std::filesystem::path& path) const;
|
||||
virtual std::shared_ptr<VfsFile> GetFileRelative(const filesystem::path& path) const;
|
||||
virtual std::shared_ptr<VfsFile> GetFileAbsolute(const filesystem::path& path) const;
|
||||
|
||||
virtual std::vector<std::shared_ptr<VfsFile>> GetFiles() const = 0;
|
||||
virtual std::shared_ptr<VfsFile> GetFile(const std::string& name) const;
|
||||
|
||||
@@ -7,16 +7,16 @@
|
||||
|
||||
namespace FileSys {
|
||||
|
||||
static const char* PermissionsToCharArray(std::filesystem::perms perms) {
|
||||
static const char* PermissionsToCharArray(filesystem::perms perms) {
|
||||
std::string out;
|
||||
if ((perms & std::filesystem::perms::owner_read) != std::filesystem::perms::none)
|
||||
if ((perms & filesystem::perms::owner_read) != filesystem::perms::none)
|
||||
out += "r";
|
||||
if ((perms & std::filesystem::perms::owner_write) != std::filesystem::perms::none)
|
||||
if ((perms & filesystem::perms::owner_write) != filesystem::perms::none)
|
||||
out += "w";
|
||||
return out.c_str();
|
||||
}
|
||||
|
||||
RealVfsFile::RealVfsFile(const std::filesystem::path& path_, std::filesystem::perms perms_)
|
||||
RealVfsFile::RealVfsFile(const filesystem::path& path_, filesystem::perms perms_)
|
||||
: backing(path_.string(), PermissionsToCharArray(perms_)), path(path_), perms(perms_) {}
|
||||
|
||||
std::string RealVfsFile::GetName() const {
|
||||
@@ -36,11 +36,11 @@ std::shared_ptr<VfsDirectory> RealVfsFile::GetContainingDirectory() const {
|
||||
}
|
||||
|
||||
bool RealVfsFile::IsWritable() const {
|
||||
return (perms & std::filesystem::perms::owner_write) != std::filesystem::perms::none;
|
||||
return (perms & filesystem::perms::owner_write) != filesystem::perms::none;
|
||||
}
|
||||
|
||||
bool RealVfsFile::IsReadable() const {
|
||||
return (perms & std::filesystem::perms::owner_read) != std::filesystem::perms::none;
|
||||
return (perms & filesystem::perms::owner_read) != filesystem::perms::none;
|
||||
}
|
||||
|
||||
size_t RealVfsFile::Read(u8* data, size_t length, size_t offset) const {
|
||||
@@ -62,13 +62,12 @@ bool RealVfsFile::Rename(const std::string& name) {
|
||||
return out;
|
||||
}
|
||||
|
||||
RealVfsDirectory::RealVfsDirectory(const std::filesystem::path& path_,
|
||||
std::filesystem::perms perms_)
|
||||
RealVfsDirectory::RealVfsDirectory(const filesystem::path& path_, filesystem::perms perms_)
|
||||
: path(path_), perms(perms_) {
|
||||
for (const auto& entry : std::filesystem::directory_iterator(path)) {
|
||||
if (std::filesystem::is_directory(entry.path()))
|
||||
for (const auto& entry : filesystem::directory_iterator(path)) {
|
||||
if (filesystem::is_directory(entry.path()))
|
||||
subdirectories.emplace_back(std::make_shared<RealVfsDirectory>(entry.path(), perms));
|
||||
else if (std::filesystem::is_regular_file(entry.path()))
|
||||
else if (filesystem::is_regular_file(entry.path()))
|
||||
files.emplace_back(std::make_shared<RealVfsFile>(entry.path(), perms));
|
||||
}
|
||||
}
|
||||
@@ -82,11 +81,11 @@ std::vector<std::shared_ptr<VfsDirectory>> RealVfsDirectory::GetSubdirectories()
|
||||
}
|
||||
|
||||
bool RealVfsDirectory::IsWritable() const {
|
||||
return (perms & std::filesystem::perms::owner_write) != std::filesystem::perms::none;
|
||||
return (perms & filesystem::perms::owner_write) != filesystem::perms::none;
|
||||
}
|
||||
|
||||
bool RealVfsDirectory::IsReadable() const {
|
||||
return (perms & std::filesystem::perms::owner_read) != std::filesystem::perms::none;
|
||||
return (perms & filesystem::perms::owner_read) != filesystem::perms::none;
|
||||
}
|
||||
|
||||
std::string RealVfsDirectory::GetName() const {
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
namespace FileSys {
|
||||
|
||||
struct RealVfsFile : public VfsFile {
|
||||
RealVfsFile(const std::filesystem::path& name, std::filesystem::perms perms);
|
||||
RealVfsFile(const filesystem::path& name, filesystem::perms perms);
|
||||
|
||||
std::string GetName() const override;
|
||||
size_t GetSize() const override;
|
||||
@@ -25,12 +25,12 @@ struct RealVfsFile : public VfsFile {
|
||||
|
||||
private:
|
||||
FileUtil::IOFile backing;
|
||||
std::filesystem::path path;
|
||||
std::filesystem::perms perms;
|
||||
filesystem::path path;
|
||||
filesystem::perms perms;
|
||||
};
|
||||
|
||||
struct RealVfsDirectory : public VfsDirectory {
|
||||
RealVfsDirectory(const std::filesystem::path& path, std::filesystem::perms perms);
|
||||
RealVfsDirectory(const filesystem::path& path, filesystem::perms perms);
|
||||
|
||||
std::vector<std::shared_ptr<VfsFile>> GetFiles() const override;
|
||||
std::vector<std::shared_ptr<VfsDirectory>> GetSubdirectories() const override;
|
||||
@@ -46,8 +46,8 @@ struct RealVfsDirectory : public VfsDirectory {
|
||||
bool Rename(const std::string& name) override;
|
||||
|
||||
private:
|
||||
std::filesystem::path path;
|
||||
std::filesystem::perms perms;
|
||||
filesystem::path path;
|
||||
filesystem::perms perms;
|
||||
std::vector<std::shared_ptr<VfsFile>> files;
|
||||
std::vector<std::shared_ptr<VfsDirectory>> subdirectories;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user