FlatImage
A configurable Linux containerization system
Loading...
Searching...
No Matches
icon.hpp
Go to the documentation of this file.
1
8
9#pragma once
10
11#include <algorithm>
12#include <filesystem>
13
14#include "../std/expected.hpp"
15#include "../macro.hpp"
16#include "reserved.hpp"
17
29{
30
31namespace
32{
33
34namespace fs = std::filesystem;
35
36}
37
38#pragma pack(push, 1)
44struct Icon
45{
46 char m_ext[4];
47 char m_data[(1<<20) - 12];
48 uint64_t m_size;
49
54 : m_size(0)
55 {
56 std::fill_n(m_ext, std::size(m_ext), 0);
57 std::fill_n(m_data, std::size(m_data), 0);
58 }
59
66 Icon(char* ext, char* data, uint64_t size)
67 : m_size(size)
68 {
69 // xxx + '\0'
70 std::copy(ext, ext+3, m_ext);
71 m_ext[3] = '\0';
72 std::copy(data, data+size, m_data);
73 } // Icon
74};
75#pragma pack(pop)
76
84inline Value<void> write(fs::path const& path_file_binary, Icon const& icon)
85{
86 uint64_t space_available = ns_reserved::FIM_RESERVED_OFFSET_ICON_END - ns_reserved::FIM_RESERVED_OFFSET_ICON_BEGIN;
87 uint64_t space_required = sizeof(Icon);
88 return_if(space_available < space_required, Error("E::Not enough space to fit icon data: {} vs {}", space_available, space_required));
89 Pop(ns_reserved::write(path_file_binary
90 , ns_reserved::FIM_RESERVED_OFFSET_ICON_BEGIN
91 , ns_reserved::FIM_RESERVED_OFFSET_ICON_END
92 , reinterpret_cast<char const*>(&icon)
93 , sizeof(icon)
94 ));
95 return {};
96}
97
104inline Value<Icon> read(fs::path const& path_file_binary)
105{
106 Icon icon;
107 uint64_t offset_begin = ns_reserved::FIM_RESERVED_OFFSET_ICON_BEGIN;
108 uint64_t size = ns_reserved::FIM_RESERVED_OFFSET_ICON_END - offset_begin;
109 Pop(ns_reserved::read(path_file_binary, offset_begin, reinterpret_cast<char*>(&icon), size));
110 return icon;
111}
112
113} // namespace ns_reserved::ns_icon
114
115/* vim: set expandtab fdm=marker ts=2 sw=2 tw=100 et :*/
Enhanced error handling framework built on std::expected.
Simplified macros for common control flow patterns with optional logging.
Application icon image storage in reserved space.
Value< Icon > read(fs::path const &path_file_binary)
Reads the Icon struct from the target binary.
Definition icon.hpp:104
Value< void > write(fs::path const &path_file_binary, Icon const &icon)
Writes the Icon struct to the target binary.
Definition icon.hpp:84
Value< void > write(fs::path const &path_file_binary, uint64_t offset_begin, uint64_t offset_end, const char *data, uint64_t length) noexcept
Writes data to a file in binary format.
Definition reserved.hpp:142
Value< std::streamsize > read(fs::path const &path_file_binary, uint64_t offset, char *data, uint64_t length) noexcept
Reads data from a file in binary format.
Definition reserved.hpp:172
Manages reserved space.
Enhanced expected type with integrated logging capabilities.
Definition expected.hpp:44
Stores icon data in reserved space.
Definition icon.hpp:45
Icon(char *ext, char *data, uint64_t size)
Constructs an icon with the specified data.
Definition icon.hpp:66
Icon()
Default constructor, initializes to empty icon.
Definition icon.hpp:53