forked from huming17/php-decoder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.cpp
More file actions
91 lines (81 loc) · 1.94 KB
/
util.cpp
File metadata and controls
91 lines (81 loc) · 1.94 KB
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
#include <QApplication>
#include <QStringList>
#include <QDir>
#include <QFileInfo>
#include <QProcess>
#include <QDateTime>
#include <QDebug>
#include "util.h"
QStringList getFileList(const QString &path)
{
QFileInfo fileinfo(path);
if ( fileinfo.isFile() ) {
return QStringList(path);
} else if ( fileinfo.isDir() ) {
QStringList fileList;
QDir dir(fileinfo.absoluteFilePath());
dir.setFilter(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
QFileInfoList fileinfoList = dir.entryInfoList();
QFileInfoList::ConstIterator i;
for( i=fileinfoList.cbegin();i!=fileinfoList.cend();i++ ) {
QFileInfo fileinfo = *i;
if ( fileinfo.isDir() ){
fileList.append(getFileList(fileinfo.absoluteFilePath()));
} else if( fileinfo.isFile() ) {
fileList.append(fileinfo.absoluteFilePath());
}
}
qApp->processEvents();
return fileList;
} else {
return QStringList();
}
}
bool overwriteFile(QString from, QString to)
{
if ( QFile::exists(to) ) {
if ( !QFile::remove(to) ) {
return false;
}
}
return QFile::copy(from,to);
}
QByteArray prettyCode(QByteArray code){
QProcess process;
process.setProgram(".\\phpcb.exe");
process.start();
if ( process.waitForStarted() ){
process.write(code);
process.closeWriteChannel();
process.waitForFinished();
code = process.readAll();
} else {
qDebug()<<"pretty code failed!";
}
qApp->processEvents();
return code;
}
bool putFileContents(QString filename, QByteArray data)
{
QFile file(filename);
if ( !file.open(QIODevice::WriteOnly) ) {
return false;
}
qint64 written = file.write(data);
file.close();
return data.length() == written;
}
QByteArray getFileContents(QString filename)
{
QFile file(filename);
file.open(QIODevice::ReadOnly);
return file.readAll();
}
QString createTempDir()
{
QString tempSubDir = QString::number(QDateTime::currentMSecsSinceEpoch());
QDir temp = QDir::temp();
temp.mkdir(tempSubDir);
temp.cd(tempSubDir);
return temp.absolutePath();
}