diff --git a/file_reader b/file_reader index 1d37009..54a063d 160000 --- a/file_reader +++ b/file_reader @@ -1 +1 @@ -Subproject commit 1d370096d9b0767627566191be1e5526a5c90238 +Subproject commit 54a063d5e6ab8ea06b1101154574d2eaeebbde5f diff --git a/src/lily_png.cpp b/src/lily_png.cpp index 1253623..2b1d98e 100644 --- a/src/lily_png.cpp +++ b/src/lily_png.cpp @@ -7,7 +7,10 @@ static std::expected read_raw_data(const std::string { std::println("Zlib version is {}", zlibVersion()); unsigned char magic[9] = {137, 80, 78, 71, 13, 10, 26, 10}; - file_reader::file_reader reader(file_path); + file_reader::file_reader reader{}; + auto result = reader.open_file(file_path); + if (!result) + return std::unexpected(lily_png::png_error::file_doesnt_exist); char file_magic[9] = {0}; auto res = reader.read_buffer(file_magic, 8).or_else([](const file_reader::RESULT &res) { diff --git a/src/lily_png.h b/src/lily_png.h index a14ca51..e935f9a 100644 --- a/src/lily_png.h +++ b/src/lily_png.h @@ -3,6 +3,7 @@ #include "../file_reader/src/file_read.h" #include #include +#include #include "utils.h" #include "filter.h" #include @@ -24,5 +25,26 @@ namespace lily_png }; + std::expected read_png(const std::string &file_path, file_reader::buffer &data); -} \ No newline at end of file +} + +template <> +struct std::formatter +{ + + constexpr auto parse(std::format_parse_context& ctx) { + return ctx.begin(); + } + + auto format(const lily_png::png_error& id, std::format_context& ctx) const + { + if (id == lily_png::png_error::file_doesnt_exist) + return std::format_to(ctx.out(), "{}", "File doesn't exist"); + if (id == lily_png::png_error::read_failed) + return std::format_to(ctx.out(), "{}", "Read failed"); + if (id == lily_png::png_error::file_is_not_a_png) + return std::format_to(ctx.out(), "{}", "File is not a png"); + return std::format_to(ctx.out(), "{}", "Unkown error"); + } +}; \ No newline at end of file