diff --git a/Userland/Libraries/LibCore/Resource.cpp b/Userland/Libraries/LibCore/Resource.cpp index b1967d1757..8fbeb5c6c4 100644 --- a/Userland/Libraries/LibCore/Resource.cpp +++ b/Userland/Libraries/LibCore/Resource.cpp @@ -53,7 +53,7 @@ ErrorOr> Resource::load_from_uri(StringView uri) return MUST(String::formatted("{}://{}", m_scheme == Scheme::Resource ? "resource"sv : "file"sv, m_path)); } -[[nodiscard]] Optional Resource::filesystem_path() const +[[nodiscard]] String Resource::filesystem_path() const { return ResourceImplementation::the().filesystem_path(*this); } @@ -97,4 +97,5 @@ ErrorOr> Resource::load_from_uri(StringView uri) { return FixedMemoryStream(data()); } + } diff --git a/Userland/Libraries/LibCore/Resource.h b/Userland/Libraries/LibCore/Resource.h index 69c12a3bc9..cbecf7a3fb 100644 --- a/Userland/Libraries/LibCore/Resource.h +++ b/Userland/Libraries/LibCore/Resource.h @@ -18,6 +18,7 @@ #include namespace Core { + class Resource : public RefCounted { public: static ErrorOr> load_from_filesystem(StringView); @@ -28,7 +29,7 @@ public: [[nodiscard]] String uri() const; [[nodiscard]] String filename() const; - [[nodiscard]] Optional filesystem_path() const; + [[nodiscard]] String filesystem_path() const; [[nodiscard]] ByteBuffer clone_data() const; [[nodiscard]] ByteBuffer release_data() &&; diff --git a/Userland/Libraries/LibCore/ResourceImplementation.cpp b/Userland/Libraries/LibCore/ResourceImplementation.cpp index edbda98713..580843d5a1 100644 --- a/Userland/Libraries/LibCore/ResourceImplementation.cpp +++ b/Userland/Libraries/LibCore/ResourceImplementation.cpp @@ -70,14 +70,14 @@ Vector ResourceImplementation::child_names(Resource const& resource) VERIFY(resource.m_scheme == Resource::Scheme::File); Vector children; - Core::DirIterator it(resource.filesystem_path().release_value().to_deprecated_string(), Core::DirIterator::SkipParentAndBaseDir); + Core::DirIterator it(resource.filesystem_path().to_deprecated_string(), Core::DirIterator::SkipParentAndBaseDir); while (it.has_next()) children.append(MUST(String::from_deprecated_string(it.next_path()))); return children; } -Optional ResourceImplementation::filesystem_path(Resource const& resource) +String ResourceImplementation::filesystem_path(Resource const& resource) { if (resource.m_scheme == Resource::Scheme::Resource) return filesystem_path_for_resource_scheme(resource.m_path); diff --git a/Userland/Libraries/LibCore/ResourceImplementation.h b/Userland/Libraries/LibCore/ResourceImplementation.h index 29df958163..308b5edcaa 100644 --- a/Userland/Libraries/LibCore/ResourceImplementation.h +++ b/Userland/Libraries/LibCore/ResourceImplementation.h @@ -11,11 +11,12 @@ #include namespace Core { + class ResourceImplementation { public: ErrorOr> load_from_uri(StringView); Vector child_names(Resource const&); - Optional filesystem_path(Resource const&); + String filesystem_path(Resource const&); virtual ~ResourceImplementation() = default; @@ -25,7 +26,7 @@ public: protected: virtual ErrorOr> load_from_resource_scheme_uri(StringView) = 0; virtual Vector child_names_for_resource_scheme(Resource const&) = 0; - virtual Optional filesystem_path_for_resource_scheme(String const&) = 0; + virtual String filesystem_path_for_resource_scheme(String const&) = 0; static bool is_directory(StringView filesystem_path); @@ -33,4 +34,5 @@ protected: static NonnullRefPtr make_resource(String full_path, ByteBuffer); static NonnullRefPtr make_directory_resource(String full_path); }; + } diff --git a/Userland/Libraries/LibCore/ResourceImplementationFile.cpp b/Userland/Libraries/LibCore/ResourceImplementationFile.cpp index 6b2a7d6cff..894afe81fe 100644 --- a/Userland/Libraries/LibCore/ResourceImplementationFile.cpp +++ b/Userland/Libraries/LibCore/ResourceImplementationFile.cpp @@ -11,6 +11,7 @@ #include namespace Core { + ResourceImplementationFile::ResourceImplementationFile(String base_directory) : m_base_directory(move(base_directory)) { @@ -33,14 +34,14 @@ ErrorOr> ResourceImplementationFile::load_from_resource_ Vector ResourceImplementationFile::child_names_for_resource_scheme(Resource const& resource) { Vector children; - Core::DirIterator it(resource.filesystem_path().release_value().to_deprecated_string(), Core::DirIterator::SkipParentAndBaseDir); + Core::DirIterator it(resource.filesystem_path().to_deprecated_string(), Core::DirIterator::SkipParentAndBaseDir); while (it.has_next()) children.append(MUST(String::from_deprecated_string(it.next_path()))); return children; } -Optional ResourceImplementationFile::filesystem_path_for_resource_scheme(String const& relative_path) +String ResourceImplementationFile::filesystem_path_for_resource_scheme(String const& relative_path) { return MUST(String::from_deprecated_string(LexicalPath::join(m_base_directory, relative_path).string())); } diff --git a/Userland/Libraries/LibCore/ResourceImplementationFile.h b/Userland/Libraries/LibCore/ResourceImplementationFile.h index f671a9c7a3..a081f4304b 100644 --- a/Userland/Libraries/LibCore/ResourceImplementationFile.h +++ b/Userland/Libraries/LibCore/ResourceImplementationFile.h @@ -12,15 +12,17 @@ #include namespace Core { + class ResourceImplementationFile : public ResourceImplementation { public: explicit ResourceImplementationFile(String base_directory); virtual ErrorOr> load_from_resource_scheme_uri(StringView) override; virtual Vector child_names_for_resource_scheme(Resource const&) override; - virtual Optional filesystem_path_for_resource_scheme(String const&) override; + virtual String filesystem_path_for_resource_scheme(String const&) override; private: String m_base_directory; }; + }