From 606a3982f34d777f121fcc4aa964141199676c20 Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Thu, 9 Feb 2023 03:02:46 +0100 Subject: LibCore: Move Stream-based file into the `Core` namespace --- Userland/Applications/HexEditor/HexDocument.cpp | 13 +++++++------ Userland/Applications/HexEditor/HexDocument.h | 14 +++++++------- Userland/Applications/HexEditor/HexEditor.cpp | 4 ++-- Userland/Applications/HexEditor/HexEditor.h | 4 ++-- Userland/Applications/HexEditor/HexEditorWidget.cpp | 8 ++++---- Userland/Applications/HexEditor/HexEditorWidget.h | 2 +- Userland/Applications/HexEditor/main.cpp | 2 +- 7 files changed, 24 insertions(+), 23 deletions(-) (limited to 'Userland/Applications/HexEditor') diff --git a/Userland/Applications/HexEditor/HexDocument.cpp b/Userland/Applications/HexEditor/HexDocument.cpp index e7e49c6c19..064ca93f91 100644 --- a/Userland/Applications/HexEditor/HexDocument.cpp +++ b/Userland/Applications/HexEditor/HexDocument.cpp @@ -5,6 +5,7 @@ */ #include "HexDocument.h" +#include #include void HexDocument::set(size_t position, u8 value) @@ -58,7 +59,7 @@ void HexDocumentMemory::clear_changes() m_changes.clear(); } -ErrorOr HexDocumentMemory::write_to_file(Core::Stream::File& file) +ErrorOr HexDocumentMemory::write_to_file(Core::File& file) { TRY(file.seek(0, SeekMode::SetPosition)); TRY(file.write(m_buffer)); @@ -69,7 +70,7 @@ ErrorOr HexDocumentMemory::write_to_file(Core::Stream::File& file) return {}; } -ErrorOr> HexDocumentFile::create(NonnullOwnPtr file) +ErrorOr> HexDocumentFile::create(NonnullOwnPtr file) { auto document = TRY(adopt_nonnull_own_or_enomem(new HexDocumentFile(move(file)))); TRY(document->initialize_internal_state()); @@ -77,7 +78,7 @@ ErrorOr> HexDocumentFile::create(NonnullOwnPtr file) +HexDocumentFile::HexDocumentFile(NonnullOwnPtr file) : m_file(move(file)) { } @@ -94,7 +95,7 @@ ErrorOr HexDocumentFile::write_to_file() return {}; } -ErrorOr HexDocumentFile::write_to_file(Core::Stream::File& file) +ErrorOr HexDocumentFile::write_to_file(Core::File& file) { TRY(file.truncate(size())); @@ -149,7 +150,7 @@ void HexDocumentFile::clear_changes() m_changes.clear(); } -ErrorOr HexDocumentFile::set_file(NonnullOwnPtr file) +ErrorOr HexDocumentFile::set_file(NonnullOwnPtr file) { m_file = move(file); TRY(initialize_internal_state()); @@ -171,7 +172,7 @@ ErrorOr HexDocumentFile::initialize_internal_state() return {}; } -NonnullOwnPtr const& HexDocumentFile::file() const +NonnullOwnPtr const& HexDocumentFile::file() const { return m_file; } diff --git a/Userland/Applications/HexEditor/HexDocument.h b/Userland/Applications/HexEditor/HexDocument.h index d5e46a4f87..256f753f65 100644 --- a/Userland/Applications/HexEditor/HexDocument.h +++ b/Userland/Applications/HexEditor/HexDocument.h @@ -52,7 +52,7 @@ public: size_t size() const override; Type type() const override; void clear_changes() override; - ErrorOr write_to_file(Core::Stream::File& file); + ErrorOr write_to_file(Core::File& file); private: ByteBuffer m_buffer; @@ -60,16 +60,16 @@ private: class HexDocumentFile final : public HexDocument { public: - static ErrorOr> create(NonnullOwnPtr file); + static ErrorOr> create(NonnullOwnPtr file); virtual ~HexDocumentFile() = default; HexDocumentFile(HexDocumentFile&&) = default; HexDocumentFile(HexDocumentFile const&) = delete; - ErrorOr set_file(NonnullOwnPtr file); - NonnullOwnPtr const& file() const; + ErrorOr set_file(NonnullOwnPtr file); + NonnullOwnPtr const& file() const; ErrorOr write_to_file(); - ErrorOr write_to_file(Core::Stream::File& file); + ErrorOr write_to_file(Core::File& file); Cell get(size_t position) override; u8 get_unchanged(size_t position) override; size_t size() const override; @@ -77,12 +77,12 @@ public: void clear_changes() override; private: - explicit HexDocumentFile(NonnullOwnPtr file); + explicit HexDocumentFile(NonnullOwnPtr file); ErrorOr initialize_internal_state(); void ensure_position_in_buffer(size_t position); - NonnullOwnPtr m_file; + NonnullOwnPtr m_file; size_t m_file_size; Array m_buffer; diff --git a/Userland/Applications/HexEditor/HexEditor.cpp b/Userland/Applications/HexEditor/HexEditor.cpp index e3c28811db..18922eeb76 100644 --- a/Userland/Applications/HexEditor/HexEditor.cpp +++ b/Userland/Applications/HexEditor/HexEditor.cpp @@ -63,7 +63,7 @@ ErrorOr HexEditor::open_new_file(size_t size) return {}; } -void HexEditor::open_file(NonnullOwnPtr file) +void HexEditor::open_file(NonnullOwnPtr file) { m_document = HexDocumentFile::create(move(file)).release_value_but_fixme_should_propagate_errors(); set_content_length(m_document->size()); @@ -136,7 +136,7 @@ void HexEditor::set_selection(size_t position, size_t length) update_status(); } -ErrorOr HexEditor::save_as(NonnullOwnPtr new_file) +ErrorOr HexEditor::save_as(NonnullOwnPtr new_file) { if (m_document->type() == HexDocument::Type::File) { auto& file_document = static_cast(*m_document); diff --git a/Userland/Applications/HexEditor/HexEditor.h b/Userland/Applications/HexEditor/HexEditor.h index 4a27d486d5..89eeeb3b5b 100644 --- a/Userland/Applications/HexEditor/HexEditor.h +++ b/Userland/Applications/HexEditor/HexEditor.h @@ -35,10 +35,10 @@ public: size_t buffer_size() const { return m_document->size(); } ErrorOr open_new_file(size_t size); - void open_file(NonnullOwnPtr file); + void open_file(NonnullOwnPtr file); ErrorOr fill_selection(u8 fill_byte); Optional get_byte(size_t position); - ErrorOr save_as(NonnullOwnPtr); + ErrorOr save_as(NonnullOwnPtr); ErrorOr save(); bool undo(); diff --git a/Userland/Applications/HexEditor/HexEditorWidget.cpp b/Userland/Applications/HexEditor/HexEditorWidget.cpp index 64a43c3e3e..9084e049b9 100644 --- a/Userland/Applications/HexEditor/HexEditorWidget.cpp +++ b/Userland/Applications/HexEditor/HexEditorWidget.cpp @@ -121,7 +121,7 @@ HexEditorWidget::HexEditorWidget() if (!request_close()) return; - auto response = FileSystemAccessClient::Client::the().open_file(window(), {}, Core::StandardPaths::home_directory(), Core::Stream::OpenMode::ReadWrite); + auto response = FileSystemAccessClient::Client::the().open_file(window(), {}, Core::StandardPaths::home_directory(), Core::File::OpenMode::ReadWrite); if (response.is_error()) return; @@ -142,7 +142,7 @@ HexEditorWidget::HexEditorWidget() }); m_save_as_action = GUI::CommonActions::make_save_as_action([&](auto&) { - auto response = FileSystemAccessClient::Client::the().save_file(window(), m_name, m_extension, Core::Stream::OpenMode::ReadWrite | Core::Stream::OpenMode::Truncate); + auto response = FileSystemAccessClient::Client::the().save_file(window(), m_name, m_extension, Core::File::OpenMode::ReadWrite | Core::File::OpenMode::Truncate); if (response.is_error()) return; auto file = response.release_value(); @@ -525,7 +525,7 @@ void HexEditorWidget::update_title() window()->set_title(builder.to_deprecated_string()); } -void HexEditorWidget::open_file(String const& filename, NonnullOwnPtr file) +void HexEditorWidget::open_file(String const& filename, NonnullOwnPtr file) { window()->set_modified(false); m_editor->open_file(move(file)); @@ -586,7 +586,7 @@ void HexEditorWidget::drop_event(GUI::DropEvent& event) return; // TODO: A drop event should be considered user consent for opening a file - auto response = FileSystemAccessClient::Client::the().request_file(window(), urls.first().path(), Core::Stream::OpenMode::Read); + auto response = FileSystemAccessClient::Client::the().request_file(window(), urls.first().path(), Core::File::OpenMode::Read); if (response.is_error()) return; open_file(response.value().filename(), response.value().release_stream()); diff --git a/Userland/Applications/HexEditor/HexEditorWidget.h b/Userland/Applications/HexEditor/HexEditorWidget.h index addddd246f..a919de7f36 100644 --- a/Userland/Applications/HexEditor/HexEditorWidget.h +++ b/Userland/Applications/HexEditor/HexEditorWidget.h @@ -25,7 +25,7 @@ class HexEditorWidget final : public GUI::Widget { C_OBJECT(HexEditorWidget) public: virtual ~HexEditorWidget() override = default; - void open_file(String const& filename, NonnullOwnPtr); + void open_file(String const& filename, NonnullOwnPtr); void initialize_menubar(GUI::Window&); bool request_close(); diff --git a/Userland/Applications/HexEditor/main.cpp b/Userland/Applications/HexEditor/main.cpp index f3311bc0e6..185653455b 100644 --- a/Userland/Applications/HexEditor/main.cpp +++ b/Userland/Applications/HexEditor/main.cpp @@ -53,7 +53,7 @@ ErrorOr serenity_main(Main::Arguments arguments) if (arguments.argc > 1) { // FIXME: Using `try_request_file_read_only_approved` doesn't work here since the file stored in the editor is only readable. - auto response = FileSystemAccessClient::Client::the().request_file(window, arguments.strings[1], Core::Stream::OpenMode::ReadWrite); + auto response = FileSystemAccessClient::Client::the().request_file(window, arguments.strings[1], Core::File::OpenMode::ReadWrite); if (response.is_error()) return 1; hex_editor_widget->open_file(response.value().filename(), response.value().release_stream()); -- cgit v1.2.3