summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTannin <sherb@gmx.net>2016-06-02 19:45:04 +0200
committerTannin <sherb@gmx.net>2016-06-02 19:45:04 +0200
commit4f1bb369330a0728e11a83bd334f8904b1c2ecc2 (patch)
treec16da01e205144573fd0a94f93e3f7693ba28b00
parentcbdea13a9c079f3de114cb96418b500e0f1d297a (diff)
fixed some filename/modname handling for names received from nexus
-rw-r--r--src/downloadmanager.cpp21
-rw-r--r--src/installationmanager.cpp8
-rw-r--r--src/nexusinterface.cpp2
3 files changed, 19 insertions, 12 deletions
diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp
index b92e171e..cb954ebe 100644
--- a/src/downloadmanager.cpp
+++ b/src/downloadmanager.cpp
@@ -757,12 +757,15 @@ QString DownloadManager::getDisplayName(int index) const
DownloadInfo *info = m_ActiveDownloads.at(index);
+ QTextDocument doc;
if (!info->m_FileInfo->name.isEmpty()) {
- return QString("%1 (%2, v%3)").arg(info->m_FileInfo->name)
+ doc.setHtml(info->m_FileInfo->name);
+ return QString("%1 (%2, v%3)").arg(doc.toPlainText())
.arg(getFileTypeString(info->m_FileInfo->fileCategory))
.arg(info->m_FileInfo->version.displayString());
} else {
- return info->m_FileName;
+ doc.setHtml(info->m_FileName);
+ return doc.toPlainText();
}
}
@@ -1058,7 +1061,9 @@ void DownloadManager::nxmDescriptionAvailable(int, QVariant userData, QVariant r
DownloadInfo *info = downloadInfoByID(userData.toInt());
if (info == nullptr) return;
info->m_FileInfo->categoryID = result["category_id"].toInt();
- info->m_FileInfo->modName = result["name"].toString().trimmed();
+ QTextDocument doc;
+ doc.setHtml(result["name"].toString().trimmed());
+ info->m_FileInfo->modName = doc.toPlainText();
info->m_FileInfo->newestVersion.parse(result["version"].toString());
if (info->m_FileInfo->fileID != 0) {
setState(info, STATE_READY);
@@ -1116,7 +1121,7 @@ void DownloadManager::nxmFilesAvailable(int, QVariant userData, QVariant resultD
bool found = false;
- foreach(QVariant file, result) {
+ for (QVariant file : result) {
QVariantMap fileInfo = file.toMap();
QString fileName = fileInfo["uri"].toString();
QString fileNameVariant = fileName.mid(0).replace(' ', '_');
@@ -1127,12 +1132,10 @@ void DownloadManager::nxmFilesAvailable(int, QVariant userData, QVariant resultD
if (!info->m_FileInfo->version.isValid()) {
info->m_FileInfo->version = info->m_FileInfo->newestVersion;
}
- //Nexus has HTMLd these so unhtml them if necessary
+ // we receive some names html-encoded. This is used to decode it
QTextDocument doc;
- doc.setHtml(info->m_FileInfo->modName);
+ doc.setHtml(fileInfo["modName"].toString());
info->m_FileInfo->modName = doc.toPlainText();
- doc.setHtml(info->m_FileInfo->name);
- info->m_FileInfo->name = doc.toPlainText();
info->m_FileInfo->fileCategory = convertFileCategory(fileInfo["category_id"].toInt());
info->m_FileInfo->fileTime = matchDate(fileInfo["date"].toString());
info->m_FileInfo->fileID = fileInfo["id"].toInt();
@@ -1148,7 +1151,7 @@ void DownloadManager::nxmFilesAvailable(int, QVariant userData, QVariant resultD
emit showMessage(tr("No matching file found on Nexus! Maybe this file is no longer available or it was renamed?"));
} else {
SelectionDialog selection(tr("No file on Nexus matches the selected file by name. Please manually choose the correct one."));
- foreach(QVariant file, result) {
+ for (QVariant file : result) {
QVariantMap fileInfo = file.toMap();
selection.addChoice(fileInfo["uri"].toString(), "", file);
}
diff --git a/src/installationmanager.cpp b/src/installationmanager.cpp
index bf5ee91a..1c9d8a42 100644
--- a/src/installationmanager.cpp
+++ b/src/installationmanager.cpp
@@ -48,6 +48,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include <QDateTime>
#include <QDirIterator>
#include <QDebug>
+#include <QTextDocument>
#include <Shellapi.h>
@@ -669,7 +670,9 @@ bool InstallationManager::install(const QString &fileName,
if (QFile(metaName).exists()) {
QSettings metaFile(metaName, QSettings::IniFormat);
modID = metaFile.value("modID", 0).toInt();
- modName.update(metaFile.value("name", "").toString(), GUESS_FALLBACK);
+ QTextDocument doc;
+ doc.setHtml(metaFile.value("name", "").toString());
+ modName.update(doc.toPlainText(), GUESS_FALLBACK);
modName.update(metaFile.value("modName", "").toString(), GUESS_META);
version = metaFile.value("version", "").toString();
@@ -688,12 +691,13 @@ bool InstallationManager::install(const QString &fileName,
{ // guess the mod name and mod if from the file name if there was no meta information
QString guessedModName;
int guessedModID = modID;
- NexusInterface::interpretNexusFileName(QFileInfo(fileName).baseName(), guessedModName, guessedModID, false);
+ NexusInterface::interpretNexusFileName(QFileInfo(fileName).fileName(), guessedModName, guessedModID, false);
if ((modID == 0) && (guessedModID != -1)) {
modID = guessedModID;
} else if (modID != guessedModID) {
qDebug("passed mod id: %d, guessed id: %d", modID, guessedModID);
}
+
modName.update(guessedModName, GUESS_GOOD);
}
diff --git a/src/nexusinterface.cpp b/src/nexusinterface.cpp
index 2c690aa4..6e989b0d 100644
--- a/src/nexusinterface.cpp
+++ b/src/nexusinterface.cpp
@@ -194,7 +194,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]+).*\\.(zip|rar|7z)");
+ static std::regex exp(R"exp(^([a-zA-Z0-9_'"\-.() ]*?)([-_ ][VvRr]?[0-9_]+)?-([1-9][0-9]*).*\.(zip|rar|7z))exp");
static std::regex simpleexp("^([a-zA-Z0-9_]+)");
QByteArray fileNameUTF8 = fileName.toUtf8();