-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCResource.cpp
More file actions
61 lines (51 loc) · 1.55 KB
/
CResource.cpp
File metadata and controls
61 lines (51 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "CResource.h"
#include "Globals.h"
#include "QJson/json_parser.hh"
#include <QFile>
#include <QMessageBox>
//-------------------------------------------------
CResource::CResource(const QString &file) :
mFile(file)
{
load();
}
//-------------------------------------------------
CResource::~CResource()
{
}
//-------------------------------------------------
void CResource::load()
{
qDebug() << "Loading resource at " << Globals::getProjectPath() + "/" + mFile;
// We read the rs file (which is under JSON format)
QFile file(Globals::getProjectPath() + "/" + mFile);
file.open(QFile::ReadOnly);
QByteArray fileContents = file.readAll();
qDebug() << "File contents: " << fileContents;
// We parse it
QJson::Parser parser;
bool ok;
QVariantMap result = parser.parse(fileContents, &ok).toMap();
if (!ok)
{
QMessageBox::critical(0, "Erreur de lecture JSON", "Le fichier " + mFile + " n'est pas au format JSON, ou possède une erreur de syntaxe!\nLigne: " + QString::number(parser.errorLine()) + "\nErreur: " + parser.errorString());
return;
}
qDebug() << "Read resource file";
mProperties = result;
}
//-------------------------------------------------
void CResource::save()
{
}
//-------------------------------------------------
QVariant& CResource::getProperty(const QString &key)
{
return mProperties[key];
}
//-------------------------------------------------
QVariantMap& CResource::getProperties()
{
return mProperties;
}
//-------------------------------------------------