Skip to content

Commit 792c3ae

Browse files
committed
Add basic NXM collections link parsing
1 parent 3d491f9 commit 792c3ae

2 files changed

Lines changed: 45 additions & 10 deletions

File tree

include/uibase/nxmurl.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,31 @@ class QDLLEXPORT NXMUrl : public QObject
7575
*/
7676
int userId() const { return m_UserId; }
7777

78+
/**
79+
* @return if collection link
80+
*/
81+
bool isCollection() const { return m_Collection; }
82+
83+
/**
84+
* @return collection ID
85+
*/
86+
QString collectionId() const { return m_CollectionId; }
87+
88+
/**
89+
* @return collection revision
90+
*/
91+
int collectionRevision() const { return m_CollectionRevision; }
92+
7893
private:
7994
QString m_Game;
8095
QString m_Key;
8196
int m_ModId;
8297
int m_FileId;
8398
int m_Expires;
8499
int m_UserId;
100+
bool m_Collection;
101+
QString m_CollectionId;
102+
int m_CollectionRevision;
85103
};
86104

87105
#endif // NXMURL_H

src/nxmurl.cpp

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,33 @@ NXMUrl::NXMUrl(const QString& url)
2929
{
3030
QUrl nxm(url);
3131
QUrlQuery query(nxm);
32-
QRegularExpression exp("nxm://[a-z0-9]+/mods/(\\d+)/files/(\\d+)",
33-
QRegularExpression::CaseInsensitiveOption);
34-
auto match = exp.match(url);
32+
// nxm://starfield/collections/7ou329/revisions/24
33+
QRegularExpression modsExp("nxm://[a-z0-9]+/mods/(\\d+)/files/(\\d+)",
34+
QRegularExpression::CaseInsensitiveOption);
35+
QRegularExpression collectionsExp(
36+
"nxm://[a-z0-9]+/collections/([a-z0-9]+)/revisions/(\\d+)",
37+
QRegularExpression::CaseInsensitiveOption);
38+
auto match = modsExp.match(url);
39+
bool collectionsLink = false;
3540
if (!match.hasMatch()) {
36-
throw MOBase::InvalidNXMLinkException(url);
41+
match = collectionsExp.match(url);
42+
if (!match.hasMatch()) {
43+
throw MOBase::InvalidNXMLinkException(url);
44+
} else {
45+
collectionsLink = true;
46+
}
47+
}
48+
m_Game = nxm.host();
49+
if (!collectionsLink) {
50+
m_ModId = match.captured(1).toInt();
51+
m_FileId = match.captured(2).toInt();
52+
m_Key = query.queryItemValue("key");
53+
m_Expires = query.queryItemValue("expires").toInt();
54+
m_UserId = query.queryItemValue("user_id").toInt();
55+
m_Collection = false;
56+
} else {
57+
m_CollectionId = match.captured(1);
58+
m_CollectionRevision = match.captured(2).toInt();
59+
m_Collection = true;
3760
}
38-
m_Game = nxm.host();
39-
m_ModId = match.captured(1).toInt();
40-
m_FileId = match.captured(2).toInt();
41-
m_Key = query.queryItemValue("key");
42-
m_Expires = query.queryItemValue("expires").toInt();
43-
m_UserId = query.queryItemValue("user_id").toInt();
4461
}

0 commit comments

Comments
 (0)