blob: 8a652e969336a57bf34800f1db94564bf73fbcd0 (
plain)
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
|
//===========================================
// Lumina-DE source code
// Copyright (c) 2013, Ken Moore
// Available under the 3-clause BSD license
// See the LICENSE file for full details
//===========================================
#include "LuminaUtils.h"
int LUtils::runCmd(QString cmd, QStringList args){
QProcess *proc = new QProcess;
proc->setProcessChannelMode(QProcess::MergedChannels);
if(args.isEmpty()){
proc->start(cmd);
}else{
proc->start(cmd, args);
}
while(!proc->waitForFinished(300)){
QCoreApplication::processEvents();
}
int ret = proc->exitCode();
delete proc;
return ret;
}
QStringList LUtils::getCmdOutput(QString cmd, QStringList args){
QProcess *proc = new QProcess;
proc->setProcessChannelMode(QProcess::MergedChannels);
if(args.isEmpty()){
proc->start(cmd);
}else{
proc->start(cmd,args);
}
while(!proc->waitForFinished(300)){
QCoreApplication::processEvents();
}
QStringList out = QString(proc->readAllStandardOutput()).split("\n");
delete proc;
return out;
}
QStringList LUtils::readFile(QString filepath){
QStringList out;
QFile file(filepath);
if(file.open(QIODevice::Text | QIODevice::ReadOnly)){
QTextStream in(&file);
while(!in.atEnd()){
out << in.readLine();
}
file.close();
}
return out;
}
bool LUtils::writeFile(QString filepath, QStringList contents, bool overwrite){
QFile file(filepath);
QFile::OpenMode mode = overwrite ? (QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate) : (QIODevice::WriteOnly | QIODevice::Text);
bool ok = false;
if(file.open( mode ) ){
QTextStream out(&file);
for(int i=0; i<contents.length(); i++){ out << contents[i]; }
file.close();
ok = true;
}
return ok;
}
|