1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:27:45 +00:00

HexEditor: Remove unveil() for CLI file, use FileSystemAccessServer

Previously we unveiled the file specified through the command-line
interface. Now, we just make the request through the
FileSystemAccessServer instead.
This commit is contained in:
Mustafa Quraish 2021-09-06 01:52:17 -04:00 committed by Ali Mohammad Pur
parent 3a7e42ba73
commit a9e9bd8d84

View file

@ -7,6 +7,7 @@
#include "HexEditorWidget.h" #include "HexEditorWidget.h"
#include <LibConfig/Client.h> #include <LibConfig/Client.h>
#include <LibFileSystemAccessClient/Client.h>
#include <LibGUI/Icon.h> #include <LibGUI/Icon.h>
#include <LibGUI/Menubar.h> #include <LibGUI/Menubar.h>
#include <LibGUI/MessageBox.h> #include <LibGUI/MessageBox.h>
@ -38,20 +39,6 @@ int main(int argc, char** argv)
return GUI::Window::CloseRequestDecision::StayOpen; return GUI::Window::CloseRequestDecision::StayOpen;
}; };
String file_to_edit = (argc > 1) ? Core::File::absolute_path(argv[1]) : "";
if (!file_to_edit.is_empty()) {
if (Core::File::exists(file_to_edit)) {
dbgln("unveil for: {}", file_to_edit);
if (unveil(file_to_edit.characters(), "r") < 0) {
perror("unveil");
return 1;
}
} else {
file_to_edit = {};
}
}
if (unveil("/res", "r") < 0) { if (unveil("/res", "r") < 0) {
perror("unveil"); perror("unveil");
return 1; return 1;
@ -71,15 +58,16 @@ int main(int argc, char** argv)
window->show(); window->show();
window->set_icon(app_icon.bitmap_for_size(16)); window->set_icon(app_icon.bitmap_for_size(16));
if (!file_to_edit.is_empty()) { if (argc > 1) {
auto file = Core::File::open(file_to_edit, Core::OpenMode::ReadOnly); auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window->window_id(), argv[1]);
if (file.is_error()) { if (response.error != 0) {
GUI::MessageBox::show_error(window, String::formatted("Opening \"{}\" failed: {}", file_to_edit, file.error())); if (response.error != -1)
GUI::MessageBox::show_error(window, String::formatted("Opening \"{}\" failed: {}", *response.chosen_file, strerror(response.error)));
return 1; return 1;
} }
hex_editor_widget.open_file(file.value()->leak_fd(), file_to_edit); hex_editor_widget.open_file(*response.fd, *response.chosen_file);
} }
return app->exec(); return app->exec();