Skip to content

Commit

Permalink
fixed a potential crash-cause when querying download info and slight …
Browse files Browse the repository at this point in the history
…improvement (?) to the regex that extracts the modid
  • Loading branch information
TanninOne committed Jan 10, 2016
1 parent 2aae65d commit a9a51f5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
23 changes: 9 additions & 14 deletions src/downloadmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -693,19 +693,14 @@ void DownloadManager::queryInfo(int index)
QString ignore;
NexusInterface::interpretNexusFileName(fileName, ignore, info->m_FileInfo->modID, true);
if (info->m_FileInfo->modID < 0) {
QString modIDString;
while (modIDString.isEmpty()) {
modIDString = QInputDialog::getText(nullptr, tr("Please enter the nexus mod id"), tr("Mod ID:"), QLineEdit::Normal,
QString(), nullptr, 0, Qt::ImhFormattedNumbersOnly);
if (modIDString.isNull()) {
// canceled
return;
} else if (modIDString.contains(QRegExp("[^0-9]"))) {
qDebug("illegal character in mod-id");
modIDString.clear();
}
}
info->m_FileInfo->modID = modIDString.toInt(nullptr, 10);
bool ok = false;
int modId = QInputDialog::getInt(
nullptr, tr("Please enter the nexus mod id"), tr("Mod ID:"), 1, 1,
std::numeric_limits<int>::max(), 1, &ok);
// careful now: while the dialog was displayed, events were processed.
// the download list might have changed and our info-ptr invalidated.
m_ActiveDownloads[index]->m_FileInfo->modID = modId;
return;
}
}
info->m_ReQueried = true;
Expand Down Expand Up @@ -1247,7 +1242,7 @@ int DownloadManager::startDownloadURLs(const QStringList &urls)
int DownloadManager::startDownloadNexusFile(int modID, int fileID)
{
int newID = m_ActiveDownloads.size();
addNXMDownload(QString("nxm://%1/mods/%2/files/%3").arg(m_ManagedGame->getGameShortName()).arg(modID).arg(fileID));
addNXMDownload(QString("nxm://%1/mods/%2/files/%3").arg(m_ManagedGame->gameShortName()).arg(modID).arg(fileID));
return newID;
}

Expand Down
2 changes: 1 addition & 1 deletion src/nexusinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ void NexusInterface::loginCompleted()
void NexusInterface::interpretNexusFileName(const QString &fileName, QString &modName, int &modID, bool query)
{
//Look for something along the lines of modulename-Vn-m + any old rubbish.
static std::regex exp("^([a-zA-Z0-9_'\"\\- ]*?)([-_ ][VvRr]?[0-9_]+)?-([1-9][0-9]+).*");
static std::regex exp("^([a-zA-Z0-9_'\"\\-.() ]*?)([-_ ][VvRr]?[0-9_]+)?-([1-9][0-9]+).*\.(zip|rar|7z)");
static std::regex simpleexp("^([a-zA-Z0-9_]+)");

QByteArray fileNameUTF8 = fileName.toUtf8();
Expand Down

0 comments on commit a9a51f5

Please sign in to comment.