forked from anak10thn/ignsdk-qt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fs.cpp
99 lines (88 loc) · 1.87 KB
/
fs.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "fs.h"
fs::fs(QObject *parent) :
QObject(parent)
{
}
bool fs::file(const QString &path, const QString &opt){
QFile file(path);
if(opt == "check"){
if(file.exists()){
return true;
}
else {
return false;
}
}
else if(opt == "remove"){
if(file.remove()){
return true;
}
else {
return false;
}
}
}
QString fs::app_dir_path(){
return QApplication::applicationDirPath();
}
QString fs::home_path(){
QString home = QDir::homePath();
return home;
}
bool fs::create_file(const QString &path, const QString &data){
QFile file(path);
if (file.open(QIODevice::WriteOnly | QIODevice::Text)){
QTextStream out(&file);
out << data;
return true;
}
else {
return false;
}
file.close();
}
QString fs::read_file(const QString &path){
//QStringList fields;
QFile file(path);
if (file.open(QIODevice::ReadOnly | QIODevice::Text)){
QTextStream out(&file);
/*while(!out.atEnd()){
fields.append(out.readLine());
}*/
QString data = out.readLine();
/*foreach (const QString text, fields){
qDebug() << text.toStdString();
}*/
file.close();
return data;
}
}
bool fs::dir(const QString &path, const QString &opt){
QDir dir;
if(opt == "create"){
if(dir.mkdir(path)){
return true;
}
else{
return false;
}
}
else if(opt == "check"){
dir = path;
if(dir.exists()){
return true;
}
else {
return false;
}
}
else if(opt == "remove"){
if(dir.rmdir(path)){
return true;
}
else {
return false;
}
}
}