1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 00:37:35 +00:00

LibCore+Everywhere: Move OpenMode out of IODevice

...and make it an enum class so people don't omit "OpenMode".
This commit is contained in:
Ali Mohammad Pur 2021-05-12 13:56:43 +04:30 committed by Linus Groh
parent 422ef7904e
commit a91a49337c
113 changed files with 180 additions and 177 deletions

View file

@ -43,7 +43,7 @@ DownloadWidget::DownloadWidget(const URL& url)
};
{
auto file_or_error = Core::File::open(m_destination_path, Core::IODevice::WriteOnly);
auto file_or_error = Core::File::open(m_destination_path, Core::OpenMode::WriteOnly);
if (file_or_error.is_error()) {
GUI::MessageBox::show(window(), String::formatted("Cannot open {} for writing", m_destination_path), "Download failed", GUI::MessageBox::Type::Error);
window()->close();

View file

@ -118,7 +118,7 @@ int main(int argc, char** argv)
Browser::g_home_url = m_config->read_entry("Preferences", "Home", "about:blank");
Browser::g_search_engine = m_config->read_entry("Preferences", "SearchEngine", {});
auto ad_filter_list_or_error = Core::File::open(String::formatted("{}/BrowserContentFilters.txt", Core::StandardPaths::config_directory()), Core::IODevice::ReadOnly);
auto ad_filter_list_or_error = Core::File::open(String::formatted("{}/BrowserContentFilters.txt", Core::StandardPaths::config_directory()), Core::OpenMode::ReadOnly);
if (!ad_filter_list_or_error.is_error()) {
auto& ad_filter_list = *ad_filter_list_or_error.value();
while (!ad_filter_list.eof()) {

View file

@ -71,7 +71,7 @@ static void run_file_operation([[maybe_unused]] FileOperation operation, const S
file_operation_windows.set(window);
auto pipe_input_file = Core::File::construct();
pipe_input_file->open(pipe_fds[0], Core::IODevice::ReadOnly, Core::File::ShouldCloseFileDescriptor::Yes);
pipe_input_file->open(pipe_fds[0], Core::OpenMode::ReadOnly, Core::File::ShouldCloseFileDescriptor::Yes);
window->set_title("Copying Files...");
window->set_main_widget<FileOperationProgressWidget>(pipe_input_file);

View file

@ -242,7 +242,7 @@ void HexEditorWidget::update_title()
void HexEditorWidget::open_file(const String& path)
{
auto file = Core::File::construct(path);
if (!file->open(Core::IODevice::ReadOnly)) {
if (!file->open(Core::OpenMode::ReadOnly)) {
GUI::MessageBox::show(window(), String::formatted("Opening \"{}\" failed: {}", path, strerror(errno)), "Error", GUI::MessageBox::Type::Error);
return;
}

View file

@ -189,7 +189,7 @@ void KeyboardMapperWidget::save_to_file(const StringView& filename)
String file_content = map_json.to_string();
auto file = Core::File::construct(filename);
file->open(Core::IODevice::WriteOnly);
file->open(Core::OpenMode::WriteOnly);
if (!file->is_open()) {
StringBuilder sb;
sb.append("Failed to open ");

View file

@ -61,7 +61,7 @@ int main(int argc, char** argv)
auto app_icon = GUI::Icon::default_icon("app-keyboard-settings");
auto proc_keymap = Core::File::construct("/proc/keymap");
if (!proc_keymap->open(Core::IODevice::OpenMode::ReadOnly))
if (!proc_keymap->open(Core::OpenMode::ReadOnly))
VERIFY_NOT_REACHED();
auto json = JsonValue::from_string(proc_keymap->read_all());

View file

@ -56,7 +56,7 @@ int main(int argc, char** argv)
auto audio_thread = LibThread::Thread::construct([&] {
auto audio = Core::File::construct("/dev/audio");
if (!audio->open(Core::IODevice::WriteOnly)) {
if (!audio->open(Core::OpenMode::WriteOnly)) {
dbgln("Can't open audio device: {}", audio->error_string());
return 1;
}

View file

@ -171,7 +171,7 @@ String RunWindow::history_file_path()
void RunWindow::load_history()
{
m_path_history.clear();
auto file_or_error = Core::File::open(history_file_path(), Core::IODevice::ReadOnly);
auto file_or_error = Core::File::open(history_file_path(), Core::OpenMode::ReadOnly);
if (file_or_error.is_error())
return;
@ -185,7 +185,7 @@ void RunWindow::load_history()
void RunWindow::save_history()
{
auto file_or_error = Core::File::open(history_file_path(), Core::IODevice::WriteOnly);
auto file_or_error = Core::File::open(history_file_path(), Core::OpenMode::WriteOnly);
if (file_or_error.is_error())
return;

View file

@ -74,7 +74,7 @@ static void fill_mounts(Vector<MountInfo>& output)
{
// Output info about currently mounted filesystems.
auto df = Core::File::construct("/proc/df");
if (!df->open(Core::IODevice::ReadOnly)) {
if (!df->open(Core::OpenMode::ReadOnly)) {
fprintf(stderr, "Failed to open /proc/df: %s\n", df->error_string());
return;
}

View file

@ -198,7 +198,7 @@ void CSVExportDialogPage::update_preview()
auto file_or_error = Core::File::open(
m_temp_output_file_path,
Core::IODevice::ReadOnly);
Core::OpenMode::ReadOnly);
if (file_or_error.is_error())
goto fail;

View file

@ -77,7 +77,7 @@ TEST_CASE(should_iterate_rows)
BENCHMARK_CASE(fairly_big_data)
{
auto file_or_error = Core::File::open(__FILE__ ".data", Core::IODevice::OpenMode::ReadOnly);
auto file_or_error = Core::File::open(__FILE__ ".data", Core::OpenMode::ReadOnly);
EXPECT_EQ_FORCE(file_or_error.is_error(), false);
auto data = file_or_error.value()->read_all();

View file

@ -46,7 +46,7 @@ Sheet::Sheet(Workbook& workbook)
global_object().put("thisSheet", &global_object()); // Self-reference is unfortunate, but required.
// Sadly, these have to be evaluated once per sheet.
auto file_or_error = Core::File::open("/res/js/Spreadsheet/runtime.js", Core::IODevice::OpenMode::ReadOnly);
auto file_or_error = Core::File::open("/res/js/Spreadsheet/runtime.js", Core::OpenMode::ReadOnly);
if (!file_or_error.is_error()) {
auto buffer = file_or_error.value()->read_all();
JS::Parser parser { JS::Lexer(buffer) };

View file

@ -52,7 +52,7 @@ bool Workbook::set_filename(const String& filename)
Result<bool, String> Workbook::load(const StringView& filename)
{
auto file_or_error = Core::File::open(filename, Core::IODevice::OpenMode::ReadOnly);
auto file_or_error = Core::File::open(filename, Core::OpenMode::ReadOnly);
if (file_or_error.is_error()) {
StringBuilder sb;
sb.append("Failed to open ");
@ -81,7 +81,7 @@ Result<bool, String> Workbook::save(const StringView& filename)
{
auto mime = Core::guess_mime_type_based_on_filename(filename);
auto file = Core::File::construct(filename);
file->open(Core::IODevice::WriteOnly);
file->open(Core::OpenMode::WriteOnly);
if (!file->is_open()) {
StringBuilder sb;
sb.append("Failed to open ");

View file

@ -122,7 +122,7 @@ GUI::Variant DevicesModel::data(const GUI::ModelIndex& index, GUI::ModelRole rol
void DevicesModel::update()
{
auto proc_devices = Core::File::construct("/proc/devices");
if (!proc_devices->open(Core::IODevice::OpenMode::ReadOnly))
if (!proc_devices->open(Core::OpenMode::ReadOnly))
VERIFY_NOT_REACHED();
auto json = JsonValue::from_string(proc_devices->read_all());

View file

@ -77,7 +77,7 @@ static inline size_t bytes_to_kb(size_t bytes)
void MemoryStatsWidget::refresh()
{
auto proc_memstat = Core::File::construct("/proc/memstat");
if (!proc_memstat->open(Core::IODevice::OpenMode::ReadOnly))
if (!proc_memstat->open(Core::OpenMode::ReadOnly))
VERIFY_NOT_REACHED();
auto file_contents = proc_memstat->read_all();

View file

@ -25,7 +25,7 @@ ProcessModel::ProcessModel()
s_the = this;
auto file = Core::File::construct("/proc/cpuinfo");
if (file->open(Core::IODevice::ReadOnly)) {
if (file->open(Core::OpenMode::ReadOnly)) {
auto json = JsonValue::from_string({ file->read_all() });
auto cpuinfo_array = json.value().as_array();
cpuinfo_array.for_each([&](auto& value) {

View file

@ -631,7 +631,7 @@ void MainWidget::update_title()
bool MainWidget::open_file(const String& path)
{
auto file = Core::File::construct(path);
if (!file->open(Core::IODevice::ReadOnly) && file->error() != ENOENT) {
if (!file->open(Core::OpenMode::ReadOnly) && file->error() != ENOENT) {
GUI::MessageBox::show(window(), String::formatted("Opening \"{}\" failed: {}", path, strerror(errno)), "Error", GUI::MessageBox::Type::Error);
return false;
}

View file

@ -86,7 +86,7 @@ WelcomeWidget::~WelcomeWidget()
void WelcomeWidget::open_and_parse_tips_file()
{
auto file = Core::File::construct("/home/anon/Documents/tips.txt");
if (!file->open(Core::IODevice::ReadOnly)) {
if (!file->open(Core::OpenMode::ReadOnly)) {
m_tip_label->set_text("~/Documents/tips.txt has gone missing!");
return;
}
@ -108,7 +108,7 @@ void WelcomeWidget::open_and_parse_tips_file()
void WelcomeWidget::open_and_parse_readme_file()
{
auto file = Core::File::construct("/home/anon/README.md");
if (!file->open(Core::IODevice::ReadOnly))
if (!file->open(Core::OpenMode::ReadOnly))
return;
auto document = Markdown::Document::parse(file->read_all());