mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 05:23:33 +02:00
Use a magic number and version on the metavoxel file, put it in the resources
directory.
This commit is contained in:
parent
110cf93cc4
commit
2f0ea47e5a
1 changed files with 28 additions and 6 deletions
|
@ -9,7 +9,9 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#include <QCoreApplication>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
#include <QDir>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QSaveFile>
|
#include <QSaveFile>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
|
@ -304,19 +306,34 @@ MetavoxelPersister::MetavoxelPersister(MetavoxelServer* server) :
|
||||||
_server(server) {
|
_server(server) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* SAVE_FILE = "metavoxels.dat";
|
const char* SAVE_FILE = "/resources/metavoxels.dat";
|
||||||
|
|
||||||
|
const int FILE_MAGIC = 0xDADAFACE;
|
||||||
|
const int FILE_VERSION = 1;
|
||||||
|
|
||||||
void MetavoxelPersister::load() {
|
void MetavoxelPersister::load() {
|
||||||
QFile file(SAVE_FILE);
|
QString path = QCoreApplication::applicationDirPath() + SAVE_FILE;
|
||||||
|
QFile file(path);
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MetavoxelData data;
|
MetavoxelData data;
|
||||||
{
|
{
|
||||||
QDebug debug = qDebug() << "Reading from" << SAVE_FILE << "...";
|
QDebug debug = qDebug() << "Reading from" << path << "...";
|
||||||
file.open(QIODevice::ReadOnly);
|
file.open(QIODevice::ReadOnly);
|
||||||
QDataStream inStream(&file);
|
QDataStream inStream(&file);
|
||||||
Bitstream in(inStream);
|
Bitstream in(inStream);
|
||||||
|
int magic, version;
|
||||||
|
in >> magic;
|
||||||
|
if (magic != FILE_MAGIC) {
|
||||||
|
debug << "wrong file magic: " << magic;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
in >> version;
|
||||||
|
if (version != FILE_VERSION) {
|
||||||
|
debug << "wrong file version: " << version;
|
||||||
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
in >> data;
|
in >> data;
|
||||||
} catch (const BitstreamException& e) {
|
} catch (const BitstreamException& e) {
|
||||||
|
@ -330,12 +347,17 @@ void MetavoxelPersister::load() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MetavoxelPersister::save(const MetavoxelData& data) {
|
void MetavoxelPersister::save(const MetavoxelData& data) {
|
||||||
QDebug debug = qDebug() << "Writing to" << SAVE_FILE << "...";
|
QString path = QCoreApplication::applicationDirPath() + SAVE_FILE;
|
||||||
QSaveFile file(SAVE_FILE);
|
QDir directory = QFileInfo(path).dir();
|
||||||
|
if (!directory.exists()) {
|
||||||
|
directory.mkpath(".");
|
||||||
|
}
|
||||||
|
QDebug debug = qDebug() << "Writing to" << path << "...";
|
||||||
|
QSaveFile file(path);
|
||||||
file.open(QIODevice::WriteOnly);
|
file.open(QIODevice::WriteOnly);
|
||||||
QDataStream outStream(&file);
|
QDataStream outStream(&file);
|
||||||
Bitstream out(outStream);
|
Bitstream out(outStream);
|
||||||
out << data;
|
out << FILE_MAGIC << FILE_VERSION << data;
|
||||||
out.flush();
|
out.flush();
|
||||||
file.commit();
|
file.commit();
|
||||||
debug << "done.";
|
debug << "done.";
|
||||||
|
|
Loading…
Reference in a new issue