summaryrefslogtreecommitdiff
path: root/Userland/Applications/HexEditor
diff options
context:
space:
mode:
authorTim Schumacher <timschumi@gmx.de>2023-02-09 03:02:46 +0100
committerLinus Groh <mail@linusgroh.de>2023-02-13 00:50:07 +0000
commit606a3982f34d777f121fcc4aa964141199676c20 (patch)
tree836fef41d11f1b77f4dac7d699e5c9f720ee4ff1 /Userland/Applications/HexEditor
parenta96339b72b3b417ffaa4fbb4e7575149f749acaa (diff)
downloadserenity-606a3982f34d777f121fcc4aa964141199676c20.zip
LibCore: Move Stream-based file into the `Core` namespace
Diffstat (limited to 'Userland/Applications/HexEditor')
-rw-r--r--Userland/Applications/HexEditor/HexDocument.cpp13
-rw-r--r--Userland/Applications/HexEditor/HexDocument.h14
-rw-r--r--Userland/Applications/HexEditor/HexEditor.cpp4
-rw-r--r--Userland/Applications/HexEditor/HexEditor.h4
-rw-r--r--Userland/Applications/HexEditor/HexEditorWidget.cpp8
-rw-r--r--Userland/Applications/HexEditor/HexEditorWidget.h2
-rw-r--r--Userland/Applications/HexEditor/main.cpp2
7 files changed, 24 insertions, 23 deletions
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 <LibCore/File.h>
#include <LibCore/Stream.h>
void HexDocument::set(size_t position, u8 value)
@@ -58,7 +59,7 @@ void HexDocumentMemory::clear_changes()
m_changes.clear();
}
-ErrorOr<void> HexDocumentMemory::write_to_file(Core::Stream::File& file)
+ErrorOr<void> HexDocumentMemory::write_to_file(Core::File& file)
{
TRY(file.seek(0, SeekMode::SetPosition));
TRY(file.write(m_buffer));
@@ -69,7 +70,7 @@ ErrorOr<void> HexDocumentMemory::write_to_file(Core::Stream::File& file)
return {};
}
-ErrorOr<NonnullOwnPtr<HexDocumentFile>> HexDocumentFile::create(NonnullOwnPtr<Core::Stream::File> file)
+ErrorOr<NonnullOwnPtr<HexDocumentFile>> HexDocumentFile::create(NonnullOwnPtr<Core::File> file)
{
auto document = TRY(adopt_nonnull_own_or_enomem(new HexDocumentFile(move(file))));
TRY(document->initialize_internal_state());
@@ -77,7 +78,7 @@ ErrorOr<NonnullOwnPtr<HexDocumentFile>> HexDocumentFile::create(NonnullOwnPtr<Co
return document;
}
-HexDocumentFile::HexDocumentFile(NonnullOwnPtr<Core::Stream::File> file)
+HexDocumentFile::HexDocumentFile(NonnullOwnPtr<Core::File> file)
: m_file(move(file))
{
}
@@ -94,7 +95,7 @@ ErrorOr<void> HexDocumentFile::write_to_file()
return {};
}
-ErrorOr<void> HexDocumentFile::write_to_file(Core::Stream::File& file)
+ErrorOr<void> HexDocumentFile::write_to_file(Core::File& file)
{
TRY(file.truncate(size()));
@@ -149,7 +150,7 @@ void HexDocumentFile::clear_changes()
m_changes.clear();
}
-ErrorOr<void> HexDocumentFile::set_file(NonnullOwnPtr<Core::Stream::File> file)
+ErrorOr<void> HexDocumentFile::set_file(NonnullOwnPtr<Core::File> file)
{
m_file = move(file);
TRY(initialize_internal_state());
@@ -171,7 +172,7 @@ ErrorOr<void> HexDocumentFile::initialize_internal_state()
return {};
}
-NonnullOwnPtr<Core::Stream::File> const& HexDocumentFile::file() const
+NonnullOwnPtr<Core::File> 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<void> write_to_file(Core::Stream::File& file);
+ ErrorOr<void> write_to_file(Core::File& file);
private:
ByteBuffer m_buffer;
@@ -60,16 +60,16 @@ private:
class HexDocumentFile final : public HexDocument {
public:
- static ErrorOr<NonnullOwnPtr<HexDocumentFile>> create(NonnullOwnPtr<Core::Stream::File> file);
+ static ErrorOr<NonnullOwnPtr<HexDocumentFile>> create(NonnullOwnPtr<Core::File> file);
virtual ~HexDocumentFile() = default;
HexDocumentFile(HexDocumentFile&&) = default;
HexDocumentFile(HexDocumentFile const&) = delete;
- ErrorOr<void> set_file(NonnullOwnPtr<Core::Stream::File> file);
- NonnullOwnPtr<Core::Stream::File> const& file() const;
+ ErrorOr<void> set_file(NonnullOwnPtr<Core::File> file);
+ NonnullOwnPtr<Core::File> const& file() const;
ErrorOr<void> write_to_file();
- ErrorOr<void> write_to_file(Core::Stream::File& file);
+ ErrorOr<void> 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<Core::Stream::File> file);
+ explicit HexDocumentFile(NonnullOwnPtr<Core::File> file);
ErrorOr<void> initialize_internal_state();
void ensure_position_in_buffer(size_t position);
- NonnullOwnPtr<Core::Stream::File> m_file;
+ NonnullOwnPtr<Core::File> m_file;
size_t m_file_size;
Array<u8, 2048> 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<void> HexEditor::open_new_file(size_t size)
return {};
}
-void HexEditor::open_file(NonnullOwnPtr<Core::Stream::File> file)
+void HexEditor::open_file(NonnullOwnPtr<Core::File> 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<void> HexEditor::save_as(NonnullOwnPtr<Core::Stream::File> new_file)
+ErrorOr<void> HexEditor::save_as(NonnullOwnPtr<Core::File> new_file)
{
if (m_document->type() == HexDocument::Type::File) {
auto& file_document = static_cast<HexDocumentFile&>(*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<void> open_new_file(size_t size);
- void open_file(NonnullOwnPtr<Core::Stream::File> file);
+ void open_file(NonnullOwnPtr<Core::File> file);
ErrorOr<void> fill_selection(u8 fill_byte);
Optional<u8> get_byte(size_t position);
- ErrorOr<void> save_as(NonnullOwnPtr<Core::Stream::File>);
+ ErrorOr<void> save_as(NonnullOwnPtr<Core::File>);
ErrorOr<void> 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<Core::Stream::File> file)
+void HexEditorWidget::open_file(String const& filename, NonnullOwnPtr<Core::File> 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<Core::Stream::File>);
+ void open_file(String const& filename, NonnullOwnPtr<Core::File>);
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<int> 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());