#pragma once #include #include #include class IOFile { FILE* handle = nullptr; static inline std::filesystem::path appData = ""; // Directory for holding app data. AppData on Windows public: IOFile(); IOFile(FILE* handle); IOFile(const std::filesystem::path& path, const char* permissions = "rb"); bool isOpen(); bool open(const std::filesystem::path& path, const char* permissions = "rb"); bool open(const char* filename, const char* permissions = "rb"); void close(); std::pair read(void* data, std::size_t length, std::size_t dataSize); std::pair readBytes(void* data, std::size_t count); std::pair write(const void* data, std::size_t length, std::size_t dataSize); std::pair writeBytes(const void* data, std::size_t count); std::optional size(); bool seek(std::int64_t offset, int origin = SEEK_SET); bool rewind(); FILE* getHandle(); static void setAppDataDir(const std::filesystem::path& dir); // Sets the size of the file to "size" and returns whether it succeeded or not bool setSize(std::uint64_t size); static std::filesystem::path getAppData(); };