diff --git a/libaegisub/audio/provider.cpp b/libaegisub/audio/provider.cpp index c3598e08a6..961e5bf89c 100644 --- a/libaegisub/audio/provider.cpp +++ b/libaegisub/audio/provider.cpp @@ -81,7 +81,7 @@ class writer { std::ostream& out; public: - writer(std::filesystem::path const& filename) : outfile(filename, true), out(outfile.Get()) { } + writer(agi::fs::path const& filename) : outfile(filename, true), out(outfile.Get()) { } template void write(const char(&str)[N]) { diff --git a/libaegisub/audio/provider_dummy.cpp b/libaegisub/audio/provider_dummy.cpp index 3e7f104ef0..01a6ae5b47 100644 --- a/libaegisub/audio/provider_dummy.cpp +++ b/libaegisub/audio/provider_dummy.cpp @@ -58,7 +58,7 @@ class DummyAudioProvider final : public AudioProvider { } public: - DummyAudioProvider(std::filesystem::path const& uri) { + DummyAudioProvider(agi::fs::path const& uri) { noise = uri.string().find(":noise?") != std::string::npos; channels = 1; sample_rate = 44100; @@ -70,7 +70,7 @@ class DummyAudioProvider final : public AudioProvider { } namespace agi { -std::unique_ptr CreateDummyAudioProvider(std::filesystem::path const& file, agi::BackgroundRunner *) { +std::unique_ptr CreateDummyAudioProvider(agi::fs::path const& file, agi::BackgroundRunner *) { if (!file.string().starts_with("dummy-audio:")) return {}; return std::make_unique(file); diff --git a/libaegisub/audio/provider_hd.cpp b/libaegisub/audio/provider_hd.cpp index 730a6534df..a5d529ce69 100644 --- a/libaegisub/audio/provider_hd.cpp +++ b/libaegisub/audio/provider_hd.cpp @@ -21,14 +21,12 @@ #include #include -#include #include #include #include namespace { using namespace agi; -using namespace std::filesystem; class HDAudioProvider final : public AudioProviderWrapper { mutable temp_file_mapping file; @@ -49,7 +47,7 @@ class HDAudioProvider final : public AudioProviderWrapper { } } - path CacheFilename(path const& dir) { + fs::path CacheFilename(fs::path const& dir) { // Check free space if ((uint64_t)num_samples * bytes_per_sample > fs::FreeSpace(dir)) throw AudioProviderError("Not enough free disk space in " + dir.string() + " to cache the audio"); @@ -59,7 +57,7 @@ class HDAudioProvider final : public AudioProviderWrapper { } public: - HDAudioProvider(std::unique_ptr src, path const& dir) + HDAudioProvider(std::unique_ptr src, fs::path const& dir) : AudioProviderWrapper(std::move(src)) , file(dir / CacheFilename(dir), num_samples * bytes_per_sample) { @@ -83,7 +81,7 @@ class HDAudioProvider final : public AudioProviderWrapper { } namespace agi { -std::unique_ptr CreateHDAudioProvider(std::unique_ptr src, std::filesystem::path const& dir) { +std::unique_ptr CreateHDAudioProvider(std::unique_ptr src, agi::fs::path const& dir) { return std::make_unique(std::move(src), dir); } } diff --git a/libaegisub/common/charset.cpp b/libaegisub/common/charset.cpp index e00687b168..2d074870ae 100644 --- a/libaegisub/common/charset.cpp +++ b/libaegisub/common/charset.cpp @@ -22,7 +22,7 @@ #endif namespace agi::charset { -std::string Detect(std::filesystem::path const& file) { +std::string Detect(agi::fs::path const& file) { agi::read_file_mapping fp(file); // First check for known magic bytes which identify the file type diff --git a/libaegisub/common/file_mapping.cpp b/libaegisub/common/file_mapping.cpp index 8f715fd112..5d88f5e8e7 100644 --- a/libaegisub/common/file_mapping.cpp +++ b/libaegisub/common/file_mapping.cpp @@ -72,7 +72,7 @@ char *map(int64_t s_offset, uint64_t length, boost::interprocess::mode_t mode, } namespace agi { -file_mapping::file_mapping(std::filesystem::path const& filename, bool temporary) +file_mapping::file_mapping(agi::fs::path const& filename, bool temporary) #ifdef _WIN32 : handle(CreateFileW(filename.wstring().c_str(), temporary ? read_write : read_only, @@ -116,7 +116,7 @@ file_mapping::~file_mapping() { } } -read_file_mapping::read_file_mapping(std::filesystem::path const& filename) +read_file_mapping::read_file_mapping(agi::fs::path const& filename) : file(filename, false) { offset_t size = 0; @@ -134,7 +134,7 @@ const char *read_file_mapping::read(int64_t offset, uint64_t length) { return map(offset, length, read_only, file_size, file, region, mapping_start); } -temp_file_mapping::temp_file_mapping(std::filesystem::path const& filename, uint64_t size) +temp_file_mapping::temp_file_mapping(agi::fs::path const& filename, uint64_t size) : file(filename, true) , file_size(size) { diff --git a/libaegisub/common/format.cpp b/libaegisub/common/format.cpp index 8c58e498d4..0259ae4756 100644 --- a/libaegisub/common/format.cpp +++ b/libaegisub/common/format.cpp @@ -17,8 +17,7 @@ #include #include - -#include +#include #ifdef _MSC_VER #define WCHAR_T_ENC "utf-16le" diff --git a/libaegisub/common/fs.cpp b/libaegisub/common/fs.cpp index 35491fda1d..1f8f817cd2 100644 --- a/libaegisub/common/fs.cpp +++ b/libaegisub/common/fs.cpp @@ -26,7 +26,7 @@ namespace sfs = std::filesystem; namespace agi::fs { namespace { -void check_error(std::error_code ec, const char *exp, sfs::path const& src_path, sfs::path const& dst_path) { +void check_error(std::error_code ec, const char *exp, path const& src_path, path const& dst_path) { if (ec == std::error_code{}) return; using enum std::errc; switch (ec.value()) { @@ -55,7 +55,7 @@ void check_error(std::error_code ec, const char *exp, sfs::path const& src_path, check_error(ec, #exp, src_path, dst_path); #define CHECKED_CALL_RETURN(exp, src_path) \ - CHECKED_CALL(auto ret = exp, src_path, std::filesystem::path()); \ + CHECKED_CALL(auto ret = exp, src_path, agi::fs::path()); \ return ret #define WRAP_SFS(sfs_name, agi_name) \ @@ -69,6 +69,12 @@ void check_error(std::error_code ec, const char *exp, sfs::path const& src_path, return sfs::sfs_name(p, ec); \ } +#define WRAP_SFS_AGI_PATH(sfs_name, agi_name) \ + auto agi_name(path const& p) -> agi::fs::path { \ + CHECKED_CALL(auto ret = sfs::sfs_name(p, ec), p, agi::fs::path()); \ + return agi::fs::path(std::move(ret)); \ + } + // sasuga windows.h #undef CreateDirectory @@ -82,7 +88,8 @@ void check_error(std::error_code ec, const char *exp, sfs::path const& src_path, WRAP_SFS(last_write_time, ModifiedTime) WRAP_SFS(create_directories, CreateDirectory) WRAP_SFS(remove, Remove) - WRAP_SFS(canonical, Canonicalize) + WRAP_SFS_AGI_PATH(canonical, Canonicalize) + WRAP_SFS_AGI_PATH(absolute, Absolute) uintmax_t Size(path const& p) { if (DirectoryExists(p)) @@ -104,4 +111,12 @@ void check_error(std::error_code ec, const char *exp, sfs::path const& src_path, if (filename[filename.size() - ext.size() - 1] != '.') return false; return boost::iends_with(filename, ext); } + + agi::fs::path CurrentPath() { + return agi::fs::path(std::filesystem::current_path()); + } + + void CurrentPath(path const& path) { + std::filesystem::current_path(path); + } } diff --git a/libaegisub/common/io.cpp b/libaegisub/common/io.cpp index 55fe42575f..b7dce25645 100644 --- a/libaegisub/common/io.cpp +++ b/libaegisub/common/io.cpp @@ -22,7 +22,7 @@ #include namespace agi::io { -using namespace std::filesystem; +using namespace agi::fs; std::unique_ptr Open(path const& file, bool binary) { LOG_D("agi/io/open/file") << file; diff --git a/libaegisub/common/json.cpp b/libaegisub/common/json.cpp index cb65d20e6d..d24d031683 100644 --- a/libaegisub/common/json.cpp +++ b/libaegisub/common/json.cpp @@ -37,7 +37,7 @@ json::UnknownElement parse(std::istream &stream) { } } -json::UnknownElement file(std::filesystem::path const& file, std::string_view default_config) { +json::UnknownElement file(agi::fs::path const& file, std::string_view default_config) { try { if (fs::FileExists(file)) return parse(*io::Open(file)); diff --git a/libaegisub/common/keyframe.cpp b/libaegisub/common/keyframe.cpp index 1917feff69..33ea971331 100644 --- a/libaegisub/common/keyframe.cpp +++ b/libaegisub/common/keyframe.cpp @@ -90,7 +90,7 @@ int wwxd(std::string const& line) { } namespace agi::keyframe { -void Save(std::filesystem::path const& filename, std::vector const& keyframes) { +void Save(agi::fs::path const& filename, std::vector const& keyframes) { io::Save file(filename); std::ostream& of = file.Get(); of << "# keyframe format v1" << std::endl; @@ -98,7 +98,7 @@ void Save(std::filesystem::path const& filename, std::vector const& keyfram boost::copy(keyframes, std::ostream_iterator(of, "\n")); } -std::vector Load(std::filesystem::path const& filename) { +std::vector Load(agi::fs::path const& filename) { auto file = io::Open(filename); std::istream &is(*file); diff --git a/libaegisub/common/log.cpp b/libaegisub/common/log.cpp index 6f1b65c2c1..96c04fd0f5 100644 --- a/libaegisub/common/log.cpp +++ b/libaegisub/common/log.cpp @@ -17,11 +17,11 @@ #include "libaegisub/cajun/elements.h" #include "libaegisub/cajun/writer.h" #include "libaegisub/dispatch.h" +#include "libaegisub/fs.h" #include "libaegisub/util.h" #include #include -#include #include namespace agi::log { @@ -97,7 +97,7 @@ Message::~Message() { agi::log::log->Log(sm); } -JsonEmitter::JsonEmitter(std::filesystem::path const& directory) +JsonEmitter::JsonEmitter(agi::fs::path const& directory) : fp(new std::ofstream(directory/util::strftime("%Y-%m-%d-%H-%M-%S.json"))) { } diff --git a/libaegisub/common/mru.cpp b/libaegisub/common/mru.cpp index 81db2715ab..b92e827062 100644 --- a/libaegisub/common/mru.cpp +++ b/libaegisub/common/mru.cpp @@ -60,7 +60,7 @@ int mru_index(std::string_view key) { } namespace agi { -MRUManager::MRUManager(std::filesystem::path const& config, std::string_view default_config, agi::Options *options) +MRUManager::MRUManager(agi::fs::path const& config, std::string_view default_config, agi::Options *options) : config_name(config) , options(options) { @@ -78,7 +78,7 @@ MRUManager::MRUListMap &MRUManager::Find(std::string_view key) { return mru[index]; } -void MRUManager::Add(std::string_view key, std::filesystem::path const& entry) { +void MRUManager::Add(std::string_view key, agi::fs::path const& entry) { MRUListMap &map = Find(key); auto it = find(begin(map), end(map), entry); if (it == begin(map) && it != end(map)) @@ -93,7 +93,7 @@ void MRUManager::Add(std::string_view key, std::filesystem::path const& entry) { Flush(); } -void MRUManager::Remove(std::string_view key, std::filesystem::path const& entry) { +void MRUManager::Remove(std::string_view key, agi::fs::path const& entry) { auto& map = Find(key); map.erase(remove(begin(map), end(map), entry), end(map)); Flush(); @@ -103,7 +103,7 @@ const MRUManager::MRUListMap* MRUManager::Get(std::string_view key) { return &Find(key); } -std::filesystem::path const& MRUManager::GetEntry(std::string_view key, const size_t entry) { +agi::fs::path const& MRUManager::GetEntry(std::string_view key, const size_t entry) { const auto map = Get(key); if (entry >= map->size()) throw MRUError("Requested element index is out of range."); diff --git a/libaegisub/common/option.cpp b/libaegisub/common/option.cpp index 13e93a3a03..0a1f8c8b3a 100644 --- a/libaegisub/common/option.cpp +++ b/libaegisub/common/option.cpp @@ -171,7 +171,7 @@ struct option_name_cmp { namespace agi { -Options::Options(std::filesystem::path const& file, std::string_view default_config, OptionSetting setting) +Options::Options(agi::fs::path const& file, std::string_view default_config, OptionSetting setting) : config_file(file) , setting(setting) { diff --git a/libaegisub/common/path.cpp b/libaegisub/common/path.cpp index a98ca5cc92..9b29e652c5 100644 --- a/libaegisub/common/path.cpp +++ b/libaegisub/common/path.cpp @@ -92,7 +92,7 @@ fs::path Path::MakeRelative(fs::path const& path, fs::path const& base) const { auto ref_it = base.begin(); for (; path_it != path.end() && ref_it != base.end() && *path_it == *ref_it; ++path_it, ++ref_it) ; - std::filesystem::path result; + agi::fs::path result; for (; ref_it != base.end(); ++ref_it) result /= ".."; for (; path_it != path.end(); ++path_it) diff --git a/libaegisub/common/thesaurus.cpp b/libaegisub/common/thesaurus.cpp index 23366e82c5..25011b4e60 100644 --- a/libaegisub/common/thesaurus.cpp +++ b/libaegisub/common/thesaurus.cpp @@ -23,7 +23,7 @@ namespace agi { -Thesaurus::Thesaurus(std::filesystem::path const& dat_path, std::filesystem::path const& idx_path) +Thesaurus::Thesaurus(agi::fs::path const& dat_path, agi::fs::path const& idx_path) : dat(std::make_unique(dat_path)) { read_file_mapping idx_file(idx_path); diff --git a/libaegisub/common/vfr.cpp b/libaegisub/common/vfr.cpp index 693613297a..559bcaebb8 100644 --- a/libaegisub/common/vfr.cpp +++ b/libaegisub/common/vfr.cpp @@ -171,7 +171,7 @@ Framerate::Framerate(std::initializer_list timecodes) SetFromTimecodes(); } -Framerate::Framerate(std::filesystem::path const& filename) +Framerate::Framerate(agi::fs::path const& filename) : denominator(default_denominator) { auto file = agi::io::Open(filename); @@ -192,7 +192,7 @@ Framerate::Framerate(std::filesystem::path const& filename) throw UnknownFormat(line); } -void Framerate::Save(std::filesystem::path const& filename, int length) const { +void Framerate::Save(agi::fs::path const& filename, int length) const { agi::io::Save file(filename); auto &out = file.Get(); diff --git a/libaegisub/include/lagi_pre.h b/libaegisub/include/lagi_pre.h index 1a85a0d6be..f1c77fae33 100644 --- a/libaegisub/include/lagi_pre.h +++ b/libaegisub/include/lagi_pre.h @@ -18,7 +18,6 @@ #endif #include -#include #include #include #include diff --git a/libaegisub/include/libaegisub/access.h b/libaegisub/include/libaegisub/access.h index 08a5f281fc..f46a27d46b 100644 --- a/libaegisub/include/libaegisub/access.h +++ b/libaegisub/include/libaegisub/access.h @@ -12,7 +12,7 @@ // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -#include +#include namespace agi::acs { enum Type { @@ -22,11 +22,11 @@ enum Type { DirWrite }; -void Check(std::filesystem::path const& file, acs::Type); +void Check(agi::fs::path const& file, acs::Type); -static inline void CheckFileRead(std::filesystem::path const& file) { Check(file, acs::FileRead); } -static inline void CheckFileWrite(std::filesystem::path const& file) { Check(file, acs::FileWrite); } +static inline void CheckFileRead(agi::fs::path const& file) { Check(file, acs::FileRead); } +static inline void CheckFileWrite(agi::fs::path const& file) { Check(file, acs::FileWrite); } -static inline void CheckDirRead(std::filesystem::path const& dir) { Check(dir, acs::DirRead); } -static inline void CheckDirWrite(std::filesystem::path const& dir) { Check(dir, acs::DirWrite); } +static inline void CheckDirRead(agi::fs::path const& dir) { Check(dir, acs::DirRead); } +static inline void CheckDirWrite(agi::fs::path const& dir) { Check(dir, acs::DirWrite); } } diff --git a/libaegisub/include/libaegisub/audio/provider.h b/libaegisub/include/libaegisub/audio/provider.h index bdd1359d97..089ad589eb 100644 --- a/libaegisub/include/libaegisub/audio/provider.h +++ b/libaegisub/include/libaegisub/audio/provider.h @@ -17,9 +17,9 @@ #pragma once #include +#include #include -#include #include #include @@ -84,14 +84,14 @@ DEFINE_EXCEPTION(AudioDataNotFound, AudioProviderError); class BackgroundRunner; -std::unique_ptr CreateDummyAudioProvider(std::filesystem::path const& filename, BackgroundRunner *); -std::unique_ptr CreatePCMAudioProvider(std::filesystem::path const& filename, BackgroundRunner *); +std::unique_ptr CreateDummyAudioProvider(agi::fs::path const& filename, BackgroundRunner *); +std::unique_ptr CreatePCMAudioProvider(agi::fs::path const& filename, BackgroundRunner *); std::unique_ptr CreateConvertAudioProvider(std::unique_ptr source_provider); std::unique_ptr CreateLockAudioProvider(std::unique_ptr source_provider); std::unique_ptr CreateHDAudioProvider(std::unique_ptr source_provider, - std::filesystem::path const& dir); + agi::fs::path const& dir); std::unique_ptr CreateRAMAudioProvider(std::unique_ptr source_provider); -void SaveAudioClip(AudioProvider const& provider, std::filesystem::path const& path, int start_time, int end_time); +void SaveAudioClip(AudioProvider const& provider, agi::fs::path const& path, int start_time, int end_time); } diff --git a/libaegisub/include/libaegisub/charset.h b/libaegisub/include/libaegisub/charset.h index c8a5a00b9c..c3f75f5c4c 100644 --- a/libaegisub/include/libaegisub/charset.h +++ b/libaegisub/include/libaegisub/charset.h @@ -12,7 +12,7 @@ // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -#include +#include #include namespace agi { @@ -22,7 +22,7 @@ namespace agi { /// @brief Returns the character set with the highest confidence /// @param file File to check /// @return Detected character set. -std::string Detect(std::filesystem::path const& file); +std::string Detect(agi::fs::path const& file); } // namespace util } // namespace agi diff --git a/libaegisub/include/libaegisub/file_mapping.h b/libaegisub/include/libaegisub/file_mapping.h index e90ade8c3b..accf04e145 100644 --- a/libaegisub/include/libaegisub/file_mapping.h +++ b/libaegisub/include/libaegisub/file_mapping.h @@ -21,7 +21,7 @@ #endif #include -#include +#include namespace agi { // boost::interprocess::file_mapping is awesome and uses CreateFileA on Windows @@ -29,7 +29,7 @@ namespace agi { boost::interprocess::file_handle_t handle; public: - file_mapping(std::filesystem::path const& filename, bool temporary); + file_mapping(agi::fs::path const& filename, bool temporary); ~file_mapping(); boost::interprocess::mapping_handle_t get_mapping_handle() const { return boost::interprocess::ipcdetail::mapping_handle_from_file_handle(handle); @@ -43,7 +43,7 @@ namespace agi { uint64_t file_size = 0; public: - read_file_mapping(std::filesystem::path const& filename); + read_file_mapping(agi::fs::path const& filename); ~read_file_mapping(); uint64_t size() const { return file_size; } @@ -61,7 +61,7 @@ namespace agi { uint64_t write_mapping_start = 0; public: - temp_file_mapping(std::filesystem::path const& filename, uint64_t size); + temp_file_mapping(agi::fs::path const& filename, uint64_t size); ~temp_file_mapping(); const char *read(int64_t offset, uint64_t length); diff --git a/libaegisub/include/libaegisub/format.h b/libaegisub/include/libaegisub/format.h index 2b750d4b26..b322817266 100644 --- a/libaegisub/include/libaegisub/format.h +++ b/libaegisub/include/libaegisub/format.h @@ -16,7 +16,7 @@ #include #include -#include +#include #include class wxString; @@ -66,8 +66,8 @@ struct writer> { }; // Ensure things with specializations don't get implicitly initialized -template<> struct writer; -template<> struct writer; +template<> struct writer; +template<> struct writer; template<> struct writer; template<> struct writer; diff --git a/libaegisub/include/libaegisub/format_path.h b/libaegisub/include/libaegisub/format_path.h index 4440a8c9e8..90c6bc1ee7 100644 --- a/libaegisub/include/libaegisub/format_path.h +++ b/libaegisub/include/libaegisub/format_path.h @@ -14,20 +14,20 @@ // // Aegisub Project http://www.aegisub.org/ -#include +#include namespace agi { // Default version quotes the path template<> -struct writer { - static void write(std::basic_ostream& out, int max_len, std::filesystem::path const& value) { +struct writer { + static void write(std::basic_ostream& out, int max_len, agi::fs::path const& value) { out << value.string(); } }; template<> -struct writer { - static void write(std::basic_ostream& out, int max_len, std::filesystem::path const& value) { +struct writer { + static void write(std::basic_ostream& out, int max_len, agi::fs::path const& value) { out << value.wstring(); } }; diff --git a/libaegisub/include/libaegisub/fs.h b/libaegisub/include/libaegisub/fs.h index f2dad7ca18..5ecb920a4d 100644 --- a/libaegisub/include/libaegisub/fs.h +++ b/libaegisub/include/libaegisub/fs.h @@ -14,6 +14,8 @@ // // Aegisub Project http://www.aegisub.org/ +#pragma once + #include #include @@ -26,7 +28,66 @@ #undef CreateDirectory namespace agi::fs { -using path = std::filesystem::path; + +/// @class agi::fs::path +/// @brief Wrapper class around std::filesystem::path that properly handles +/// charset conversions. +/// +/// Takes UTF-8 strings in its constructor and returns UTF-8 strings +/// in string(). Should be used everywhere instead of std::filesystem::path. +/// +class path : public std::filesystem::path { +public: + path(std::string_view string) : std::filesystem::path(std::u8string(reinterpret_cast(string.data()), string.size())) {} + path(std::string const& string) : std::filesystem::path(std::u8string(reinterpret_cast(string.c_str()), string.size())) {} + path(const char *c_str) : std::filesystem::path(std::u8string(reinterpret_cast(c_str))) {} + + path() : std::filesystem::path() {} + + // These are marked as explicit so that there is no way to accidentally go + // from string to std::filesystem::path to agi::fs::path by implicit conversions + explicit path(std::filesystem::path const& inner) : std::filesystem::path(inner) {} + explicit path(std::filesystem::path &&inner) : std::filesystem::path(std::move(inner)) {} + + path(path const& other) = default; + path(path &&other) = default; + + path& operator=(path const& other) = default; + path& operator=(path &&other) = default; + + inline std::string string() const { + const auto result = agi::fs::path::u8string(); + return std::string(reinterpret_cast(result.c_str()), result.size()); + } + + // We do not override wstring() here: While the conversion method for this is technically unspecified here, + // it seems to always return UTF-16 in practice. If this ever changes, wstring() can be overwritten or deleted here. + + inline friend path operator/(path const& lhs, path const& rhs) { + const std::filesystem::path &lhs_ = lhs; + const std::filesystem::path &rhs_ = rhs; + return path(lhs_ / rhs_); + } + +#define WRAP_SFP(name) \ + inline path name() const { \ + return path(std::filesystem::path::name()); \ + }; + + WRAP_SFP(root_name); + WRAP_SFP(root_directory); + WRAP_SFP(root_path); + WRAP_SFP(relative_path); + WRAP_SFP(parent_path); + WRAP_SFP(filename); + WRAP_SFP(stem); + WRAP_SFP(extension); + + inline path& make_preferred() { + std::filesystem::path::make_preferred(); + return *this; + }; +}; /// Define a filesystem error which takes a path or a string #define DEFINE_FS_EXCEPTION(type, base, message) \ @@ -140,7 +201,10 @@ bool Remove(path const& file); /// @param ext Case-insensitive extension, without leading dot bool HasExtension(path const& p, std::string const& ext); -std::filesystem::path Canonicalize(std::filesystem::path const& path); +[[nodiscard]] path Canonicalize(path const& path); +[[nodiscard]] path Absolute(path const& path); +path CurrentPath(); +void CurrentPath(path const& path); class DirectoryIterator { struct PrivData; diff --git a/libaegisub/include/libaegisub/hotkey.h b/libaegisub/include/libaegisub/hotkey.h index 59180f4be4..d867ad462c 100644 --- a/libaegisub/include/libaegisub/hotkey.h +++ b/libaegisub/include/libaegisub/hotkey.h @@ -12,12 +12,12 @@ // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -#include #include #include #include #include +#include #include namespace json { @@ -64,7 +64,7 @@ class Hotkey { private: HotkeyMap cmd_map; ///< Command name -> Combo std::vector str_map; ///< Sorted by string representation - const std::filesystem::path config_file; ///< Default user config location. + const agi::fs::path config_file; ///< Default user config location. bool backup_config_file = false; /// Build hotkey map. @@ -83,7 +83,7 @@ class Hotkey { /// Constructor /// @param file Location of user config file. /// @param default_config Default config. - Hotkey(std::filesystem::path const& file, std::string_view default_config); + Hotkey(agi::fs::path const& file, std::string_view default_config); /// Scan for a matching key. /// @param context Context requested. diff --git a/libaegisub/include/libaegisub/io.h b/libaegisub/include/libaegisub/io.h index 8ac1ed3543..e3014cf7e9 100644 --- a/libaegisub/include/libaegisub/io.h +++ b/libaegisub/include/libaegisub/io.h @@ -13,8 +13,8 @@ // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include +#include -#include #include #include @@ -23,15 +23,15 @@ namespace agi::io { DEFINE_EXCEPTION(IOError, Exception); DEFINE_EXCEPTION(IOFatal, IOError); -std::unique_ptr Open(std::filesystem::path const& file, bool binary = false); +std::unique_ptr Open(agi::fs::path const& file, bool binary = false); class Save { std::unique_ptr fp; - const std::filesystem::path file_name; - const std::filesystem::path tmp_name; + const agi::fs::path file_name; + const agi::fs::path tmp_name; public: - Save(std::filesystem::path const& file, bool binary = false); + Save(agi::fs::path const& file, bool binary = false); ~Save() noexcept(false); std::ostream& Get() { return *fp; } }; diff --git a/libaegisub/include/libaegisub/json.h b/libaegisub/include/libaegisub/json.h index 1bb981af01..d781e14955 100644 --- a/libaegisub/include/libaegisub/json.h +++ b/libaegisub/include/libaegisub/json.h @@ -13,8 +13,7 @@ // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include - -#include +#include namespace agi::json_util { @@ -27,6 +26,6 @@ json::UnknownElement parse(std::istream &stream); /// @param file Path to JSON file. /// @param Default config file to load incase of nonexistent file /// @return json::UnknownElement -json::UnknownElement file(std::filesystem::path const& file, std::string_view default_config); +json::UnknownElement file(agi::fs::path const& file, std::string_view default_config); } diff --git a/libaegisub/include/libaegisub/keyframe.h b/libaegisub/include/libaegisub/keyframe.h index 91ac96fd48..9991310c14 100644 --- a/libaegisub/include/libaegisub/keyframe.h +++ b/libaegisub/include/libaegisub/keyframe.h @@ -12,21 +12,21 @@ // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +#include #include -#include #include namespace agi::keyframe { /// @brief Load a keyframe file /// @param filename File to load /// @return List of frame numbers which are keyframes -std::vector Load(std::filesystem::path const& filename); +std::vector Load(agi::fs::path const& filename); /// @brief Save keyframes to a file /// @param filename File to save to /// @param keyframes List of keyframes to save -void Save(std::filesystem::path const& filename, std::vector const& keyframes); +void Save(agi::fs::path const& filename, std::vector const& keyframes); DEFINE_EXCEPTION(KeyframeFormatParseError, agi::InvalidInputException); DEFINE_EXCEPTION(UnknownKeyframeFormatError, agi::InvalidInputException); diff --git a/libaegisub/include/libaegisub/log.h b/libaegisub/include/libaegisub/log.h index b25daaf456..424b821cdb 100644 --- a/libaegisub/include/libaegisub/log.h +++ b/libaegisub/include/libaegisub/log.h @@ -12,9 +12,9 @@ // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +#include #include #include -#include #include #include @@ -112,7 +112,7 @@ class JsonEmitter final : public Emitter { public: /// Constructor /// @param directory Directory to write the log file in - JsonEmitter(std::filesystem::path const& directory); + JsonEmitter(agi::fs::path const& directory); void log(SinkMessage const&) override; }; diff --git a/libaegisub/include/libaegisub/lua/script_reader.h b/libaegisub/include/libaegisub/lua/script_reader.h index 655ce1114f..760d440256 100644 --- a/libaegisub/include/libaegisub/lua/script_reader.h +++ b/libaegisub/include/libaegisub/lua/script_reader.h @@ -14,15 +14,15 @@ // // Aegisub Project http://www.aegisub.org/ -#include +#include #include struct lua_State; namespace agi::lua { /// Load a Lua or Moonscript file at the given path - bool LoadFile(lua_State *L, std::filesystem::path const& filename); + bool LoadFile(lua_State *L, agi::fs::path const& filename); /// Install our module loader and add include_path to the module search /// path of the given lua state - bool Install(lua_State *L, std::vector const& include_path); + bool Install(lua_State *L, std::vector const& include_path); } diff --git a/libaegisub/include/libaegisub/mru.h b/libaegisub/include/libaegisub/mru.h index 326576e16d..b95d31961e 100644 --- a/libaegisub/include/libaegisub/mru.h +++ b/libaegisub/include/libaegisub/mru.h @@ -13,11 +13,11 @@ // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include -#include #include #include #include +#include namespace json { class UnknownElement; @@ -39,23 +39,23 @@ DEFINE_EXCEPTION(MRUError, Exception); class MRUManager { public: /// @brief Map for time->value pairs. - using MRUListMap = std::vector; + using MRUListMap = std::vector; /// @brief Constructor /// @param config File to load MRU values from - MRUManager(std::filesystem::path const& config, std::string_view default_config, agi::Options *options = nullptr); + MRUManager(agi::fs::path const& config, std::string_view default_config, agi::Options *options = nullptr); /// @brief Add entry to the list. /// @param key List name /// @param entry Entry to add /// @exception MRUError thrown when an invalid key is used. - void Add(std::string_view key, std::filesystem::path const& entry); + void Add(std::string_view key, agi::fs::path const& entry); /// @brief Remove entry from the list. /// @param key List name /// @param entry Entry to add /// @exception MRUError thrown when an invalid key is used. - void Remove(std::string_view key, std::filesystem::path const& entry); + void Remove(std::string_view key, agi::fs::path const& entry); /// @brief Return list /// @param key List name @@ -66,14 +66,14 @@ class MRUManager { /// @param key List name /// @param entry 0-base position of entry /// @exception MRUError thrown when an invalid key is used. - std::filesystem::path const& GetEntry(std::string_view key, const size_t entry); + agi::fs::path const& GetEntry(std::string_view key, const size_t entry); /// Write MRU lists to disk. void Flush(); private: /// Internal name of the config file, set during object construction. - const std::filesystem::path config_name; + const agi::fs::path config_name; /// User preferences object for maximum number of items to list agi::Options *const options; diff --git a/libaegisub/include/libaegisub/option.h b/libaegisub/include/libaegisub/option.h index 61e19fb3fc..164c746d51 100644 --- a/libaegisub/include/libaegisub/option.h +++ b/libaegisub/include/libaegisub/option.h @@ -14,7 +14,7 @@ #pragma once -#include +#include #include #include #include @@ -40,7 +40,7 @@ class Options { std::vector> values; /// User config (file that will be written to disk) - const std::filesystem::path config_file; + const agi::fs::path config_file; /// Settings. const OptionSetting setting; @@ -54,7 +54,7 @@ class Options { /// @brief Constructor /// @param file User config that will be loaded from and written back to. /// @param default_config Default configuration. - Options(std::filesystem::path const& file, std::string_view default_config, OptionSetting setting = NONE); + Options(agi::fs::path const& file, std::string_view default_config, OptionSetting setting = NONE); /// Destructor ~Options(); diff --git a/libaegisub/include/libaegisub/path.h b/libaegisub/include/libaegisub/path.h index ab17c2f184..c980d9146a 100644 --- a/libaegisub/include/libaegisub/path.h +++ b/libaegisub/include/libaegisub/path.h @@ -14,11 +14,11 @@ // // Aegisub Project http://www.aegisub.org/ +#include + #include -#include namespace agi { -namespace fs { using path = std::filesystem::path; } /// Class for handling everything path-related in Aegisub class Path { /// Token -> Path map diff --git a/libaegisub/include/libaegisub/thesaurus.h b/libaegisub/include/libaegisub/thesaurus.h index e0a4fc9fae..4e1da08421 100644 --- a/libaegisub/include/libaegisub/thesaurus.h +++ b/libaegisub/include/libaegisub/thesaurus.h @@ -13,7 +13,7 @@ // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include -#include +#include #include #include #include @@ -40,7 +40,7 @@ class Thesaurus { /// Constructor /// @param dat_path Path to data file /// @param idx_path Path to index file - Thesaurus(std::filesystem::path const& dat_path, std::filesystem::path const& idx_path); + Thesaurus(agi::fs::path const& dat_path, agi::fs::path const& idx_path); ~Thesaurus(); /// Look up synonyms for a word diff --git a/libaegisub/include/libaegisub/vfr.h b/libaegisub/include/libaegisub/vfr.h index 92f6a89c31..3957b498f5 100644 --- a/libaegisub/include/libaegisub/vfr.h +++ b/libaegisub/include/libaegisub/vfr.h @@ -15,10 +15,10 @@ #pragma once #include -#include #include #include +#include namespace agi { /// Framerate handling. @@ -91,7 +91,7 @@ class Framerate { /// not the same thing as CFR X. When timecodes are loaded from a file, /// mkvmerge-style rounding is applied, while setting a constant frame rate /// uses truncation. - Framerate(std::filesystem::path const& filename); + Framerate(agi::fs::path const& filename); /// @brief CFR constructor /// @param fps Frames per second or 0 for unloaded @@ -190,7 +190,7 @@ class Framerate { /// CFR, but saving CFR timecodes is a bit silly). Extra timecodes generated /// to hit length with v2 timecodes will monotonically increase but may not /// be otherwise sensible. - void Save(std::filesystem::path const& file, int length = -1) const; + void Save(agi::fs::path const& file, int length = -1) const; /// Is this frame rate possibly variable? bool IsVFR() const {return timecodes.size() > 1; } diff --git a/libaegisub/lua/modules/lfs.cpp b/libaegisub/lua/modules/lfs.cpp index 0ed61ef23b..205d082bcc 100644 --- a/libaegisub/lua/modules/lfs.cpp +++ b/libaegisub/lua/modules/lfs.cpp @@ -46,7 +46,7 @@ auto wrap(char **err, Func f) -> decltype(f()) { } template -bool setter(const char *path, char **err, Ret (*f)(sfs::path const&)) { +bool setter(const char *path, char **err, Ret (*f)(agi::fs::path const&)) { return wrap(err, [=]{ f(path); return true; @@ -54,12 +54,12 @@ bool setter(const char *path, char **err, Ret (*f)(sfs::path const&)) { } bool lfs_chdir(const char *dir, char **err) { - return setter(dir, err, &sfs::current_path); + return setter(dir, err, CurrentPath); } char *currentdir(char **err) { return wrap(err, []{ - return strndup(sfs::current_path().string()); + return strndup(CurrentPath().string()); }); } diff --git a/libaegisub/lua/script_reader.cpp b/libaegisub/lua/script_reader.cpp index 95d0278f64..07d4dbd7e7 100644 --- a/libaegisub/lua/script_reader.cpp +++ b/libaegisub/lua/script_reader.cpp @@ -25,7 +25,7 @@ #include namespace agi::lua { - bool LoadFile(lua_State *L, std::filesystem::path const& raw_filename) { + bool LoadFile(lua_State *L, agi::fs::path const& raw_filename) { auto filename = raw_filename; try { filename = agi::fs::Canonicalize(raw_filename); @@ -89,9 +89,9 @@ namespace agi::lua { // If there's a .moon file at that path, load it instead of the // .lua file - std::filesystem::path path = filename; + agi::fs::path path = filename; if (agi::fs::HasExtension(path, "lua")) { - std::filesystem::path moonpath = path; + agi::fs::path moonpath = path; moonpath.replace_extension("moon"); if (agi::fs::FileExists(moonpath)) path = moonpath; diff --git a/libaegisub/unix/access.cpp b/libaegisub/unix/access.cpp index a8f42131c8..5fa0fae638 100644 --- a/libaegisub/unix/access.cpp +++ b/libaegisub/unix/access.cpp @@ -16,14 +16,13 @@ #include "libaegisub/fs.h" -#include #include #include #include namespace agi::acs { -void Check(std::filesystem::path const& file, acs::Type type) { +void Check(agi::fs::path const& file, acs::Type type) { auto cu = std::filesystem::current_path(); std::error_code ec; auto s = std::filesystem::status(file, ec); diff --git a/libaegisub/unix/fs.cpp b/libaegisub/unix/fs.cpp index a9adb12a61..19642594c1 100644 --- a/libaegisub/unix/fs.cpp +++ b/libaegisub/unix/fs.cpp @@ -19,7 +19,6 @@ #include "libaegisub/io.h" #include -#include #include #include #include diff --git a/libaegisub/unix/path.cpp b/libaegisub/unix/path.cpp index a171bc2a43..5dada5b06b 100644 --- a/libaegisub/unix/path.cpp +++ b/libaegisub/unix/path.cpp @@ -69,12 +69,12 @@ std::string exe_dir() { namespace agi { void Path::FillPlatformSpecificPaths() { #ifndef __APPLE__ - std::filesystem::path home = home_dir(); + agi::fs::path home = home_dir(); SetToken("?user", home/".aegisub"); SetToken("?local", home/".aegisub"); #ifdef APPIMAGE_BUILD - std::filesystem::path data = exe_dir(); + agi::fs::path data = exe_dir(); if (data == "") data = home/".aegisub"; SetToken("?data", data); SetToken("?dictionary", Decode("?data/dictionaries")); @@ -84,13 +84,13 @@ void Path::FillPlatformSpecificPaths() { #endif #else - std::filesystem::path app_support = agi::util::GetApplicationSupportDirectory(); + agi::fs::path app_support = agi::util::GetApplicationSupportDirectory(); SetToken("?user", app_support/"Aegisub"); SetToken("?local", app_support/"Aegisub"); SetToken("?data", agi::util::GetBundleSharedSupportDirectory()); SetToken("?dictionary", Decode("?data/dictionaries")); #endif - SetToken("?temp", std::filesystem::temp_directory_path()); + SetToken("?temp", agi::fs::path(std::filesystem::temp_directory_path())); } } diff --git a/libaegisub/windows/path_win.cpp b/libaegisub/windows/path_win.cpp index deddb42d5f..c1d21761ef 100644 --- a/libaegisub/windows/path_win.cpp +++ b/libaegisub/windows/path_win.cpp @@ -26,18 +26,22 @@ #include namespace { +agi::fs::path PathFromWString(std::wstring_view path) { + return agi::fs::path(std::filesystem::path(path)); +} + agi::fs::path WinGetFolderPath(int folder) { wchar_t path[MAX_PATH+1] = {0}; if (FAILED(SHGetFolderPathW(0, folder, 0, 0, path))) throw agi::EnvironmentError("SHGetFolderPath failed. This should not happen."); - return path; + return PathFromWString(path); } } namespace agi { void Path::FillPlatformSpecificPaths() { - SetToken("?temp", std::filesystem::temp_directory_path()); + SetToken("?temp", agi::fs::path(std::filesystem::temp_directory_path())); SetToken("?user", WinGetFolderPath(CSIDL_APPDATA)/"Aegisub"); SetToken("?local", WinGetFolderPath(CSIDL_LOCAL_APPDATA)/"Aegisub"); @@ -45,7 +49,7 @@ void Path::FillPlatformSpecificPaths() { std::wstring filename(MAX_PATH + 1, L'\0'); while (static_cast(filename.size()) == GetModuleFileNameW(nullptr, &filename[0], filename.size())) filename.resize(filename.size() * 2); - SetToken("?data", filename); + SetToken("?data", PathFromWString(filename)); SetToken("?dictionary", Decode("?data/dictionaries")); } diff --git a/src/ass_attachment.cpp b/src/ass_attachment.cpp index d198039517..21c4a4c482 100644 --- a/src/ass_attachment.cpp +++ b/src/ass_attachment.cpp @@ -33,7 +33,7 @@ AssAttachment::AssAttachment(std::string const& header, AssEntryGroup group) { } -AssAttachment::AssAttachment(std::filesystem::path const& name, AssEntryGroup group) +AssAttachment::AssAttachment(agi::fs::path const& name, AssEntryGroup group) : filename(name.filename().string()) , group(group) { @@ -53,7 +53,7 @@ size_t AssAttachment::GetSize() const { return entry_data.get().size() - header_end - 1; } -void AssAttachment::Extract(std::filesystem::path const& filename) const { +void AssAttachment::Extract(agi::fs::path const& filename) const { auto header_end = entry_data.get().find('\n'); auto decoded = agi::ass::UUDecode(entry_data.get().c_str() + header_end + 1, &entry_data.get().back() + 1); agi::io::Save(filename, true).Get().write(&decoded[0], decoded.size()); diff --git a/src/ass_attachment.h b/src/ass_attachment.h index 81f1af224f..94233b5c4d 100644 --- a/src/ass_attachment.h +++ b/src/ass_attachment.h @@ -17,7 +17,7 @@ #include "ass_entry.h" #include -#include +#include /// @class AssAttachment class AssAttachment final : public AssEntry { @@ -38,7 +38,7 @@ class AssAttachment final : public AssEntry { /// Extract the contents of this attachment to a file /// @param filename Path to save the attachment to - void Extract(std::filesystem::path const& filename) const; + void Extract(agi::fs::path const& filename) const; /// Get the name of the attached file /// @param raw If false, remove the SSA filename mangling @@ -49,5 +49,5 @@ class AssAttachment final : public AssEntry { AssAttachment(AssAttachment const& rgt) = default; AssAttachment(std::string const& header, AssEntryGroup group); - AssAttachment(std::filesystem::path const& name, AssEntryGroup group); + AssAttachment(agi::fs::path const& name, AssEntryGroup group); }; diff --git a/src/ass_exporter.cpp b/src/ass_exporter.cpp index 39b227706b..c5726ad13c 100644 --- a/src/ass_exporter.cpp +++ b/src/ass_exporter.cpp @@ -79,7 +79,7 @@ std::vector AssExporter::GetAllFilterNames() const { return names; } -void AssExporter::Export(std::filesystem::path const& filename, const char *charset, wxWindow *export_dialog) { +void AssExporter::Export(agi::fs::path const& filename, const char *charset, wxWindow *export_dialog) { AssFile subs(*c->ass); for (auto filter : filters) { diff --git a/src/ass_exporter.h b/src/ass_exporter.h index 4dd8ea804d..cd8149c266 100644 --- a/src/ass_exporter.h +++ b/src/ass_exporter.h @@ -27,7 +27,7 @@ // // Aegisub Project http://www.aegisub.org/ -#include +#include #include #include #include @@ -67,7 +67,7 @@ class AssExporter { /// @param file Target filename /// @param charset Target charset /// @param parent_window Parent window the filters should use when opening dialogs - void Export(std::filesystem::path const& file, const char *charset, wxWindow *parent_window= nullptr); + void Export(agi::fs::path const& file, const char *charset, wxWindow *parent_window= nullptr); /// Add configuration panels for all registered filters to the target sizer /// @param parent Parent window for controls diff --git a/src/ass_file.cpp b/src/ass_file.cpp index 35557de6ff..ed02ef3eee 100644 --- a/src/ass_file.cpp +++ b/src/ass_file.cpp @@ -97,7 +97,7 @@ EntryList::iterator AssFile::iterator_to(AssDialogue& line) { return in_list ? Events.iterator_to(line) : Events.end(); } -void AssFile::InsertAttachment(std::filesystem::path const& filename) { +void AssFile::InsertAttachment(agi::fs::path const& filename) { AssEntryGroup group = AssEntryGroup::GRAPHIC; auto ext = boost::to_lower_copy(filename.extension().string()); diff --git a/src/ass_file.h b/src/ass_file.h index eb94a9cd12..be4735b62f 100644 --- a/src/ass_file.h +++ b/src/ass_file.h @@ -29,9 +29,9 @@ #include "ass_entry.h" +#include #include -#include #include #include #include @@ -105,7 +105,7 @@ class AssFile { /// @param style_catalog Style catalog name to fill styles from, blank to use default style void LoadDefault(bool defline = true, std::string const& style_catalog = std::string()); /// Attach a file to the ass file - void InsertAttachment(std::filesystem::path const& filename); + void InsertAttachment(agi::fs::path const& filename); /// Get the names of all of the styles available std::vector GetStyles() const; /// @brief Get a style by name diff --git a/src/ass_style_storage.cpp b/src/ass_style_storage.cpp index 0cdcea462d..5a9a374f00 100644 --- a/src/ass_style_storage.cpp +++ b/src/ass_style_storage.cpp @@ -57,7 +57,7 @@ void AssStyleStorage::Save() const { out.Get() << cur->GetEntryData() << "\n"; } -void AssStyleStorage::Load(std::filesystem::path const& filename) { +void AssStyleStorage::Load(agi::fs::path const& filename) { file = filename; clear(); @@ -102,7 +102,7 @@ AssStyle *AssStyleStorage::GetStyle(std::string_view name) { std::vector AssStyleStorage::GetCatalogs() { std::vector catalogs; for (auto const& file : agi::fs::DirectoryIterator(config::path->Decode("?user/catalog/"), "*.sty")) - catalogs.push_back(std::filesystem::path(file).stem().string()); + catalogs.push_back(agi::fs::path(file).stem().string()); return catalogs; } diff --git a/src/ass_style_storage.h b/src/ass_style_storage.h index 6b1f7cb8e1..aa607ff591 100644 --- a/src/ass_style_storage.h +++ b/src/ass_style_storage.h @@ -27,7 +27,7 @@ // // Aegisub Project http://www.aegisub.org/ -#include +#include #include #include #include @@ -36,7 +36,7 @@ class AssFile; class AssStyle; class AssStyleStorage { - std::filesystem::path file; + agi::fs::path file; std::vector> style; public: @@ -70,7 +70,7 @@ class AssStyleStorage { /// Load stored styles from a file /// @param filename Catalog filename. Does not have to exist. - void Load(std::filesystem::path const& filename); + void Load(agi::fs::path const& filename); /// Load stored styles from a file in the default location /// @param catalogname Basename for the catalog file. Does not have to exist. diff --git a/src/async_video_provider.cpp b/src/async_video_provider.cpp index ddd0c4c6f2..54e5789e0e 100644 --- a/src/async_video_provider.cpp +++ b/src/async_video_provider.cpp @@ -91,7 +91,7 @@ static std::unique_ptr get_subs_provider(wxEvtHandler *evt_ha } } -AsyncVideoProvider::AsyncVideoProvider(std::filesystem::path const& video_filename, std::string_view colormatrix, wxEvtHandler *parent, agi::BackgroundRunner *br) +AsyncVideoProvider::AsyncVideoProvider(agi::fs::path const& video_filename, std::string_view colormatrix, wxEvtHandler *parent, agi::BackgroundRunner *br) : worker(agi::dispatch::Create()) , subs_provider(get_subs_provider(parent, br)) , source_provider(VideoProviderFactory::GetProvider(video_filename, colormatrix, br)) diff --git a/src/async_video_provider.h b/src/async_video_provider.h index 8d06f26dd0..6b4603842c 100644 --- a/src/async_video_provider.h +++ b/src/async_video_provider.h @@ -17,9 +17,9 @@ #include "include/aegisub/video_provider.h" #include +#include #include -#include #include #include #include @@ -127,7 +127,7 @@ class AsyncVideoProvider { /// @brief Constructor /// @param videoFileName File to open /// @param parent Event handler to send FrameReady events to - AsyncVideoProvider(std::filesystem::path const& filename, std::string_view colormatrix, wxEvtHandler *parent, agi::BackgroundRunner *br); + AsyncVideoProvider(agi::fs::path const& filename, std::string_view colormatrix, wxEvtHandler *parent, agi::BackgroundRunner *br); ~AsyncVideoProvider(); }; diff --git a/src/audio_provider_avs.cpp b/src/audio_provider_avs.cpp index 895e8c0283..ca6eb85d42 100644 --- a/src/audio_provider_avs.cpp +++ b/src/audio_provider_avs.cpp @@ -57,12 +57,12 @@ class AvisynthAudioProvider final : public agi::AudioProvider { void FillBuffer(void *buf, int64_t start, int64_t count) const; public: - AvisynthAudioProvider(std::filesystem::path const& filename); + AvisynthAudioProvider(agi::fs::path const& filename); bool NeedsCache() const override { return true; } }; -AvisynthAudioProvider::AvisynthAudioProvider(std::filesystem::path const& filename) { +AvisynthAudioProvider::AvisynthAudioProvider(agi::fs::path const& filename) { agi::acs::CheckFileRead(filename); std::lock_guard lock(avs_wrapper.GetMutex()); @@ -79,7 +79,7 @@ AvisynthAudioProvider::AvisynthAudioProvider(std::filesystem::path const& filena AVSValue args[3] = { env->SaveString(agi::fs::ShortName(filename).c_str()), false, true }; // Load DirectShowSource.dll from app dir if it exists - std::filesystem::path dsspath(config::path->Decode("?data/DirectShowSource.dll")); + agi::fs::path dsspath(config::path->Decode("?data/DirectShowSource.dll")); if (agi::fs::FileExists(dsspath)) env->Invoke("LoadPlugin", env->SaveString(agi::fs::ShortName(dsspath).c_str())); @@ -142,7 +142,7 @@ void AvisynthAudioProvider::FillBuffer(void *buf, int64_t start, int64_t count) } } -std::unique_ptr CreateAvisynthAudioProvider(std::filesystem::path const& file, agi::BackgroundRunner *) { +std::unique_ptr CreateAvisynthAudioProvider(agi::fs::path const& file, agi::BackgroundRunner *) { return std::make_unique(file); } #endif diff --git a/src/audio_provider_factory.h b/src/audio_provider_factory.h index a8a58646f5..7e0c6b0649 100644 --- a/src/audio_provider_factory.h +++ b/src/audio_provider_factory.h @@ -14,7 +14,7 @@ // // Aegisub Project http://www.aegisub.org/ -#include +#include #include #include @@ -24,7 +24,7 @@ namespace agi { class Path; } -std::unique_ptr GetAudioProvider(std::filesystem::path const& filename, +std::unique_ptr GetAudioProvider(agi::fs::path const& filename, agi::Path const& path_helper, agi::BackgroundRunner *br); std::vector GetAudioProviderNames(); diff --git a/src/audio_provider_ffmpegsource.cpp b/src/audio_provider_ffmpegsource.cpp index 76cd7ab307..7788ea34aa 100644 --- a/src/audio_provider_ffmpegsource.cpp +++ b/src/audio_provider_ffmpegsource.cpp @@ -50,21 +50,21 @@ class FFmpegSourceAudioProvider final : public agi::AudioProvider, FFmpegSourceP mutable char FFMSErrMsg[1024]; ///< FFMS error message mutable FFMS_ErrorInfo ErrInfo; ///< FFMS error codes/messages - void LoadAudio(std::filesystem::path const& filename); + void LoadAudio(agi::fs::path const& filename); void FillBuffer(void *Buf, int64_t Start, int64_t Count) const override { if (FFMS_GetAudio(AudioSource, Buf, Start, Count, &ErrInfo)) throw agi::AudioDecodeError(std::string("Failed to get audio samples: ") + ErrInfo.Buffer); } public: - FFmpegSourceAudioProvider(std::filesystem::path const& filename, agi::BackgroundRunner *br); + FFmpegSourceAudioProvider(agi::fs::path const& filename, agi::BackgroundRunner *br); bool NeedsCache() const override { return true; } }; /// @brief Constructor /// @param filename The filename to open -FFmpegSourceAudioProvider::FFmpegSourceAudioProvider(std::filesystem::path const& filename, agi::BackgroundRunner *br) try +FFmpegSourceAudioProvider::FFmpegSourceAudioProvider(agi::fs::path const& filename, agi::BackgroundRunner *br) try : FFmpegSourceProvider(br) , AudioSource(nullptr, FFMS_DestroyAudioSource) { @@ -80,7 +80,7 @@ catch (agi::EnvironmentError const& err) { throw agi::AudioProviderError(err.GetMessage()); } -void FFmpegSourceAudioProvider::LoadAudio(std::filesystem::path const& filename) { +void FFmpegSourceAudioProvider::LoadAudio(agi::fs::path const& filename) { FFMS_Indexer *Indexer = FFMS_CreateIndexer(filename.string().c_str(), &ErrInfo); if (!Indexer) { if (ErrInfo.SubType == FFMS_ERROR_FILE_READ) @@ -106,7 +106,7 @@ void FFmpegSourceAudioProvider::LoadAudio(std::filesystem::path const& filename) throw agi::AudioDataNotFound("no audio tracks found"); // generate a name for the cache file - std::filesystem::path CacheName = GetCacheFilename(filename); + agi::fs::path CacheName = GetCacheFilename(filename); // try to read index agi::scoped_holder @@ -181,7 +181,7 @@ void FFmpegSourceAudioProvider::LoadAudio(std::filesystem::path const& filename) } -std::unique_ptr CreateFFmpegSourceAudioProvider(std::filesystem::path const& file, agi::BackgroundRunner *br) { +std::unique_ptr CreateFFmpegSourceAudioProvider(agi::fs::path const& file, agi::BackgroundRunner *br) { return std::make_unique(file, br); } diff --git a/src/auto4_base.cpp b/src/auto4_base.cpp index 70a72599a2..a97aa24ec7 100644 --- a/src/auto4_base.cpp +++ b/src/auto4_base.cpp @@ -249,7 +249,7 @@ namespace Automation4 { } // Script - Script::Script(std::filesystem::path const& filename) + Script::Script(agi::fs::path const& filename) : filename(filename) { include_path.emplace_back(filename.parent_path()); @@ -315,7 +315,7 @@ namespace Automation4 { std::vector>> script_futures; - std::set dirnames; + std::set dirnames; for (auto tok : agi::Split(path, '|')) { auto dirname = config::path->Decode(std::string(tok)); if (!agi::fs::DirectoryExists(dirname)) continue; @@ -375,7 +375,7 @@ namespace Automation4 { char first_char = tok[0]; std::string trimmed(begin(tok) + 1, end(tok)); - std::filesystem::path basepath; + agi::fs::path basepath; if (first_char == '~') { basepath = context->subsController->Filename().parent_path(); } else if (first_char == '$') { @@ -407,7 +407,7 @@ namespace Automation4 { // 3. If step 2 failed, or absolute path is shorter than path relative to ass, use absolute path ("/") // 4. Otherwise, use path relative to ass ("~") std::string scripts_string; - std::filesystem::path autobasefn(OPT_GET("Path/Automation/Base")->GetString()); + agi::fs::path autobasefn(OPT_GET("Path/Automation/Base")->GetString()); for (auto& script : GetScripts()) { if (!scripts_string.empty()) @@ -445,7 +445,7 @@ namespace Automation4 { Factories().emplace_back(std::move(factory)); } - std::unique_ptr