|
| 1 | +#pragma once |
| 2 | + |
| 3 | +#ifdef __linux__ |
| 4 | + |
| 5 | +#include <filesystem> |
| 6 | +#include <format> |
| 7 | + |
| 8 | +#include <File/Common.hpp> |
| 9 | +#include <File/FileType/FileBase.hpp> |
| 10 | +#include <File/Macros.hpp> |
| 11 | + |
| 12 | +// NOTE: This file is effectively a stub. |
| 13 | +// The LinuxFile class has not been implemented! |
| 14 | +// File operations through the Output::* system doesn't work, for example FileDevice and NewFileDevice. |
| 15 | + |
| 16 | +namespace RC::File |
| 17 | +{ |
| 18 | + class LinuxFile : public FileInterface<LinuxFile> |
| 19 | + { |
| 20 | + private: |
| 21 | + using HANDLE = void*; |
| 22 | + |
| 23 | + struct IdentifyingProperties |
| 24 | + { |
| 25 | + unsigned long volume_serial_number{}; |
| 26 | + unsigned long file_index_low{}; |
| 27 | + unsigned long file_index_high{}; |
| 28 | + unsigned long creation_time_low{}; |
| 29 | + unsigned long creation_time_high{}; |
| 30 | + unsigned long last_write_time_high{}; |
| 31 | + unsigned long last_write_time_low{}; |
| 32 | + unsigned long file_size_low{}; |
| 33 | + unsigned long file_size_high{}; |
| 34 | + }; |
| 35 | + |
| 36 | + private: |
| 37 | + HANDLE m_file{}; |
| 38 | + HANDLE m_map_handle{}; |
| 39 | + uint8_t* m_memory_map{}; |
| 40 | + OpenProperties m_open_properties{}; |
| 41 | + std::filesystem::path m_file_path_and_name{}; |
| 42 | + std::filesystem::path m_serialization_file_path_and_name{}; |
| 43 | + IdentifyingProperties m_identifying_properties{}; |
| 44 | + constexpr static inline size_t cache_size = 0x500; |
| 45 | + unsigned char m_cache[cache_size]{}; |
| 46 | + size_t m_offset_to_next_serialized_item{}; |
| 47 | + bool m_has_cache_in_memory{}; |
| 48 | + bool m_has_cached_identifying_properties{}; |
| 49 | + bool m_is_file_open{}; |
| 50 | + |
| 51 | + public: |
| 52 | + ~LinuxFile() override = default; |
| 53 | + |
| 54 | + private: |
| 55 | + auto static create_all_directories(const std::filesystem::path& file_name_and_path) -> void; |
| 56 | + |
| 57 | + private: |
| 58 | + auto close_file() -> void; |
| 59 | + |
| 60 | + public: |
| 61 | + [[nodiscard]] auto is_file_open() const -> bool; |
| 62 | + |
| 63 | + public: |
| 64 | + RC_FILE_API auto set_file(HANDLE new_file) -> void; |
| 65 | + RC_FILE_API auto set_is_file_open(bool new_is_open) -> void; |
| 66 | + RC_FILE_API auto get_file() -> HANDLE; |
| 67 | + RC_FILE_API auto serialization_file_exists() -> bool; |
| 68 | + |
| 69 | + // File Interface -> START |
| 70 | + RC_FILE_API auto is_valid() noexcept -> bool override; |
| 71 | + RC_FILE_API auto invalidate_file() noexcept -> void override; |
| 72 | + RC_FILE_API auto static delete_file(const std::filesystem::path&) -> void; |
| 73 | + RC_FILE_API auto delete_file() -> void override; |
| 74 | + RC_FILE_API auto get_raw_handle() noexcept -> void* override; |
| 75 | + [[nodiscard]] RC_FILE_API auto get_file_path() const noexcept -> const std::filesystem::path& override; |
| 76 | + RC_FILE_API auto set_serialization_output_file(const std::filesystem::path& output_file) noexcept -> void override; |
| 77 | + RC_FILE_API auto serialize_identifying_properties() -> void override; |
| 78 | + RC_FILE_API auto deserialize_identifying_properties() -> void override; |
| 79 | + RC_FILE_API auto is_deserialized_and_live_equal() -> bool override; |
| 80 | + RC_FILE_API auto invalidate_serialization() -> void override; |
| 81 | + RC_FILE_API auto serialize_item(const GenericItemData& data, bool is_internal_item = false) -> void override; |
| 82 | + RC_FILE_API auto get_serialized_item(size_t data_size, bool is_internal_item = false) -> void* override; |
| 83 | + RC_FILE_API auto close_current_file() -> void override; |
| 84 | + RC_FILE_API auto write_string_to_file(StringViewType string_to_write) -> void override; |
| 85 | + RC_FILE_API auto is_same_as(LinuxFile& other_file) -> bool override; |
| 86 | + [[nodiscard]] RC_FILE_API auto read_all() const -> StringType override; |
| 87 | + [[nodiscard]] RC_FILE_API auto memory_map() -> std::span<uint8_t> override; |
| 88 | + [[nodiscard]] RC_FILE_API auto static open_file(const std::filesystem::path& file_name_and_path, const OpenProperties& open_properties) -> LinuxFile; |
| 89 | + // File Interface -> END |
| 90 | + }; |
| 91 | + |
| 92 | + // This file is automatically included ONLY if Windows is detected |
| 93 | + // Therefore, it's not necessary to do any checks here |
| 94 | + template <ImplementsFileInterface UnderlyingAbstraction> |
| 95 | + class HandleTemplate; |
| 96 | + using Handle = HandleTemplate<LinuxFile>; |
| 97 | +} // namespace RC::File |
| 98 | + |
| 99 | +#endif // ifdef __linux__ |
0 commit comments