-
Notifications
You must be signed in to change notification settings - Fork 23
/
fileio.cpp
154 lines (132 loc) · 3.81 KB
/
fileio.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#include "fileio.h"
#include <QFile>
#include <QTextStream>
#include <QStandardPaths>
#include <QDebug>
#include <QDir>
FileIO::FileIO(QObject *parent) :
QObject(parent)
{
}
QString FileIO::read()
{
if (mSource.isEmpty()){
emit error("source is empty");
return QString();
}
QString mDataPath = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation).value(0);
qDebug() << "Data Path: " << mDataPath;
QDir myDir(mDataPath);
if (!myDir.exists()) {
bool ok = myDir.mkpath(mDataPath);
if(!ok) {
qWarning() << "Couldn't create dir. " << mDataPath;
}
qDebug() << "created directory path" << mDataPath;
}
QFile file(mDataPath + "/" + mSource);
QString fileContent;
if ( file.open(QIODevice::ReadOnly) ) {
QString line;
QTextStream t( &file );
do {
line = t.readLine();
fileContent += line;
} while (!line.isNull());
file.close();
} else {
emit error("Unable to open the file");
return QString();
}
return fileContent;
}
QString FileIO::readPrivate()
{
if (mSource.isEmpty()){
emit error("source is empty");
return QString();
}
QString mDataPath = QStandardPaths::standardLocations(QStandardPaths::AppLocalDataLocation).value(0);
qDebug() << "Data Path: " << mDataPath;
QDir myDir(mDataPath);
if (!myDir.exists()) {
bool ok = myDir.mkpath(mDataPath);
if(!ok) {
qWarning() << "Couldn't create dir. " << mDataPath;
}
qDebug() << "created directory path" << mDataPath;
}
QFile file(mDataPath + "/" + mSource);
QString fileContent;
if ( file.open(QIODevice::ReadOnly) ) {
QString line;
QTextStream t( &file );
fileContent = t.readAll();
file.close();
} else {
emit error("Unable to open the file");
return QString();
}
return fileContent;
}
bool FileIO::write(const QString& data)
{
if (mSource.isEmpty())
return false;
QString mDataPath = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation).value(0);
qDebug() << "Data Path: " << mDataPath;
QDir myDir(mDataPath);
if (!myDir.exists()) {
bool ok = myDir.mkpath(mDataPath);
if(!ok) {
qWarning() << "Couldn't create dir. " << mDataPath;
}
qDebug() << "created directory path" << mDataPath;
}
QFile file(mDataPath + "/" + mSource);
if (!file.open(QFile::WriteOnly | QFile::Truncate))
return false;
QTextStream out(&file);
out << data;
file.close();
return true;
}
bool FileIO::writePrivate(const QString& data)
{
if (mSource.isEmpty())
return false;
QString mDataPath = QStandardPaths::standardLocations(QStandardPaths::AppLocalDataLocation).value(0);
qDebug() << "Data Path: " << mDataPath;
QDir myDir(mDataPath);
if (!myDir.exists()) {
bool ok = myDir.mkpath(mDataPath);
if(!ok) {
qWarning() << "Couldn't create dir. " << mDataPath;
}
qDebug() << "created directory path" << mDataPath;
}
QFile file(mDataPath + "/" + mSource);
if (!file.open(QFile::WriteOnly | QFile::Truncate))
return false;
QTextStream out(&file);
out << data;
file.close();
return true;
}
QString FileIO::readPresets()
{
QString mDataPath = "/system/etc/com.volla.launcher/volla_properties.json";
qDebug() << "Data Path: " << mDataPath;
QFile file(mDataPath);
QString fileContent;
if ( file.open(QIODevice::ReadOnly) ) {
QString line;
QTextStream t( &file );
fileContent = t.readAll();
file.close();
} else {
emit error("Unable to open the file");
return QString();
}
return fileContent;
}