forked from frida/cryptoshark
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.cpp
More file actions
65 lines (55 loc) · 1.41 KB
/
models.cpp
File metadata and controls
65 lines (55 loc) · 1.41 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
62
63
64
65
#include "models.h"
#include <QCoreApplication>
#include <QDir>
Models *Models::s_instance = nullptr;
Models::Models(QObject *parent) :
QObject(parent),
m_modules(nullptr),
m_functions(nullptr)
{
}
Models::~Models()
{
s_instance = nullptr;
}
Models *Models::instance()
{
if (s_instance == nullptr)
s_instance = new Models();
return s_instance;
}
void Models::open(QString name)
{
m_db = QSqlDatabase::addDatabase("QSQLITE");
m_db.setDatabaseName(dbFilePath(name));
m_db.open();
m_db.exec("PRAGMA synchronous = OFF");
m_db.exec("PRAGMA journal_mode = MEMORY");
delete m_modules;
delete m_functions;
m_modules = new Modules(this, m_db);
m_functions = new Functions(this, m_db);
emit modulesChanged(m_modules);
emit functionsChanged(m_functions);
}
void Models::close()
{
delete m_modules;
delete m_functions;
m_modules = nullptr;
m_functions = nullptr;
emit modulesChanged(m_modules);
emit functionsChanged(m_functions);
m_db.close();
}
QString Models::dbFilePath(QString name)
{
QString fileName = name + ".db3"; // TODO: normalize
#if defined (Q_OS_WIN)
return QCoreApplication::applicationDirPath() + QDir::separator() + fileName;
#elif defined (Q_OS_MAC)
return QDir::homePath() + QDir::separator() + "Desktop" + QDir::separator() + fileName;
#else
return QDir::homePath() + QDir::separator() + fileName;
#endif
}