@@ -204,12 +204,9 @@ void AddonManager::unload(const QString& addonId) {
204204 addon->disable ();
205205 }
206206
207- QDir dir;
208- if (m_addonDirectory.getDirectory (&dir)) {
209- QString addonFileName (QString (" %1.rcc" ).arg (addonId));
210- QString addonFilePath (dir.filePath (addonFileName));
211- QResource::unregisterResource (addonFilePath, mountPath (addonId));
212- }
207+ QResource::unregisterResource (
208+ reinterpret_cast <const uchar*>(m_addons[addonId].m_buffer .constData ()),
209+ mountPath (addonId));
213210
214211 addon->deleteLater ();
215212 }
@@ -242,41 +239,43 @@ bool AddonManager::validateAndLoad(const QString& addonId,
242239 return false ;
243240 }
244241
245- m_addons.insert (addonId, {QByteArray (), addonId, nullptr });
242+ m_addons.insert (addonId, {QByteArray (), QByteArray (), addonId, nullptr });
246243
247244 QString addonFileName (QString (" %1.rcc" ).arg (addonId));
248245
249246 QDir dir;
250247 if (!m_addonDirectory.getDirectory (&dir)) {
251248 return false ;
252249 }
253- QString addonFilePath (dir.filePath (addonFileName));
250+ QByteArray addonFileContents;
251+ if (!m_addonDirectory.readFile (addonFileName, &addonFileContents)) {
252+ return false ;
253+ }
254254
255255 // Hash validation
256- if (checkSha256) {
257- QByteArray addonFileContents;
258-
259- if (!m_addonDirectory.readFile (addonFileName, &addonFileContents)) {
260- return false ;
261- }
262-
263- if (QCryptographicHash::hash (addonFileContents,
264- QCryptographicHash::Sha256) != sha256) {
265- logger.warning () << " Addon hash does not match" << addonId;
266- return false ;
267- }
256+ if (checkSha256 &&
257+ QCryptographicHash::hash (addonFileContents, QCryptographicHash::Sha256) !=
258+ sha256) {
259+ logger.warning () << " Addon hash does not match" << addonId;
260+ return false ;
268261 }
269262
270263 m_addons[addonId].m_sha256 = sha256;
264+ m_addons[addonId].m_buffer = addonFileContents;
265+
271266 QString addonMountPath = mountPath (addonId);
272267
273- if (!QResource::registerResource (addonFilePath, addonMountPath)) {
268+ if (!QResource::registerResource (reinterpret_cast <const uchar*>(
269+ m_addons[addonId].m_buffer .constData ()),
270+ addonMountPath)) {
274271 logger.warning () << " Unable to load resource from file" << addonId;
275272 return false ;
276273 }
277274
278275 if (!loadManifest (QString (" :%1/manifest.json" ).arg (addonMountPath))) {
279- QResource::unregisterResource (addonFilePath, addonMountPath);
276+ QResource::unregisterResource (
277+ reinterpret_cast <const uchar*>(m_addons[addonId].m_buffer .constData ()),
278+ addonMountPath);
280279 return false ;
281280 }
282281
0 commit comments