mirror of
https://github.com/KytyPS5/KytyPS5.git
synced 2026-10-19 18:36:53 +02:00
4b0de1b672
* Simplify archive loading and harden filesystem integration * Restore directory entry name length assertion * Keep graphics-dependent filesystem tests out of CI --------- Co-authored-by: nmzik <Nmzik@mail.ru>
116 lines
3.3 KiB
C++
116 lines
3.3 KiB
C++
#ifndef KYTY_COMMON_FILE_H_
|
|
#define KYTY_COMMON_FILE_H_
|
|
|
|
#include "common/common.h"
|
|
#include "common/dateTime.h"
|
|
|
|
#include <cstddef>
|
|
#include <filesystem>
|
|
#include <memory>
|
|
#include <optional>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#if KYTY_PLATFORM == KYTY_PLATFORM_WINDOWS
|
|
#ifdef CreateDirectory
|
|
#undef CreateDirectory
|
|
#endif
|
|
#ifdef DeleteFile
|
|
#undef DeleteFile
|
|
#endif
|
|
#ifdef CopyFile
|
|
#undef CopyFile
|
|
#endif
|
|
#endif
|
|
|
|
namespace Common {
|
|
|
|
// SUBSYSTEM_DEFINE(File);
|
|
|
|
class File {
|
|
public:
|
|
enum class Mode { Read, Write, ReadWrite, WriteRead };
|
|
|
|
struct DirEntry {
|
|
std::string name;
|
|
bool is_file;
|
|
};
|
|
struct Info {
|
|
bool is_file;
|
|
uint64_t size;
|
|
};
|
|
|
|
File();
|
|
explicit File(const std::filesystem::path& name);
|
|
File(const std::filesystem::path& name, Mode mode);
|
|
virtual ~File();
|
|
|
|
bool Create(const std::filesystem::path& name);
|
|
bool Open(const std::filesystem::path& name, Mode mode);
|
|
bool OpenInMem(void* buf, uint32_t buf_size);
|
|
bool CreateInMem();
|
|
|
|
void Close();
|
|
|
|
bool Flush();
|
|
|
|
[[nodiscard]] uint64_t Size() const;
|
|
[[nodiscard]] uint64_t Remaining() const;
|
|
|
|
bool Seek(uint64_t offset);
|
|
[[nodiscard]] uint64_t Tell() const;
|
|
|
|
bool Truncate(uint64_t size);
|
|
bool Unlink();
|
|
|
|
[[nodiscard]] bool IsInvalid() const;
|
|
|
|
[[nodiscard]] bool IsEOF() const { return Tell() >= Size(); }
|
|
|
|
void GetLastAccessAndWriteTimeUTC(DateTime* access, DateTime* write);
|
|
|
|
void Read(void* data, uint32_t size, uint32_t* bytes_read = nullptr);
|
|
void Write(const void* data, uint32_t size, uint32_t* bytes_written = nullptr);
|
|
|
|
void Printf(const char* format, ...) KYTY_FORMAT_PRINTF(2, 3);
|
|
|
|
std::vector<std::byte> ReadWholeBuffer();
|
|
|
|
static uint64_t Size(const std::filesystem::path& name);
|
|
static std::optional<Info> GetInfo(const std::filesystem::path& name);
|
|
|
|
static bool IsDirectoryExisting(const std::filesystem::path& path);
|
|
static bool IsFileExisting(const std::filesystem::path& name);
|
|
static bool CreateDirectory(const std::filesystem::path& path);
|
|
static bool CreateDirectories(const std::filesystem::path& path);
|
|
static bool DeleteDirectory(const std::filesystem::path& path);
|
|
static bool DeleteDirectories(const std::filesystem::path& path);
|
|
static bool DeleteFile(const std::filesystem::path& name);
|
|
|
|
static DateTime GetLastAccessTimeUTC(const std::filesystem::path& name);
|
|
static DateTime GetLastWriteTimeUTC(const std::filesystem::path& name);
|
|
static void GetLastAccessAndWriteTimeUTC(const std::filesystem::path& name, DateTime* access,
|
|
DateTime* write);
|
|
static bool SetLastAccessTimeUTC(const std::filesystem::path& name, const DateTime& dt);
|
|
static bool SetLastWriteTimeUTC(const std::filesystem::path& name, const DateTime& dt);
|
|
static bool SetLastAccessAndWriteTimeUTC(const std::filesystem::path& name,
|
|
const DateTime& access, const DateTime& write);
|
|
|
|
static std::vector<DirEntry> GetDirEntries(const std::filesystem::path& path);
|
|
static bool CopyFile(const std::filesystem::path& src, const std::filesystem::path& dst);
|
|
static bool RenameFile(const std::filesystem::path& src, const std::filesystem::path& dst);
|
|
static void RemoveReadonly(const std::filesystem::path& name);
|
|
|
|
KYTY_CLASS_NO_COPY(File);
|
|
|
|
private:
|
|
struct FilePrivate;
|
|
|
|
std::filesystem::path m_file_name;
|
|
std::unique_ptr<FilePrivate> m_p;
|
|
};
|
|
|
|
} // namespace Common
|
|
|
|
#endif /* KYTY_COMMON_FILE_H_ */
|