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

PixelPaint: Use unveil to hide file system

This commit is contained in:
Timothy 2021-08-06 14:37:53 +10:00 committed by Andreas Kling
parent 62af82f494
commit 1927dbf025
6 changed files with 206 additions and 64 deletions

View file

@ -95,7 +95,7 @@ PaletteWidget::PaletteWidget()
bottom_color_container.set_layout<GUI::HorizontalBoxLayout>();
bottom_color_container.layout()->set_spacing(1);
auto result = load_palette_file("/res/color-palettes/default.palette");
auto result = load_palette_path("/res/color-palettes/default.palette");
if (result.is_error()) {
GUI::MessageBox::show_error(window(), String::formatted("Loading default palette failed: {}", result.error()));
display_color_list(fallback_colors());
@ -192,14 +192,8 @@ Vector<Color> PaletteWidget::colors()
return colors;
}
Result<Vector<Color>, String> PaletteWidget::load_palette_file(String const& file_path)
Result<Vector<Color>, String> PaletteWidget::load_palette_file(Core::File& file)
{
auto file_or_error = Core::File::open(file_path, Core::OpenMode::ReadOnly);
if (file_or_error.is_error())
return file_or_error.error();
auto& file = *file_or_error.value();
Vector<Color> palette;
while (file.can_read_line()) {
@ -224,20 +218,39 @@ Result<Vector<Color>, String> PaletteWidget::load_palette_file(String const& fil
return palette;
}
Result<void, String> PaletteWidget::save_palette_file(Vector<Color> palette, String const& file_path)
Result<Vector<Color>, String> PaletteWidget::load_palette_fd_and_close(int fd)
{
auto file_or_error = Core::File::open(file_path, Core::OpenMode::WriteOnly);
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);
if (file_or_error.is_error())
return file_or_error.error();
auto& file = *file_or_error.value();
return load_palette_file(file);
}
Result<void, String> PaletteWidget::save_palette_fd_and_close(Vector<Color> palette, int fd)
{
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();
file->close();
return {};
}