Skip to content

Commit b715d1a

Browse files
authored
Use the in-memory buffer for loading add-ons (#10960)
1 parent e0ed3c3 commit b715d1a

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

src/addons/manager/addonindex.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ QList<AddonData> AddonIndex::extractAddonsFromIndex(
264264
QJsonObject addon = item.toObject();
265265
addons.append(
266266
{QByteArray::fromHex(addon["sha256"].toString().toLocal8Bit()),
267-
addon["id"].toString(), nullptr});
267+
QByteArray(), addon["id"].toString(), nullptr});
268268
}
269269

270270
return addons;

src/addons/manager/addonindex.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ constexpr const char* ADDON_INDEX_SIGNATURE_FILENAME = "manifest.json.sig";
2323
// addon does not need to be loaded for unmatched conditions.
2424
struct AddonData {
2525
QByteArray m_sha256;
26+
QByteArray m_buffer;
2627
QString m_addonId;
2728
Addon* m_addon;
2829
};

src/addons/manager/addonmanager.cpp

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)