Skip to content

Add basic NXM collections link parsing#184

Merged
Silarn merged 2 commits into
masterfrom
dev/collections-link-handling
May 2, 2026
Merged

Add basic NXM collections link parsing#184
Silarn merged 2 commits into
masterfrom
dev/collections-link-handling

Conversation

@Silarn

@Silarn Silarn commented Apr 29, 2026

Copy link
Copy Markdown
Member

No description provided.

Comment thread src/nxmurl.cpp
Comment on lines 30 to 60
QUrl nxm(url);
QUrlQuery query(nxm);
QRegularExpression exp("nxm://[a-z0-9]+/mods/(\\d+)/files/(\\d+)",
QRegularExpression::CaseInsensitiveOption);
auto match = exp.match(url);
// nxm://starfield/collections/7ou329/revisions/24
QRegularExpression modsExp("nxm://[a-z0-9]+/mods/(\\d+)/files/(\\d+)",
QRegularExpression::CaseInsensitiveOption);
QRegularExpression collectionsExp(
"nxm://[a-z0-9]+/collections/([a-z0-9]+)/revisions/(\\d+)",
QRegularExpression::CaseInsensitiveOption);
auto match = modsExp.match(url);
bool collectionsLink = false;
if (!match.hasMatch()) {
throw MOBase::InvalidNXMLinkException(url);
match = collectionsExp.match(url);
if (!match.hasMatch()) {
throw MOBase::InvalidNXMLinkException(url);
} else {
collectionsLink = true;
}
}
m_Game = nxm.host();
if (!collectionsLink) {
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();
m_Collection = false;
} else {
m_CollectionId = match.captured(1);
m_CollectionRevision = match.captured(2).toInt();
m_Collection = true;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code is a bit confusing here, I would suggest something like:

QUrl nxm(url);
QUrlQuery query(nxm);

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);
}

@Silarn Silarn merged commit 82962e7 into master May 2, 2026
5 checks passed
@Silarn Silarn deleted the dev/collections-link-handling branch May 2, 2026 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants