-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilemanager.cpp
72 lines (65 loc) · 1.86 KB
/
filemanager.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
/*
* filemanager of railroad [- FILEMANGER.CPP -]
**************************************************************************
*/
#include "filemanager.h"
#include <QDebug>
#include <QVariant>
#include <QFileInfo>
#include <QDir>
#include <QStandardPaths>
filemanager::filemanager( QString dir){
file.setFileName(dir);
}
filemanager::~filemanager(){
}
void filemanager::read(){
QFileInfo check(file.filesystemFileName());
if( !check.exists() or !check.isFile() ){
// file does not exist or is a dir
qInfo()<<"__filemanager__: File turnouts.txt does not exist. It will be created when closing the program.";
}
else{
// file exists, read it
isExistent = true;
if(file.open(QIODevice::ReadOnly | QIODevice::Text)){
QTextStream stream(&file);
while (!stream.atEnd()){
status.append( QVariant(stream.readLine()).toBool() );
}
}
file.close();
qDebug() << "__filemanager__: Reading file done.";
}
}
void filemanager::write(){
if( !isExistent ){
QString home = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
QDir newdir;
newdir.mkdir(home + "/.config/StellwerkQt");
QFile file(home + "/.config/StellwerkQt/turnouts.txt");
file.open(QIODevice::WriteOnly);
file.close();
qInfo()<<"__filemanager__: Automatically created turnouts.txt in $HOME/.config/StellwerkQt.";
}
if(file.open( QIODevice::WriteOnly | QIODevice::Text) ){
// We're going to streaming text to the file
QTextStream stream(&file);
for( int writer = 0; writer < weichen.size(); writer++){
stream << weichen.at(writer) <<'\n';
}
file.close();
qDebug() << "__filenamager__: Writing file done.";
}
}
bool filemanager::passstate(int position){
if( isExistent ){
return status.at(position-1);
}
else{
return false;
}
}
void filemanager::add( bool newstate ){
weichen.append(newstate);
}