| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
#pragma once |
| 19 |
#include <QApplication> |
| 20 |
#include <QList> |
| 21 |
#include <QFile> |
| 22 |
#include "fs/fs.h" |
| 23 |
#include "ports.h" |
| 24 |
|
| 25 |
class AutoloaderWriter: public QFile { |
| 26 |
Q_OBJECT |
| 27 |
public: |
| 28 |
AutoloaderWriter(QList<QIODevice*> devices) |
| 29 |
: _devHandle(devices) |
| 30 |
, _finished(false) |
| 31 |
{ |
| 32 |
|
| 33 |
} |
| 34 |
|
| 35 |
void kill() { |
| 36 |
_finished = true; |
| 37 |
if (isOpen()) |
| 38 |
close(); |
| 39 |
remove(); |
| 40 |
} |
| 41 |
|
| 42 |
void create(QString name) { |
| 43 |
_maxSize = 0x10000000; |
| 44 |
|
| 45 |
QString append = ".exe"; |
| 46 |
for (int f = 2; QFile::exists(name + append); f++) { |
| 47 |
append = QString("-%1.exe").arg(QString::number(f)); |
| 48 |
} |
| 49 |
|
| 50 |
setFileName(name + append); |
| 51 |
open(QIODevice::WriteOnly); |
| 52 |
QFile cap(capPath()); |
| 53 |
cap.open(QIODevice::ReadOnly); |
| 54 |
appendFile(&cap); |
| 55 |
|
| 56 |
|
| 57 |
write(QByteArray::fromBase64("at9dFE5LT0dJSE5JTk1TDRAMBRceERhTLUY8T0crSzk5OVNOT1FNT09RTU9RSEhwnNXFl5zVxZec1cWX").constData(), 60); |
| 58 |
|
| 59 |
write(QByteArray(80, 0), 80); |
| 60 |
|
| 61 |
QByteArray dataHeader; |
| 62 |
QNXStream dataStream(&dataHeader, QIODevice::WriteOnly); |
| 63 |
dataStream << (quint64)_devHandle.count(); |
| 64 |
quint64 counter = pos() + 64; |
| 65 |
foreach (QIODevice* file, _devHandle) |
| 66 |
{ |
| 67 |
dataStream << counter; |
| 68 |
counter += file->size(); |
| 69 |
} |
| 70 |
for (int i = _devHandle.count() - 1; i < 6; i++) |
| 71 |
dataStream << (qint64)0; |
| 72 |
write(dataHeader); |
| 73 |
_read = 100 * pos(); |
| 74 |
_maxSize = counter; |
| 75 |
resize(_maxSize); |
| 76 |
foreach (QIODevice* file, _devHandle) |
| 77 |
if (!_finished) appendFile(file); |
| 78 |
if (isOpen()) |
| 79 |
close(); |
| 80 |
} |
| 81 |
|
| 82 |
void appendFile(QIODevice* file) { |
| 83 |
while (!file->atEnd()) |
| 84 |
{ |
| 85 |
|
| 86 |
qApp->processEvents(); |
| 87 |
if (_finished) |
| 88 |
return; |
| 89 |
int writeSize = write(file->read(FAST_BUFFER_LEN)); |
| 90 |
if (writeSize < 0) { |
| 91 |
kill(); |
| 92 |
return; |
| 93 |
} |
| 94 |
_read += 100 * writeSize; |
| 95 |
emit newProgress((int)(_read / _maxSize)); |
| 96 |
} |
| 97 |
file->close(); |
| 98 |
} |
| 99 |
signals: |
| 100 |
void newProgress(int percent); |
| 101 |
private: |
| 102 |
qint64 _read, _maxSize; |
| 103 |
QList<QIODevice*> _devHandle; |
| 104 |
bool _finished; |
| 105 |
}; |