Exemple #1
0
    const QByteArray Helpers::createBackup(const QDir& keystore) {
        const QByteArray settingsData = exportSettings();
        const QByteArray addressData = exportAddresses(keystore);
        QByteArray testnetData;

        QDir testnet(keystore);
        // can't use && because C++ doesn't enforce execution order AFAIK
        if ( testnet.cd("../testnet") ) {
            if ( testnet.cd("keystore") ) {
                testnetData = exportAddresses(testnet);
            }
        }

        QByteArray all; // all without checksum
        QByteArray result; // full result with 16bit checksum
        QDataStream allStream(&all, QIODevice::WriteOnly);
        QDataStream resultStream(&result, QIODevice::WriteOnly);
        quint32 segmentSize;

        segmentSize = settingsData.size();
        allStream << segmentSize;
        allStream << settingsData;
        segmentSize = addressData.size();
        allStream << segmentSize;
        allStream << addressData;
        // add testnet addresses if present
        if ( testnetData.size() > 0 ) {
            segmentSize = testnetData.size();
            allStream << segmentSize;
            allStream << testnetData;
        }

        quint32 allSize = all.size();
        quint16 crc = qChecksum(all.data(), all.size());
        resultStream << allSize;
        resultStream << crc;
        resultStream << all;

        return qCompress(result, 9);
    }
Exemple #2
0
//! Called when program is closed. Saves settings and writes them to disk.
void Window::closeEvent(QCloseEvent *event)
{
	exportSettings();
	config->xmlWrite(this->configFileURI);
	event->accept();
}