diff --git a/Userland/Libraries/LibCore/Resource.cpp b/Userland/Libraries/LibCore/Resource.cpp index e6ec770dd1..f196828f43 100644 --- a/Userland/Libraries/LibCore/Resource.cpp +++ b/Userland/Libraries/LibCore/Resource.cpp @@ -58,6 +58,14 @@ String Resource::filesystem_path() const return ResourceImplementation::the().filesystem_path(*this); } +String Resource::file_url() const +{ + if (m_scheme == Scheme::File) + return uri(); + + return MUST(String::formatted("file://{}", filesystem_path())); +} + String Resource::filename() const { return MUST(String::from_utf8(LexicalPath(m_path.bytes_as_string_view()).basename())); diff --git a/Userland/Libraries/LibCore/Resource.h b/Userland/Libraries/LibCore/Resource.h index cbecf7a3fb..c79def4a4f 100644 --- a/Userland/Libraries/LibCore/Resource.h +++ b/Userland/Libraries/LibCore/Resource.h @@ -30,6 +30,7 @@ public: [[nodiscard]] String uri() const; [[nodiscard]] String filename() const; [[nodiscard]] String filesystem_path() const; + [[nodiscard]] String file_url() const; [[nodiscard]] ByteBuffer clone_data() const; [[nodiscard]] ByteBuffer release_data() &&;