Change html to dark mode by default and stat in vfs

This commit is contained in:
2026-04-19 23:07:17 -05:00
parent 5435280209
commit c5cf13e1b7
40 changed files with 1110 additions and 1956 deletions

View File

@@ -1,7 +1,10 @@
#include "TessesFramework/Filesystem/LocalFS.hpp"
#include "TessesFramework/Streams/FileStream.hpp"
#include <cerrno>
#include <filesystem>
#include <iostream>
#include <sys/stat.h>
#include <sys/types.h>
#if defined(_WIN32)
#include <windows.h>
#include "TessesFramework/Filesystem/VFSFix.hpp"
@@ -27,16 +30,31 @@ namespace Tesses::Framework::Filesystem
pft->dwHighDateTime = time_value.HighPart;
}
#endif
void LocalFilesystem::GetDate(VFSPath path, Date::DateTime& lastWrite, Date::DateTime& lastAccess)
bool LocalFilesystem::Stat(VFSPath path, StatData& sfs)
{
std::string s = VFSPathToSystem(path);
struct stat st;
if(stat(s.c_str(),&st) == 0)
{
lastAccess = Date::DateTime((int64_t)st.st_atime);
lastWrite = Date::DateTime((int64_t)st.st_mtime);
sfs.Device = (uint64_t)st.st_dev;
sfs.Inode = (uint64_t)st.st_ino;
sfs.Mode = (uint32_t)st.st_mode;
sfs.HardLinks = (uint64_t)st.st_nlink;
sfs.UserId = (uint32_t)st.st_uid;
sfs.GroupId = (uint32_t)st.st_gid;
sfs.DeviceId = (uint64_t)st.st_rdev;
sfs.Size = (uint64_t)st.st_size;
sfs.BlockSize = (uint64_t)st.st_blksize;
sfs.BlockCount = (uint64_t)st.st_blocks;
sfs.LastAccess = Date::DateTime((int64_t)st.st_atime);
sfs.LastModified = Date::DateTime((int64_t)st.st_mtime);
sfs.LastStatus = Date::DateTime((int64_t)st.st_ctime);
return true;
}
return false;
}
void LocalFilesystem::SetDate(VFSPath path, Date::DateTime lastWrite, Date::DateTime lastAccess)
{
std::string s = VFSPathToSystem(path);
@@ -44,7 +62,7 @@ namespace Tesses::Framework::Filesystem
#if defined(_WIN32)
FILETIME lastWriteF;
FILETIME lastAccessF;
TimetToFileTime((time_t)lastWrite.ToEpoch(),&lastWriteF);
TimetToFileTime((time_t)lastAccess.ToEpoch(),&lastAccessF);
HANDLE hFile = CreateFileA(
@@ -96,34 +114,6 @@ namespace Tesses::Framework::Filesystem
{
std::filesystem::create_directories(VFSPathToSystem(path));
}
bool LocalFilesystem::DirectoryExists(VFSPath path)
{
return std::filesystem::is_directory(VFSPathToSystem(path));
}
bool LocalFilesystem::RegularFileExists(VFSPath path)
{
return std::filesystem::is_regular_file(VFSPathToSystem(path));
}
bool LocalFilesystem::SymlinkExists(VFSPath path)
{
return std::filesystem::is_symlink(VFSPathToSystem(path));
}
bool LocalFilesystem::BlockDeviceExists(VFSPath path)
{
return std::filesystem::is_block_file(VFSPathToSystem(path));
}
bool LocalFilesystem::CharacterDeviceExists(VFSPath path)
{
return std::filesystem::is_character_file(VFSPathToSystem(path));
}
bool LocalFilesystem::SocketFileExists(VFSPath path)
{
return std::filesystem::is_socket(VFSPathToSystem(path));
}
bool LocalFilesystem::FIFOFileExists(VFSPath path)
{
return std::filesystem::is_fifo(VFSPathToSystem(path));
}
void LocalFilesystem::CreateSymlink(VFSPath existingFile, VFSPath symlinkFile)
{
if(std::filesystem::is_directory(VFSPathToSystem(existingFile)))
@@ -182,10 +172,13 @@ namespace Tesses::Framework::Filesystem
}
return p;
}
VFSPathEnumerator LocalFilesystem::EnumeratePaths(VFSPath path)
{
auto dir = new std::filesystem::directory_iterator(VFSPathToSystem(path));
std::filesystem::path sysPath = VFSPathToSystem(path);
if(!std::filesystem::is_directory(sysPath)) return VFSPathEnumerator();
auto dir = new std::filesystem::directory_iterator(sysPath);
return VFSPathEnumerator([dir,path](VFSPath& path0)->bool {
std::filesystem::directory_iterator& ittr = *dir;
if(ittr != std::filesystem::directory_iterator())
@@ -236,8 +229,47 @@ namespace Tesses::Framework::Filesystem
chmod(pathStr.c_str(), (mode_t)mode);
#endif
}
void LocalFilesystem::Chown(VFSPath path, uint32_t uid, uint32_t gid)
{
auto pathStr = this->VFSPathToSystem(path);
#if defined(_WIN32)
#else
chown(pathStr.c_str(), (uid_t)uid, (gid_t)gid);
#endif
}
FIFOCreationResult LocalFilesystem::CreateFIFO(VFSPath path, uint32_t mod)
{
auto pathStr = this->VFSPathToSystem(path);
#if defined(_WIN32)
return FIFOCreationResult::Unsupported;
#else
int res = mkfifo(pathStr.c_str(), (mode_t)mod);
if(res == 0) return FIFOCreationResult::Success;
else if(res == -1)
{
switch(res)
{
case EEXIST:
return FIFOCreationResult::Exists;
case ENOTSUP:
return FIFOCreationResult::Unsupported;
case EACCES:
return FIFOCreationResult::Denied;
case ENOSPC:
return FIFOCreationResult::OutOfInodes;
case EROFS:
return FIFOCreationResult::ReadOnlyFS;
}
}
return FIFOCreationResult::UnknownError;
#endif
}
void LocalFilesystem::Lock(VFSPath path)
{
auto p2 = VFSPathToSystem(path);
@@ -275,7 +307,7 @@ namespace Tesses::Framework::Filesystem
lflags |= (((uint32_t)flags & (uint32_t)FSWatcherEventType::MoveOld) != 0) ? IN_MOVED_FROM : 0;
lflags |= (((uint32_t)flags & (uint32_t)FSWatcherEventType::MoveNew) != 0) ? IN_MOVED_TO : 0;
lflags |= (((uint32_t)flags & (uint32_t)FSWatcherEventType::Opened) != 0) ? IN_OPEN : 0;
return lflags;
}
static FSWatcherEventType from_linux_mask(uint32_t lflags)
@@ -293,7 +325,7 @@ namespace Tesses::Framework::Filesystem
flags |= ((lflags & IN_MOVED_FROM) != 0) ? (uint32_t)FSWatcherEventType::MoveOld : 0;
flags |= ((lflags & IN_MOVED_TO) != 0) ? (uint32_t)FSWatcherEventType::MoveNew : 0;
flags |= ((lflags & IN_OPEN) != 0) ? (uint32_t)FSWatcherEventType::Opened : 0;
return (FSWatcherEventType)flags;
}
public:
@@ -303,7 +335,7 @@ namespace Tesses::Framework::Filesystem
}
protected:
void SetEnabledImpl(bool enabled)
{
if(enabled)
@@ -325,7 +357,7 @@ namespace Tesses::Framework::Filesystem
__attribute__ ((aligned(__alignof__(struct inotify_event))));
const struct inotify_event *event;
ssize_t size;
bool fail=false;
FSWatcherEvent evt;
@@ -397,12 +429,12 @@ namespace Tesses::Framework::Filesystem
close(fd);
return;
}
}
}
}
}
}
}
close(fd);
});
@@ -420,8 +452,8 @@ namespace Tesses::Framework::Filesystem
}
};
#endif
std::shared_ptr<FSWatcher> LocalFilesystem::CreateWatcher(std::shared_ptr<VFS> vfs, VFSPath path)
{

View File

@@ -1,669 +0,0 @@
#include "TessesFramework/Filesystem/MemoryFilesystem.hpp"
#include <iostream>
namespace Tesses::Framework::Filesystem
{
MemoryFilesystemStream::MemoryFilesystemStream(std::shared_ptr<Tesses::Framework::Threading::Mutex> mtx, std::shared_ptr<MemoryFileData> data,bool canRead, bool canWrite, bool canSeek)
{
this->mtx = mtx;
this->data = data;
this->canRead = canRead;
this->canWrite = canWrite;
this->canSeek = canSeek;
this->pos=0;
}
size_t MemoryFilesystemStream::Read(uint8_t* buff, size_t sz)
{
if(!this->canRead) return 0;
if(this->pos >= this->data->file.size()) return 0;
size_t toRead = std::min(sz, (size_t)(this->data->file.size()-this->pos));
memcpy(buff, this->data->file.data() + this->pos, toRead);
this->pos += toRead;
return toRead;
}
size_t MemoryFilesystemStream::Write(const uint8_t* buff, size_t sz)
{
if(!this->canWrite) return 0;
if(this->canSeek)
{
if(this->pos > this->data->file.size())
{
this->data->file.resize(this->pos+sz);
}
this->data->file.insert(this->data->file.begin()+this->pos, buff, buff+sz);
this->pos+=sz;
}
else
{
this->data->file.insert(this->data->file.end(), buff, buff+sz);
}
return sz;
}
bool MemoryFilesystemStream::CanRead()
{
return canRead;
}
bool MemoryFilesystemStream::CanWrite()
{
return canWrite;
}
bool MemoryFilesystemStream::CanSeek()
{
return canSeek;
}
int64_t MemoryFilesystemStream::GetPosition()
{
if(!this->canSeek) return (int64_t)this->data->file.size();
return pos;
}
void MemoryFilesystemStream::Flush()
{
//its already flushed
}
void MemoryFilesystemStream::Seek(int64_t pos, Streams::SeekOrigin whence)
{
if(canSeek) return;
switch(whence)
{
case Streams::SeekOrigin::Begin:
this->pos = (size_t)pos;
break;
case Streams::SeekOrigin::Current:
this->pos += (size_t)pos;
break;
case Streams::SeekOrigin::End:
this->pos = (size_t)(this->data->file.size() + pos);
break;
}
}
MemoryFilesystemStream::~MemoryFilesystemStream()
{
mtx->Lock();
if(this->canWrite) this->data->canAccess=true;
this->data->readers--;
mtx->Unlock();
}
MemoryEntry* MemoryFilesystem::GetEntry(VFSPath path,bool followSymlink)
{
if(path.relative) return nullptr;
if(path.path.empty()) return &this->root;
auto entry = GetEntry(path.GetParent(),true);
if(entry == nullptr) return nullptr;
auto dir = dynamic_cast<MemoryDirectory*>(entry);
if(dir != nullptr)
{
for(auto item : dir->entries)
{
if(item->name == path.GetFileName())
{
auto link = dynamic_cast<MemorySymlink*>(item);
if(followSymlink && link != nullptr)
{
item = GetEntry(link->linkedTo,true);
}
return item;
}
}
}
return nullptr;
}
std::shared_ptr<Streams::Stream> MemoryFilesystem::OpenFile(VFSPath path, std::string mode)
{
bool canRead=false;
bool canWrite=false;
bool canSeek=true;
bool mustExist=false;
bool truncate=false;
if(mode.size() >= 1)
{
if(mode[0] == 'r')
{
canRead = true;
mustExist=true;
}
else if(mode[0] == 'w')
{
canWrite = true;
truncate=true;
}
else if(mode[0] == 'a')
{
canSeek = false;
canWrite = true;
}
}
if(((mode.size() >= 2 && mode[1] == '+') || (mode.size() >= 2 && mode[1] == 'b' && mode[2] == '+')))
{
canRead = true;
canWrite = true;
}
mtx->Lock();
if(mustExist)
{
auto file = GetEntry(path,true);
if(file == nullptr)
{
mtx->Unlock();
return nullptr;
}
auto f = dynamic_cast<MemoryFile*>(file);
if(f == nullptr)
{
mtx->Unlock();
return nullptr;
}
if(!f->data->canAccess)
{
mtx->Unlock();
return nullptr;
}
if(canWrite && f->data->readers > 0)
{
mtx->Unlock();
return nullptr;
}
f->data->readers++;
if(canWrite) f->data->canAccess=false;
mtx->Unlock();
return std::make_shared<MemoryFilesystemStream>(mtx,f->data,canRead,canWrite,canSeek);
}
else
{
auto file = dynamic_cast<MemoryFile*>(GetEntry(path,true));
if(file != nullptr)
{
if(!file->data->canAccess)
{
mtx->Unlock();
return nullptr;
}
if(file->data->readers > 0)
{
mtx->Unlock();
return nullptr;
}
file->data->canAccess=false;
file->data->readers++;
if(truncate) {file->data->file.clear(); file->data->lastWrite=Date::DateTime::NowUTC();}
mtx->Unlock();
return std::make_shared<MemoryFilesystemStream>(mtx,file->data,canRead,canWrite,canSeek);
}
auto dir = GetEntry(path.GetParent(),true);
if(dir == nullptr)
{
mtx->Unlock();
return nullptr;
}
auto myDir = dynamic_cast<MemoryDirectory*>(dir);
if(myDir == nullptr)
{
mtx->Unlock();
return nullptr;
}
MemoryFile* thefile=nullptr;
for(auto f : myDir->entries)
{
if(f->name == path.GetFileName())
{
auto symlink = dynamic_cast<MemorySymlink*>(f);
while(symlink != nullptr)
{
auto ent = GetEntry(symlink->name,false);
auto sym = dynamic_cast<MemorySymlink*>(f);
if(sym != nullptr)
symlink = sym;
else
{
auto myDir0 = dynamic_cast<MemoryDirectory*>(GetEntry(symlink->linkedTo.GetParent(),true));
if(myDir0 != nullptr)
{
for(auto f2 : myDir0->entries)
{
if(f2->name == symlink->linkedTo.GetFileName())
{
auto myFile = dynamic_cast<MemoryFile*>(f2);
if(myFile != nullptr)
{
thefile = myFile;
break;
}
else
{
mtx->Unlock();
return nullptr;
}
}
}
myDir = myDir0;
}
else
{
mtx->Unlock();
return nullptr;
}
break;
}
}
break;
}
}
if(thefile == nullptr)
{
MemoryFile* f = new MemoryFile();
f->name = path.GetFileName();
f->data = std::make_shared<MemoryFileData>();
f->data->canAccess=false;
f->data->readers++;
myDir->entries.push_back(f);
mtx->Unlock();
return std::make_shared<MemoryFilesystemStream>(mtx,f->data,canRead,canWrite,canSeek);
}
if(thefile != nullptr)
{
if(!thefile->data->canAccess)
{
mtx->Unlock();
return nullptr;
}
if(thefile->data->readers > 0)
{
mtx->Unlock();
return nullptr;
}
thefile->data->canAccess=false;
thefile->data->readers++;
if(truncate) {thefile->data->file.clear(); thefile->data->lastWrite=Date::DateTime::NowUTC();}
mtx->Unlock();
return std::make_shared<MemoryFilesystemStream>(mtx,thefile->data,canRead,canWrite,canSeek);
}
}
mtx->Unlock();
return nullptr;
}
void MemoryFilesystem::CreateDirectory(VFSPath path)
{
if(path.relative) return;
if(path.path.empty()) return;
mtx->Lock();
MemoryDirectory* dir=&root;
for(auto part : path.path)
{
bool have=false;
for(auto dirent : dir->entries)
{
if(dirent->name == part)
{
auto symlink = dynamic_cast<MemorySymlink*>(dirent);
if(symlink != nullptr)
{
dirent = GetEntry(symlink->linkedTo,true);
}
auto dirdirent = dynamic_cast<MemoryDirectory*>(dirent);
if(dirdirent != nullptr)
{
dir = dirdirent;
have=true;
break;
}
else
{
mtx->Unlock();
return;
}
}
}
if(!have)
{
MemoryDirectory* dir2 = new MemoryDirectory();
dir2->name = part;
dir2->lastWrite=Date::DateTime::NowUTC();
dir->entries.push_back(dir2);
dir->lastWrite=Date::DateTime::NowUTC();
dir=dir2;
}
}
mtx->Unlock();
}
void MemoryFilesystem::DeleteFile(VFSPath path)
{
if(path.relative || path.path.empty()) return;
mtx->Lock();
MemoryDirectory* dir=&root;
if(path.path.size() > 1)
{
dir = dynamic_cast<MemoryDirectory*>(GetEntry(path.GetParent(),true));
}
if(dir == nullptr)
{
mtx->Unlock();
return;
}
std::string fname = path.GetFileName();
for(auto index = dir->entries.begin(); index < dir->entries.end(); index++)
{
auto item = *index;
if(item->name == fname)
{
auto p = dynamic_cast<MemoryDirectory*>(item);
if(p == nullptr)
{
delete item;
dir->entries.erase(index);
dir->lastWrite=Date::DateTime::NowUTC();
}
break;
}
}
mtx->Unlock();
}
bool MemoryFilesystem::RegularFileExists(VFSPath path)
{
if(path.relative) return false;
if(path.path.empty()) return false;
mtx->Lock();
auto f = GetEntry(path,false);
mtx->Unlock();
return dynamic_cast<MemoryFile*>(f) != nullptr;
}
bool MemoryFilesystem::SymlinkExists(VFSPath path)
{
if(path.relative) return false;
if(path.path.empty()) return false;
mtx->Lock();
auto f = GetEntry(path,false);
mtx->Unlock();
return dynamic_cast<MemorySymlink*>(f) != nullptr;
}
bool MemoryFilesystem::DirectoryExists(VFSPath path)
{
if(path.relative) return false;
if(path.path.empty()) return true;
mtx->Lock();
auto f = GetEntry(path,false);
mtx->Unlock();
return dynamic_cast<MemoryDirectory*>(f) != nullptr;
}
void MemoryFilesystem::DeleteDirectory(VFSPath path)
{
if(path.relative || path.path.empty()) return;
mtx->Lock();
MemoryDirectory* dir=&root;
if(path.path.size() > 1)
{
dir = dynamic_cast<MemoryDirectory*>(GetEntry(path.GetParent(),true));
}
if(dir == nullptr)
{
mtx->Unlock();
return;
}
std::string fname = path.GetFileName();
for(auto index = dir->entries.begin(); index < dir->entries.end(); index++)
{
auto item = *index;
if(item->name == fname)
{
auto p = dynamic_cast<MemoryDirectory*>(item);
if(p != nullptr)
{
delete item;
dir->entries.erase(index);
dir->lastWrite=Date::DateTime::NowUTC();
}
break;
}
}
mtx->Unlock();
}
void MemoryFilesystem::CreateSymlink(VFSPath existingFile, VFSPath symlinkFile)
{
if(existingFile.relative || symlinkFile.relative || symlinkFile.path.empty()) return;
mtx->Lock();
MemoryDirectory* dir=&root;
if(symlinkFile.path.size() > 1)
{
dir = dynamic_cast<MemoryDirectory*>(GetEntry(symlinkFile.GetParent(),true));
}
if(dir == nullptr)
{
mtx->Unlock();
return;
}
std::string fname = symlinkFile.GetFileName();
for(auto index = dir->entries.begin(); index < dir->entries.end(); index++)
{
auto item = *index;
if(item->name == fname)
{
auto p = dynamic_cast<MemorySymlink*>(item);
if(p != nullptr)
{
p->linkedTo = existingFile;
p->lastWrite = Date::DateTime::NowUTC();
}
mtx->Unlock();
return;
}
}
MemorySymlink* symlink = new MemorySymlink();
symlink->name = fname;
symlink->linkedTo = existingFile;
symlink->lastWrite = Date::DateTime::NowUTC();
dir->entries.push_back(symlink);
dir->lastWrite = Date::DateTime::NowUTC();
mtx->Unlock();
}
VFSPathEnumerator MemoryFilesystem::EnumeratePaths(VFSPath path)
{
std::pair<size_t,std::vector<std::string>>* paths=new std::pair<size_t,std::vector<std::string>>();
paths->first=0;
mtx->Lock();
auto dir = dynamic_cast<MemoryDirectory*>(GetEntry(path,true));
if(dir != nullptr)
{
for(auto item : dir->entries) paths->second.push_back(item->name);
}
mtx->Unlock();
return VFSPathEnumerator([paths,path](VFSPath& _path)->bool{
if(paths->first < paths->second.size())
{
_path = path / paths->second[paths->first++];
return true;
}
return false;
},[paths]()->void{
delete paths;
});
}
void MemoryFilesystem::CreateHardlink(VFSPath existingFile, VFSPath newName)
{
mtx->Lock();
auto existing = dynamic_cast<MemoryFile*>(GetEntry(existingFile,true));
if(existing == nullptr)
{
mtx->Unlock();
return;
}
MemoryDirectory* dir=&root;
if(newName.path.size() > 1)
{
dir = dynamic_cast<MemoryDirectory*>(GetEntry(newName.GetParent(),true));
}
if(dir == nullptr)
{
mtx->Unlock();
return;
}
std::string fname = newName.GetFileName();
for(auto index = dir->entries.begin(); index < dir->entries.end(); index++)
{
auto item = *index;
if(item->name == fname)
{
mtx->Unlock();
return;
}
}
MemoryFile* memFile = new MemoryFile();
memFile->name = fname;
memFile->data = existing->data;
dir->entries.push_back(memFile);
dir->lastWrite=Date::DateTime::NowUTC();
mtx->Unlock();
}
void MemoryFilesystem::MoveFile(VFSPath src, VFSPath dest)
{
DeleteFile(dest);
CreateHardlink(src,dest);
DeleteFile(src);
}
void MemoryFilesystem::MoveDirectory(VFSPath src, VFSPath dest)
{
CreateDirectory(dest);
for(auto ent : EnumeratePaths(src))
{
VFSPath destPath = dest / ent.GetFileName();
if(FileExists(ent)) MoveFile(ent,destPath);
if(DirectoryExists(ent)) MoveDirectory(ent,destPath);
}
DeleteDirectory(src);
}
VFSPath MemoryFilesystem::ReadLink(VFSPath p)
{
mtx->Lock();
VFSPath p2;
auto symlink = dynamic_cast<MemorySymlink*>(GetEntry(p,false));
if(symlink != nullptr)
{
p2 = symlink->linkedTo;
}
mtx->Unlock();
return p2;
}
std::string MemoryFilesystem::VFSPathToSystem(VFSPath path)
{
return path.ToString();
}
VFSPath MemoryFilesystem::SystemToVFSPath(std::string path)
{
return path;
}
void MemoryFilesystem::GetDate(VFSPath path, Date::DateTime& lastWrite, Date::DateTime& lastAccess)
{
mtx->Lock();
auto node = GetEntry(path,false);
auto dir = dynamic_cast<MemoryDirectory*>(node);
auto file = dynamic_cast<MemoryFile*>(node);
auto sym = dynamic_cast<MemorySymlink*>(node);
if(dir != nullptr) lastWrite = dir->lastWrite;
if(file != nullptr) lastWrite = file->data->lastWrite;
if(sym != nullptr) lastWrite = sym->lastWrite;
mtx->Unlock();
lastAccess = lastWrite;
}
void MemoryFilesystem::SetDate(VFSPath path, Date::DateTime lastWrite, Date::DateTime lastAccess)
{
mtx->Lock();
auto node = GetEntry(path,false);
auto dir = dynamic_cast<MemoryDirectory*>(node);
auto file = dynamic_cast<MemoryFile*>(node);
auto sym = dynamic_cast<MemorySymlink*>(node);
if(dir != nullptr) dir->lastWrite = lastWrite;
if(file != nullptr) file->data->lastWrite = lastWrite;
if(sym != nullptr) sym->lastWrite = lastWrite;
mtx->Unlock();
}
MemoryFilesystem::~MemoryFilesystem()
{
}
MemoryFilesystem::MemoryFilesystem()
{
mtx = std::make_shared<Threading::Mutex>();
}
MemoryEntry::~MemoryEntry()
{
}
MemoryFile::~MemoryFile()
{
}
MemoryDirectory::MemoryDirectory()
{
this->lastWrite = Date::DateTime::NowUTC();
}
MemoryDirectory::~MemoryDirectory()
{
for(auto item : this->entries) delete item;
}
MemoryFileData::MemoryFileData()
{
this->lastWrite = Date::DateTime::NowUTC();
this->canAccess=true;
this->readers=0;
}
}

View File

@@ -24,7 +24,7 @@ namespace Tesses::Framework::Filesystem
void MountableFilesystem::GetFS(VFSPath srcPath, VFSPath& destRoot, VFSPath& destPath, std::shared_ptr<VFS>& vfs)
void MountableFilesystem::GetFS(VFSPath srcPath, VFSPath& destRoot, VFSPath& destPath, std::shared_ptr<VFS>& vfs)
{
if(srcPath.path.empty()) return;
for(auto item : this->directories)
@@ -38,8 +38,8 @@ namespace Tesses::Framework::Filesystem
srcPath1.relative=false;
destPath = srcPath1;
destRoot = VFSPath(VFSPath(),item->name);
}
VFSPath srcPath2(std::vector(srcPath.path.begin()+1,srcPath.path.end()));
srcPath2.relative=false;
@@ -49,9 +49,9 @@ namespace Tesses::Framework::Filesystem
}
}
void MountableDirectory::GetFS(VFSPath srcPath, VFSPath curDir, VFSPath& destRoot, VFSPath& destPath, std::shared_ptr<VFS>& vfs)
void MountableDirectory::GetFS(VFSPath srcPath, VFSPath curDir, VFSPath& destRoot, VFSPath& destPath, std::shared_ptr<VFS>& vfs)
{
if(srcPath.path.empty()) return;
for(auto item : this->dirs)
@@ -61,13 +61,13 @@ namespace Tesses::Framework::Filesystem
if(item->vfs != nullptr)
{
vfs = item->vfs;
VFSPath srcPath1(std::vector(srcPath.path.begin()+1,srcPath.path.end()));
srcPath1.relative=false;
destPath = srcPath1;
destRoot = curDir;
}
VFSPath srcPath2(std::vector(srcPath.path.begin()+1,srcPath.path.end()));
srcPath2.relative=false;
@@ -83,7 +83,7 @@ namespace Tesses::Framework::Filesystem
VFSPath destRoot;
VFSPath destPath = path;
std::shared_ptr<VFS> vfs = root;
GetFS(path, destRoot, destPath, vfs);
if(vfs != nullptr)
return VFSPath(destRoot,vfs->ReadLink(destPath));
@@ -96,24 +96,65 @@ namespace Tesses::Framework::Filesystem
VFSPath destRoot;
VFSPath destPath = path;
std::shared_ptr<VFS> vfs = root;
GetFS(path, destRoot, destPath, vfs);
if(vfs != nullptr)
return vfs->StatVFS(destPath,data);
return false;
}
bool MountableFilesystem::Stat(VFSPath path, StatData& data)
{
path = path.CollapseRelativeParents();
VFSPath destRoot;
VFSPath destPath = path;
std::shared_ptr<VFS> vfs = root;
GetFS(path, destRoot, destPath, vfs);
if(vfs != nullptr)
return vfs->Stat(destPath,data);
return false;
}
void MountableFilesystem::Chmod(VFSPath path, uint32_t mode)
{
path = path.CollapseRelativeParents();
VFSPath destRoot;
VFSPath destPath = path;
std::shared_ptr<VFS> vfs = root;
GetFS(path, destRoot, destPath, vfs);
if(vfs != nullptr)
vfs->Chmod(destPath,mode);
}
void MountableFilesystem::Chown(VFSPath path, uint32_t uid, uint32_t gid)
{
path = path.CollapseRelativeParents();
VFSPath destRoot;
VFSPath destPath = path;
std::shared_ptr<VFS> vfs = root;
GetFS(path, destRoot, destPath, vfs);
if(vfs != nullptr)
vfs->Chown(destPath,uid, gid);
}
FIFOCreationResult MountableFilesystem::CreateFIFO(VFSPath path, uint32_t mod)
{
path = path.CollapseRelativeParents();
VFSPath destRoot;
VFSPath destPath = path;
std::shared_ptr<VFS> vfs = root;
GetFS(path, destRoot, destPath, vfs);
if(vfs != nullptr)
return vfs->CreateFIFO(destPath,mod);
return FIFOCreationResult::UnknownError;
}
std::shared_ptr<Tesses::Framework::Streams::Stream> MountableFilesystem::OpenFile(VFSPath path, std::string mode)
{
@@ -121,7 +162,7 @@ namespace Tesses::Framework::Filesystem
VFSPath destRoot;
VFSPath destPath = path;
std::shared_ptr<VFS> vfs = root;
GetFS(path, destRoot, destPath, vfs);
if(vfs != nullptr)
@@ -131,238 +172,92 @@ namespace Tesses::Framework::Filesystem
void MountableFilesystem::CreateDirectory(VFSPath path)
{
path = path.CollapseRelativeParents();
VFSPath destRoot;
VFSPath destPath = path;
std::shared_ptr<VFS> vfs = root;
GetFS(path, destRoot, destPath, vfs);
if(destPath.path.empty()) return;
if(vfs != nullptr)
vfs->CreateDirectory(destPath);
}
void MountableFilesystem::DeleteDirectory(VFSPath path)
{
path = path.CollapseRelativeParents();
VFSPath destRoot;
VFSPath destPath = path;
std::shared_ptr<VFS> vfs = root;
GetFS(path, destRoot, destPath, vfs);
if(destPath.path.empty()) return;
if(vfs != nullptr)
vfs->DeleteDirectory(destPath);
}
bool MountableFilesystem::SpecialFileExists(VFSPath path)
{
path = path.CollapseRelativeParents();
VFSPath destRoot;
VFSPath destPath = path;
std::shared_ptr<VFS> vfs = root;
GetFS(path, destRoot, destPath, vfs);
if(vfs != nullptr)
return vfs->SpecialFileExists(destPath);
return false;
}
bool MountableFilesystem::FileExists(VFSPath path)
{
path = path.CollapseRelativeParents();
VFSPath destRoot;
VFSPath destPath = path;
std::shared_ptr<VFS> vfs = root;
GetFS(path, destRoot, destPath, vfs);
if(vfs != nullptr)
return vfs->FileExists(destPath);
return false;
}
bool MountableFilesystem::RegularFileExists(VFSPath path)
{
path = path.CollapseRelativeParents();
VFSPath destRoot;
VFSPath destPath = path;
std::shared_ptr<VFS> vfs = root;
GetFS(path, destRoot, destPath, vfs);
if(vfs != nullptr)
return vfs->RegularFileExists(destPath);
return false;
}
bool MountableFilesystem::SymlinkExists(VFSPath path)
{
path = path.CollapseRelativeParents();
VFSPath destRoot;
VFSPath destPath = path;
std::shared_ptr<VFS> vfs = root;
GetFS(path, destRoot, destPath, vfs);
if(vfs != nullptr)
return vfs->SymlinkExists(destPath);
return false;
}
bool MountableFilesystem::CharacterDeviceExists(VFSPath path)
{
path = path.CollapseRelativeParents();
VFSPath destRoot;
VFSPath destPath = path;
std::shared_ptr<VFS> vfs = root;
GetFS(path, destRoot, destPath, vfs);
if(vfs != nullptr)
return vfs->CharacterDeviceExists(destPath);
return false;
}
bool MountableFilesystem::BlockDeviceExists(VFSPath path)
{
path = path.CollapseRelativeParents();
VFSPath destRoot;
VFSPath destPath = path;
std::shared_ptr<VFS> vfs = root;
GetFS(path, destRoot, destPath, vfs);
if(vfs != nullptr)
return vfs->BlockDeviceExists(destPath);
return false;
}
bool MountableFilesystem::SocketFileExists(VFSPath path)
{
path = path.CollapseRelativeParents();
VFSPath destRoot;
VFSPath destPath = path;
std::shared_ptr<VFS> vfs = root;
GetFS(path, destRoot, destPath, vfs);
if(vfs != nullptr)
return vfs->SocketFileExists(destPath);
return false;
}
bool MountableFilesystem::FIFOFileExists(VFSPath path)
{
path = path.CollapseRelativeParents();
VFSPath destRoot;
VFSPath destPath = path;
std::shared_ptr<VFS> vfs = root;
GetFS(path, destRoot, destPath, vfs);
if(vfs != nullptr)
return vfs->FIFOFileExists(destPath);
return false;
}
bool MountableFilesystem::DirectoryExists(VFSPath path)
{
path = path.CollapseRelativeParents();
VFSPath destRoot;
VFSPath destPath = path;
std::shared_ptr<VFS> vfs = root;
GetFS(path, destRoot, destPath, vfs);
if(destPath.path.empty()) return true;
if(vfs != nullptr)
return vfs->DirectoryExists(destPath);
return false;
}
void MountableFilesystem::DeleteFile(VFSPath path)
{
path = path.CollapseRelativeParents();
VFSPath destRoot;
VFSPath destPath = path;
std::shared_ptr<VFS> vfs = root;
GetFS(path, destRoot, destPath, vfs);
if(vfs != nullptr)
vfs->DeleteFile(destPath);
}
void MountableFilesystem::Lock(VFSPath path)
{
path = path.CollapseRelativeParents();
VFSPath destRoot;
VFSPath destPath = path;
std::shared_ptr<VFS> vfs = root;
GetFS(path, destRoot, destPath, vfs);
if(vfs != nullptr)
vfs->Lock(destPath);
}
void MountableFilesystem::Unlock(VFSPath path)
{
path = path.CollapseRelativeParents();
VFSPath destRoot;
VFSPath destPath = path;
std::shared_ptr<VFS> vfs = root;
GetFS(path, destRoot, destPath, vfs);
if(vfs != nullptr)
vfs->Unlock(destPath);
}
void MountableFilesystem::GetDate(VFSPath path, Date::DateTime& lastWrite, Date::DateTime& lastAccess)
{
path = path.CollapseRelativeParents();
VFSPath destRoot;
VFSPath destPath = path;
std::shared_ptr<VFS> vfs = root;
GetFS(path, destRoot, destPath, vfs);
if(vfs != nullptr)
vfs->GetDate(destPath,lastWrite,lastAccess);
}
void MountableFilesystem::SetDate(VFSPath path, Date::DateTime lastWrite, Date::DateTime lastAccess)
{
path = path.CollapseRelativeParents();
VFSPath destRoot;
VFSPath destPath = path;
std::shared_ptr<VFS> vfs = root;
GetFS(path, destRoot, destPath, vfs);
if(vfs != nullptr)
@@ -372,17 +267,17 @@ namespace Tesses::Framework::Filesystem
{
existingFile = existingFile.CollapseRelativeParents();
symlinkFile = existingFile.CollapseRelativeParents();
VFSPath existingDestRoot;
VFSPath existingDestPath = existingFile;
std::shared_ptr<VFS> existingVFS = root;
VFSPath symlinkDestRoot;
VFSPath symlinkDestPath = symlinkFile;
std::shared_ptr<VFS> symlinkVFS = root;
GetFS(existingFile, existingDestRoot, existingDestPath, existingVFS);
GetFS(symlinkFile, symlinkDestRoot, symlinkDestPath, symlinkVFS);
if(existingVFS != nullptr && existingVFS == symlinkVFS)
existingVFS->CreateSymlink(existingDestPath, symlinkDestPath);
}
@@ -391,17 +286,17 @@ namespace Tesses::Framework::Filesystem
{
src = src.CollapseRelativeParents();
dest = dest.CollapseRelativeParents();
VFSPath srcDestRoot;
VFSPath srcDestPath = src;
std::shared_ptr<VFS> srcVFS = root;
VFSPath destDestRoot;
VFSPath destDestPath = dest;
std::shared_ptr<VFS> destVFS = root;
GetFS(src, srcDestRoot, srcDestPath, srcVFS);
GetFS(dest, destDestRoot, destDestPath, destVFS);
if(srcVFS != nullptr && srcVFS == destVFS)
srcVFS->MoveDirectory(srcDestPath, destDestPath);
}
@@ -409,17 +304,17 @@ namespace Tesses::Framework::Filesystem
{
src = src.CollapseRelativeParents();
dest = dest.CollapseRelativeParents();
VFSPath srcDestRoot;
VFSPath srcDestPath = src;
std::shared_ptr<VFS> srcVFS = root;
VFSPath destDestRoot;
VFSPath destDestPath = dest;
std::shared_ptr<VFS> destVFS = root;
GetFS(src, srcDestRoot, srcDestPath, srcVFS);
GetFS(dest, destDestRoot, destDestPath, destVFS);
if(srcVFS != nullptr && srcVFS == destVFS)
srcVFS->MoveFile(srcDestPath, destDestPath);
}
@@ -427,17 +322,17 @@ namespace Tesses::Framework::Filesystem
{
existingFile = existingFile.CollapseRelativeParents();
newName = existingFile.CollapseRelativeParents();
VFSPath existingDestRoot;
VFSPath existingDestPath = existingFile;
std::shared_ptr<VFS> existingVFS = root;
VFSPath newNameRoot;
VFSPath newNamePath = newName;
std::shared_ptr<VFS> newNameVFS = root;
GetFS(existingFile, existingDestRoot, existingDestPath, existingVFS);
GetFS(newName, newNameRoot, newNamePath, newNameVFS);
if(existingVFS != nullptr && existingVFS == newNameVFS)
existingVFS->CreateHardlink(existingDestPath, newNamePath);
}
@@ -449,17 +344,17 @@ namespace Tesses::Framework::Filesystem
};
VFSPathEnumerator MountableFilesystem::EnumeratePaths(VFSPath path)
{
path = path.CollapseRelativeParents();
bool mydirs = path.path.empty();
std::vector<MountableDirectory*>* dirs = &this->directories;
if(!path.path.empty())
for(auto p : path.path)
{
mydirs=true;
bool hasSet=false;
for(auto itm : *dirs)
{
if(itm->name == p)
@@ -476,13 +371,13 @@ namespace Tesses::Framework::Filesystem
break;
}
}
VFSPath destRoot;
VFSPath destPath = path;
std::shared_ptr<VFS> vfs = root;
GetFS(path, destRoot, destPath, vfs);
MountableEnumerationState* state = new MountableEnumerationState();
state->dirs = *dirs;
@@ -493,11 +388,11 @@ namespace Tesses::Framework::Filesystem
state->enumerator = nullptr;
return VFSPathEnumerator([state,path](VFSPath& path0)->bool{
while(state->enumerator != nullptr && state->enumerator->MoveNext())
{
auto fname = state->enumerator->Current.GetFileName();
bool mustContinue=false;
for(auto item : state->dirs)
{
@@ -527,11 +422,11 @@ namespace Tesses::Framework::Filesystem
delete state;
});
}
void MountableFilesystem::Mount(VFSPath path, std::shared_ptr<VFS> fs)
{
path = path.CollapseRelativeParents();
if(path.path.empty())
{
return;
@@ -557,12 +452,12 @@ namespace Tesses::Framework::Filesystem
dir->name = *index;
dir->owns=false;
dir->vfs=NULL;
fsLs->push_back(dir);
fsLs = &(dir->dirs);
}
}
needToCreate=true;
std::string lastDir = path.GetFileName();
@@ -571,7 +466,7 @@ namespace Tesses::Framework::Filesystem
if(item->name == lastDir)
{
needToCreate=false;
item->vfs = fs;
break;
}
@@ -581,7 +476,7 @@ namespace Tesses::Framework::Filesystem
{
MountableDirectory* dir = new MountableDirectory();
dir->name = lastDir;
dir->vfs=fs;
fsLs->push_back(dir);
}
@@ -590,11 +485,11 @@ namespace Tesses::Framework::Filesystem
static bool myumount(MountableDirectory* dir,VFSPath path)
{
if(path.path.empty())
if(path.path.empty())
{
dir->vfs = nullptr;
}
if(dir->dirs.empty())
{
delete dir;
@@ -608,8 +503,8 @@ namespace Tesses::Framework::Filesystem
{
VFSPath srcPath2(std::vector(path.path.begin()+1,path.path.end()));
if(myumount(item,srcPath2))
{
dir->dirs.erase(index);
@@ -629,14 +524,14 @@ namespace Tesses::Framework::Filesystem
void MountableFilesystem::Unmount(VFSPath path)
{
path = path.CollapseRelativeParents();
for(auto index = this->directories.begin(); index < this->directories.end(); index++)
{
auto item = *index;
if(!path.path.empty() && path.path.front() == item->name)
{
VFSPath srcPath2(std::vector(path.path.begin()+1,path.path.end()));
if(myumount(item,srcPath2))
{
this->directories.erase(index);
@@ -654,4 +549,4 @@ namespace Tesses::Framework::Filesystem
{
return VFSPath(path);
}
}
}

View File

@@ -6,33 +6,11 @@ namespace Tesses::Framework::Filesystem
{
return nullptr;
}
void NullFilesystem::CreateDirectory(VFSPath path)
{
}
void NullFilesystem::DeleteDirectory(VFSPath path)
{
}
bool NullFilesystem::RegularFileExists(VFSPath path)
{
return false;
}
bool NullFilesystem::DirectoryExists(VFSPath path)
{
return false;
}
void NullFilesystem::DeleteFile(VFSPath path)
{
}
VFSPathEnumerator NullFilesystem::EnumeratePaths(VFSPath path)
{
return VFSPathEnumerator();
}
void NullFilesystem::MoveFile(VFSPath src, VFSPath dest)
{
}
std::string NullFilesystem::VFSPathToSystem(VFSPath path)
{
@@ -42,4 +20,9 @@ namespace Tesses::Framework::Filesystem
{
return VFSPath(path);
}
}
bool NullFilesystem::Stat(VFSPath path, StatData& data)
{
return false;
}
}

View File

@@ -13,7 +13,7 @@ namespace Tesses::Framework::Filesystem
// /a/b/c
VFSPath newPath;
newPath.relative=false;
if(path.path.size() >= this->path.path.size())
{
newPath.path.reserve(path.path.size()-this->path.path.size());
@@ -41,7 +41,7 @@ namespace Tesses::Framework::Filesystem
}
else
this->path = path;
}
std::shared_ptr<Tesses::Framework::Streams::Stream> SubdirFilesystem::OpenFile(VFSPath path, std::string mode)
{
@@ -55,34 +55,6 @@ namespace Tesses::Framework::Filesystem
{
this->parent->DeleteDirectory(ToParent(path));
}
bool SubdirFilesystem::RegularFileExists(VFSPath path)
{
return this->parent->RegularFileExists(ToParent(path));
}
bool SubdirFilesystem::SymlinkExists(VFSPath path)
{
return this->parent->SymlinkExists(ToParent(path));
}
bool SubdirFilesystem::CharacterDeviceExists(VFSPath path)
{
return this->parent->CharacterDeviceExists(ToParent(path));
}
bool SubdirFilesystem::BlockDeviceExists(VFSPath path)
{
return this->parent->BlockDeviceExists(ToParent(path));
}
bool SubdirFilesystem::SocketFileExists(VFSPath path)
{
return this->parent->SocketFileExists(ToParent(path));
}
bool SubdirFilesystem::FIFOFileExists(VFSPath path)
{
return this->parent->FIFOFileExists(ToParent(path));
}
bool SubdirFilesystem::DirectoryExists(VFSPath path)
{
return this->parent->DirectoryExists(ToParent(path));
}
void SubdirFilesystem::DeleteFile(VFSPath path)
{
this->parent->DeleteFile(ToParent(path));
@@ -116,15 +88,12 @@ namespace Tesses::Framework::Filesystem
delete enumerator;
});
}
void SubdirFilesystem::GetDate(VFSPath path, Date::DateTime& lastWrite, Date::DateTime& lastAccess)
{
this->parent->GetDate(ToParent(path),lastWrite,lastAccess);
}
void SubdirFilesystem::SetDate(VFSPath path, Date::DateTime lastWrite, Date::DateTime lastAccess)
{
this->parent->SetDate(ToParent(path),lastWrite,lastAccess);
}
void SubdirFilesystem::CreateHardlink(VFSPath existingFile, VFSPath newName)
{
this->parent->CreateHardlink(ToParent(existingFile),ToParent(newName));
@@ -142,34 +111,39 @@ namespace Tesses::Framework::Filesystem
return this->parent->VFSPathToSystem(ToParent(path));
}
VFSPath SubdirFilesystem::SystemToVFSPath(std::string path)
{
{
return FromParent(this->parent->SystemToVFSPath(path));
}
void SubdirFilesystem::DeleteDirectoryRecurse(VFSPath path)
{
this->parent->DeleteDirectoryRecurse(ToParent(path));
}
bool SubdirFilesystem::SpecialFileExists(VFSPath path)
{
return this->parent->SpecialFileExists(ToParent(path));
}
bool SubdirFilesystem::FileExists(VFSPath path)
{
return this->parent->FileExists(ToParent(path));
}
SubdirFilesystem::~SubdirFilesystem()
{
}
bool SubdirFilesystem::StatVFS(VFSPath path, StatVFSData& vfsData)
{
return this->parent->StatVFS(ToParent(path), vfsData);
}
bool SubdirFilesystem::Stat(VFSPath path, StatData& data)
{
return this->parent->Stat(ToParent(path), data);
}
void SubdirFilesystem::Chmod(VFSPath path, uint32_t mode)
{
return this->parent->Chmod(ToParent(path), mode);
}
void SubdirFilesystem::Chown(VFSPath path, uint32_t uid, uint32_t gid)
{
return this->parent->Chown(ToParent(path), uid, gid);
}
FIFOCreationResult SubdirFilesystem::CreateFIFO(VFSPath path, uint32_t mod)
{
return this->parent->CreateFIFO(path, mod);
}
}

View File

@@ -7,12 +7,12 @@ namespace Tesses::Framework::Filesystem {
Tesses::Framework::Threading::Mutex umtx;
int64_t uidx=0;
void UniqueString(std::string& text)
{
{
umtx.Lock();
text += std::to_string((int64_t)time(NULL));
text += "_";
text += std::to_string(uidx);
uidx++;
umtx.Unlock();
@@ -54,56 +54,7 @@ namespace Tesses::Framework::Filesystem {
if(this->vfs == nullptr) return;
this->vfs->DeleteDirectory(path);
}
bool TempFS::SpecialFileExists(VFSPath path)
{
if(this->vfs == nullptr) return false;
return this->vfs->SpecialFileExists(path);
}
bool TempFS::FileExists(VFSPath path)
{
if(this->vfs == nullptr) return false;
return this->vfs->FileExists(path);
}
bool TempFS::RegularFileExists(VFSPath path)
{
if(this->vfs == nullptr) return false;
return this->vfs->RegularFileExists(path);
}
bool TempFS::SymlinkExists(VFSPath path)
{
if(this->vfs == nullptr) return false;
return this->vfs->SymlinkExists(path);
}
bool TempFS::CharacterDeviceExists(VFSPath path)
{
if(this->vfs == nullptr) return false;
return this->vfs->CharacterDeviceExists(path);
}
bool TempFS::BlockDeviceExists(VFSPath path)
{
if(this->vfs == nullptr) return false;
return this->vfs->BlockDeviceExists(path);
}
bool TempFS::SocketFileExists(VFSPath path)
{
if(this->vfs == nullptr) return false;
return this->vfs->SocketFileExists(path);
}
bool TempFS::FIFOFileExists(VFSPath path)
{
if(this->vfs == nullptr) return false;
return this->vfs->FIFOFileExists(path);
}
bool TempFS::DirectoryExists(VFSPath path)
{
if(this->vfs == nullptr) return false;
return this->vfs->DirectoryExists(path);
}
void TempFS::DeleteFile(VFSPath path)
{
if(this->vfs == nullptr) return;
@@ -126,7 +77,7 @@ namespace Tesses::Framework::Filesystem {
}
VFSPathEnumerator TempFS::EnumeratePaths(VFSPath path)
{
if(this->vfs == nullptr) return VFSPathEnumerator();
return this->vfs->EnumeratePaths(path);
@@ -172,13 +123,7 @@ namespace Tesses::Framework::Filesystem {
if(this->vfs == nullptr) return VFSPath();
return this->vfs->SystemToVFSPath(path);
}
void TempFS::GetDate(VFSPath path, Date::DateTime& lastWrite, Date::DateTime& lastAccess)
{
if(this->vfs == nullptr) return;
this->vfs->GetDate(path,lastWrite,lastAccess);
}
void TempFS::SetDate(VFSPath path, Date::DateTime lastWrite, Date::DateTime lastAccess)
{
@@ -187,10 +132,16 @@ namespace Tesses::Framework::Filesystem {
}
bool TempFS::StatVFS(VFSPath path, StatVFSData& vfsData)
{
if(this->vfs == nullptr) return false;
return this->vfs->StatVFS(path, vfsData);
}
bool TempFS::Stat(VFSPath path, StatData& data)
{
if(this->vfs == nullptr) return false;
return this->vfs->Stat(path, data);
}
void TempFS::Chmod(VFSPath path, uint32_t mode)
{
@@ -198,6 +149,17 @@ namespace Tesses::Framework::Filesystem {
if(this->vfs == nullptr) return;
this->vfs->Chmod(path,mode);
}
void TempFS::Chown(VFSPath path, uint32_t uid, uint32_t gid)
{
if(this->vfs == nullptr) return;
this->vfs->Chown(path,uid, gid);
}
FIFOCreationResult TempFS::CreateFIFO(VFSPath path, uint32_t mod)
{
if(this->vfs == nullptr) return FIFOCreationResult::UnknownError;
return this->vfs->CreateFIFO(path, mod);
}
void TempFS::Close()
{
@@ -218,5 +180,5 @@ namespace Tesses::Framework::Filesystem {
this->parent->DeleteDirectoryRecurse(p);
}
}
}

View File

@@ -1,6 +1,7 @@
#include "TessesFramework/Filesystem/VFS.hpp"
#include "TessesFramework/Http/HttpUtils.hpp"
#include "TessesFramework/Filesystem/LocalFS.hpp"
#include <TessesFramework/Filesystem/FSHelpers.hpp>
namespace Tesses::Framework::Filesystem
{
VFSPathEnumeratorItterator::VFSPathEnumeratorItterator()
@@ -21,12 +22,12 @@ namespace Tesses::Framework::Filesystem
enumerator->MoveNext();
return *this;
}
VFSPath& VFSPathEnumeratorItterator::operator*()
{
std::filesystem::directory_iterator i;
if(enumerator != nullptr)
return enumerator->Current;
return this->e;
@@ -46,7 +47,7 @@ namespace Tesses::Framework::Filesystem
if(right.enumerator == nullptr)
{
auto r = !enumerator->IsDone();
return r;
}
return true;
@@ -88,7 +89,7 @@ namespace Tesses::Framework::Filesystem
}
bool VFSPathEnumerator::IsDone()
{
if(this->data)
{
return data->eof;
@@ -132,7 +133,7 @@ namespace Tesses::Framework::Filesystem
{
mid.append(p.path.back());
}
if(!p2.path.empty())
{
mid.append(p2.path.front());
@@ -169,7 +170,7 @@ namespace Tesses::Framework::Filesystem
for(size_t i = 0; i < p.path.size(); i++)
if(p.path[i] != p2.path[i]) return true;
return false;
}
bool operator==(std::string p,VFSPath p2)
{
@@ -216,13 +217,98 @@ namespace Tesses::Framework::Filesystem
{
return MakeRelative(GetAbsoluteCurrentDirectory());
}
FIFOCreationResult VFS::CreateFIFO(VFSPath path, uint32_t mode)
{
return FIFOCreationResult::Unsupported;
}
bool VFS::DirectoryExists(VFSPath path)
{
StatData data;
if(this->Stat(path, data))
{
return data.IsDirectory();
}
return false;
}
bool VFS::RegularFileExists(VFSPath path)
{
StatData data;
if(this->Stat(path, data))
{
return data.IsRegularFile();
}
return false;
}
bool VFS::SymlinkExists(VFSPath path)
{
StatData data;
if(this->Stat(path, data))
{
return data.IsSymlink();
}
return false;
}
bool VFS::CharacterDeviceExists(VFSPath path)
{
StatData data;
if(this->Stat(path, data))
{
return data.IsCharDevice();
}
return false;
}
bool VFS::BlockDeviceExists(VFSPath path)
{
StatData data;
if(this->Stat(path, data))
{
return data.IsBlockDevice();
}
return false;
}
bool VFS::SocketFileExists(VFSPath path)
{
StatData data;
if(this->Stat(path, data))
{
return data.IsSocket();
}
return false;
}
bool VFS::FIFOFileExists(VFSPath path)
{
StatData data;
if(this->Stat(path, data))
{
return data.IsFIFO();
}
return false;
}
bool VFS::FileExists(VFSPath path)
{
StatData data;
if(this->Stat(path, data))
{
return !data.IsDirectory();
}
return false;
}
bool VFS::SpecialFileExists(VFSPath path)
{
StatData data;
if(this->Stat(path, data))
{
return data.IsSpecial();
}
return false;
}
VFSPath VFSPath::MakeRelative(VFSPath toMakeRelativeTo) const
{
if(this->relative) return *this;
size_t i;
size_t len = std::min(toMakeRelativeTo.path.size(),this->path.size());
for(i = 0; i < len; i++)
@@ -239,7 +325,7 @@ namespace Tesses::Framework::Filesystem
}
std::vector<std::string> parts(this->path.begin()+i, this->path.end());
if(i < toMakeRelativeTo.path.size())
{
for(; i < toMakeRelativeTo.path.size();i++)
@@ -264,7 +350,7 @@ namespace Tesses::Framework::Filesystem
parts.erase(parts.end()-1);
}
}
else if(item == ".")
else if(item == ".")
{
//do nothing but don't emit this
}
@@ -284,7 +370,7 @@ namespace Tesses::Framework::Filesystem
path.relative=true;
return path;
}
std::vector<std::string> VFSPath::SplitPath(std::string path)
{
std::vector<std::string> parts;
@@ -386,7 +472,7 @@ namespace Tesses::Framework::Filesystem
str = str.substr(0,index);
}
if(ext.empty()) return;
if(ext[0] != '.')
if(ext[0] != '.')
{
str += '.';
str += ext;
@@ -400,7 +486,7 @@ namespace Tesses::Framework::Filesystem
{
ChangeExtension({});
}
VFSPath::VFSPath(std::string str)
{
this->path = SplitPath(str);
@@ -418,13 +504,21 @@ namespace Tesses::Framework::Filesystem
if(!firstPartPath.empty() && firstPartPath.back() == ':') this->relative=false;
}
}
}
void VFS::CreateDirectory(VFSPath path)
{
}
void VFS::DeleteDirectory(VFSPath path)
{
}
VFSPath::VFSPath(VFSPath p1, VFSPath p2)
{
this->relative = p1.relative;
this->path.insert(this->path.end(),p1.path.begin(),p1.path.end());
this->path.insert(this->path.end(),p2.path.begin(),p2.path.end());
}
}
VFSPath::VFSPath(VFSPath p1, std::string subpath) : VFSPath(p1, VFSPath(subpath))
{
@@ -462,20 +556,30 @@ namespace Tesses::Framework::Filesystem
}
return p;
}
void VFS::DeleteFile(VFSPath path)
{
}
void VFS::MoveFile(VFSPath src, VFSPath dest)
{
{
auto srcStrm = this->OpenFile(src, "rb");
if(!srcStrm->CanRead()) return;
auto destStrm = this->OpenFile(dest, "wb");
if(!destStrm->CanWrite()) return;
srcStrm->CopyTo(destStrm);
}
VFS::DeleteFile(src);
}
VFS::~VFS()
{
}
bool VFS::FIFOFileExists(VFSPath path) {return false;}
bool VFS::SocketFileExists(VFSPath path) {return false;}
bool VFS::CharacterDeviceExists(VFSPath path) {return false;}
bool VFS::BlockDeviceExists(VFSPath path) {return false;}
bool VFS::SymlinkExists(VFSPath path) {return false;}
void VFS::MoveDirectory(VFSPath src, VFSPath dest)
{
for(auto item : EnumeratePaths(src))
{
if(DirectoryExists(item))
@@ -488,7 +592,7 @@ namespace Tesses::Framework::Filesystem
}
}
DeleteDirectory(src);
DeleteDirectory(src);
}
void VFS::CreateSymlink(VFSPath existingFile, VFSPath symlinkFile)
{
@@ -496,22 +600,14 @@ namespace Tesses::Framework::Filesystem
}
void VFS::CreateHardlink(VFSPath existingFile, VFSPath newName)
{
}
bool VFS::SpecialFileExists(VFSPath path)
{
return SymlinkExists(path) || BlockDeviceExists(path) || CharacterDeviceExists(path) || SocketFileExists(path) || FIFOFileExists(path);
}
bool VFS::FileExists(VFSPath path)
{
return RegularFileExists(path) || SpecialFileExists(path);
}
void VFS::DeleteDirectoryRecurse(VFSPath path)
{
if(!DirectoryExists(path)) return;
for(auto item : EnumeratePaths(path))
{
if(DirectoryExists(item))
@@ -527,7 +623,12 @@ namespace Tesses::Framework::Filesystem
}
void VFS::GetDate(VFSPath path, Date::DateTime& lastWrite, Date::DateTime& lastAccess)
{
StatData data;
if(Stat(path, data))
{
lastWrite = data.LastModified;
lastAccess = data.LastAccess;
}
}
void VFS::SetDate(VFSPath path, Date::DateTime lastWrite, Date::DateTime lastAccess)
{
@@ -550,9 +651,12 @@ namespace Tesses::Framework::Filesystem
}
void VFS::Chmod(VFSPath path, uint32_t mode) {
}
void VFS::Chown(VFSPath path, uint32_t uid, uint32_t gid) {
}
void VFS::Close() {
}
void VFS::Lock(VFSPath path)
{
@@ -560,7 +664,7 @@ namespace Tesses::Framework::Filesystem
}
void VFS::Unlock(VFSPath path)
{
}
@@ -599,7 +703,7 @@ namespace Tesses::Framework::Filesystem
{
}
std::shared_ptr<FSWatcher> FSWatcher::Create(std::shared_ptr<VFS> vfs, VFSPath path)
{
return vfs->CreateWatcher(vfs,path);
@@ -671,4 +775,4 @@ namespace Tesses::Framework::Filesystem
return "";
}
}
}

View File

@@ -24,7 +24,7 @@ namespace Tesses::Framework::Http
}
FileServer::FileServer(std::shared_ptr<Tesses::Framework::Filesystem::VFS> fs, bool allowListing,bool spa) : FileServer(fs,allowListing,spa,{"index.html","default.html","index.htm","default.htm"})
{
}
FileServer::FileServer(std::shared_ptr<Tesses::Framework::Filesystem::VFS> fs, bool allowListing, bool spa, std::vector<std::string> defaultNames)
{
@@ -44,7 +44,7 @@ namespace Tesses::Framework::Http
this->vfs->GetDate(path,lw,la);
ctx.WithLastModified(lw).WithMimeType(HttpUtils::MimeType(path.GetFileName())).SendStream(strm);
retVal = true;
}
return retVal;
}
@@ -52,8 +52,8 @@ namespace Tesses::Framework::Http
bool FileServer::Handle(ServerContext& ctx)
{
auto path = ((VFSPath)HttpUtils::UrlPathDecode(ctx.path)).CollapseRelativeParents();
if(this->vfs->DirectoryExists(path))
{
TF_LOG("Directory exists");
@@ -73,10 +73,10 @@ namespace Tesses::Framework::Http
std::string p = HttpUtils::HtmlEncode(ctx.originalPath);
std::string html = "<!DOCTYPE html><html><head><meta charset=\"UTF-8\"><title>Index of ";
html.append(p);
html.append("</title></head><body><h1>Index of ");
html.append("</title><meta name=\"color-scheme\" content=\"dark light\"></head><body><h1>Index of ");
html.append(p);
html.append("</h1><hr><pre><a href=\"../\">../</a>\r\n");
for(auto item : vfs->EnumeratePaths(path))
{
@@ -103,7 +103,7 @@ namespace Tesses::Framework::Http
}
html.append("</pre><hr></body></html>");
ctx.WithMimeType("text/html").SendText(html);
return true;
}
@@ -126,6 +126,6 @@ namespace Tesses::Framework::Http
}
FileServer::~FileServer()
{
}
}
}

View File

@@ -13,6 +13,7 @@
#include "TessesFramework/Filesystem/VFSFix.hpp"
#include "TessesFramework/Filesystem/VFS.hpp"
#include <TessesFramework/Http/HttpUtils.hpp>
#include <iostream>
using FileStream = Tesses::Framework::Streams::FileStream;
using Stream = Tesses::Framework::Streams::Stream;
@@ -26,7 +27,7 @@ using namespace Tesses::Framework::TextStreams;
namespace Tesses::Framework::Http
{
class WSServer
class WSServer
{
public:
Threading::Mutex mtx;
@@ -43,9 +44,9 @@ namespace Tesses::Framework::Http
uint8_t firstByte= finField | 0x8;
strm->WriteByte(firstByte);
strm->WriteByte(0);
this->strm = nullptr;
mtx.Unlock();
mtx.Unlock();
this->conn->OnClose(true);
}
void write_len_bytes(uint64_t len)
@@ -84,7 +85,7 @@ namespace Tesses::Framework::Http
{
uint8_t buff[8];
if(strm->ReadBlock(buff,sizeof(buff)) != sizeof(buff)) return 0;
uint64_t v = 0;
v |= (uint64_t)buff[0] << 56;
v |= (uint64_t)buff[1] << 48;
@@ -100,7 +101,7 @@ namespace Tesses::Framework::Http
{
uint8_t buff[2];
if(strm->ReadBlock(buff,sizeof(buff)) != sizeof(buff)) return 0;
uint16_t v = 0;
v |= (uint16_t)buff[0] << 8;
v |= (uint16_t)buff[1];
@@ -110,7 +111,7 @@ namespace Tesses::Framework::Http
{
while(!hasInit);
mtx.Lock();
uint8_t opcode = msg->isBinary ? 0x2 : 0x1;
size_t lengthLastByte = msg->data.size() % 4096;
@@ -123,21 +124,21 @@ namespace Tesses::Framework::Http
uint8_t finField = fin ? 0b10000000 : 0;
uint8_t opcode2 = i == 0 ? opcode : 0;
uint8_t firstByte = finField | (opcode2 & 0xF);
size_t len = std::min((size_t)4096,msg->data.size()- offset);
strm->WriteByte(firstByte);
write_len_bytes((uint64_t)len);
strm->WriteBlock(msg->data.data() + offset,len);
offset += len;
}
}
mtx.Unlock();
}
void ping_send(std::vector<uint8_t>& pData)
{
mtx.Lock();
uint8_t finField = 0b10000000 ;
uint8_t firstByte= finField | 0x9;
strm->WriteByte(firstByte);
@@ -148,7 +149,7 @@ namespace Tesses::Framework::Http
void pong_send(std::vector<uint8_t>& pData)
{
mtx.Lock();
uint8_t finField = 0b10000000 ;
uint8_t firstByte= finField | 0xA;
strm->WriteByte(firstByte);
@@ -158,7 +159,7 @@ namespace Tesses::Framework::Http
}
bool read_packet(uint8_t len,std::vector<uint8_t>& data)
{
uint8_t realLen=len & 127;
bool masked=(len & 0b10000000) > 0;
uint64_t reallen2 = realLen >= 126 ? realLen > 126 ? get_long() : get_short() : realLen;
@@ -180,7 +181,7 @@ namespace Tesses::Framework::Http
}
return true;
}
WSServer(ServerContext* ctx,std::shared_ptr<WebSocketConnection> conn)
{
this->ctx = ctx;
@@ -188,7 +189,7 @@ namespace Tesses::Framework::Http
this->strm = this->ctx->GetStream();
this->hasInit=false;
}
void Start()
{
@@ -198,7 +199,7 @@ namespace Tesses::Framework::Http
{
key.append("258EAFA5-E914-47DA-95CA-C5AB0DC85B11");
auto res = Crypto::Sha1::ComputeHash((const uint8_t*)key.c_str(),key.size());
if(res.empty()) return;
key = Crypto::Base64_Encode(res);
@@ -206,7 +207,7 @@ namespace Tesses::Framework::Http
return;
}
if(!ctx->requestHeaders.AnyEquals("Upgrade","websocket"))
{
@@ -221,7 +222,7 @@ namespace Tesses::Framework::Http
ctx->responseHeaders.SetValue("Connection","Upgrade");
ctx->responseHeaders.SetValue("Upgrade","websocket");
ctx->responseHeaders.SetValue("Sec-WebSocket-Accept",key);
ctx->WriteHeaders();
bool hasMessage =false;
@@ -232,11 +233,11 @@ namespace Tesses::Framework::Http
while( !strm->EndOfStream())
{
uint8_t frame_start[2];
if( strm->ReadBlock(frame_start,2) != 2) return;
uint8_t opcode = frame_start[0] & 0xF;
bool fin = (frame_start[0] & 0b10000000) > 0;
switch(opcode)
@@ -250,7 +251,7 @@ namespace Tesses::Framework::Http
hasMessage=true;
message.data = {};
message.isBinary = opcode == 0x2;
read_packet(frame_start[1], message.data);
break;
case 0x8:
@@ -280,7 +281,7 @@ namespace Tesses::Framework::Http
}
this->conn->OnClose(false);
}
};
};
/*
static int _header_field(multipart_parser* p, const char *at, size_t length)
{
@@ -362,7 +363,7 @@ namespace Tesses::Framework::Http
strm2->CopyTo(strm);
}
}
std::string ServerContext::ReadString()
{
if(strm == nullptr) return {};
@@ -390,7 +391,7 @@ namespace Tesses::Framework::Http
{
bool hasMore=true;
uint8_t* checkBuffer = new uint8_t[boundary.size()];
int b;
size_t i = 0;
size_t i2 = 0;
@@ -429,21 +430,21 @@ namespace Tesses::Framework::Http
{
dest->Write(buffer, sizeof(buffer));
offsetInMem=0;
}
buffer[offsetInMem++] = checkBuffer[idx];
idx++;
}
i = 0;
if(offsetInMem >= sizeof(buffer))
{
dest->Write(buffer, sizeof(buffer));
offsetInMem=0;
}
buffer[offsetInMem++] = (uint8_t)b;
@@ -455,7 +456,7 @@ namespace Tesses::Framework::Http
dest->Write(buffer,offsetInMem);
}
delete[] checkBuffer;
return hasMore;
}
@@ -466,7 +467,7 @@ namespace Tesses::Framework::Http
std::string line;
while(reader.ReadLineHttp(line))
{
auto v = HttpUtils::SplitString(line,": ", 2);
auto v = HttpUtils::SplitString(line,": ", 2);
if(v.size() == 2)
req.AddValue(v[0],v[1]);
line.clear();
@@ -475,7 +476,7 @@ namespace Tesses::Framework::Http
std::string cd0;
ContentDisposition cd1;
std::string ct;
if(!req.TryGetFirst("Content-Type",ct))
ct = "application/octet-stream";
if(req.TryGetFirst("Content-Disposition", cd0) && ContentDisposition::TryParse(cd0,cd1))
@@ -494,10 +495,10 @@ namespace Tesses::Framework::Http
}
else
{
auto strm = cb(ct, cd1.filename, cd1.fieldName);
auto strm = cb(ct, cd1.filename, cd1.fieldName);
if(strm == nullptr) strm = std::make_shared<Stream>();
bool retVal = parseUntillBoundaryEnd(ctx->GetStream(),strm,boundary);
return retVal;
}
}
@@ -521,9 +522,9 @@ namespace Tesses::Framework::Http
parseUntillBoundaryEnd(this->strm,nullStrm, ct);
while(parseSection(this, ct, cb));
}
}
HttpServer::HttpServer(std::shared_ptr<Tesses::Framework::Streams::TcpServer> tcpServer, std::shared_ptr<IHttpServer> http, bool showIPs)
HttpServer::HttpServer(std::shared_ptr<Tesses::Framework::Streams::TcpServer> tcpServer, std::shared_ptr<IHttpServer> http, bool showIPs, bool debug)
{
this->server = tcpServer;
this->http = http;
@@ -531,19 +532,20 @@ namespace Tesses::Framework::Http
this->showIPs = showIPs;
this->thrd=nullptr;
this->showARTL = showIPs;
this->debug = debug;
}
HttpServer::HttpServer(uint16_t port, std::shared_ptr<IHttpServer> http, bool showIPs) : HttpServer(std::make_shared<TcpServer>(port,10),http,showIPs)
HttpServer::HttpServer(uint16_t port, std::shared_ptr<IHttpServer> http, bool showIPs, bool debug) : HttpServer(std::make_shared<TcpServer>(port,10),http,showIPs, debug)
{
}
HttpServer::HttpServer(std::string unixPath, std::shared_ptr<IHttpServer> http) : HttpServer(std::make_shared<TcpServer>(unixPath,10),http,false)
HttpServer::HttpServer(std::string unixPath, std::shared_ptr<IHttpServer> http, bool debug) : HttpServer(std::make_shared<TcpServer>(unixPath,10),http,false, debug)
{
this->showARTL=true;
}
uint16_t HttpServer::GetPort()
{
@@ -557,7 +559,7 @@ namespace Tesses::Framework::Http
int64_t length = -1;
if(!this->responseHeaders.TryGetFirstInt("Content-Length",length))
length = -1;
if(this->version == "HTTP/1.1" && length == -1)
this->responseHeaders.SetValue("Transfer-Encoding","chunked");
@@ -584,27 +586,29 @@ namespace Tesses::Framework::Http
auto serverPort = this->server->GetPort();
auto http = this->http;
TF_LOG("Before Creating Thread");
thrd = new Threading::Thread([svr,http,serverPort]()->void {
bool debug = this->debug;
thrd = new Threading::Thread([svr,http,serverPort,debug]()->void {
while(TF_IsRunning())
{
TF_LOG("after TF_IsRunning");
std::string ip;
uint16_t port;
auto sock =svr->GetStream(ip,port);
TF_LOG("New Host IP: " + ip + ":" + std::to_string(port));
if(sock == nullptr)
if(sock == nullptr)
{
std::cout << "STREAM ERROR" << std::endl;
return;
}
TF_LOG("Before entering socket thread");
Threading::Thread thrd2([sock,http,ip,port,serverPort]()->void {
Threading::Thread thrd2([sock,http,ip,port,serverPort,debug]()->void {
TF_LOG("In thread to process");
HttpServer::Process(sock,http,ip,port,serverPort,false);
HttpServer::Process(sock,http,ip,port,serverPort,false, debug);
TF_LOG("In thread after process");
});
TF_LOG("Before attach");
thrd2.Detach();
@@ -614,7 +618,7 @@ namespace Tesses::Framework::Http
if(this->showIPs)
{
TF_LOG("Before printing interfaces");
StdOut() << "\x1B[34mInterfaces:" << NewLine();
for(auto _ip : NetworkStream::GetIPs())
{
@@ -623,15 +627,15 @@ namespace Tesses::Framework::Http
<< "\x1B[35mhttp://"
<< _ip.second << ":" << (uint64_t)this->GetPort() << "/" << NewLine();
}
}
if(this->showARTL)
{
if(!svr->IsValid()) std::cout << "\x1B[31mError, we failed to bind or something\x1B[39m\n" << std::endl;
StdOut() << "\x1B[31mAlmost Ready to Listen\x1B[39m" << NewLine();
}
TF_LOG("After printing interfaces");
}
HttpServer::~HttpServer()
@@ -644,18 +648,20 @@ namespace Tesses::Framework::Http
this->thrd->Join();
delete this->thrd;
}
}
IHttpServer::~IHttpServer()
{
}
ServerContext::ServerContext(std::shared_ptr<Stream> strm)
ServerContext::ServerContext(std::shared_ptr<Stream> strm, bool debug)
{
this->statusCode = OK;
this->strm = strm;
this->debug = debug;
this->sent = false;
this->queryParams.SetCaseSensitive(true);
this->pathArguments.SetCaseSensitive(true);
this->responseHeaders.AddValue("Server","TessesFrameworkWebServer");
}
std::shared_ptr<Stream> ServerContext::GetStream()
@@ -677,7 +683,7 @@ namespace Tesses::Framework::Http
void ServerContext::SendText(std::string text)
{
std::shared_ptr<MemoryStream> strm=std::make_shared<MemoryStream>(false);
auto& buff= strm->GetBuffer();
buff.insert(buff.end(),text.begin(),text.end());
SendStream(strm);
@@ -685,11 +691,13 @@ namespace Tesses::Framework::Http
void ServerContext::SendErrorPage(bool showPath)
{
if(sent) return;
std::string errorHtml = showPath ? ("<html><head><title>File " + HttpUtils::HtmlEncode(this->originalPath) + " " + HttpUtils::StatusCodeString(this->statusCode) + "</title></head><body><h1>" + std::to_string((int)this->statusCode) + " " + HttpUtils::StatusCodeString(this->statusCode) + "</h1><h4>" + HttpUtils::HtmlEncode(this->originalPath) + "</h4></body></html>") : "";
std::string errorHtml = showPath ? ("<html><head><title>File " + HttpUtils::HtmlEncode(this->originalPath) + " " + HttpUtils::StatusCodeString(this->statusCode) + "</title><meta name=\"color-scheme\" content=\"dark light\"></head><body><h1>" + std::to_string((int)this->statusCode) + " " + HttpUtils::StatusCodeString(this->statusCode) + "</h1><h4>" + HttpUtils::HtmlEncode(this->originalPath) + "</h4></body></html>") : (
"<html><head><title>" + std::to_string(this->statusCode) + " " + HttpUtils::StatusCodeString(this->statusCode) + "</title><meta name=\"color-scheme\" content=\"dark light\"></head><body><h1>" + std::to_string((int)this->statusCode) + " " + HttpUtils::StatusCodeString(this->statusCode) + "</h1></body></html>"
);
WithMimeType("text/html").SendText(errorHtml);
}
ServerContext::~ServerContext()
{
for(auto item : this->data)
@@ -699,7 +707,7 @@ namespace Tesses::Framework::Http
}
ServerContextData::~ServerContextData()
{
}
void ServerContext::SendStream(std::shared_ptr<Stream> strm)
{
@@ -722,7 +730,7 @@ namespace Tesses::Framework::Http
return;
}
res = HttpUtils::SplitString(res[1],", ",2);
if(res.size() != 1)
if(res.size() != 1)
{
this->statusCode = BadRequest;
this->WriteHeaders();
@@ -764,7 +772,7 @@ namespace Tesses::Framework::Http
if(end == -1)
{
end = len-1;
end = len-1;
}
if(end > len-1)
@@ -796,7 +804,7 @@ namespace Tesses::Framework::Http
uint8_t buffer[1024];
size_t read=0;
do {
read = sizeof(buffer);
myLen = (end - begin)+1;
@@ -809,7 +817,7 @@ namespace Tesses::Framework::Http
begin += read;
} while(read > 0 && !this->strm->EndOfStream());
}
}
else
{
@@ -833,19 +841,19 @@ namespace Tesses::Framework::Http
}
else
{
auto chunkedStream = this->OpenResponseStream();
if(method != "HEAD")
strm->CopyTo(chunkedStream);
}
}
ServerContext& ServerContext::WithHeader(std::string key, std::string value)
{
this->responseHeaders.AddValue(key, value);
return *this;
return *this;
}
ServerContext& ServerContext::WithSingleHeader(std::string key, std::string value)
{
@@ -900,24 +908,40 @@ namespace Tesses::Framework::Http
statusCode = StatusCode::BadRequest;
SendErrorPage(false);
}
ServerContext& ServerContext::WithStatusCode(StatusCode code)
{
this->statusCode = code;
return *this;
}
void ServerContext::SendException(std::exception& ex)
{
/*<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Internal Server Error at /</title>
</head>
<body>
<h1>Internal Server Error at /</h1>
<p>what(): std::exception</p>
</body>
</html>*/
this->WithMimeType("text/html").SendText("<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"UTF-8\"> <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"><title>Internal Server Error at " + HttpUtils::HtmlEncode(this->originalPath) + "</title></head><body><h1>Internal Server Error at " + HttpUtils::HtmlEncode(this->originalPath) + "</h1><p>what(): " + HttpUtils::HtmlEncode(ex.what()) + "</p></body></html>");
if(this->debug)
{
this->WithMimeType("text/html").WithStatusCode(StatusCode::InternalServerError).SendText("<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"UTF-8\"> <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"><title>Internal Server Error at " + HttpUtils::HtmlEncode(this->originalPath) + "</title><meta name=\"color-scheme\" content=\"dark light\"></head><body><h1>Internal Server Error at " + HttpUtils::HtmlEncode(this->originalPath) + "</h1><p>what(): " + HttpUtils::HtmlEncode(ex.what()) + "</p></body></html>");
}
else {
this->WithStatusCode(StatusCode::InternalServerError).SendErrorPage(true);
}
}
ServerContext& ServerContext::WithHeaderIntercepter(std::function<bool(ServerContext&)> cb)
{
this->headerhandlers.push(cb);
return *this;
}
ServerContext& ServerContext::WriteHeaders()
{
if(this->sent) return *this;
while(!this->headerhandlers.empty())
{
auto header = this->headerhandlers.front();
this->headerhandlers.pop();
if(header(*this)) {
break;
}
}
if(this->sent) return *this;
this->sent = true;
@@ -933,22 +957,20 @@ namespace Tesses::Framework::Http
}
}
writer.WriteLine();
return *this;
}
void HttpServer::Process(std::shared_ptr<Stream> strm, std::shared_ptr<IHttpServer> server, std::string ip, uint16_t port,uint16_t serverPort, bool encrypted)
void HttpServer::Process(std::shared_ptr<Stream> strm, std::shared_ptr<IHttpServer> server, std::string ip, uint16_t port,uint16_t serverPort, bool encrypted, bool debug)
{
TF_LOG("In process");
while(true)
{
std::shared_ptr<BufferedStream> bStrm = std::make_shared<BufferedStream>(strm);
StreamReader reader(bStrm);
ServerContext ctx(bStrm);
ctx.ip = ip;
ctx.port = port;
ctx.encrypted = encrypted;
ctx.serverPort = serverPort;
try{
std::shared_ptr<BufferedStream> bStrm = std::make_shared<BufferedStream>(strm);
StreamReader reader(bStrm);
ServerContext ctx(bStrm);
ctx.ip = ip;
ctx.port = port;
ctx.encrypted = encrypted;
ctx.serverPort = serverPort;
try{
bool firstLine = true;
std::string line;
while(reader.ReadLineHttp(line))
@@ -987,9 +1009,9 @@ namespace Tesses::Framework::Http
ctx.WithMimeType("text/plain").SendText("Header line is not 2 elements");
return;
}
ctx.requestHeaders.AddValue(v[0],v[1]);
}
line.clear();
firstLine=false;
@@ -1009,12 +1031,15 @@ namespace Tesses::Framework::Http
delete[] buffer;
HttpUtils::QueryParamsDecode(ctx.queryParams, query);
}
if(!server->Handle(ctx))
if(!server->Handle(ctx))
{
ctx.SendNotFound();
if((int)ctx.statusCode < 400)
ctx.SendNotFound();
else
ctx.SendErrorPage(true);
}
}
}
catch(std::exception& ex)
{
@@ -1033,26 +1058,23 @@ namespace Tesses::Framework::Http
catch(...)
{
std::runtime_error ex("An unknown error occurred");
ctx.SendException(ex);
ctx.SendException(ex);
}
if(ctx.version != "HTTP/1.1" ) return;
std::string connection;
if(ctx.requestHeaders.TryGetFirst("Connection", connection))
{
if(HttpUtils::ToLower(connection) != "keep-alive") return;
}
if(ctx.responseHeaders.TryGetFirst("Connection", connection))
{
if(HttpUtils::ToLower(connection) != "keep-alive") return;
}
if(bStrm->EndOfStream()) {
return;
}
}
}
bool ServerContext::Debug()
{
return this->debug;
}
ServerContext& ServerContext::WithDebug(bool debug)
{
this->debug = debug;
return *this;
}
WebSocketConnection::~WebSocketConnection()
@@ -1064,7 +1086,7 @@ namespace Tesses::Framework::Http
std::shared_ptr<CallbackWebSocketConnection> wsc = std::make_shared<CallbackWebSocketConnection>(onOpen,onReceive,onClose);
StartWebSocketSession(wsc);
}
void ServerContext::StartWebSocketSession(std::shared_ptr<WebSocketConnection> connection)
{
WSServer svr(this,connection);
@@ -1080,7 +1102,7 @@ namespace Tesses::Framework::Http
}
});
svr.Start();
thrd.Join();
}
@@ -1105,4 +1127,3 @@ namespace Tesses::Framework::Http
}

View File

@@ -6,11 +6,15 @@
#include "TessesFramework/Filesystem/FSHelpers.hpp"
#include "TessesFramework/Serialization/Json.hpp"
#include <atomic>
#include <chrono>
#include <csignal>
#include <functional>
#include <iostream>
#include <memory>
#include <queue>
#include <ratio>
#if defined(TESSESFRAMEWORK_ENABLE_SQLITE)
#if defined(TESSESFRAMEWORK_ENABLE_SQLITE)
extern "C" {
#include "Serialization/sqlite/sqlite3.h"
}
@@ -52,8 +56,6 @@ static GXRModeObj *rmode = NULL;
namespace Tesses::Framework
{
EventList<uint64_t> OnItteraton;
#if defined(TESSESFRAMEWORK_ENABLE_THREADING) && (defined(GEKKO) || defined(__SWITCH__))
namespace Threading
{
@@ -64,13 +66,14 @@ namespace Tesses::Framework
volatile static bool isRunningSig=true;
volatile static std::atomic<bool> isRunning;
volatile static std::atomic<bool> gaming_console_events=true;
#if defined(TESSESFRAMEWORK_ENABLE_THREADING)
Threading::Mutex timers_mtx;
Threading::Mutex invokings_mtx;
std::queue<std::function<void()>> invokings;
#endif
void TF_Invoke(std::function<void()> cb)
{
@@ -86,7 +89,7 @@ namespace Tesses::Framework
void TF_ConnectToSelf(uint16_t port)
{
Tesses::Framework::Streams::NetworkStream ns("127.0.0.1",port,false,false,false);
}
bool TF_IsRunning()
{
@@ -106,16 +109,142 @@ namespace Tesses::Framework
}
#if defined(__SWITCH__)
bool initedConsole=false;
PadState default_pad;
PadState default_pad;
#endif
uint64_t ittr=0;
static std::shared_ptr<TF_Timer_Handler> timer_handler = std::make_shared<TF_Timer_Handler>();
std::shared_ptr<TF_Timer_Handle> TF_Timer_Handler::Make(std::shared_ptr<TF_Timer_Handler> handler)
{
auto timer = new TF_Timer_Handle(handler);
std::shared_ptr<TF_Timer_Handle> handle(timer);
#if defined(TESSESFRAMEWORK_ENABLE_THREADING)
timers_mtx.Lock();
#endif
handler->handles.push_back(handle);
#if defined(TESSESFRAMEWORK_ENABLE_THREADING)
timers_mtx.Unlock();
#endif
return handle;
}
std::shared_ptr<TF_Timer_Handle> TF_Timer()
{
return TF_Timer_Handler::Make(timer_handler);
}
std::shared_ptr<TF_Timer_Handle> TF_Timer(std::function<void()> cb, int64_t interval, bool enabled)
{
auto handle = TF_Timer();
handle->SetCallback(cb);
handle->SetIntervalFromMilliseconds(interval);
handle->SetEnabled(enabled);
return handle;
}
std::shared_ptr<TF_Timer_Handle> TF_Timer(std::function<void()> cb, std::chrono::duration<int64_t,std::milli> interval, bool enabled)
{
auto handle = TF_Timer();
handle->SetCallback(cb);
handle->SetIntervalFromDuration(interval);
handle->SetEnabled(enabled);
return handle;
}
void TF_Timer_Handler::Update()
{
std::chrono::time_point<std::chrono::steady_clock,std::chrono::milliseconds> cur = std::chrono::time_point_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now());
std::vector<std::function<void()>> cbs;
#if defined(TESSESFRAMEWORK_ENABLE_THREADING)
timers_mtx.Lock();
#endif
for(auto index = this->handles.begin(); index != this->handles.end(); index++)
{
if(index->expired())
{
this->handles.erase(index);
index--;
}
else {
auto handle = index->lock();
if(handle && handle->enabled && (handle->last + handle->interval) <= cur && handle->cb)
{
handle->last = cur;
cbs.push_back(handle->cb);
}
}
}
#if defined(TESSESFRAMEWORK_ENABLE_THREADING)
timers_mtx.Unlock();
#endif
for(auto item : cbs)
{
item();
}
}
void TF_Timer_Handle::SetCallback(std::function<void()> cb)
{
#if defined(TESSESFRAMEWORK_ENABLE_THREADING)
timers_mtx.Lock();
#endif
this->cb = cb;
#if defined(TESSESFRAMEWORK_ENABLE_THREADING)
timers_mtx.Unlock();
#endif
}
TF_Timer_Handle::TF_Timer_Handle(std::shared_ptr<TF_Timer_Handler> handler) : timerHandler(handler)
{
}
void TF_Timer_Handle::SetEnabled(bool enabled)
{
#if defined(TESSESFRAMEWORK_ENABLE_THREADING)
timers_mtx.Lock();
#endif
this->enabled = enabled;
#if defined(TESSESFRAMEWORK_ENABLE_THREADING)
timers_mtx.Unlock();
#endif
}
bool TF_Timer_Handle::GetEnabled()
{
return this->enabled;
}
void TF_Timer_Handle::SetIntervalFromDuration(std::chrono::milliseconds ms)
{
#if defined(TESSESFRAMEWORK_ENABLE_THREADING)
timers_mtx.Lock();
#endif
this->interval = ms;
#if defined(TESSESFRAMEWORK_ENABLE_THREADING)
timers_mtx.Unlock();
#endif
}
void TF_Timer_Handle::SetIntervalFromMilliseconds(int64_t ms)
{
SetIntervalFromDuration(std::chrono::milliseconds(ms));
}
std::chrono::duration<int64_t,std::milli> TF_Timer_Handle::GetIntervalDuration()
{
return this->interval;
}
int64_t TF_Timer_Handle::GetIntervalMilliseconds()
{
return this->interval.count();
}
void TF_RunEventLoopItteration()
{
OnItteraton.Invoke(ittr++);
#if defined(TESSESFRAMEWORK_ENABLE_THREADING) && (defined(GEKKO) || defined(__SWITCH__))
Tesses::Framework::Threading::LookForFinishedThreads();
#endif
#if defined(TESSESFRAMEWORK_ENABLE_THREADING)
invokings_mtx.Lock();
@@ -125,10 +254,10 @@ namespace Tesses::Framework
{
invokes.front()();
invokes.pop();
}
#endif
if(!isRunningSig) isRunning=false;
#if defined(GEKKO)
if(gaming_console_events)
@@ -140,7 +269,7 @@ namespace Tesses::Framework
if(gaming_console_events)
{
if(!appletMainLoop()) isRunning=false;
padUpdate(&default_pad);
u64 kDown = padGetButtonsDown(&default_pad);
@@ -163,7 +292,9 @@ namespace Tesses::Framework
isRunning = false;
}
#endif
timer_handler->Update();
}
void TF_SetIsRunning(bool _isRunning)
@@ -200,7 +331,7 @@ namespace Tesses::Framework
signal(SIGINT, _sigInt);
signal(SIGTERM, _sigInt);
#endif
isRunning=true;
#if defined(_WIN32)
WSADATA wsaData;
@@ -230,9 +361,9 @@ if (iResult != 0) {
// Initialize the default gamepad (which reads handheld mode inputs as well as the first connected controller)
#else
signal(SIGPIPE,SIG_IGN);
#endif
}
bool TF_GetConsoleEventsEnabled()
{
@@ -332,7 +463,7 @@ if (iResult != 0) {
}
std::optional<std::string> _argv0=std::nullopt;
void TF_AllowPortable(std::string argv0)
{
@@ -346,7 +477,7 @@ if (iResult != 0) {
auto portable=dir / "portable.json";
if(LocalFS->FileExists(portable))
{
std::string portable_str;
Helpers::ReadAllText(LocalFS,portable, portable_str);
auto jsonObj=Json::Decode(portable_str);
@@ -403,7 +534,7 @@ if (iResult != 0) {
{
if(paf_data)
portable_config.user = LocalFS->SystemToVFSPath(*paf_data) / "TF_User";
}
}
else if(portable_str == "documents")
{
if(paf_documents)
@@ -416,7 +547,7 @@ if (iResult != 0) {
{
if(portable_config.user)
portable_config.desktop = *(portable_config.user) / "Desktop";
}
}
else if(portable_str == "documents")
{
if(paf_documents)
@@ -429,7 +560,7 @@ if (iResult != 0) {
{
if(portable_config.user)
portable_config.downloads = *(portable_config.user) / "Downloads";
}
}
else if(portable_str == "documents")
{
if(paf_documents)
@@ -466,21 +597,21 @@ if (iResult != 0) {
{
if(dict2.TryGetValueAsType("user",portable_str))
{
if(portable_str != "system")
if(portable_str != "system")
{
auto userDir = dir / portable_str;
portable_config.user = userDir.CollapseRelativeParents();
}
}
if(dict2.TryGetValueAsType("documents", portable_str))
{
if(portable_str != "system")
{
if(portable_str == "default")
@@ -490,7 +621,7 @@ if (iResult != 0) {
portable_config.documents = *(portable_config.user) / "Documents";
}
}
else
else
{
auto userDir = dir / portable_str;
portable_config.documents = userDir.CollapseRelativeParents();
@@ -500,7 +631,7 @@ if (iResult != 0) {
}
if(dict2.TryGetValueAsType("downloads", portable_str))
{
if(portable_str != "system")
{
if(portable_str == "default")
@@ -510,7 +641,7 @@ if (iResult != 0) {
portable_config.downloads = *(portable_config.user) / "Downloads";
}
}
else
else
{
auto userDir = dir / portable_str;
portable_config.downloads = userDir.CollapseRelativeParents();
@@ -520,7 +651,7 @@ if (iResult != 0) {
}
if(dict2.TryGetValueAsType("desktop", portable_str))
{
if(portable_str != "system")
{
if(portable_str == "default")
@@ -530,7 +661,7 @@ if (iResult != 0) {
portable_config.desktop = *(portable_config.user) / "Desktop";
}
}
else
else
{
auto userDir = dir / portable_str;
portable_config.desktop = userDir.CollapseRelativeParents();
@@ -540,7 +671,7 @@ if (iResult != 0) {
}
if(dict2.TryGetValueAsType("pictures", portable_str))
{
if(portable_str != "system")
{
if(portable_str == "default")
@@ -550,7 +681,7 @@ if (iResult != 0) {
portable_config.pictures = *(portable_config.user) / "Pictures";
}
}
else
else
{
auto userDir = dir / portable_str;
portable_config.pictures = userDir.CollapseRelativeParents();
@@ -560,7 +691,7 @@ if (iResult != 0) {
}
if(dict2.TryGetValueAsType("videos", portable_str))
{
if(portable_str != "system")
{
if(portable_str == "default")
@@ -570,7 +701,7 @@ if (iResult != 0) {
portable_config.videos = *(portable_config.user) / "Videos";
}
}
else
else
{
auto userDir = dir / portable_str;
portable_config.videos = userDir.CollapseRelativeParents();
@@ -580,7 +711,7 @@ if (iResult != 0) {
}
if(dict2.TryGetValueAsType("music", portable_str))
{
if(portable_str != "system")
{
if(portable_str == "default")
@@ -590,7 +721,7 @@ if (iResult != 0) {
portable_config.music = *(portable_config.user) / "Music";
}
}
else
else
{
auto userDir = dir / portable_str;
portable_config.music = userDir.CollapseRelativeParents();
@@ -600,7 +731,7 @@ if (iResult != 0) {
}
if(dict2.TryGetValueAsType("config", portable_str))
{
if(portable_str != "system")
{
if(portable_str == "default")
@@ -610,7 +741,7 @@ if (iResult != 0) {
portable_config.config = *(portable_config.user) / "Config";
}
}
else
else
{
auto userDir = dir / portable_str;
portable_config.config = userDir.CollapseRelativeParents();
@@ -620,7 +751,7 @@ if (iResult != 0) {
}
if(dict2.TryGetValueAsType("cache", portable_str))
{
if(portable_str != "system")
{
if(portable_str == "default")
@@ -630,7 +761,7 @@ if (iResult != 0) {
portable_config.cache = *(portable_config.user) / "Cache";
}
}
else
else
{
auto userDir = dir / portable_str;
portable_config.cache = userDir.CollapseRelativeParents();
@@ -640,7 +771,7 @@ if (iResult != 0) {
}
if(dict2.TryGetValueAsType("data", portable_str))
{
if(portable_str != "system")
{
if(portable_str == "default")
@@ -650,7 +781,7 @@ if (iResult != 0) {
portable_config.data = *(portable_config.user) / "Data";
}
}
else
else
{
auto userDir = dir / portable_str;
portable_config.data = userDir.CollapseRelativeParents();
@@ -660,7 +791,7 @@ if (iResult != 0) {
}
if(dict2.TryGetValueAsType("state", portable_str))
{
if(portable_str != "system")
{
if(portable_str == "default")
@@ -670,7 +801,7 @@ if (iResult != 0) {
portable_config.state = *(portable_config.user) / "State";
}
}
else
else
{
auto userDir = dir / portable_str;
portable_config.state = userDir.CollapseRelativeParents();
@@ -680,7 +811,7 @@ if (iResult != 0) {
}
if(dict2.TryGetValueAsType("temp", portable_str))
{
if(portable_str != "system")
{
if(portable_str == "default")
@@ -690,7 +821,7 @@ if (iResult != 0) {
portable_config.temp = *(portable_config.user) / "Temp";
}
}
else
else
{
auto userDir = dir / portable_str;
portable_config.temp = userDir.CollapseRelativeParents();
@@ -698,40 +829,40 @@ if (iResult != 0) {
}
}
}
}
else if(portable_str == "absolute")
{
if(dict2.TryGetValueAsType("user",portable_str))
{
if(portable_str != "system")
if(portable_str != "system")
{
VFSPath userDir = portable_str;
portable_config.user = userDir.CollapseRelativeParents();
}
}
if(dict2.TryGetValueAsType("documents", portable_str))
{
if(portable_str != "system")
{
if(portable_str == "default")
@@ -741,7 +872,7 @@ if (iResult != 0) {
portable_config.documents = *(portable_config.user) / "Documents";
}
}
else
else
{
VFSPath userDir = portable_str;
portable_config.documents = userDir.CollapseRelativeParents();
@@ -751,7 +882,7 @@ if (iResult != 0) {
}
if(dict2.TryGetValueAsType("downloads", portable_str))
{
if(portable_str != "system")
{
if(portable_str == "default")
@@ -761,7 +892,7 @@ if (iResult != 0) {
portable_config.downloads = *(portable_config.user) / "Downloads";
}
}
else
else
{
VFSPath userDir = portable_str;
portable_config.downloads = userDir.CollapseRelativeParents();
@@ -771,7 +902,7 @@ if (iResult != 0) {
}
if(dict2.TryGetValueAsType("desktop", portable_str))
{
if(portable_str != "system")
{
if(portable_str == "default")
@@ -781,7 +912,7 @@ if (iResult != 0) {
portable_config.desktop = *(portable_config.user) / "Desktop";
}
}
else
else
{
VFSPath userDir = portable_str;
portable_config.desktop = userDir.CollapseRelativeParents();
@@ -791,7 +922,7 @@ if (iResult != 0) {
}
if(dict2.TryGetValueAsType("pictures", portable_str))
{
if(portable_str != "system")
{
if(portable_str == "default")
@@ -801,7 +932,7 @@ if (iResult != 0) {
portable_config.pictures = *(portable_config.user) / "Pictures";
}
}
else
else
{
VFSPath userDir = portable_str;
portable_config.pictures = userDir.CollapseRelativeParents();
@@ -811,7 +942,7 @@ if (iResult != 0) {
}
if(dict2.TryGetValueAsType("videos", portable_str))
{
if(portable_str != "system")
{
if(portable_str == "default")
@@ -821,7 +952,7 @@ if (iResult != 0) {
portable_config.videos = *(portable_config.user) / "Videos";
}
}
else
else
{
VFSPath userDir = portable_str;
portable_config.videos = userDir.CollapseRelativeParents();
@@ -831,7 +962,7 @@ if (iResult != 0) {
}
if(dict2.TryGetValueAsType("music", portable_str))
{
if(portable_str != "system")
{
if(portable_str == "default")
@@ -841,7 +972,7 @@ if (iResult != 0) {
portable_config.music = *(portable_config.user) / "Music";
}
}
else
else
{
VFSPath userDir = portable_str;
portable_config.music = userDir.CollapseRelativeParents();
@@ -851,7 +982,7 @@ if (iResult != 0) {
}
if(dict2.TryGetValueAsType("config", portable_str))
{
if(portable_str != "system")
{
if(portable_str == "default")
@@ -861,7 +992,7 @@ if (iResult != 0) {
portable_config.config = *(portable_config.user) / "Config";
}
}
else
else
{
VFSPath userDir = portable_str;
portable_config.config = userDir.CollapseRelativeParents();
@@ -871,7 +1002,7 @@ if (iResult != 0) {
}
if(dict2.TryGetValueAsType("cache", portable_str))
{
if(portable_str != "system")
{
if(portable_str == "default")
@@ -881,7 +1012,7 @@ if (iResult != 0) {
portable_config.cache = *(portable_config.user) / "Cache";
}
}
else
else
{
VFSPath userDir = portable_str;
portable_config.cache = userDir.CollapseRelativeParents();
@@ -891,7 +1022,7 @@ if (iResult != 0) {
}
if(dict2.TryGetValueAsType("data", portable_str))
{
if(portable_str != "system")
{
if(portable_str == "default")
@@ -901,7 +1032,7 @@ if (iResult != 0) {
portable_config.data = *(portable_config.user) / "Data";
}
}
else
else
{
VFSPath userDir = portable_str;
portable_config.data = userDir.CollapseRelativeParents();
@@ -911,7 +1042,7 @@ if (iResult != 0) {
}
if(dict2.TryGetValueAsType("state", portable_str))
{
if(portable_str != "system")
{
if(portable_str == "default")
@@ -921,7 +1052,7 @@ if (iResult != 0) {
portable_config.state = *(portable_config.user) / "State";
}
}
else
else
{
VFSPath userDir = portable_str;
portable_config.state = userDir.CollapseRelativeParents();
@@ -931,7 +1062,7 @@ if (iResult != 0) {
}
if(dict2.TryGetValueAsType("temp", portable_str))
{
if(portable_str != "system")
{
if(portable_str == "default")
@@ -941,7 +1072,7 @@ if (iResult != 0) {
portable_config.temp = *(portable_config.user) / "Temp";
}
}
else
else
{
VFSPath userDir = portable_str;
portable_config.temp = userDir.CollapseRelativeParents();
@@ -949,7 +1080,7 @@ if (iResult != 0) {
}
}
}
}
}
}