mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 09:34:59 +00:00
FileSystemAccessServer: Use Core::Stream
This patch also updates corresponding functions from `LibFileSystemAccessServerClient`. From the FileSystemAccessClient point of view, it only makes the server take `Core::Stream::OpenMode` instead of `Core::OpenMode`. So, `enum` conversions only happen within deprecated functions and not in the new `Core::Stream` friendly API. On the server side, it just removes two usages of `Core::File::open()`.
This commit is contained in:
parent
4e164c9de7
commit
c0bc3b9814
4 changed files with 62 additions and 38 deletions
|
@ -48,7 +48,28 @@ DeprecatedResult Client::try_request_file_read_only_approved(GUI::Window* parent
|
|||
return handle_promise<DeprecatedResult>(id);
|
||||
}
|
||||
|
||||
DeprecatedResult Client::try_request_file(GUI::Window* parent_window, DeprecatedString const& path, Core::OpenMode mode)
|
||||
static Core::Stream::OpenMode to_stream_open_mode(Core::OpenMode open_mode)
|
||||
{
|
||||
Core::Stream::OpenMode result {};
|
||||
if ((open_mode & Core::OpenMode::ReadOnly) == Core::OpenMode::ReadOnly)
|
||||
result |= Core::Stream::OpenMode::Read;
|
||||
if ((open_mode & Core::OpenMode::WriteOnly) == Core::OpenMode::WriteOnly)
|
||||
result |= Core::Stream::OpenMode::Write;
|
||||
if ((open_mode & Core::OpenMode::ReadWrite) == Core::OpenMode::ReadWrite)
|
||||
result |= Core::Stream::OpenMode::ReadWrite;
|
||||
if ((open_mode & Core::OpenMode::Append) == Core::OpenMode::Append)
|
||||
result |= Core::Stream::OpenMode::Append;
|
||||
if ((open_mode & Core::OpenMode::Truncate) == Core::OpenMode::Truncate)
|
||||
result |= Core::Stream::OpenMode::Truncate;
|
||||
if ((open_mode & Core::OpenMode::MustBeNew) == Core::OpenMode::MustBeNew)
|
||||
result |= Core::Stream::OpenMode::MustBeNew;
|
||||
if ((open_mode & Core::OpenMode::KeepOnExec) == Core::OpenMode::KeepOnExec)
|
||||
result |= Core::Stream::OpenMode::KeepOnExec;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
DeprecatedResult Client::try_request_file(GUI::Window* parent_window, DeprecatedString const& path, Core::OpenMode deprecated_mode)
|
||||
{
|
||||
auto const id = get_new_id();
|
||||
m_promises.set(id, PromiseAndWindow { { Core::Promise<DeprecatedResult>::construct() }, parent_window });
|
||||
|
@ -63,6 +84,8 @@ DeprecatedResult Client::try_request_file(GUI::Window* parent_window, Deprecated
|
|||
GUI::ConnectionToWindowServer::the().remove_window_stealing_for_client(child_window_server_client_id, parent_window_id);
|
||||
});
|
||||
|
||||
auto const mode = to_stream_open_mode(deprecated_mode);
|
||||
|
||||
if (path.starts_with('/')) {
|
||||
async_request_file(id, parent_window_server_client_id, parent_window_id, path, mode);
|
||||
} else {
|
||||
|
@ -73,7 +96,7 @@ DeprecatedResult Client::try_request_file(GUI::Window* parent_window, Deprecated
|
|||
return handle_promise<DeprecatedResult>(id);
|
||||
}
|
||||
|
||||
DeprecatedResult Client::try_open_file(GUI::Window* parent_window, DeprecatedString const& window_title, StringView path, Core::OpenMode requested_access)
|
||||
DeprecatedResult Client::try_open_file(GUI::Window* parent_window, DeprecatedString const& window_title, StringView path, Core::OpenMode deprecated_requested_access)
|
||||
{
|
||||
auto const id = get_new_id();
|
||||
m_promises.set(id, PromiseAndWindow { { Core::Promise<DeprecatedResult>::construct() }, parent_window });
|
||||
|
@ -88,12 +111,14 @@ DeprecatedResult Client::try_open_file(GUI::Window* parent_window, DeprecatedStr
|
|||
GUI::ConnectionToWindowServer::the().remove_window_stealing_for_client(child_window_server_client_id, parent_window_id);
|
||||
});
|
||||
|
||||
auto const requested_access = to_stream_open_mode(deprecated_requested_access);
|
||||
|
||||
async_prompt_open_file(id, parent_window_server_client_id, parent_window_id, window_title, path, requested_access);
|
||||
|
||||
return handle_promise<DeprecatedResult>(id);
|
||||
}
|
||||
|
||||
DeprecatedResult Client::try_save_file_deprecated(GUI::Window* parent_window, DeprecatedString const& name, DeprecatedString const ext, Core::OpenMode requested_access)
|
||||
DeprecatedResult Client::try_save_file_deprecated(GUI::Window* parent_window, DeprecatedString const& name, DeprecatedString const ext, Core::OpenMode deprecated_requested_access)
|
||||
{
|
||||
auto const id = get_new_id();
|
||||
m_promises.set(id, PromiseAndWindow { { Core::Promise<DeprecatedResult>::construct() }, parent_window });
|
||||
|
@ -108,6 +133,8 @@ DeprecatedResult Client::try_save_file_deprecated(GUI::Window* parent_window, De
|
|||
GUI::ConnectionToWindowServer::the().remove_window_stealing_for_client(child_window_server_client_id, parent_window_id);
|
||||
});
|
||||
|
||||
auto const requested_access = to_stream_open_mode(deprecated_requested_access);
|
||||
|
||||
async_prompt_save_file(id, parent_window_server_client_id, parent_window_id, name.is_null() ? "Untitled" : name, ext.is_null() ? "txt" : ext, Core::StandardPaths::home_directory(), requested_access);
|
||||
|
||||
return handle_promise<DeprecatedResult>(id);
|
||||
|
@ -128,10 +155,7 @@ Result Client::save_file(GUI::Window* parent_window, DeprecatedString const& nam
|
|||
GUI::ConnectionToWindowServer::the().remove_window_stealing_for_client(child_window_server_client_id, parent_window_id);
|
||||
});
|
||||
|
||||
// The endpoint only cares about ReadOnly, WriteOnly and ReadWrite and both enum shares the same layout for these.
|
||||
Core::OpenMode deprecated_requested_access = static_cast<Core::OpenMode>(requested_access);
|
||||
|
||||
async_prompt_save_file(id, parent_window_server_client_id, parent_window_id, name.is_null() ? "Untitled" : name, ext.is_null() ? "txt" : ext, Core::StandardPaths::home_directory(), deprecated_requested_access);
|
||||
async_prompt_save_file(id, parent_window_server_client_id, parent_window_id, name.is_null() ? "Untitled" : name, ext.is_null() ? "txt" : ext, Core::StandardPaths::home_directory(), requested_access);
|
||||
|
||||
return handle_promise<Result>(id);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue