mirror of
https://github.com/cemu-project/Cemu.git
synced 2025-07-05 14:31:17 +12:00
Separate filestream.h into OS specific implementation files (#190)
This commit is contained in:
parent
f8b5024c09
commit
e20bfd00ec
37 changed files with 550 additions and 471 deletions
56
src/Common/unix/FileStream_unix.h
Normal file
56
src/Common/unix/FileStream_unix.h
Normal file
|
@ -0,0 +1,56 @@
|
|||
#pragma once
|
||||
#include "Common/precompiled.h"
|
||||
|
||||
class FileStream
|
||||
{
|
||||
public:
|
||||
static FileStream* openFile(std::string_view path);
|
||||
static FileStream* openFile(const wchar_t* path, bool allowWrite = false);
|
||||
static FileStream* openFile2(const fs::path& path, bool allowWrite = false);
|
||||
|
||||
static FileStream* createFile(const wchar_t* path);
|
||||
static FileStream* createFile(std::string_view path);
|
||||
static FileStream* createFile2(const fs::path& path);
|
||||
|
||||
// helper function to load a file into memory
|
||||
static std::optional<std::vector<uint8>> LoadIntoMemory(const fs::path& path);
|
||||
|
||||
// size and seek
|
||||
void SetPosition(uint64 pos);
|
||||
|
||||
uint64 GetSize();
|
||||
bool SetEndOfFile();
|
||||
void extract(std::vector<uint8>& data);
|
||||
|
||||
// reading
|
||||
uint32 readData(void* data, uint32 length);
|
||||
bool readU64(uint64& v);
|
||||
bool readU32(uint32& v);
|
||||
bool readU16(uint16& v);
|
||||
bool readU8(uint8& v);
|
||||
bool readLine(std::string& line);
|
||||
|
||||
// writing (binary)
|
||||
sint32 writeData(const void* data, sint32 length);
|
||||
void writeU64(uint64 v);
|
||||
void writeU32(uint32 v);
|
||||
void writeU16(uint16 v);
|
||||
void writeU8(uint8 v);
|
||||
|
||||
// writing (strings)
|
||||
void writeStringFmt(const char* format, ...);
|
||||
void writeString(const char* str);
|
||||
void writeLine(const char* str);
|
||||
|
||||
~FileStream();
|
||||
FileStream() {};
|
||||
|
||||
private:
|
||||
void SyncReadWriteSeek(bool nextOpIsWrite);
|
||||
FileStream(const fs::path& path, bool isOpen, bool isWriteable);
|
||||
|
||||
bool m_isValid{};
|
||||
std::fstream m_fileStream;
|
||||
bool m_prevOperationWasWrite{false};
|
||||
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue