Change html to dark mode by default and stat in vfs
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
#include <cstring>
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
#include <ratio>
|
||||
#include <string>
|
||||
#include <filesystem>
|
||||
#include <map>
|
||||
@@ -15,83 +18,55 @@
|
||||
namespace Tesses::Framework
|
||||
{
|
||||
|
||||
template<typename...TArgs>
|
||||
class Event {
|
||||
public:
|
||||
virtual void Invoke(TArgs... args)=0;
|
||||
virtual ~Event()
|
||||
{}
|
||||
};
|
||||
template<typename...TArgs>
|
||||
class FunctionalEvent : public Event<TArgs...> {
|
||||
std::function<void(TArgs...)> cb;
|
||||
public:
|
||||
FunctionalEvent(std::function<void(TArgs...)> cb)
|
||||
{
|
||||
this->cb = cb;
|
||||
}
|
||||
void Invoke(TArgs... args)
|
||||
{
|
||||
this->cb(args...);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename...TArgs>
|
||||
class EventList : public Event<TArgs...> {
|
||||
Threading::Mutex mtx;
|
||||
std::vector<std::shared_ptr<Event<TArgs...>>> items;
|
||||
public:
|
||||
void operator+=(std::shared_ptr<Event<TArgs...>> event)
|
||||
{
|
||||
mtx.Lock();
|
||||
for(std::shared_ptr<Event<TArgs...>>& item : this->items)
|
||||
{
|
||||
if(item.get() == event.get()) {
|
||||
mtx.Unlock();
|
||||
return;
|
||||
}
|
||||
}
|
||||
this->items.push_back(event);
|
||||
mtx.Unlock();
|
||||
}
|
||||
void operator-=(std::shared_ptr<Event<TArgs...>> event)
|
||||
{
|
||||
mtx.Lock();
|
||||
for(auto i = this->items.begin(); i != this->items.end(); i++)
|
||||
{
|
||||
if(i->get() == event.get())
|
||||
{
|
||||
this->items.erase(i);
|
||||
mtx.Unlock();
|
||||
return;
|
||||
}
|
||||
}
|
||||
mtx.Unlock();
|
||||
}
|
||||
void Invoke(TArgs... args)
|
||||
{
|
||||
mtx.Lock();
|
||||
for(auto& item : this->items)
|
||||
{
|
||||
item->Invoke(args...);
|
||||
}
|
||||
mtx.Unlock();
|
||||
}
|
||||
void Remove(std::function<bool(std::shared_ptr<Event<TArgs...>>)> cb)
|
||||
{
|
||||
for(auto index = this->items.begin(); index != this->items.end(); index++)
|
||||
{
|
||||
if(cb(*index))
|
||||
{
|
||||
this->items.erase(index);
|
||||
index--;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
extern EventList<uint64_t> OnItteraton;
|
||||
|
||||
std::optional<std::string> TF_GetCommandName();
|
||||
class TF_Timer_Handle;
|
||||
//Used for internal purposes, don't use unless you want to run timer events on another thread
|
||||
|
||||
class TF_Timer_Handler {
|
||||
private:
|
||||
std::vector<std::weak_ptr<TF_Timer_Handle>> handles;
|
||||
public:
|
||||
void Update();
|
||||
|
||||
|
||||
static std::shared_ptr<TF_Timer_Handle> Make(std::shared_ptr<TF_Timer_Handler> handler);
|
||||
friend class TF_Timer_Handle;
|
||||
};
|
||||
|
||||
class TF_Timer_Handle {
|
||||
|
||||
private:
|
||||
std::shared_ptr<TF_Timer_Handler> timerHandler;
|
||||
std::function<void()> cb;
|
||||
std::chrono::milliseconds interval;
|
||||
std::chrono::time_point<std::chrono::steady_clock, std::chrono::milliseconds> last;
|
||||
bool enabled;
|
||||
TF_Timer_Handle() = delete;
|
||||
|
||||
TF_Timer_Handle(std::shared_ptr<TF_Timer_Handler> timerHandler);
|
||||
|
||||
public:
|
||||
|
||||
void SetCallback(std::function<void()> cb);
|
||||
|
||||
int64_t GetIntervalMilliseconds();
|
||||
std::chrono::duration<int64_t,std::milli> GetIntervalDuration();
|
||||
|
||||
void SetIntervalFromMilliseconds(int64_t ms);
|
||||
|
||||
void SetIntervalFromDuration(std::chrono::milliseconds dur);
|
||||
|
||||
|
||||
void SetEnabled(bool enabled);
|
||||
bool GetEnabled();
|
||||
friend class TF_Timer_Handler;
|
||||
};
|
||||
|
||||
|
||||
std::shared_ptr<TF_Timer_Handle> TF_Timer();
|
||||
std::shared_ptr<TF_Timer_Handle> TF_Timer(std::function<void()> cb, int64_t interval=1000, bool enabled=true);
|
||||
std::shared_ptr<TF_Timer_Handle> TF_Timer(std::function<void()> cb, std::chrono::milliseconds interval, bool enabled=true);
|
||||
|
||||
void TF_Init();
|
||||
void TF_InitWithConsole();
|
||||
|
||||
@@ -1,50 +1,46 @@
|
||||
#pragma once
|
||||
#include "VFS.hpp"
|
||||
#include "VFSFix.hpp"
|
||||
|
||||
|
||||
namespace Tesses::Framework::Filesystem
|
||||
{
|
||||
class LocalFilesystem : public VFS
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> OpenFile(VFSPath path, std::string mode);
|
||||
|
||||
|
||||
void CreateDirectory(VFSPath path);
|
||||
void DeleteDirectory(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);
|
||||
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);
|
||||
|
||||
void SetDate(VFSPath path, Date::DateTime lastWrite, Date::DateTime lastAccess);
|
||||
bool Stat(VFSPath path, StatData& stat);
|
||||
bool StatVFS(VFSPath path, StatVFSData& vfsData);
|
||||
|
||||
void Chmod(VFSPath path, uint32_t mode);
|
||||
void Chown(VFSPath path, uint32_t uid, uint32_t gid);
|
||||
|
||||
void Lock(VFSPath path);
|
||||
void Unlock(VFSPath path);
|
||||
|
||||
FIFOCreationResult CreateFIFO(VFSPath path, uint32_t mod);
|
||||
|
||||
protected:
|
||||
std::shared_ptr<FSWatcher> CreateWatcher(std::shared_ptr<VFS> vfs, VFSPath path);
|
||||
|
||||
};
|
||||
};
|
||||
extern std::shared_ptr<LocalFilesystem> LocalFS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,100 +0,0 @@
|
||||
#pragma once
|
||||
#include "VFS.hpp"
|
||||
#include "VFSFix.hpp"
|
||||
#include "../Threading/Mutex.hpp"
|
||||
#include <atomic>
|
||||
namespace Tesses::Framework::Filesystem
|
||||
{
|
||||
class MemoryEntry {
|
||||
public:
|
||||
std::string name;
|
||||
virtual ~MemoryEntry();
|
||||
};
|
||||
class MemoryFileData {
|
||||
public:
|
||||
MemoryFileData();
|
||||
Date::DateTime lastWrite;
|
||||
|
||||
bool canAccess;
|
||||
size_t readers;
|
||||
std::vector<uint8_t> file;
|
||||
};
|
||||
|
||||
class MemoryFile : public MemoryEntry
|
||||
{
|
||||
public:
|
||||
std::shared_ptr<MemoryFileData> data;
|
||||
~MemoryFile();
|
||||
};
|
||||
|
||||
class MemoryDirectory : public MemoryEntry
|
||||
{
|
||||
public:
|
||||
MemoryDirectory();
|
||||
Date::DateTime lastWrite;
|
||||
std::vector<MemoryEntry*> entries;
|
||||
~MemoryDirectory();
|
||||
};
|
||||
|
||||
class MemorySymlink : public MemoryEntry
|
||||
{
|
||||
public:
|
||||
Date::DateTime lastWrite;
|
||||
VFSPath linkedTo;
|
||||
};
|
||||
|
||||
class MemoryFilesystemStream : public Streams::Stream
|
||||
{
|
||||
public:
|
||||
std::shared_ptr<Tesses::Framework::Threading::Mutex> mtx;
|
||||
std::shared_ptr<MemoryFileData> data;
|
||||
bool canRead;
|
||||
bool canWrite;
|
||||
bool canSeek;
|
||||
int64_t pos;
|
||||
MemoryFilesystemStream(std::shared_ptr<Tesses::Framework::Threading::Mutex> mtx, std::shared_ptr<MemoryFileData> data,bool canRead, bool canWrite, bool canSeek);
|
||||
size_t Read(uint8_t* buff, size_t sz);
|
||||
size_t Write(const uint8_t* buff, size_t sz);
|
||||
bool CanRead();
|
||||
bool CanWrite();
|
||||
bool CanSeek();
|
||||
int64_t GetPosition();
|
||||
void Flush();
|
||||
void Seek(int64_t pos, Streams::SeekOrigin whence);
|
||||
~MemoryFilesystemStream();
|
||||
};
|
||||
|
||||
|
||||
class MemoryFilesystem : public VFS
|
||||
{
|
||||
std::shared_ptr<Tesses::Framework::Threading::Mutex> mtx;
|
||||
MemoryDirectory root;
|
||||
|
||||
MemoryEntry* GetEntry(VFSPath path,bool followSymlink);
|
||||
public:
|
||||
MemoryFilesystem();
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> OpenFile(VFSPath path, std::string mode);
|
||||
|
||||
void CreateDirectory(VFSPath path);
|
||||
void DeleteDirectory(VFSPath path);
|
||||
bool RegularFileExists(VFSPath path);
|
||||
bool SymlinkExists(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);
|
||||
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);
|
||||
|
||||
~MemoryFilesystem();
|
||||
};
|
||||
};
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include "VFS.hpp"
|
||||
#include "VFSFix.hpp"
|
||||
|
||||
|
||||
namespace Tesses::Framework::Filesystem
|
||||
{
|
||||
class MountableDirectory {
|
||||
@@ -19,10 +19,10 @@ namespace Tesses::Framework::Filesystem
|
||||
std::shared_ptr<VFS> root;
|
||||
|
||||
std::vector<MountableDirectory*> directories;
|
||||
|
||||
|
||||
void GetFS(VFSPath srcPath, VFSPath& destRoot, VFSPath& destPath, std::shared_ptr<VFS>& vfs);
|
||||
|
||||
|
||||
|
||||
public:
|
||||
MountableFilesystem();
|
||||
MountableFilesystem(std::shared_ptr<VFS> root);
|
||||
@@ -31,15 +31,7 @@ namespace Tesses::Framework::Filesystem
|
||||
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);
|
||||
bool Stat(VFSPath path, StatData& data);
|
||||
void DeleteFile(VFSPath path);
|
||||
void CreateSymlink(VFSPath existingFile, VFSPath symlinkFile);
|
||||
VFSPathEnumerator EnumeratePaths(VFSPath path);
|
||||
@@ -50,14 +42,18 @@ namespace Tesses::Framework::Filesystem
|
||||
std::string VFSPathToSystem(VFSPath path);
|
||||
VFSPath SystemToVFSPath(std::string path);
|
||||
~MountableFilesystem();
|
||||
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 Chown(VFSPath path, uint32_t uid, uint32_t gid);
|
||||
FIFOCreationResult CreateFIFO(VFSPath path, uint32_t mode);
|
||||
|
||||
|
||||
void Lock(VFSPath path);
|
||||
void Unlock(VFSPath path);
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,16 @@
|
||||
#pragma once
|
||||
#include "VFS.hpp"
|
||||
#include "VFSFix.hpp"
|
||||
|
||||
|
||||
namespace Tesses::Framework::Filesystem
|
||||
{
|
||||
class NullFilesystem : public VFS
|
||||
{
|
||||
public:
|
||||
public:
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> OpenFile(VFSPath path, std::string mode);
|
||||
void CreateDirectory(VFSPath path);
|
||||
void DeleteDirectory(VFSPath path);
|
||||
bool RegularFileExists(VFSPath path);
|
||||
bool DirectoryExists(VFSPath path);
|
||||
void DeleteFile(VFSPath path);
|
||||
VFSPathEnumerator EnumeratePaths(VFSPath path);
|
||||
void MoveFile(VFSPath src, VFSPath dest);
|
||||
bool Stat(VFSPath path, StatData& data);
|
||||
std::string VFSPathToSystem(VFSPath path);
|
||||
VFSPath SystemToVFSPath(std::string path);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include "VFS.hpp"
|
||||
#include "VFSFix.hpp"
|
||||
|
||||
|
||||
namespace Tesses::Framework::Filesystem
|
||||
{
|
||||
class SubdirFilesystem : public VFS
|
||||
@@ -15,15 +15,6 @@ namespace Tesses::Framework::Filesystem
|
||||
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);
|
||||
@@ -35,13 +26,14 @@ namespace Tesses::Framework::Filesystem
|
||||
std::string VFSPathToSystem(VFSPath path);
|
||||
VFSPath SystemToVFSPath(std::string path);
|
||||
~SubdirFilesystem();
|
||||
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);
|
||||
bool Stat(VFSPath path, StatData& data);
|
||||
|
||||
void Chown(VFSPath path, uint32_t uid, uint32_t gid);
|
||||
void Chmod(VFSPath path, uint32_t mode);
|
||||
|
||||
FIFOCreationResult CreateFIFO(VFSPath path, uint32_t mode);
|
||||
void Lock(VFSPath path);
|
||||
void Unlock(VFSPath path);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "../Common.hpp"
|
||||
#include "VFS.hpp"
|
||||
#include "VFSFix.hpp"
|
||||
namespace Tesses::Framework::Filesystem
|
||||
namespace Tesses::Framework::Filesystem
|
||||
{
|
||||
void UniqueString(std::string& text);
|
||||
|
||||
@@ -20,15 +20,6 @@ namespace Tesses::Framework::Filesystem
|
||||
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);
|
||||
@@ -39,16 +30,19 @@ namespace Tesses::Framework::Filesystem
|
||||
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);
|
||||
bool Stat(VFSPath path, StatData& data);
|
||||
|
||||
void Chmod(VFSPath path, uint32_t mode);
|
||||
|
||||
void Chown(VFSPath path, uint32_t uid, uint32_t gid);
|
||||
FIFOCreationResult CreateFIFO(VFSPath path, uint32_t mode);
|
||||
void Close();
|
||||
|
||||
void Lock(VFSPath path);
|
||||
void Unlock(VFSPath path);
|
||||
~TempFS();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
#pragma once
|
||||
#include "../Common.hpp"
|
||||
#include "../Streams/Stream.hpp"
|
||||
#include <TessesFramework/Common.hpp>
|
||||
#include <TessesFramework/Date/Date.hpp>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include "../Date/Date.hpp"
|
||||
#include "VFSFix.hpp"
|
||||
|
||||
|
||||
namespace Tesses::Framework::Filesystem
|
||||
{
|
||||
|
||||
class StatVFSData {
|
||||
public:
|
||||
struct StatVFSData {
|
||||
|
||||
uint64_t BlockSize;
|
||||
uint64_t FragmentSize;
|
||||
uint64_t Blocks;
|
||||
@@ -23,12 +25,94 @@ namespace Tesses::Framework::Filesystem
|
||||
uint64_t Flags;
|
||||
uint64_t MaxNameLength;
|
||||
};
|
||||
|
||||
constexpr uint32_t MODE_USER_READ = 0400;
|
||||
constexpr uint32_t MODE_USER_WRITE = 0200;
|
||||
constexpr uint32_t MODE_USER_EXEC = 0100;
|
||||
|
||||
constexpr uint32_t MODE_GROUP_READ = (MODE_USER_READ >> 3);
|
||||
constexpr uint32_t MODE_GROUP_WRITE = (MODE_USER_WRITE >> 3);
|
||||
constexpr uint32_t MODE_GROUP_EXEC = (MODE_USER_EXEC >> 3);
|
||||
|
||||
constexpr uint32_t MODE_OTHER_READ = (MODE_GROUP_READ >> 3);
|
||||
constexpr uint32_t MODE_OTHER_WRITE = (MODE_GROUP_WRITE >> 3);
|
||||
constexpr uint32_t MODE_OTHER_EXEC = (MODE_GROUP_EXEC >> 3);
|
||||
|
||||
constexpr uint32_t MODE_REGULAR = 0100000;
|
||||
constexpr uint32_t MODE_DIRECTORY = 0040000;
|
||||
constexpr uint32_t MODE_CHAR_DEVICE = 0020000;
|
||||
constexpr uint32_t MODE_BLOCK_DEVICE = 0060000;
|
||||
constexpr uint32_t MODE_SOCKET = 0140000;
|
||||
constexpr uint32_t MODE_FIFO = 0010000;
|
||||
constexpr uint32_t MODE_SYMLINK = 0120000;
|
||||
|
||||
|
||||
struct StatData {
|
||||
uint64_t Device;
|
||||
uint64_t Inode;
|
||||
uint32_t Mode;
|
||||
uint64_t HardLinks;
|
||||
uint32_t UserId;
|
||||
uint32_t GroupId;
|
||||
uint64_t DeviceId;
|
||||
uint64_t Size;
|
||||
uint64_t BlockSize;
|
||||
uint64_t BlockCount;
|
||||
Date::DateTime LastAccess;
|
||||
Date::DateTime LastModified;
|
||||
Date::DateTime LastStatus;
|
||||
|
||||
bool IsRegularFile()
|
||||
{
|
||||
return (Mode & MODE_REGULAR) > 0;
|
||||
}
|
||||
bool IsDirectory()
|
||||
{
|
||||
return (Mode & MODE_DIRECTORY) > 0;
|
||||
}
|
||||
|
||||
bool IsCharDevice()
|
||||
{
|
||||
return (Mode & MODE_CHAR_DEVICE) > 0;
|
||||
}
|
||||
|
||||
bool IsBlockDevice()
|
||||
{
|
||||
return (Mode & MODE_BLOCK_DEVICE) > 0;
|
||||
}
|
||||
|
||||
bool IsSocket()
|
||||
{
|
||||
return (Mode & MODE_SOCKET) > 0;
|
||||
}
|
||||
bool IsFIFO()
|
||||
{
|
||||
return (Mode & MODE_FIFO) > 0;
|
||||
}
|
||||
|
||||
bool IsSymlink()
|
||||
{
|
||||
return (Mode & MODE_SYMLINK) > 0;
|
||||
}
|
||||
|
||||
bool IsSpecial()
|
||||
{
|
||||
if(IsRegularFile()) return false;
|
||||
if(IsDirectory()) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string ToSizeString(bool usesBin=true)
|
||||
{
|
||||
return TF_FileSize(this->Size, usesBin);
|
||||
}
|
||||
};
|
||||
class VFSPath {
|
||||
public:
|
||||
static VFSPath CurrentDirectoryAsRelative();
|
||||
bool relative;
|
||||
static std::vector<std::string> SplitPath(std::string path);
|
||||
std::vector<std::string> path;
|
||||
std::vector<std::string> path;
|
||||
VFSPath();
|
||||
explicit VFSPath(const char* path) : VFSPath(std::string(path))
|
||||
{}
|
||||
@@ -36,7 +120,7 @@ namespace Tesses::Framework::Filesystem
|
||||
VFSPath(std::string path);
|
||||
VFSPath(VFSPath p, std::string subent);
|
||||
VFSPath(VFSPath p, VFSPath p2);
|
||||
|
||||
|
||||
//does not check for ?
|
||||
static VFSPath ParseUriPath(std::string path);
|
||||
|
||||
@@ -52,7 +136,7 @@ namespace Tesses::Framework::Filesystem
|
||||
static VFSPath GetAbsoluteCurrentDirectory();
|
||||
static void SetAbsoluteCurrentDirectory(VFSPath path);
|
||||
VFSPath MakeAbsolute() const;
|
||||
|
||||
|
||||
VFSPath MakeAbsolute(VFSPath curDir) const;
|
||||
VFSPath MakeRelative() const;
|
||||
VFSPath MakeRelative(VFSPath toMakeRelativeTo) const;
|
||||
@@ -98,10 +182,10 @@ namespace Tesses::Framework::Filesystem
|
||||
|
||||
VFSPathEnumeratorItterator& operator++();
|
||||
VFSPathEnumeratorItterator& operator++(int);
|
||||
|
||||
|
||||
VFSPath& operator*();
|
||||
VFSPath* operator->();
|
||||
|
||||
|
||||
bool operator!=(VFSPathEnumeratorItterator right);
|
||||
bool operator==(VFSPathEnumeratorItterator right);
|
||||
};
|
||||
@@ -185,48 +269,60 @@ namespace Tesses::Framework::Filesystem
|
||||
std::shared_ptr<VFS> GetFilesystem();
|
||||
const VFSPath& GetPath();
|
||||
virtual ~FSWatcher() = default;
|
||||
|
||||
static std::shared_ptr<FSWatcher> Create(std::shared_ptr<VFS> vfs, VFSPath path);
|
||||
|
||||
static std::shared_ptr<FSWatcher> Create(std::shared_ptr<VFS> vfs, VFSPath path);
|
||||
};
|
||||
|
||||
enum class FIFOCreationResult {
|
||||
Success=0,
|
||||
Exists = 1,
|
||||
ReadOnlyFS = 2,
|
||||
Denied = 3,
|
||||
OutOfInodes = 4,
|
||||
UnknownError = 5,
|
||||
Unsupported = 255
|
||||
};
|
||||
|
||||
class VFS {
|
||||
public:
|
||||
|
||||
|
||||
virtual std::shared_ptr<Tesses::Framework::Streams::Stream> OpenFile(VFSPath path, std::string mode)=0;
|
||||
virtual void CreateDirectory(VFSPath path)=0;
|
||||
virtual void DeleteDirectory(VFSPath path)=0;
|
||||
virtual bool RegularFileExists(VFSPath path)=0;
|
||||
virtual bool SymlinkExists(VFSPath path);
|
||||
virtual bool CharacterDeviceExists(VFSPath path);
|
||||
virtual bool BlockDeviceExists(VFSPath path);
|
||||
virtual bool SocketFileExists(VFSPath path);
|
||||
virtual bool FIFOFileExists(VFSPath path);
|
||||
virtual bool FileExists(VFSPath path);
|
||||
virtual bool SpecialFileExists(VFSPath path);
|
||||
virtual void CreateDirectory(VFSPath path);
|
||||
virtual void DeleteDirectory(VFSPath path);
|
||||
bool DirectoryExists(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 FileExists(VFSPath path);
|
||||
bool SpecialFileExists(VFSPath path);
|
||||
virtual void CreateSymlink(VFSPath existingFile, VFSPath symlinkFile);
|
||||
virtual void CreateHardlink(VFSPath existingFile, VFSPath newName);
|
||||
virtual bool DirectoryExists(VFSPath path)=0;
|
||||
virtual void DeleteFile(VFSPath path)=0;
|
||||
virtual void DeleteFile(VFSPath path);
|
||||
virtual void DeleteDirectoryRecurse(VFSPath path);
|
||||
virtual VFSPathEnumerator EnumeratePaths(VFSPath path) = 0;
|
||||
virtual void MoveFile(VFSPath src, VFSPath dest)=0;
|
||||
virtual void MoveFile(VFSPath src, VFSPath dest);
|
||||
virtual void MoveDirectory(VFSPath src, VFSPath dest);
|
||||
virtual VFSPath ReadLink(VFSPath path);
|
||||
virtual std::string VFSPathToSystem(VFSPath path)=0;
|
||||
virtual VFSPath SystemToVFSPath(std::string path)=0;
|
||||
|
||||
|
||||
virtual void GetDate(VFSPath path, Date::DateTime& lastWrite, Date::DateTime& lastAccess);
|
||||
void GetDate(VFSPath path, Date::DateTime& lastWrite, Date::DateTime& lastAccess);
|
||||
virtual void SetDate(VFSPath path, Date::DateTime lastWrite, Date::DateTime lastAccess);
|
||||
|
||||
virtual bool Stat(VFSPath path, StatData& data) = 0;
|
||||
virtual bool StatVFS(VFSPath path, StatVFSData& data);
|
||||
|
||||
virtual void Chmod(VFSPath path, uint32_t mode);
|
||||
virtual void Chown(VFSPath path, uint32_t userId, uint32_t groupId);
|
||||
|
||||
virtual void Lock(VFSPath path);
|
||||
virtual void Unlock(VFSPath path);
|
||||
|
||||
|
||||
virtual FIFOCreationResult CreateFIFO(VFSPath path, uint32_t mode);
|
||||
|
||||
virtual ~VFS();
|
||||
|
||||
virtual void Close();
|
||||
@@ -236,7 +332,6 @@ namespace Tesses::Framework::Filesystem
|
||||
friend class FSWatcher;
|
||||
};
|
||||
|
||||
|
||||
|
||||
namespace Literals
|
||||
{
|
||||
@@ -246,4 +341,3 @@ namespace Tesses::Framework::Filesystem
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "../Date/Date.hpp"
|
||||
#include <unordered_map>
|
||||
#include "WebSocket.hpp"
|
||||
#include <queue>
|
||||
namespace Tesses::Framework::Http
|
||||
{
|
||||
class ServerContextData {
|
||||
@@ -13,12 +14,14 @@ namespace Tesses::Framework::Http
|
||||
virtual ~ServerContextData();
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
class ServerContext {
|
||||
bool sent;
|
||||
bool debug;
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> strm;
|
||||
std::map<std::string,ServerContextData*> data;
|
||||
std::queue<std::function<bool(ServerContext& ctx)>> headerhandlers;
|
||||
public:
|
||||
HttpDictionary requestHeaders;
|
||||
HttpDictionary responseHeaders;
|
||||
@@ -34,7 +37,7 @@ namespace Tesses::Framework::Http
|
||||
uint16_t serverPort;
|
||||
std::string version;
|
||||
bool encrypted;
|
||||
ServerContext(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
ServerContext(std::shared_ptr<Tesses::Framework::Streams::Stream> strm, bool debug=false);
|
||||
~ServerContext();
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> GetStream();
|
||||
std::string GetOriginalPathWithQuery();
|
||||
@@ -53,6 +56,7 @@ namespace Tesses::Framework::Http
|
||||
void SendException(std::exception& ex);
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> OpenResponseStream();
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> OpenRequestStream();
|
||||
ServerContext& WithStatusCode(StatusCode code);
|
||||
ServerContext& WithLastModified(Date::DateTime time);
|
||||
ServerContext& WithHeader(std::string key, std::string value);
|
||||
ServerContext& WithSingleHeader(std::string key, std::string value);
|
||||
@@ -61,6 +65,9 @@ namespace Tesses::Framework::Http
|
||||
ServerContext& WriteHeaders();
|
||||
ServerContext& WithLocationHeader(std::string url);
|
||||
ServerContext& WithLocationHeader(std::string url,StatusCode sc);
|
||||
ServerContext& WithHeaderIntercepter(std::function<bool(ServerContext&)> cb);
|
||||
ServerContext& WithDebug(bool debug=true);
|
||||
bool Debug();
|
||||
void StartWebSocketSession(std::function<void(std::function<void(WebSocketMessage&)>,std::function<void()>,std::function<void()>)> onOpen, std::function<void(WebSocketMessage&)> onReceive, std::function<void(bool)> onClose);
|
||||
void StartWebSocketSession(std::shared_ptr<WebSocketConnection> connection);
|
||||
std::string GetServerRoot();
|
||||
@@ -68,7 +75,7 @@ namespace Tesses::Framework::Http
|
||||
void SendRedirect(std::string url);
|
||||
void SendRedirect(std::string url, StatusCode sc);
|
||||
|
||||
|
||||
|
||||
template<class T>
|
||||
T* GetServerContentData(std::string tag)
|
||||
{
|
||||
@@ -95,14 +102,15 @@ namespace Tesses::Framework::Http
|
||||
|
||||
bool showIPs;
|
||||
bool showARTL;
|
||||
|
||||
bool debug;
|
||||
|
||||
public:
|
||||
HttpServer(std::shared_ptr<Tesses::Framework::Streams::TcpServer> tcpServer, std::shared_ptr<IHttpServer> http, bool showIPs=true);
|
||||
HttpServer(uint16_t port, std::shared_ptr<IHttpServer> http, bool showIPs=true);
|
||||
HttpServer(std::string unixPath, std::shared_ptr<IHttpServer> http);
|
||||
HttpServer(std::shared_ptr<Tesses::Framework::Streams::TcpServer> tcpServer, std::shared_ptr<IHttpServer> http, bool showIPs=true, bool debug=false);
|
||||
HttpServer(uint16_t port, std::shared_ptr<IHttpServer> http, bool showIPs=true, bool debug=false);
|
||||
HttpServer(std::string unixPath, std::shared_ptr<IHttpServer> http, bool debug=false);
|
||||
uint16_t GetPort();
|
||||
void StartAccepting();
|
||||
static void Process(std::shared_ptr<Tesses::Framework::Streams::Stream> strm, std::shared_ptr<IHttpServer> server, std::string ip, uint16_t port,uint16_t serverPort, bool encrypted);
|
||||
static void Process(std::shared_ptr<Tesses::Framework::Streams::Stream> strm, std::shared_ptr<IHttpServer> server, std::string ip, uint16_t port,uint16_t serverPort, bool encrypted, bool debug=false);
|
||||
~HttpServer();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
#include "Filesystem/SubdirFilesystem.hpp"
|
||||
#include "Filesystem/NullFilesystem.hpp"
|
||||
#include "Filesystem/MountableFilesystem.hpp"
|
||||
#include "Filesystem/MemoryFilesystem.hpp"
|
||||
#include "Filesystem/FSHelpers.hpp"
|
||||
#include "Crypto/ClientTLSStream.hpp"
|
||||
#include "Crypto/Crypto.hpp"
|
||||
@@ -46,4 +45,4 @@
|
||||
#include "Serialization/BitConverter.hpp"
|
||||
#include "Args.hpp"
|
||||
#include "BitTorrent/TorrentFile.hpp"
|
||||
#include "Random.hpp"
|
||||
#include "Random.hpp"
|
||||
|
||||
Reference in New Issue
Block a user