Remove hack to circumvent physfs for writing ini files. Require physfs 2 or greater to circumvent
write corruption bug in physfs. Use utf-8 in file names in virtual filesystem.master
parent
8be8d0949f
commit
4e865bcb3c
|
@ -42,9 +42,7 @@
|
|||
class WzConfig : public QSettings
|
||||
{
|
||||
public:
|
||||
/// Set writedir to true to force reading and writing from the physfs write directory. This MUST be used if the
|
||||
/// file already exists!
|
||||
WzConfig(const QString &name, bool writedir = false, QObject *parent = 0) : QSettings(writedir ? PHYSFS_getWriteDir() + name : QString("wz::") + name, QSettings::IniFormat, parent) {}
|
||||
WzConfig(const QString &name, QObject *parent = 0) : QSettings(QString("wz::") + name, QSettings::IniFormat, parent) {}
|
||||
Vector3f vector3f(const QString &name);
|
||||
void setVector3f(const QString &name, const Vector3f &v);
|
||||
Vector3i vector3i(const QString &name);
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
#ifndef QTPHYSFS_H
|
||||
#define QTPHYSFS_H
|
||||
|
||||
// todo use utf-8 when physfs 2.0 is supported on windows
|
||||
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QDateTime>
|
||||
#include <QtCore/QAbstractFileEngine>
|
||||
|
@ -32,18 +30,18 @@ private:
|
|||
PHYSFS_file *fp;
|
||||
FileFlags flags;
|
||||
QString name;
|
||||
QDateTime lastMod; // PHYSFS_getLastModTime
|
||||
QDateTime lastMod;
|
||||
|
||||
void realSetFileName(const QString &file)
|
||||
{
|
||||
name = file;
|
||||
if (!PHYSFS_exists(name.toAscii().constData())) return;
|
||||
if (!PHYSFS_exists(name.toUtf8().constData())) return;
|
||||
// Show potential until actually opened
|
||||
flags = QAbstractFileEngine::ExistsFlag | QAbstractFileEngine::ReadOtherPerm | QAbstractFileEngine::WriteOwnerPerm \
|
||||
| QAbstractFileEngine::ReadOwnerPerm | QAbstractFileEngine::ReadUserPerm | QAbstractFileEngine::WriteUserPerm;
|
||||
lastMod = QDateTime::fromTime_t(PHYSFS_getLastModTime(name.toAscii().constData()));
|
||||
if (PHYSFS_isDirectory(name.toAscii().constData())) flags |= QAbstractFileEngine::DirectoryType;
|
||||
if (PHYSFS_isSymbolicLink(name.toAscii().constData())) flags |= QAbstractFileEngine::LinkType;
|
||||
lastMod = QDateTime::fromTime_t(PHYSFS_getLastModTime(name.toUtf8().constData()));
|
||||
if (PHYSFS_isDirectory(name.toUtf8().constData())) flags |= QAbstractFileEngine::DirectoryType;
|
||||
if (PHYSFS_isSymbolicLink(name.toUtf8().constData())) flags |= QAbstractFileEngine::LinkType;
|
||||
if (!(flags & QAbstractFileEngine::DirectoryType || flags & QAbstractFileEngine::LinkType)) flags |= QAbstractFileEngine::FileType;
|
||||
}
|
||||
|
||||
|
@ -52,37 +50,24 @@ public:
|
|||
PhysicsFileSystem(QString filename) : fp(NULL), flags(0), name(filename) { realSetFileName(filename); }
|
||||
virtual ~PhysicsFileSystem() { if (fp) PHYSFS_close(fp); }
|
||||
bool atEnd() const { return PHYSFS_eof(fp) != 0; }
|
||||
//virtual Iterator *beginEntryList(QDir::Filters filters, const QStringList & filterNames) { return NULL; }
|
||||
virtual bool caseSensitive() const { return true; }
|
||||
virtual bool close() { if (fp) { int retval = PHYSFS_close(fp); fp = NULL; return retval != 0; } else return true; }
|
||||
//virtual bool copy(const QString & newName) { return false; }
|
||||
virtual QStringList entryList(QDir::Filters filters, const QStringList & filterNames) const { return QStringList(); } // dummy, TODO
|
||||
QFile::FileError error() const { return QFile::UnspecifiedError; }
|
||||
QString errorString() const { return QString(PHYSFS_getLastError()); }
|
||||
virtual bool extension(Extension extension, const ExtensionOption * option = 0, ExtensionReturn * output = 0) { return extension == QAbstractFileEngine::AtEndExtension; }
|
||||
virtual FileFlags fileFlags(FileFlags type = FileInfoAll) const { return type & flags; }
|
||||
virtual QDateTime fileTime(FileTime time) const { if (time == QAbstractFileEngine::ModificationTime) return lastMod; else return QDateTime(); }
|
||||
virtual bool flush() { return PHYSFS_flush(fp) != 0; }
|
||||
//virtual int handle() const { return 0; }
|
||||
virtual bool isRelativePath() const { return true; } // in physfs, all paths are relative
|
||||
virtual bool isSequential() const { return true; }
|
||||
virtual bool link(const QString & newName) { return false; }
|
||||
//uchar *map(qint64 offset, qint64 size, QFile::MemoryMapFlags flags) { return NULL; }
|
||||
virtual bool mkdir(const QString & dirName, bool createParentDirectories) const { Q_UNUSED(createParentDirectories); return PHYSFS_mkdir(dirName.toAscii().constData()) != 0; }
|
||||
virtual QString owner(FileOwner owner) const { qWarning("owner() not supported"); return QString(); }
|
||||
virtual uint ownerId(FileOwner owner) const { qWarning("ownerId() not supported"); return -2; }
|
||||
virtual bool mkdir(const QString & dirName, bool createParentDirectories) const { Q_UNUSED(createParentDirectories); return PHYSFS_mkdir(dirName.toUtf8().constData()) != 0; }
|
||||
virtual qint64 pos() const { return PHYSFS_tell(fp); }
|
||||
virtual qint64 read(char *data, qint64 maxlen) { return PHYSFS_read(fp, data, 1, maxlen); }
|
||||
//virtual qint64 readLine(char * data, qint64 maxlen) { return 0; }
|
||||
virtual bool remove() { return PHYSFS_delete(name.toAscii().constData()) != 0; }
|
||||
//virtual bool rename(const QString & newName) { return false; }
|
||||
virtual bool rmdir(const QString & dirName, bool recurseParentDirectories) const { Q_UNUSED(recurseParentDirectories); return PHYSFS_delete(name.toAscii().constData()) != 0; }
|
||||
virtual bool remove() { return PHYSFS_delete(name.toUtf8().constData()) != 0; }
|
||||
virtual bool rmdir(const QString & dirName, bool recurseParentDirectories) const { Q_UNUSED(recurseParentDirectories); return PHYSFS_delete(name.toUtf8().constData()) != 0; }
|
||||
virtual bool seek(qint64 offset) { return PHYSFS_seek(fp, offset) != 0; }
|
||||
virtual bool setPermissions(uint perms) { return false; }
|
||||
virtual bool setSize(qint64 size) { return false; } // oops... no mapping for physfs here!
|
||||
virtual bool supportsExtension(Extension extension) const { return extension == QAbstractFileEngine::AtEndExtension; }
|
||||
//bool unmap(uchar * address) { return NULL; }
|
||||
virtual qint64 write(const char * data, qint64 len) { return PHYSFS_write(fp, data, len, 1); }
|
||||
virtual qint64 write(const char *data, qint64 len) { return PHYSFS_write(fp, data, 1, len); }
|
||||
|
||||
virtual qint64 size() const
|
||||
{
|
||||
|
@ -90,10 +75,10 @@ public:
|
|||
{
|
||||
if (!PHYSFS_exists(name.toUtf8().constData())) return 0;
|
||||
PHYSFS_file *tmp;
|
||||
tmp = PHYSFS_openRead(name.toAscii().constData());
|
||||
tmp = PHYSFS_openRead(name.toUtf8().constData());
|
||||
if (!tmp)
|
||||
{
|
||||
qWarning("Failed to open %s for size info: %s", name.toAscii().constData(), PHYSFS_getLastError());
|
||||
qWarning("Failed to open %s for size info: %s", name.toUtf8().constData(), PHYSFS_getLastError());
|
||||
return -1;
|
||||
}
|
||||
int retval = PHYSFS_fileLength(tmp);
|
||||
|
@ -114,47 +99,31 @@ public:
|
|||
if (mode & QIODevice::WriteOnly)
|
||||
{
|
||||
flags = QAbstractFileEngine::WriteOwnerPerm | QAbstractFileEngine::WriteUserPerm | QAbstractFileEngine::FileType;
|
||||
fp = PHYSFS_openWrite(name.toAscii().constData()); // will truncate
|
||||
fp = PHYSFS_openWrite(name.toUtf8().constData()); // will truncate
|
||||
}
|
||||
else if (mode & QIODevice::ReadOnly)
|
||||
{
|
||||
flags = QAbstractFileEngine::ReadOwnerPerm | QAbstractFileEngine::ReadUserPerm | QAbstractFileEngine::FileType | QAbstractFileEngine::ReadOtherPerm;
|
||||
fp = PHYSFS_openRead(name.toAscii().constData());
|
||||
fp = PHYSFS_openRead(name.toUtf8().constData());
|
||||
}
|
||||
else if (mode & QIODevice::Append)
|
||||
{
|
||||
flags = QAbstractFileEngine::WriteOwnerPerm | QAbstractFileEngine::WriteUserPerm | QAbstractFileEngine::FileType;
|
||||
fp = PHYSFS_openAppend(name.toAscii().constData());
|
||||
fp = PHYSFS_openAppend(name.toUtf8().constData());
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning("Bad file open mode: %d", (int)mode);
|
||||
}
|
||||
if (fp) flags |= QAbstractFileEngine::ExistsFlag;
|
||||
else qWarning("Failed to open %s: %s", name.toAscii().constData(), PHYSFS_getLastError());
|
||||
else qWarning("Failed to open %s: %s", name.toUtf8().constData(), PHYSFS_getLastError());
|
||||
return fp != NULL;
|
||||
}
|
||||
|
||||
virtual QString fileName(FileName file = DefaultName) const
|
||||
{
|
||||
switch (file)
|
||||
{
|
||||
case QAbstractFileEngine::DefaultName:
|
||||
return name;
|
||||
case QAbstractFileEngine::CanonicalName:
|
||||
case QAbstractFileEngine::AbsoluteName:
|
||||
if (PHYSFS_exists(name.toAscii().constData()))
|
||||
{
|
||||
return "wz::" + name;
|
||||
}
|
||||
else
|
||||
{
|
||||
return QString(PHYSFS_getWriteDir()) + name;
|
||||
}
|
||||
default:
|
||||
qWarning("Unsupported path lookup type (%d)", (int)file);
|
||||
return QString(PHYSFS_getRealDir(name.toAscii().constData()));
|
||||
}
|
||||
if (file == QAbstractFileEngine::AbsolutePathName) return PHYSFS_getWriteDir(); // hack for QSettings
|
||||
return "wz::" + name;
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -54,7 +54,7 @@ static const char *fileName = "config";
|
|||
// ////////////////////////////////////////////////////////////////////////////
|
||||
bool loadConfig()
|
||||
{
|
||||
WzConfig ini(fileName, true);
|
||||
WzConfig ini(fileName);
|
||||
if (ini.status() != QSettings::NoError)
|
||||
{
|
||||
debug(LOG_ERROR, "Could not open configuration file \"%s\"", fileName);
|
||||
|
@ -133,7 +133,7 @@ bool loadConfig()
|
|||
// ////////////////////////////////////////////////////////////////////////////
|
||||
bool saveConfig()
|
||||
{
|
||||
WzConfig ini(fileName, true);
|
||||
WzConfig ini(fileName);
|
||||
if (ini.status() != QSettings::NoError)
|
||||
{
|
||||
debug(LOG_ERROR, "Could not open configuration file \"%s\"", fileName);
|
||||
|
@ -208,7 +208,7 @@ bool saveConfig()
|
|||
// Ensures that others' games don't change our own configuration settings
|
||||
bool reloadMPConfig(void)
|
||||
{
|
||||
WzConfig ini(fileName, true);
|
||||
WzConfig ini(fileName);
|
||||
if (ini.status() != QSettings::NoError)
|
||||
{
|
||||
debug(LOG_ERROR, "Could not open configuration file \"%s\"", fileName);
|
||||
|
|
|
@ -595,6 +595,11 @@ static void initialize_PhysicsFS(const char* argv_0)
|
|||
compiled.major, compiled.minor, compiled.patch);
|
||||
debug(LOG_WZ, "Linked against PhysFS version: %d.%d.%d",
|
||||
linked.major, linked.minor, linked.patch);
|
||||
if (linked.major < 2)
|
||||
{
|
||||
debug(LOG_FATAL, "At least version 2 of PhysicsFS required!");
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue