11#include " package_manager.hpp"
2+ #include " package_url_utils.hpp"
23#include " effect_registry.hpp"
34#include " settings_manager.hpp"
45#include " shader_compiler.hpp"
@@ -46,10 +47,6 @@ bool isValidPackageType(const QString &packageType) {
4647 packageType == QStringLiteral (" object" ) || packageType == QStringLiteral (" transition" );
4748}
4849
49- bool isSecureNetworkUrl (const QUrl &url) {
50- return url.isValid () && url.scheme () == QStringLiteral (" https" ) && !url.host ().isEmpty ();
51- }
52-
5350bool writeJsonAtomically (const QString &path, const QJsonDocument &document) {
5451 QSaveFile file (path);
5552 if (!file.open (QIODevice::WriteOnly))
@@ -272,7 +269,7 @@ void PackageManager::saveRepositories(const QVariantList &repos) {
272269}
273270
274271void PackageManager::addRepository (const QString &url, bool enabled, int priority) {
275- if (!isSecureNetworkUrl (QUrl (url)))
272+ if (!Internal:: isSecureNetworkUrl (QUrl (url)))
276273 return ;
277274 QVariantList repos = repositories ();
278275 for (const auto &r : repos) {
@@ -369,16 +366,6 @@ void PackageManager::refreshRepositories() {
369366 continue ;
370367
371368 QString repoUrl = repo.value (QStringLiteral (" url" )).toString ();
372- QUrl baseUrl (repoUrl);
373- QString basePath = repoUrl;
374- if (basePath.endsWith (QStringLiteral (" /repo.json" )))
375- basePath.chop (9 );
376- else if (basePath.endsWith (QStringLiteral (" .json" ))) {
377- int slash = basePath.lastIndexOf (' /' );
378- if (slash != -1 )
379- basePath = basePath.left (slash);
380- }
381-
382369 struct SyncCtx {
383370 QVariantMap repoInfo;
384371 QByteArray catalogData;
@@ -391,15 +378,15 @@ void PackageManager::refreshRepositories() {
391378 if (!fetchUrl.path ().endsWith (QStringLiteral (" /repo.json" )))
392379 fetchUrl.setPath (fetchUrl.path () + (fetchUrl.path ().endsWith (' /' ) ? QStringLiteral (" repo.json" ) : QStringLiteral (" /repo.json" )));
393380
394- if (!isSecureNetworkUrl (fetchUrl)) {
381+ if (!Internal:: isSecureNetworkUrl (fetchUrl)) {
395382 m_pendingRequests--;
396383 emit errorOccurred (tr (" Repository URL must use HTTPS: %1" ).arg (repoUrl));
397384 tryFinishSyncLegacy (installed);
398385 continue ;
399386 }
400387 QNetworkReply *reply = m_networkManager->get (packageNetworkRequest (fetchUrl));
401388 enforceReplySizeLimit (reply, kMaxRepositoryResponseBytes );
402- connect (reply, &QNetworkReply::finished, this , [this , reply, fetchUrl, repoUrl, basePath, ctx, installed]() {
389+ connect (reply, &QNetworkReply::finished, this , [this , reply, fetchUrl, repoUrl, ctx, installed]() {
403390 reply->deleteLater ();
404391 m_pendingRequests--;
405392
@@ -411,13 +398,9 @@ void PackageManager::refreshRepositories() {
411398 ctx->repoInfo [QStringLiteral (" name" )] = repoObj.value (QStringLiteral (" repo_name" )).toString ();
412399 QString catalogUrl = repoObj.value (QStringLiteral (" catalog_url" )).toString ();
413400 if (!catalogUrl.isEmpty ()) {
414- QUrl absUrl;
415- if (catalogUrl.startsWith (QStringLiteral (" http://" )) || catalogUrl.startsWith (QStringLiteral (" https://" )))
416- absUrl = QUrl (catalogUrl);
417- else
418- absUrl = QUrl (basePath + QStringLiteral (" /" ) + catalogUrl);
401+ const QUrl absUrl = Internal::resolveRepositoryReference (fetchUrl, catalogUrl);
419402
420- if (!isSecureNetworkUrl (absUrl)) {
403+ if (!Internal:: isSecureNetworkUrl (absUrl)) {
421404 emit errorOccurred (tr (" Catalog URL must use HTTPS: %1" ).arg (absUrl.toString ()));
422405 onCatalogFetched (ctx->repoInfo , {}, installed);
423406 tryFinishSyncLegacy (installed);
@@ -646,7 +629,7 @@ void PackageManager::fetchPackageMetadata(const QString &packageId, const QStrin
646629
647630 setStatus (tr (" Fetching package details: %1" ).arg (packageId));
648631 QUrl url (metadataUrl);
649- if (!isSecureNetworkUrl (url)) {
632+ if (!Internal:: isSecureNetworkUrl (url)) {
650633 emit errorOccurred (tr (" Invalid or insecure metadata URL for package: %1" ).arg (packageId));
651634 return ;
652635 }
@@ -837,7 +820,7 @@ void PackageManager::downloadPackage(const QString &packageId, const QUrl &url,
837820 emit errorOccurred (tr (" Invalid package ID or type." ));
838821 return ;
839822 }
840- if (!isSecureNetworkUrl (url)) {
823+ if (!Internal:: isSecureNetworkUrl (url)) {
841824 setBusy (false );
842825 emit errorOccurred (tr (" Invalid or insecure package download URL." ));
843826 return ;
@@ -884,7 +867,11 @@ void PackageManager::downloadPackage(const QString &packageId, const QUrl &url,
884867 emit errorOccurred (tr (" Package archive exceeds the maximum allowed size." ));
885868 return ;
886869 }
887- file.write (data);
870+ if (file.write (data) != data.size ()) {
871+ setBusy (false );
872+ emit errorOccurred (tr (" Failed to write the complete downloaded package." ));
873+ return ;
874+ }
888875 file.close ();
889876
890877 // SHA256 verification
0 commit comments