diff --git a/include/uibase/nxmurl.h b/include/uibase/nxmurl.h index bd06d3d..dd1935e 100644 --- a/include/uibase/nxmurl.h +++ b/include/uibase/nxmurl.h @@ -75,6 +75,21 @@ class QDLLEXPORT NXMUrl : public QObject */ int userId() const { return m_UserId; } + /** + * @return if collection link + */ + bool isCollection() const { return m_Collection; } + + /** + * @return collection ID + */ + QString collectionId() const { return m_CollectionId; } + + /** + * @return collection revision + */ + int collectionRevision() const { return m_CollectionRevision; } + private: QString m_Game; QString m_Key; @@ -82,6 +97,9 @@ class QDLLEXPORT NXMUrl : public QObject int m_FileId; int m_Expires; int m_UserId; + bool m_Collection; + QString m_CollectionId; + int m_CollectionRevision; }; #endif // NXMURL_H diff --git a/src/nxmurl.cpp b/src/nxmurl.cpp index 0e94c05..eab55cf 100644 --- a/src/nxmurl.cpp +++ b/src/nxmurl.cpp @@ -29,16 +29,28 @@ NXMUrl::NXMUrl(const QString& url) { QUrl nxm(url); QUrlQuery query(nxm); - QRegularExpression exp("nxm://[a-z0-9]+/mods/(\\d+)/files/(\\d+)", - QRegularExpression::CaseInsensitiveOption); - auto match = exp.match(url); - if (!match.hasMatch()) { + + static const QRegularExpression modRegex("nxm://[a-z0-9]+/mods/(\\d+)/files/(\\d+)", + QRegularExpression::CaseInsensitiveOption); + static const QRegularExpression collectionRegex( + "nxm://[a-z0-9]+/collections/([a-z0-9]+)/revisions/(\\d+)", + QRegularExpression::CaseInsensitiveOption); + + m_Game = nxm.host(); + + if (const auto modMatch = modRegex.match(url); modMatch.hasMatch()) { + m_Collection = false; + m_ModId = modMatch.captured(1).toInt(); + m_FileId = modMatch.captured(2).toInt(); + m_Key = query.queryItemValue("key"); + m_Expires = query.queryItemValue("expires").toInt(); + m_UserId = query.queryItemValue("user_id").toInt(); + } else if (const auto collectionMatch = collectionRegex.match(url); + collectionMatch.hasMatch()) { + m_Collection = true; + m_CollectionId = collectionMatch.captured(1); + m_CollectionRevision = collectionMatch.captured(2).toInt(); + } else { throw MOBase::InvalidNXMLinkException(url); } - m_Game = nxm.host(); - m_ModId = match.captured(1).toInt(); - m_FileId = match.captured(2).toInt(); - m_Key = query.queryItemValue("key"); - m_Expires = query.queryItemValue("expires").toInt(); - m_UserId = query.queryItemValue("user_id").toInt(); }