filesystem: use std for PathExists

Remove custom platform implementation of `PathExists` and replace uses
with `std::filesystem::exists`.
This commit is contained in:
Sandy Carter 2020-04-09 10:09:18 -04:00 committed by Rick Gibbed
parent a9fa38c88b
commit c8e64da4eb
12 changed files with 23 additions and 36 deletions

View File

@ -351,7 +351,7 @@ void EmulatorWindow::ShowContentDirectory() {
target_path = package_root;
}
if (!xe::filesystem::PathExists(target_path)) {
if (!std::filesystem::exists(target_path)) {
xe::filesystem::CreateFolder(target_path);
}

View File

@ -215,7 +215,7 @@ int xenia_main(const std::vector<std::string>& args) {
std::filesystem::path storage_root = cvars::storage_root;
if (storage_root.empty()) {
storage_root = xe::filesystem::GetExecutableFolder();
if (!xe::filesystem::PathExists(storage_root / "portable.txt")) {
if (!std::filesystem::exists(storage_root / "portable.txt")) {
storage_root = xe::filesystem::GetUserFolder();
#if defined(XE_PLATFORM_WIN32) || defined(XE_PLATFORM_LINUX)
storage_root = storage_root / "Xenia";

View File

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

View File

@ -36,9 +36,6 @@ std::filesystem::path GetExecutableFolder();
// Get user folder.
std::filesystem::path GetUserFolder();
// Returns true of the specified path exists as either a directory or file.
bool PathExists(const std::filesystem::path& path);
// Creates the parent folder of the specified path if needed.
// This can be used to ensure the destination path for a new file exists before
// attempting to create it.

View File

@ -77,11 +77,6 @@ std::filesystem::path GetUserFolder() {
return std::filesystem::path(home) / ".local" / "share";
}
bool PathExists(const std::filesystem::path& path) {
struct stat st;
return stat(path.c_str(), &st) == 0;
}
FILE* OpenFile(const std::filesystem::path& path, const std::string_view mode) {
return fopen(path.c_str(), std::string(mode).c_str());
}

View File

@ -61,18 +61,13 @@ std::filesystem::path GetUserFolder() {
return result;
}
bool PathExists(const std::filesystem::path& path) {
DWORD attrib = GetFileAttributes(path.c_str());
return attrib != INVALID_FILE_ATTRIBUTES;
}
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 PathExists(path);
return std::filesystem::exists(path);
}
bool DeleteFolder(const std::filesystem::path& path) {

View File

@ -114,7 +114,7 @@ void SaveConfig() {
output << fmt::format("\t# {}\n", config_var->description());
}
if (xe::filesystem::PathExists(config_path)) {
if (std::filesystem::exists(config_path)) {
std::ifstream existingConfigStream(config_path);
const std::string existingConfig(
(std::istreambuf_iterator<char>(existingConfigStream)),
@ -136,7 +136,7 @@ void SetupConfig(const std::filesystem::path& config_folder) {
// check if the user specified a specific config to load
if (!cvars::config.empty()) {
config_path = xe::to_path(cvars::config);
if (xe::filesystem::PathExists(config_path)) {
if (std::filesystem::exists(config_path)) {
ReadConfig(config_path);
return;
}
@ -145,7 +145,7 @@ void SetupConfig(const std::filesystem::path& config_folder) {
// let's also load the default config
if (!config_folder.empty()) {
config_path = config_folder / config_name;
if (xe::filesystem::PathExists(config_path)) {
if (std::filesystem::exists(config_path)) {
ReadConfig(config_path);
}
// we only want to save the config if the user is using the default
@ -158,7 +158,7 @@ void LoadGameConfig(const std::string_view title_id) {
const auto game_config_folder = config_folder / "config";
const auto game_config_path =
game_config_folder / (std::string(title_id) + game_config_suffix);
if (xe::filesystem::PathExists(game_config_path)) {
if (std::filesystem::exists(game_config_path)) {
ReadGameConfig(game_config_path);
}
}

View File

@ -121,7 +121,7 @@ X_STATUS SDLInputDriver::Setup() {
sdl_gamecontroller_initialized_ = true;
if (!cvars::mappings_file.empty()) {
if (!filesystem::PathExists(cvars::mappings_file)) {
if (!std::filesystem::exists(cvars::mappings_file)) {
XELOGW("SDL GameControllerDB: file '{}' does not exist.",
xe::path_to_utf8(cvars::mappings_file));
} else {

View File

@ -122,7 +122,7 @@ std::vector<XCONTENT_DATA> ContentManager::ListContent(uint32_t device_id,
std::unique_ptr<ContentPackage> ContentManager::ResolvePackage(
const std::string_view root_name, const XCONTENT_DATA& data) {
auto package_path = ResolvePackagePath(data);
if (!xe::filesystem::PathExists(package_path)) {
if (!std::filesystem::exists(package_path)) {
return nullptr;
}
@ -135,7 +135,7 @@ std::unique_ptr<ContentPackage> ContentManager::ResolvePackage(
bool ContentManager::ContentExists(const XCONTENT_DATA& data) {
auto path = ResolvePackagePath(data);
return xe::filesystem::PathExists(path);
return std::filesystem::exists(path);
}
X_RESULT ContentManager::CreateContent(const std::string_view root_name,
@ -148,7 +148,7 @@ X_RESULT ContentManager::CreateContent(const std::string_view root_name,
}
auto package_path = ResolvePackagePath(data);
if (xe::filesystem::PathExists(package_path)) {
if (std::filesystem::exists(package_path)) {
// Exists, must not!
return X_ERROR_ALREADY_EXISTS;
}
@ -175,7 +175,7 @@ X_RESULT ContentManager::OpenContent(const std::string_view root_name,
}
auto package_path = ResolvePackagePath(data);
if (!xe::filesystem::PathExists(package_path)) {
if (!std::filesystem::exists(package_path)) {
// Does not exist, must be created.
return X_ERROR_FILE_NOT_FOUND;
}
@ -209,7 +209,7 @@ X_RESULT ContentManager::GetContentThumbnail(const XCONTENT_DATA& data,
auto global_lock = global_critical_region_.Acquire();
auto package_path = ResolvePackagePath(data);
auto thumb_path = package_path / kThumbnailFileName;
if (xe::filesystem::PathExists(thumb_path)) {
if (std::filesystem::exists(thumb_path)) {
auto file = xe::filesystem::OpenFile(thumb_path, "rb");
fseek(file, 0, SEEK_END);
size_t file_len = ftell(file);
@ -228,7 +228,7 @@ X_RESULT ContentManager::SetContentThumbnail(const XCONTENT_DATA& data,
auto global_lock = global_critical_region_.Acquire();
auto package_path = ResolvePackagePath(data);
xe::filesystem::CreateFolder(package_path);
if (xe::filesystem::PathExists(package_path)) {
if (std::filesystem::exists(package_path)) {
auto thumb_path = package_path / kThumbnailFileName;
auto file = xe::filesystem::OpenFile(thumb_path, "wb");
fwrite(buffer.data(), 1, buffer.size(), file);
@ -243,7 +243,7 @@ X_RESULT ContentManager::DeleteContent(const XCONTENT_DATA& data) {
auto global_lock = global_critical_region_.Acquire();
auto package_path = ResolvePackagePath(data);
if (xe::filesystem::PathExists(package_path)) {
if (std::filesystem::exists(package_path)) {
xe::filesystem::DeleteFolder(package_path);
return X_ERROR_SUCCESS;
} else {

View File

@ -11,7 +11,6 @@
#include "third_party/imgui/imgui.h"
#include "xenia/base/assert.h"
#include "xenia/base/filesystem.h"
#include "xenia/base/logging.h"
#include "xenia/ui/window.h"
@ -136,7 +135,7 @@ void ImGuiDrawer::SetupFont() {
// TODO(benvanik): jp font on other platforms?
// https://github.com/Koruri/kibitaki looks really good, but is 1.5MiB.
const char* jp_font_path = "C:\\Windows\\Fonts\\msgothic.ttc";
if (xe::filesystem::PathExists(jp_font_path)) {
if (std::filesystem::exists(jp_font_path)) {
ImFontConfig jp_font_config;
jp_font_config.MergeMode = true;
jp_font_config.OversampleH = jp_font_config.OversampleV = 1;

View File

@ -26,7 +26,7 @@ HostPathDevice::HostPathDevice(const std::string_view mount_path,
HostPathDevice::~HostPathDevice() = default;
bool HostPathDevice::Initialize() {
if (!xe::filesystem::PathExists(host_path_)) {
if (!std::filesystem::exists(host_path_)) {
if (!read_only_) {
// Create the path.
xe::filesystem::CreateFolder(host_path_);

View File

@ -61,13 +61,14 @@ StfsContainerDevice::~StfsContainerDevice() = default;
bool StfsContainerDevice::Initialize() {
// Resolve a valid STFS file if a directory is given.
if (std::filesystem::is_directory(host_path_) && !ResolveFromFolder(host_path_)) {
if (std::filesystem::is_directory(host_path_) &&
!ResolveFromFolder(host_path_)) {
XELOGE("Could not resolve an STFS container given path {}",
xe::path_to_utf8(host_path_));
return false;
}
if (!filesystem::PathExists(host_path_)) {
if (!std::filesystem::exists(host_path_)) {
XELOGE("Path to STFS container does not exist: {}",
xe::path_to_utf8(host_path_));
return false;
@ -120,7 +121,7 @@ StfsContainerDevice::Error StfsContainerDevice::MapFiles() {
// If the STFS package is multi-file, it is an SVOD system. We need to map
// the files in the .data folder and can discard the header.
auto data_fragment_path = host_path_ / ".data";
if (!filesystem::PathExists(data_fragment_path)) {
if (!std::filesystem::exists(data_fragment_path)) {
XELOGE("STFS container is multi-file, but path {} does not exist.",
xe::path_to_utf8(data_fragment_path));
return Error::kErrorFileMismatch;