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

PixelPaint: Use FileSystemAccessClient::try_* APIs

This commit is contained in:
Mustafa Quraish 2022-01-16 04:30:06 -05:00 committed by Andreas Kling
parent aae96af812
commit 1c3e93c6e0
11 changed files with 59 additions and 105 deletions

View file

@ -255,16 +255,6 @@ Result<Vector<Color>, String> PaletteWidget::load_palette_file(Core::File& file)
return palette;
}
Result<Vector<Color>, String> PaletteWidget::load_palette_fd_and_close(int fd)
{
auto file = Core::File::construct();
file->open(fd, Core::OpenMode::ReadOnly, Core::File::ShouldCloseFileDescriptor::Yes);
if (file->has_error())
return String { file->error_string() };
return load_palette_file(file);
}
Result<Vector<Color>, String> PaletteWidget::load_palette_path(String const& file_path)
{
auto file_or_error = Core::File::open(file_path, Core::OpenMode::ReadOnly);
@ -275,20 +265,12 @@ Result<Vector<Color>, String> PaletteWidget::load_palette_path(String const& fil
return load_palette_file(file);
}
Result<void, String> PaletteWidget::save_palette_fd_and_close(Vector<Color> palette, int fd)
Result<void, String> PaletteWidget::save_palette_file(Vector<Color> palette, Core::File& file)
{
auto file = Core::File::construct();
file->open(fd, Core::OpenMode::WriteOnly, Core::File::ShouldCloseFileDescriptor::Yes);
if (file->has_error())
return String { file->error_string() };
for (auto& color : palette) {
file->write(color.to_string_without_alpha());
file->write("\n");
file.write(color.to_string_without_alpha());
file.write("\n");
}
file->close();
return {};
}