Add fshelpers and temp

This commit is contained in:
2025-11-24 01:00:01 -06:00
parent ae6ae23075
commit f74f66a77d
19 changed files with 920 additions and 54 deletions

View File

@@ -0,0 +1,33 @@
#pragma once
#include "TempFS.hpp"
#include "VFSFix.hpp"
namespace Tesses::Framework::Filesystem::Helpers
{
void ReadAllText(std::shared_ptr<VFS> vfs, VFSPath path, std::string& text);
void ReadAllLines(std::shared_ptr<VFS> vfs, VFSPath path, std::vector<std::string>& lines);
void ReadAllBytes(std::shared_ptr<VFS> vfs, VFSPath path, std::vector<uint8_t>& array);
std::string ReadAllText(std::shared_ptr<VFS> vfs, VFSPath path);
std::vector<std::string> ReadAllLines(std::shared_ptr<VFS> vfs, VFSPath path);
std::vector<uint8_t> ReadAllBytes(std::shared_ptr<VFS> vfs, VFSPath path);
void WriteAllText(std::shared_ptr<VFS> vfs, VFSPath path, const std::string& text);
void WriteAllLines(std::shared_ptr<VFS> vfs, VFSPath path, const std::vector<std::string>& parts);
void WriteAllBytes(std::shared_ptr<VFS> vfs, VFSPath path, const std::vector<uint8_t>& bytes);
void CopyStreamProgress(std::shared_ptr<Streams::Stream> src,std::shared_ptr<Streams::Stream> dest, std::function<void(int64_t offset, int64_t length)> progress);
void CopyFile(std::shared_ptr<VFS> vfsSrc, VFSPath pathSrc, std::shared_ptr<VFS> vfsDest, VFSPath pathDest, bool overwrite=true);
void CopyFile(std::shared_ptr<VFS> vfsSrc, VFSPath pathSrc, std::shared_ptr<VFS> vfsDest, VFSPath pathDest, std::function<void(int64_t offset, int64_t length)> progress, bool overwrite=true);
void CopyDirectory(std::shared_ptr<VFS> vfsSrc, VFSPath pathSrc, std::shared_ptr<VFS> vfsDest, VFSPath pathDest, bool overwrite=true);
void CopyDirectory(std::shared_ptr<VFS> vfsSrc, VFSPath pathSrc, std::shared_ptr<VFS> vfsDest, VFSPath pathDest, std::function<void(int64_t offset, int64_t length, VFSPath currentFile)> progress, bool overwrite=true);
inline std::shared_ptr<TempFS> CreateTempFS(bool deleteOnDestroy=true)
{
return std::make_shared<TempFS>(deleteOnDestroy);
}
inline std::shared_ptr<TempFS> CreateTempFS(std::shared_ptr<VFS> vfs,bool deleteOnDestroy=true)
{
return std::make_shared<TempFS>(vfs,deleteOnDestroy);
}
}

View File

@@ -0,0 +1,51 @@
#pragma once
#include "../Common.hpp"
#include "VFS.hpp"
#include "VFSFix.hpp"
namespace Tesses::Framework::Filesystem
{
void UniqueString(std::string& text);
class TempFS : public VFS
{
std::shared_ptr<VFS> vfs;
bool deleteOnDestroy;
std::shared_ptr<VFS> parent;
std::string tmp_str;
public:
std::string TempDirectoryName();
TempFS(bool deleteOnDestroy=true);
TempFS(std::shared_ptr<VFS> vfs,bool deleteOnDestroy=true);
std::shared_ptr<Tesses::Framework::Streams::Stream> OpenFile(VFSPath path, std::string mode);
void CreateDirectory(VFSPath path);
void DeleteDirectory(VFSPath path);
bool SpecialFileExists(VFSPath path);
bool FileExists(VFSPath path);
bool RegularFileExists(VFSPath path);
bool SymlinkExists(VFSPath path);
bool CharacterDeviceExists(VFSPath path);
bool BlockDeviceExists(VFSPath path);
bool SocketFileExists(VFSPath path);
bool FIFOFileExists(VFSPath path);
bool DirectoryExists(VFSPath path);
void DeleteFile(VFSPath path);
void CreateSymlink(VFSPath existingFile, VFSPath symlinkFile);
VFSPathEnumerator EnumeratePaths(VFSPath path);
void CreateHardlink(VFSPath existingFile, VFSPath newName);
void MoveFile(VFSPath src, VFSPath dest);
void MoveDirectory(VFSPath src, VFSPath dest);
void DeleteDirectoryRecurse(VFSPath path);
VFSPath ReadLink(VFSPath path);
std::string VFSPathToSystem(VFSPath path);
VFSPath SystemToVFSPath(std::string path);
void GetDate(VFSPath path, Date::DateTime& lastWrite, Date::DateTime& lastAccess);
void SetDate(VFSPath path, Date::DateTime lastWrite, Date::DateTime lastAccess);
bool StatVFS(VFSPath path, StatVFSData& vfsData);
void Chmod(VFSPath path, uint32_t mode);
void Close();
~TempFS();
};
}

View File

@@ -29,6 +29,8 @@ namespace Tesses::Framework::Filesystem
static std::vector<std::string> SplitPath(std::string path);
std::vector<std::string> path;
VFSPath();
VFSPath(const char* path) : VFSPath((std::string)path)
{}
VFSPath(std::vector<std::string> path);
VFSPath(std::string path);
VFSPath(VFSPath p, std::string subent);
@@ -36,22 +38,27 @@ namespace Tesses::Framework::Filesystem
VFSPath GetParent();
VFSPath CollapseRelativeParents();
std::string GetFileName();
bool HasExtension();
std::string GetExtension();
VFSPath GetParent() const;
VFSPath CollapseRelativeParents() const;
std::string GetFileName() const;
bool HasExtension() const;
std::string GetExtension() const;
void ChangeExtension(std::string ext);
void RemoveExtension();
std::string ToString();
std::string ToString() const;
operator std::string() const
{
return ToString();
}
static VFSPath GetAbsoluteCurrentDirectory();
static void SetAbsoluteCurrentDirectory(VFSPath path);
VFSPath MakeAbsolute();
VFSPath MakeAbsolute() const;
VFSPath MakeAbsolute(VFSPath curDir);
VFSPath MakeRelative();
VFSPath MakeRelative(VFSPath toMakeRelativeTo);
VFSPath MakeAbsolute(VFSPath curDir) const;
VFSPath MakeRelative() const;
VFSPath MakeRelative(VFSPath toMakeRelativeTo) const;
};
VFSPath operator/(VFSPath p, VFSPath p2);
VFSPath operator/(VFSPath p, std::string p2);