-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsystemconfig.cpp
64 lines (49 loc) · 1.1 KB
/
systemconfig.cpp
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
#include "systemconfig.h"
#include <QFile>
#include <QMessageBox>
SystemConfig* SystemConfig::p = nullptr;
QMutex SystemConfig::mutex;
SystemConfig::SystemConfig()
{
filename = "./config.dat";
obj.insert(DF_crypt_lv,1);
obj.insert(DF_no_outdir,true);
obj.insert(DF_outdir_str,"");
obj.insert(DF_threads_count,2);
read();
}
SystemConfig *SystemConfig::getinstance()
{
if( !p )
{
QMutexLocker locker(&mutex);
if( !p )
{
p = new SystemConfig();
}
}
return p;
}
void SystemConfig::save()
{
QFile file(filename);
if( !file.open(QFile::WriteOnly) )
{
//QMessageBox::information(nullptr,"设置失败","配置文件保存失败" );
return;
}
QJsonDocument doc(obj);
QByteArray bytes = doc.toJson();
file.write( bytes );
file.close();
}
void SystemConfig::read()
{
QFile file(filename);
if( !file.open(QFile::ReadOnly) )
return;
QByteArray bytes = file.readAll();
file.close();
QJsonDocument doc = QJsonDocument::fromJson(bytes);
obj = doc.object();
}