C++17ification.

C++17ification!

- Filesystem interaction now uses std::filesystem::path.
- Usage of const char*, std::string have been changed to
  std::string_view where appropriate.
- Usage of printf-style functions changed to use fmt.
This commit is contained in:
gibbed
2020-03-02 09:37:11 -06:00
committed by Rick Gibbed
parent 114cea6fb7
commit 5bf0b34445
220 changed files with 4944 additions and 4294 deletions

View File

@@ -2,7 +2,7 @@
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2015 Ben Vanik. All rights reserved. *
* Copyright 2020 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
@@ -10,6 +10,7 @@
#ifndef XENIA_BASE_FILESYSTEM_H_
#define XENIA_BASE_FILESYSTEM_H_
#include <filesystem>
#include <iterator>
#include <memory>
#include <string>
@@ -18,45 +19,48 @@
#include "xenia/base/string.h"
namespace xe {
std::string path_to_utf8(const std::filesystem::path& path);
std::u16string path_to_utf16(const std::filesystem::path& path);
std::filesystem::path to_path(const std::string_view source);
std::filesystem::path to_path(const std::u16string_view source);
namespace filesystem {
// Get executable path.
std::wstring GetExecutablePath();
std::filesystem::path GetExecutablePath();
// Get executable folder.
std::wstring GetExecutableFolder();
std::filesystem::path GetExecutableFolder();
// Get user folder.
std::wstring GetUserFolder();
// Canonicalizes a path, removing ..'s.
std::string CanonicalizePath(const std::string& original_path);
std::filesystem::path GetUserFolder();
// Returns true of the specified path exists as either a directory or file.
bool PathExists(const std::wstring& path);
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.
bool CreateParentFolder(const std::wstring& path);
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::wstring& path);
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::wstring& path);
bool DeleteFolder(const std::filesystem::path& path);
// Returns true if the given path exists and is a folder.
bool IsFolder(const std::wstring& path);
bool IsFolder(const std::filesystem::path& path);
// Creates an empty file at the given path.
bool CreateFile(const std::wstring& path);
bool CreateFile(const std::filesystem::path& path);
// Opens the file at the given path with the specified mode.
// This behaves like fopen and the returned handle can be used with stdio.
FILE* OpenFile(const std::wstring& path, const char* mode);
FILE* OpenFile(const std::filesystem::path& path, const std::string_view mode);
// Wrapper for the 64-bit version of fseek, returns true on success.
bool Seek(FILE* file, int64_t offset, int origin);
@@ -71,7 +75,7 @@ bool TruncateStdioFile(FILE* file, uint64_t length);
// Deletes the file at the given path.
// Returns true if the file was found and removed.
bool DeleteFile(const std::wstring& path);
bool DeleteFile(const std::filesystem::path& path);
struct FileAccess {
// Implies kFileReadData.
@@ -89,12 +93,12 @@ class FileHandle {
public:
// Opens the file, failing if it doesn't exist.
// The desired_access bitmask denotes the permissions on the file.
static std::unique_ptr<FileHandle> OpenExisting(std::wstring path,
uint32_t desired_access);
static std::unique_ptr<FileHandle> OpenExisting(
const std::filesystem::path& path, uint32_t desired_access);
virtual ~FileHandle() = default;
std::wstring path() const { return path_; }
const std::filesystem::path& path() const { return path_; }
// Reads the requested number of bytes from the file starting at the given
// offset. The total number of bytes read is returned only if the complete
@@ -115,9 +119,9 @@ class FileHandle {
virtual void Flush() = 0;
protected:
explicit FileHandle(std::wstring path) : path_(std::move(path)) {}
explicit FileHandle(const std::filesystem::path& path) : path_(path) {}
std::wstring path_;
std::filesystem::path path_;
};
struct FileInfo {
@@ -126,15 +130,15 @@ struct FileInfo {
kDirectory,
};
Type type;
std::wstring name;
std::wstring path;
std::filesystem::path name;
std::filesystem::path path;
size_t total_size;
uint64_t create_timestamp;
uint64_t access_timestamp;
uint64_t write_timestamp;
};
bool GetInfo(const std::wstring& path, FileInfo* out_info);
std::vector<FileInfo> ListFiles(const std::wstring& path);
bool GetInfo(const std::filesystem::path& path, FileInfo* out_info);
std::vector<FileInfo> ListFiles(const std::filesystem::path& path);
} // namespace filesystem
} // namespace xe