quickmod/FuseMounter/fsproxy.h
Daniel O'Neill 1393a796b2 Implement FUSE VFS as a very early implementation. It can, does, and will break your game.
Updated QML and C++ in various places to build and work with new Qt (6.4+)
Minor bugfixes, possibly caused by the Qt version bump, and mostly in JS logic.
Tried (again) to get mod sorting working by dragging them within the list.
Initial support for Profiles. (To switch between FO4 and FOLON, for example.)
Initial "Launch Game" stuff, but it's far from done. Don't use it (yet).
2025-08-20 07:57:00 -07:00

130 lines
2.9 KiB
C++

#ifndef FSPROXY_H
#define FSPROXY_H
#include <QObject>
#include <QFile>
#include <QMap>
#include <QMutex>
#include <fcntl.h>
#include <sys/stat.h>
class Database;
class OpenFile : public QObject
{
Q_OBJECT
public:
QString m_logicalpath;
QString m_filepath;
int m_fd;
QFile *m_file;
QMutex m_mutex;
};
class ProxyCacheEntryChunk : public QObject
{
Q_OBJECT
public:
quint64 m_start;
QByteArray m_data;
time_t m_lastAccess;
quint32 m_accessCount;
ProxyCacheEntryChunk(quint64 start, QObject *parent=NULL) :
QObject(parent),
m_start{start},
m_lastAccess{0},
m_accessCount{0}
{}
};
class FSProxy;
class ProxyCacheEntry : public QObject
{
Q_OBJECT
FSProxy *m_parent;
public:
QString m_logicalpath;
QString m_filepath;
int m_accessCount;
off_t m_offset;
struct stat m_stat;
time_t m_lastAccess;
QMutex m_mutex;
QMap< quint64, ProxyCacheEntryChunk * > m_chunks;
ProxyCacheEntry(FSProxy *parent=NULL);
~ProxyCacheEntry() { clear(); }
void clear();
void clean();
qint64 sparseRead(int fd, char *buf, size_t size, off_t offset);
};
class FSProxyElement : public QObject
{
Q_OBJECT
QString m_path;
public:
explicit FSProxyElement(const QString &path, QObject *parent=nullptr);
QString resolvePath(const QString &path, int *matchlength);
};
class FSProxy : public QObject
{
Q_OBJECT
Database *m_db;
int m_profileId;
QString m_gamename;
QString m_gamedir;
public:
//QString m_path;
QMap< QString, ProxyCacheEntry * > m_cache;
//QMap< QString, QString > m_cache;
QMap< int, OpenFile * > m_openFiles;
QMutex m_filesMutex;
QList< FSProxyElement * > m_proxies;
explicit FSProxy(QObject *parent = nullptr);
void setup(Database *db, int profileId, const QString &gamename, const QString &gamedir);
//void setRoot(const QString &path);
QStringList readdir(const QString &path);
bool getattr(const QString &path, struct stat *st);
int open(const QString &path, bool createIfNeeded=false);
bool close(int fd);
size_t read(int fd, char *buf, size_t size, off_t offset);
int mknod(const QString &qpath, mode_t mode, dev_t dev);
int mkdir(const QString &qpath, mode_t mode);
int unlink(const QString &qpath);
int rmdir(const QString &qpath);
int rename(const QString &qpath, const QString &qnewpath, unsigned int flags);
int truncate(const QString &qpath, off_t offset);
int write(int fd, const char *buf, size_t bufsz, off_t offset);
off_t lseek(int fd, off_t off, int whence);
ProxyCacheEntry *cacheFile(const QString &qpath);
public slots:
void addRoot(const QString &path);
void clear();
void reload();
void cleanCache();
signals:
};
#endif // FSPROXY_H