Atlas-Launcher/source/script/module/filesystem/File.hpp

67 lines
1.6 KiB
C++

#pragma once
#include <string>
#include <filesystem>
#include <vector>
#include <fstream>
#include "script/engine/Engine.hpp"
#include "utils/angelscript/MixinAsReferenceCount.hpp"
/**
* Represent a file in the Atlas engine
*/
class File : public atlas::utils::angelscript::MixinAsReferenceCount {
public:
explicit File(const vfs::VirtualFileSystem* fileSystem, const std::filesystem::path& virtualPath);
/**
* Open the file to access its content.
* @param mode the opening mode of the file, using "r", "w", "+", etc...
*/
void open(const std::string& mode = "r");
/**
* Read the content of the file.
* @param size the size of the content to read.
* @return the content of the file
*/
std::vector<std::uint8_t> read(std::uint64_t size = std::numeric_limits<std::uint64_t>::max());
/**
* Write data into the file
* @param buffer the data to write into the file
* @return the size of the data written
*/
void write(const std::vector<std::uint8_t>& buffer);
/**
* Get the current cursor position
* @return the current cursor position
*/
std::uint64_t tell();
/**
* Set the cursor position
* @param position the new cursor position
*/
void seek(std::uint64_t position);
/**
* Close the file.
*/
void close();
private:
/**
* Get the corresponding real file path
* @return the real file path
*/
std::filesystem::path getRealPath() const;
std::filesystem::path virtualPath;
/// the Atlas engine
const vfs::VirtualFileSystem* fileSystem;
/// the internal file streamer
std::fstream stream;
};