Changeset View
Changeset View
Standalone View
Standalone View
src/util/externalcommandhelper.cpp
Show First 20 Lines • Show All 84 Lines • ▼ Show 20 Line(s) | 47 | { | |||
---|---|---|---|---|---|
85 | return reply; | 85 | return reply; | ||
86 | } | 86 | } | ||
87 | 87 | | |||
88 | /** Generates cryptographic nonce | 88 | /** Generates cryptographic nonce | ||
89 | * @return nonce | 89 | * @return nonce | ||
90 | */ | 90 | */ | ||
91 | quint64 ExternalCommandHelper::getNonce() | 91 | quint64 ExternalCommandHelper::getNonce() | ||
92 | { | 92 | { | ||
93 | quint64 nonce = m_Generator.generate(); | 93 | const quint64 nonce = m_Generator.generate(); | ||
94 | m_Nonces.insert(nonce); | 94 | m_Nonces.insert(nonce); | ||
95 | return nonce; | 95 | return nonce; | ||
96 | } | 96 | } | ||
97 | 97 | | |||
98 | /** Reads the given number of bytes from the sourceDevice into the given buffer. | 98 | /** Reads the given number of bytes from the sourceDevice into the given buffer. | ||
99 | @param sourceDevice device or file to read from | 99 | @param sourceDevice device or file to read from | ||
100 | @param buffer buffer to store the bytes read in | 100 | @param buffer buffer to store the bytes read in | ||
101 | @param offset offset where to begin reading | 101 | @param offset offset where to begin reading | ||
Show All 28 Lines | 129 | /** Writes the data from buffer to a given device or file. | |||
130 | @param targetDevice device or file to write to | 130 | @param targetDevice device or file to write to | ||
131 | @param buffer the data that we write | 131 | @param buffer the data that we write | ||
132 | @param offset offset where to begin writing | 132 | @param offset offset where to begin writing | ||
133 | @return true on success | 133 | @return true on success | ||
134 | */ | 134 | */ | ||
135 | bool ExternalCommandHelper::writeData(const QString &targetDevice, const QByteArray& buffer, qint64 offset) | 135 | bool ExternalCommandHelper::writeData(const QString &targetDevice, const QByteArray& buffer, qint64 offset) | ||
136 | { | 136 | { | ||
137 | QFile device(targetDevice); | 137 | QFile device(targetDevice); | ||
138 | | ||||
138 | if (!device.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Unbuffered)) { | 139 | if (!device.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Unbuffered)) { | ||
139 | qCritical() << xi18n("Could not open device <filename>%1</filename> for writing.", targetDevice); | 140 | qCritical() << xi18n("Could not open device <filename>%1</filename> for writing.", targetDevice); | ||
140 | return false; | 141 | return false; | ||
141 | } | 142 | } | ||
142 | 143 | | |||
143 | if (!device.seek(offset)) { | 144 | if (!device.seek(offset)) { | ||
144 | qCritical() << xi18n("Could not seek position %1 on device <filename>%2</filename>.", offset, targetDevice); | 145 | qCritical() << xi18n("Could not seek position %1 on device <filename>%2</filename>.", offset, targetDevice); | ||
145 | return false; | 146 | return false; | ||
146 | } | 147 | } | ||
147 | 148 | | |||
148 | if (device.write(buffer) != buffer.size()) { | 149 | if (device.write(buffer) != buffer.size()) { | ||
149 | qCritical() << xi18n("Could not write to device <filename>%1</filename>.", targetDevice); | 150 | qCritical() << xi18n("Could not write to device <filename>%1</filename>.", targetDevice); | ||
150 | return false; | 151 | return false; | ||
151 | } | 152 | } | ||
153 | | ||||
152 | return true; | 154 | return true; | ||
153 | } | 155 | } | ||
154 | 156 | | |||
155 | // If targetDevice is empty then return QByteArray with data that was read from disk. | 157 | // If targetDevice is empty then return QByteArray with data that was read from disk. | ||
156 | QVariantMap ExternalCommandHelper::copyblocks(const QByteArray& signature, const quint64 nonce, const QString& sourceDevice, const qint64 sourceFirstByte, const qint64 sourceLength, const QString& targetDevice, const qint64 targetFirstByte, const qint64 blockSize) | 158 | QVariantMap ExternalCommandHelper::copyblocks(const QByteArray& signature, const quint64 nonce, const QString& sourceDevice, const qint64 sourceFirstByte, const qint64 sourceLength, const QString& targetDevice, const qint64 targetFirstByte, const qint64 blockSize) | ||
157 | { | 159 | { | ||
158 | QVariantMap reply; | 160 | QVariantMap reply; | ||
159 | reply[QStringLiteral("success")] = true; | 161 | reply[QStringLiteral("success")] = true; | ||
▲ Show 20 Lines • Show All 228 Lines • Show Last 20 Lines |