From 299a769a83a883e68ecf47ee928113ed45b533b3 Mon Sep 17 00:00:00 2001 From: Al Date: Sat, 5 Jan 2019 18:44:15 +0100 Subject: Improve performance of refresh (regex and code distribution) --- src/pluginlist.cpp | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'src/pluginlist.cpp') diff --git a/src/pluginlist.cpp b/src/pluginlist.cpp index 8f336dae..5171bf19 100644 --- a/src/pluginlist.cpp +++ b/src/pluginlist.cpp @@ -41,6 +41,7 @@ along with Mod Organizer. If not, see . #include #include #include +#include #include #include #include @@ -174,6 +175,19 @@ void PluginList::refresh(const QString &profileName QStringList availablePlugins; + QRegExp bsaReg = QRegExp(); + QRegExp ba2Reg = QRegExp(); + bsaReg.setPatternSyntax(QRegExp::Wildcard); + bsaReg.setCaseSensitivity(Qt::CaseInsensitive); + ba2Reg.setPatternSyntax(QRegExp::Wildcard); + ba2Reg.setCaseSensitivity(Qt::CaseInsensitive); + + //TODO: try QRegularExpression when we move to Qt5.12 + /*QRegularExpression bsaReg = QRegularExpression(); + QRegularExpression ba2Reg = QRegularExpression(); + bsaReg.setPatternOptions(QRegularExpression::CaseInsensitiveOption); + ba2Reg.setPatternOptions(QRegularExpression::CaseInsensitiveOption);*/ + std::vector files = baseDirectory.getFiles(); for (FileEntry::Ptr current : files) { if (current.get() == nullptr) { @@ -198,15 +212,23 @@ void PluginList::refresh(const QString &profileName try { FilesOrigin &origin = baseDirectory.getOriginByID(current->getOrigin(archive)); + //name without extension + QString baseName = QFileInfo(filename).baseName(); - QString iniPath = QFileInfo(filename).baseName() + ".ini"; + QString iniPath = baseName + ".ini"; bool hasIni = baseDirectory.findFile(ToWString(iniPath)).get() != nullptr; + bsaReg.setPattern(baseName + "*.bsa"); + ba2Reg.setPattern(baseName + "*.ba2"); + + + //bsaReg.setPattern(QRegularExpression::wildcardToRegularExpression(baseName + "*.bsa")); + //ba2Reg.setPattern(QRegularExpression::wildcardToRegularExpression(baseName + "*.ba2")); std::set loadedArchives; + QString candidateName; for (FileEntry::Ptr archiveCandidate : files) { - QString candidateName = ToQString(archiveCandidate->getName()); - if (candidateName.contains(QRegExp(QFileInfo(filename).baseName() + "*.bsa", Qt::CaseInsensitive, QRegExp::Wildcard)) || - candidateName.contains(QRegExp(QFileInfo(filename).baseName() + "*.ba2", Qt::CaseInsensitive, QRegExp::Wildcard))) { + candidateName = ToQString(archiveCandidate->getName()); + if (candidateName.contains(bsaReg) || candidateName.contains(ba2Reg)) { loadedArchives.insert(candidateName); } } -- cgit v1.3.1 From f2c145b2fc9d6ffce838398e06f7aa583d05887d Mon Sep 17 00:00:00 2001 From: LostDragonist Date: Sat, 5 Jan 2019 16:34:10 -0600 Subject: Change qPrintable to qUtf8Printable to better support non-ASCII text --- src/bbcode.cpp | 2 +- src/directoryrefresher.cpp | 2 +- src/downloadmanager.cpp | 18 +++++++++--------- src/editexecutablesdialog.cpp | 2 +- src/icondelegate.cpp | 2 +- src/installationmanager.cpp | 8 ++++---- src/instancemanager.cpp | 2 +- src/logbuffer.cpp | 14 +++++++------- src/main.cpp | 24 ++++++++++++------------ src/mainwindow.cpp | 20 ++++++++++---------- src/messagedialog.cpp | 2 +- src/moapplication.cpp | 2 +- src/modinforegular.cpp | 2 +- src/modlist.cpp | 2 +- src/nexusinterface.cpp | 8 ++++---- src/nxmaccessmanager.cpp | 6 +++--- src/organizercore.cpp | 24 ++++++++++++------------ src/persistentcookiejar.cpp | 6 +++--- src/plugincontainer.cpp | 14 +++++++------- src/pluginlist.cpp | 12 ++++++------ src/profile.cpp | 18 +++++++++--------- src/profilesdialog.cpp | 2 +- src/selfupdater.cpp | 10 +++++----- src/settings.cpp | 4 ++-- src/usvfsconnector.cpp | 2 +- 25 files changed, 104 insertions(+), 104 deletions(-) (limited to 'src/pluginlist.cpp') diff --git a/src/bbcode.cpp b/src/bbcode.cpp index 56369538..84d7a7c0 100644 --- a/src/bbcode.cpp +++ b/src/bbcode.cpp @@ -88,7 +88,7 @@ public: return temp.replace(tagIter->second.first, QString("%2").arg(color, content)); } } else { - qWarning("don't know how to deal with tag %s", qPrintable(tagName)); + qWarning("don't know how to deal with tag %s", qUtf8Printable(tagName)); } } else { if (tagName == "*") { diff --git a/src/directoryrefresher.cpp b/src/directoryrefresher.cpp index 272b0596..cc745cc8 100644 --- a/src/directoryrefresher.cpp +++ b/src/directoryrefresher.cpp @@ -117,7 +117,7 @@ void DirectoryRefresher::addModFilesToStructure(DirectoryEntry *directoryStructu origin.addFile(file->getIndex()); file->addOrigin(origin.getID(), file->getFileTime(), L""); } else { - qWarning("%s not found", qPrintable(fileInfo.fileName())); + qWarning("%s not found", qUtf8Printable(fileInfo.fileName())); } } } else { diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index b408f1a6..15831126 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -400,7 +400,7 @@ bool DownloadManager::addDownload(const QStringList &URLs, QString gameName, } QUrl preferredUrl = QUrl::fromEncoded(URLs.first().toLocal8Bit()); - qDebug("selected download url: %s", qPrintable(preferredUrl.toString())); + qDebug("selected download url: %s", qUtf8Printable(preferredUrl.toString())); QNetworkRequest request(preferredUrl); request.setHeader(QNetworkRequest::UserAgentHeader, m_NexusInterface->getAccessManager()->userAgent()); return addDownload(m_NexusInterface->getAccessManager()->get(request), URLs, fileName, gameName, modID, fileID, fileInfo); @@ -540,9 +540,9 @@ void DownloadManager::addNXMDownload(const QString &url) QStringList validGames; validGames.append(m_ManagedGame->gameShortName()); validGames.append(m_ManagedGame->validShortNames()); - qDebug("add nxm download: %s", qPrintable(url)); + qDebug("add nxm download: %s", qUtf8Printable(url)); if (!validGames.contains(nxmInfo.game(), Qt::CaseInsensitive)) { - qDebug("download requested for wrong game (game: %s, url: %s)", qPrintable(m_ManagedGame->gameShortName()), qPrintable(nxmInfo.game())); + qDebug("download requested for wrong game (game: %s, url: %s)", qUtf8Printable(m_ManagedGame->gameShortName()), qUtf8Printable(nxmInfo.game())); QMessageBox::information(nullptr, tr("Wrong Game"), tr("The download link is for a mod for \"%1\" but this instance of MO " "has been set up for \"%2\".").arg(nxmInfo.game()).arg(m_ManagedGame->gameShortName()), QMessageBox::Ok); return; @@ -550,7 +550,7 @@ void DownloadManager::addNXMDownload(const QString &url) for (auto tuple : m_PendingDownloads) { if (std::get<0>(tuple).compare(nxmInfo.game(), Qt::CaseInsensitive) == 0, std::get<1>(tuple) == nxmInfo.modId() && std::get<2>(tuple) == nxmInfo.fileId()) { - qDebug("download requested is already started (mod id: %s, file id: %s)", qPrintable(QString(nxmInfo.modId())), qPrintable(QString(nxmInfo.fileId()))); + qDebug("download requested is already started (mod id: %s, file id: %s)", qUtf8Printable(QString(nxmInfo.modId())), qUtf8Printable(QString(nxmInfo.fileId()))); QMessageBox::information(nullptr, tr("Already Started"), tr("A download for this mod file has already been queued."), QMessageBox::Ok); return; } @@ -559,8 +559,8 @@ void DownloadManager::addNXMDownload(const QString &url) for (DownloadInfo *download : m_ActiveDownloads) { if (download->m_FileInfo->modID == nxmInfo.modId() && download->m_FileInfo->fileID == nxmInfo.fileId()) { if (download->m_State == STATE_DOWNLOADING || download->m_State == STATE_PAUSED || download->m_State == STATE_STARTED) { - qDebug("download requested is already started (mod: %s, file: %s)", qPrintable(QString(download->m_FileInfo->modID)), - qPrintable(download->m_FileInfo->fileName)); + qDebug("download requested is already started (mod: %s, file: %s)", qUtf8Printable(QString(download->m_FileInfo->modID)), + qUtf8Printable(download->m_FileInfo->fileName)); QMessageBox::information(nullptr, tr("Already Started"), tr("There is already a download started for this file (mod: %1, file: %2).") .arg(download->m_FileInfo->modName).arg(download->m_FileInfo->fileName), QMessageBox::Ok); @@ -814,7 +814,7 @@ void DownloadManager::resumeDownloadInt(int index) if (info->m_State == STATE_ERROR) { info->m_CurrentUrl = (info->m_CurrentUrl + 1) % info->m_Urls.count(); } - qDebug("request resume from url %s", qPrintable(info->currentURL())); + qDebug("request resume from url %s", qUtf8Printable(info->currentURL())); QNetworkRequest request(QUrl::fromEncoded(info->currentURL().toLocal8Bit())); request.setHeader(QNetworkRequest::UserAgentHeader, m_NexusInterface->getAccessManager()->userAgent()); if (info->m_State != STATE_ERROR) { @@ -1434,7 +1434,7 @@ QDateTime DownloadManager::matchDate(const QString &timeString) if (m_DateExpression.exactMatch(timeString)) { return QDateTime::fromMSecsSinceEpoch(m_DateExpression.cap(1).toLongLong()); } else { - qWarning("date not matched: %s", qPrintable(timeString)); + qWarning("date not matched: %s", qUtf8Printable(timeString)); return QDateTime::currentDateTime(); } } @@ -1783,7 +1783,7 @@ void DownloadManager::downloadError(QNetworkReply::NetworkError error) { if (error != QNetworkReply::OperationCanceledError) { QNetworkReply *reply = qobject_cast(sender()); - qWarning("%s (%d)", reply != nullptr ? qPrintable(reply->errorString()) + qWarning("%s (%d)", reply != nullptr ? qUtf8Printable(reply->errorString()) : "Download error occured", error); } diff --git a/src/editexecutablesdialog.cpp b/src/editexecutablesdialog.cpp index fde6b397..be2ee127 100644 --- a/src/editexecutablesdialog.cpp +++ b/src/editexecutablesdialog.cpp @@ -324,7 +324,7 @@ void EditExecutablesDialog::on_executablesListBox_clicked(const QModelIndex &cur QString customOverwrite = m_Profile->setting("custom_overwrites", selectedExecutable.m_Title).toString(); if (!customOverwrite.isEmpty()) { index = ui->newFilesModBox->findText(customOverwrite); - qDebug("find %s -> %d", qPrintable(customOverwrite), index); + qDebug("find %s -> %d", qUtf8Printable(customOverwrite), index); } ui->newFilesModCheckBox->setChecked(index != -1); diff --git a/src/icondelegate.cpp b/src/icondelegate.cpp index e502dc69..249dae6f 100644 --- a/src/icondelegate.cpp +++ b/src/icondelegate.cpp @@ -54,7 +54,7 @@ void IconDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, if (!QPixmapCache::find(fullIconId, &icon)) { icon = QIcon(iconId).pixmap(iconWidth, iconWidth); if (icon.isNull()) { - qWarning("failed to load icon %s", qPrintable(iconId)); + qWarning("failed to load icon %s", qUtf8Printable(iconId)); } QPixmapCache::insert(fullIconId, icon); } diff --git a/src/installationmanager.cpp b/src/installationmanager.cpp index 76b1e086..57c5e861 100644 --- a/src/installationmanager.cpp +++ b/src/installationmanager.cpp @@ -758,7 +758,7 @@ bool InstallationManager::install(const QString &fileName, if (fileInfo.dir() == QDir(m_DownloadsDirectory)) { m_CurrentFile = fileInfo.fileName(); } - qDebug("using mod name \"%s\" (id %d) -> %s", modName->toUtf8().constData(), modID, qPrintable(m_CurrentFile)); + qDebug("using mod name \"%s\" (id %d) -> %s", modName->toUtf8().constData(), modID, qUtf8Printable(m_CurrentFile)); //If there's an archive already open, close it. This happens with the bundle //installer when it uncompresses a split archive, then finds it has a real archive @@ -770,8 +770,8 @@ bool InstallationManager::install(const QString &fileName, new MethodCallback(this, &InstallationManager::queryPassword)); if (!archiveOpen) { qDebug("integrated archiver can't open %s: %s (%d)", - qPrintable(fileName), - qPrintable(getErrorString(m_ArchiveHandler->getLastError())), + qUtf8Printable(fileName), + qUtf8Printable(getErrorString(m_ArchiveHandler->getLastError())), m_ArchiveHandler->getLastError()); } ON_BLOCK_EXIT(std::bind(&InstallationManager::postInstallCleanup, this)); @@ -841,7 +841,7 @@ bool InstallationManager::install(const QString &fileName, } } catch (const IncompatibilityException &e) { qCritical("plugin \"%s\" incompatible: %s", - qPrintable(installer->name()), e.what()); + qUtf8Printable(installer->name()), e.what()); } // act upon the installation result. at this point the files have already been diff --git a/src/instancemanager.cpp b/src/instancemanager.cpp index 9066741d..a5a52d63 100644 --- a/src/instancemanager.cpp +++ b/src/instancemanager.cpp @@ -86,7 +86,7 @@ bool InstanceManager::deleteLocalInstance(const QString &instanceId) const if (!MOBase::shellDelete(QStringList(instancePath),true)) { - qWarning("Failed to shell-delete \"%s\" (errorcode %lu), trying regular delete", qPrintable(instancePath), ::GetLastError()); + qWarning("Failed to shell-delete \"%s\" (errorcode %lu), trying regular delete", qUtf8Printable(instancePath), ::GetLastError()); if (!MOBase::removeDir(instancePath)) { qWarning("regular delete failed too"); diff --git a/src/logbuffer.cpp b/src/logbuffer.cpp index 522ce3c8..485e27db 100644 --- a/src/logbuffer.cpp +++ b/src/logbuffer.cpp @@ -127,7 +127,7 @@ void LogBuffer::log(QtMsgType type, const QMessageLogContext &context, { // QMutexLocker doesn't support timeout... if (!s_Mutex.tryLock(100)) { - fprintf(stderr, "failed to log: %s", qPrintable(message)); + fprintf(stderr, "failed to log: %s", qUtf8Printable(message)); return; } ON_BLOCK_EXIT([]() { s_Mutex.unlock(); }); @@ -137,17 +137,17 @@ void LogBuffer::log(QtMsgType type, const QMessageLogContext &context, } if (type == QtDebugMsg) { - fprintf(stdout, "%s [%c] %s\n", qPrintable(QTime::currentTime().toString()), - msgTypeID(type), qPrintable(message)); + fprintf(stdout, "%s [%c] %s\n", qUtf8Printable(QTime::currentTime().toString()), + msgTypeID(type), qUtf8Printable(message)); } else { if (context.line != 0) { fprintf(stdout, "%s [%c] (%s:%u) %s\n", - qPrintable(QTime::currentTime().toString()), msgTypeID(type), - context.file, context.line, qPrintable(message)); + qUtf8Printable(QTime::currentTime().toString()), msgTypeID(type), + context.file, context.line, qUtf8Printable(message)); } else { fprintf(stdout, "%s [%c] %s\n", - qPrintable(QTime::currentTime().toString()), msgTypeID(type), - qPrintable(message)); + qUtf8Printable(QTime::currentTime().toString()), msgTypeID(type), + qUtf8Printable(message)); } } fflush(stdout); diff --git a/src/main.cpp b/src/main.cpp index 4d2bb7ed..190a8f4b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -262,7 +262,7 @@ QString determineProfile(QStringList &arguments, const QSettings &settings) qDebug("no configured profile"); selectedProfileName = "Default"; } else { - qDebug("configured profile: %s", qPrintable(selectedProfileName)); + qDebug("configured profile: %s", qUtf8Printable(selectedProfileName)); } return selectedProfileName; @@ -401,7 +401,7 @@ void setupPath() { static const int BUFSIZE = 4096; - qDebug("MO at: %s", qPrintable(QDir::toNativeSeparators( + qDebug("MO at: %s", qUtf8Printable(QDir::toNativeSeparators( QCoreApplication::applicationDirPath()))); QCoreApplication::setLibraryPaths(QStringList(QCoreApplication::applicationDirPath() + "/dlls") + QCoreApplication::libraryPaths()); @@ -429,18 +429,18 @@ static void preloadSsl() else { QString libeay32 = appPath + "\\libeay32.dll"; if (!QFile::exists(libeay32)) - qWarning("libeay32.dll not found: %s", qPrintable(libeay32)); + qWarning("libeay32.dll not found: %s", qUtf8Printable(libeay32)); else if (!LoadLibraryW(libeay32.toStdWString().c_str())) - qWarning("failed to load: %s, %d", qPrintable(libeay32), GetLastError()); + qWarning("failed to load: %s, %d", qUtf8Printable(libeay32), GetLastError()); } if (GetModuleHandleA("ssleay32.dll")) qWarning("ssleay32.dll already loaded?!"); else { QString ssleay32 = appPath + "\\ssleay32.dll"; if (!QFile::exists(ssleay32)) - qWarning("ssleay32.dll not found: %s", qPrintable(ssleay32)); + qWarning("ssleay32.dll not found: %s", qUtf8Printable(ssleay32)); else if (!LoadLibraryW(ssleay32.toStdWString().c_str())) - qWarning("failed to load: %s, %d", qPrintable(ssleay32), GetLastError()); + qWarning("failed to load: %s, %d", qUtf8Printable(ssleay32), GetLastError()); } } @@ -453,7 +453,7 @@ int runApplication(MOApplication &application, SingleInstance &instance, const QString &splashPath) { - qDebug("Starting Mod Organizer version %s revision %s", qPrintable(getVersionDisplayString()), + qDebug("Starting Mod Organizer version %s revision %s", qUtf8Printable(getVersionDisplayString()), #if defined(HGID) HGID #elif defined(GITID) @@ -471,7 +471,7 @@ int runApplication(MOApplication &application, SingleInstance &instance, #endif QString dataPath = application.property("dataPath").toString(); - qDebug("data path: %s", qPrintable(dataPath)); + qDebug("data path: %s", qUtf8Printable(dataPath)); if (!bootstrap()) { reportError("failed to set up data paths"); @@ -483,7 +483,7 @@ int runApplication(MOApplication &application, SingleInstance &instance, QStringList arguments = application.arguments(); try { - qDebug("Working directory: %s", qPrintable(QDir::toNativeSeparators(QDir::currentPath()))); + qDebug("Working directory: %s", qUtf8Printable(QDir::toNativeSeparators(QDir::currentPath()))); QSettings settings(dataPath + "/" + QString::fromStdWString(AppConfig::iniFileName()), @@ -552,7 +552,7 @@ int runApplication(MOApplication &application, SingleInstance &instance, } game->setGameVariant(settings.value("game_edition").toString()); - qDebug("managing game at %s", qPrintable(QDir::toNativeSeparators( + qDebug("managing game at %s", qUtf8Printable(QDir::toNativeSeparators( game->gameDirectory().absolutePath()))); organizer.updateExecutablesList(settings); @@ -578,12 +578,12 @@ int runApplication(MOApplication &application, SingleInstance &instance, } else if (OrganizerCore::isNxmLink(arguments.at(1))) { qDebug("starting download from command line: %s", - qPrintable(arguments.at(1))); + qUtf8Printable(arguments.at(1))); organizer.externalMessage(arguments.at(1)); } else { QString exeName = arguments.at(1); - qDebug("starting %s from command line", qPrintable(exeName)); + qDebug("starting %s from command line", qUtf8Printable(exeName)); arguments.removeFirst(); // remove application name (ModOrganizer.exe) arguments.removeFirst(); // remove binary name // pass the remaining parameters to the binary diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 83205ac4..ae37968c 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1558,7 +1558,7 @@ void MainWindow::refreshSaveList() QDir savesDir = currentSavesDir(); savesDir.setNameFilters(filters); - qDebug("reading save games from %s", qPrintable(savesDir.absolutePath())); + qDebug("reading save games from %s", qUtf8Printable(savesDir.absolutePath())); QFileInfoList files = savesDir.entryInfoList(QDir::Files, QDir::Time); for (const QFileInfo &file : files) { @@ -1763,7 +1763,7 @@ void MainWindow::setupNetworkProxy(bool activate) query.setProtocolTag("http"); QList proxies = QNetworkProxyFactory::systemProxyForQuery(query); if ((proxies.size() > 0) && (proxies.at(0).type() != QNetworkProxy::NoProxy)) { - qDebug("Using proxy: %s", qPrintable(proxies.at(0).hostName())); + qDebug("Using proxy: %s", qUtf8Printable(proxies.at(0).hostName())); QNetworkProxy::setApplicationProxy(proxies[0]); } else { qDebug("Not using proxy"); @@ -2418,7 +2418,7 @@ void MainWindow::refreshFilters() while (currentID != 0) { categoriesUsed.insert(currentID); if (!cycleTest.insert(currentID).second) { - qWarning("cycle in categories: %s", qPrintable(SetJoin(cycleTest, ", "))); + qWarning("cycle in categories: %s", qUtf8Printable(SetJoin(cycleTest, ", "))); break; } currentID = m_CategoryFactory.getParentID(m_CategoryFactory.getCategoryIndex(currentID)); @@ -2732,7 +2732,7 @@ void MainWindow::unendorse_clicked() void MainWindow::loginFailed(const QString &error) { - qDebug("login failed: %s", qPrintable(error)); + qDebug("login failed: %s", qUtf8Printable(error)); statusBar()->hide(); } @@ -3711,7 +3711,7 @@ void MainWindow::addRemoveCategories_MenuHandler() { int maxRow = -1; for (const QPersistentModelIndex &idx : selected) { - qDebug("change categories on: %s", qPrintable(idx.data().toString())); + qDebug("change categories on: %s", qUtf8Printable(idx.data().toString())); QModelIndex modIdx = mapToModel(m_OrganizerCore.modList(), idx); if (modIdx.row() != m_ContextIdx.row()) { addRemoveCategoriesFromMenu(menu, modIdx.row(), m_ContextIdx.row()); @@ -3793,7 +3793,7 @@ void MainWindow::saveArchiveList() } } if (archiveFile.commitIfDifferent(m_ArchiveListHash)) { - qDebug("%s saved", qPrintable(QDir::toNativeSeparators(m_OrganizerCore.currentProfile()->getArchivesFileName()))); + qDebug("%s saved", qUtf8Printable(QDir::toNativeSeparators(m_OrganizerCore.currentProfile()->getArchivesFileName()))); } } else { qWarning("archive list not initialised"); @@ -4693,7 +4693,7 @@ void MainWindow::installTranslator(const QString &name) QString fileName = name + "_" + m_CurrentLanguage; if (!translator->load(fileName, qApp->applicationDirPath() + "/translations")) { if (m_CurrentLanguage.compare("en", Qt::CaseInsensitive)) { - qDebug("localization file %s not found", qPrintable(fileName)); + qDebug("localization file %s not found", qUtf8Printable(fileName)); } // we don't actually expect localization files for English } @@ -4718,7 +4718,7 @@ void MainWindow::languageChange(const QString &newLanguage) installTranslator(QFileInfo(fileName).baseName()); } ui->retranslateUi(this); - qDebug("loaded language %s", qPrintable(newLanguage)); + qDebug("loaded language %s", qUtf8Printable(newLanguage)); ui->profileBox->setItemText(0, QObject::tr("")); @@ -6134,7 +6134,7 @@ void MainWindow::dropLocalFile(const QUrl &url, const QString &outputDir, bool m { QFileInfo file(url.toLocalFile()); if (!file.exists()) { - qWarning("invalid source file %s", qPrintable(file.absoluteFilePath())); + qWarning("invalid source file %s", qUtf8Printable(file.absoluteFilePath())); return; } QString target = outputDir + "/" + file.fileName(); @@ -6167,7 +6167,7 @@ void MainWindow::dropLocalFile(const QUrl &url, const QString &outputDir, bool m success = shellCopy(file.absoluteFilePath(), target, true, this); } if (!success) { - qCritical("file operation failed: %s", qPrintable(windowsErrorString(::GetLastError()))); + qCritical("file operation failed: %s", qUtf8Printable(windowsErrorString(::GetLastError()))); } } diff --git a/src/messagedialog.cpp b/src/messagedialog.cpp index 90b0a9d3..6c6de3e7 100644 --- a/src/messagedialog.cpp +++ b/src/messagedialog.cpp @@ -81,7 +81,7 @@ void MessageDialog::resizeEvent(QResizeEvent *event) void MessageDialog::showMessage(const QString &text, QWidget *reference, bool bringToFront) { - qDebug("%s", qPrintable(text)); + qDebug("%s", qUtf8Printable(text)); if (reference != nullptr) { if (bringToFront || (qApp->activeWindow() != nullptr)) { MessageDialog *dialog = new MessageDialog(text, reference); diff --git a/src/moapplication.cpp b/src/moapplication.cpp index 9ddd9e54..3a791827 100644 --- a/src/moapplication.cpp +++ b/src/moapplication.cpp @@ -137,7 +137,7 @@ void MOApplication::updateStyle(const QString &fileName) if (QFile::exists(fileName)) { setStyleSheet(QString("file:///%1").arg(fileName)); } else { - qWarning("invalid stylesheet: %s", qPrintable(fileName)); + qWarning("invalid stylesheet: %s", qUtf8Printable(fileName)); } } } diff --git a/src/modinforegular.cpp b/src/modinforegular.cpp index 548e3178..45c3985b 100644 --- a/src/modinforegular.cpp +++ b/src/modinforegular.cpp @@ -302,7 +302,7 @@ bool ModInfoRegular::setName(const QString &name) } else { if (!shellRename(modDir.absoluteFilePath(m_Name), modDir.absoluteFilePath(name))) { qCritical("failed to rename mod %s (errorcode %d)", - qPrintable(name), ::GetLastError()); + qUtf8Printable(name), ::GetLastError()); return false; } } diff --git a/src/modlist.cpp b/src/modlist.cpp index 2cb74d50..c1954b39 100644 --- a/src/modlist.cpp +++ b/src/modlist.cpp @@ -960,7 +960,7 @@ bool ModList::dropURLs(const QMimeData *mimeData, int row, const QModelIndex &pa QString overwriteName = ModInfo::getByIndex(overwriteIndex)->name(); for (const QUrl &url : mimeData->urls()) { - qDebug("URL drop requested: %s", qPrintable(url.toLocalFile())); + qDebug("URL drop requested: %s", qUtf8Printable(url.toLocalFile())); if (!url.isLocalFile()) { qDebug("URL drop ignored: Not a local file."); continue; diff --git a/src/nexusinterface.cpp b/src/nexusinterface.cpp index e97e9800..c6f05405 100644 --- a/src/nexusinterface.cpp +++ b/src/nexusinterface.cpp @@ -226,7 +226,7 @@ void NexusInterface::interpretNexusFileName(const QString &fileName, QString &mo } else { modID = strtol(candidate.c_str(), nullptr, 10); } - qDebug("mod id guessed: %s -> %d", qPrintable(fileName), modID); + qDebug("mod id guessed: %s -> %d", qUtf8Printable(fileName), modID); } else if (std::regex_search(fileNameUTF8.constData(), result, simpleexp)) { qDebug("simple expression matched, using name only"); modName = QString::fromUtf8(result[1].str().c_str()); @@ -542,7 +542,7 @@ void NexusInterface::requestFinished(std::list::iterator iter) if (nexusError.length() == 0) { nexusError = tr("empty response"); } - qDebug("nexus error: %s", qPrintable(nexusError)); + qDebug("nexus error: %s", qUtf8Printable(nexusError)); emit nxmRequestFailed(iter->m_GameName, iter->m_ModID, iter->m_FileID, iter->m_UserData, iter->m_ID, nexusError); } else { bool ok; @@ -602,8 +602,8 @@ void NexusInterface::requestError(QNetworkReply::NetworkError) } qCritical("request (%s) error: %s (%d)", - qPrintable(reply->url().toString()), - qPrintable(reply->errorString()), + qUtf8Printable(reply->url().toString()), + qUtf8Printable(reply->errorString()), reply->error()); } diff --git a/src/nxmaccessmanager.cpp b/src/nxmaccessmanager.cpp index 426c8b9c..912eab30 100644 --- a/src/nxmaccessmanager.cpp +++ b/src/nxmaccessmanager.cpp @@ -106,7 +106,7 @@ void NXMAccessManager::showCookies() const for (const QNetworkCookie &cookie : cookieJar()->cookiesForUrl(url)) { qDebug("%s - %s (expires: %s)", cookie.name().constData(), cookie.value().constData(), - qPrintable(cookie.expirationDate().toString())); + qUtf8Printable(cookie.expirationDate().toString())); } } @@ -164,7 +164,7 @@ void NXMAccessManager::retrieveCredentials() connect(reply, static_cast(&QNetworkReply::error), [=] (QNetworkReply::NetworkError) { - qDebug("failed to retrieve account credentials: %s", qPrintable(reply->errorString())); + qDebug("failed to retrieve account credentials: %s", qUtf8Printable(reply->errorString())); reply->deleteLater(); }); } @@ -235,7 +235,7 @@ QString NXMAccessManager::userAgent(const QString &subModule) const void NXMAccessManager::pageLogin() { - qDebug("logging %s in on Nexus", qPrintable(m_Username)); + qDebug("logging %s in on Nexus", qUtf8Printable(m_Username)); QString requestString = (Nexus_Management_URL + "/Sessions/?Login&uri=%1") .arg(QString(QUrl::toPercentEncoding(Nexus_Management_URL))); diff --git a/src/organizercore.cpp b/src/organizercore.cpp index 9ebe9f47..c4029a6d 100644 --- a/src/organizercore.cpp +++ b/src/organizercore.cpp @@ -47,7 +47,7 @@ #include #include -#include // for qPrintable, etc +#include // for qUtf8Printable, etc #include #include @@ -89,8 +89,8 @@ static bool isOnline() continue; } qDebug("interface %s seems to be up (address: %s)", - qPrintable(iter->humanReadableName()), - qPrintable(addresses[0].ip().toString())); + qUtf8Printable(iter->humanReadableName()), + qUtf8Printable(addresses[0].ip().toString())); connected = true; } } @@ -640,7 +640,7 @@ bool OrganizerCore::nexusLogin(bool retry) if ((!retry && m_Settings.getNexusLogin(username, password)) || (m_AskForNexusPW && queryLogin(username, password))) { // credentials stored or user entered them manually - qDebug("attempt login with username %s", qPrintable(username)); + qDebug("attempt login with username %s", qUtf8Printable(username)); accessManager->login(username, password); return true; } else { @@ -681,7 +681,7 @@ void OrganizerCore::startMOUpdate() void OrganizerCore::downloadRequestedNXM(const QString &url) { - qDebug("download requested: %s", qPrintable(url)); + qDebug("download requested: %s", qUtf8Printable(url)); if (nexusLogin()) { m_PendingDownloads.append(url); } else { @@ -1116,7 +1116,7 @@ QStringList OrganizerCore::findFiles( } } } else { - qWarning("directory %s not found", qPrintable(path)); + qWarning("directory %s not found", qUtf8Printable(path)); } return result; } @@ -1135,7 +1135,7 @@ QStringList OrganizerCore::getFileOrigins(const QString &fileName) const ToQString(m_DirectoryStructure->getOriginByID(i.first).getName())); } } else { - qDebug("%s not found", qPrintable(fileName)); + qDebug("%s not found", qUtf8Printable(fileName)); } return result; } @@ -1402,7 +1402,7 @@ HANDLE OrganizerCore::spawnBinaryProcess(const QFileInfo &binary, } } else { qDebug("start of \"%s\" canceled by plugin", - qPrintable(binary.absoluteFilePath())); + qUtf8Printable(binary.absoluteFilePath())); return INVALID_HANDLE_VALUE; } } @@ -1781,7 +1781,7 @@ void OrganizerCore::updateModActiveState(int index, bool active) dir.entryList(QStringList() << "*.esm", QDir::Files)) { const FileEntry::Ptr file = m_DirectoryStructure->findFile(ToWString(esm)); if (file.get() == nullptr) { - qWarning("failed to activate %s", qPrintable(esm)); + qWarning("failed to activate %s", qUtf8Printable(esm)); continue; } @@ -1797,7 +1797,7 @@ void OrganizerCore::updateModActiveState(int index, bool active) dir.entryList(QStringList() << "*.esl", QDir::Files)) { const FileEntry::Ptr file = m_DirectoryStructure->findFile(ToWString(esl)); if (file.get() == nullptr) { - qWarning("failed to activate %s", qPrintable(esl)); + qWarning("failed to activate %s", qUtf8Printable(esl)); continue; } @@ -1813,7 +1813,7 @@ void OrganizerCore::updateModActiveState(int index, bool active) for (const QString &esp : esps) { const FileEntry::Ptr file = m_DirectoryStructure->findFile(ToWString(esp)); if (file.get() == nullptr) { - qWarning("failed to activate %s", qPrintable(esp)); + qWarning("failed to activate %s", qUtf8Printable(esp)); continue; } @@ -2140,7 +2140,7 @@ std::vector OrganizerCore::activeProblems() const // of a "log spam". But since this is a sevre error which will most likely make the // game crash/freeze/etc. and is very hard to diagnose, this "log spam" will make it // easier for the user to notice the warning. - qWarning("hook.dll found in game folder: %s", qPrintable(hookdll)); + qWarning("hook.dll found in game folder: %s", qUtf8Printable(hookdll)); problems.push_back(PROBLEM_MO1SCRIPTEXTENDERWORKAROUND); } return problems; diff --git a/src/persistentcookiejar.cpp b/src/persistentcookiejar.cpp index a6eb78fa..1ed463c6 100644 --- a/src/persistentcookiejar.cpp +++ b/src/persistentcookiejar.cpp @@ -11,7 +11,7 @@ PersistentCookieJar::PersistentCookieJar(const QString &fileName, QObject *paren } PersistentCookieJar::~PersistentCookieJar() { - qDebug("save %s", qPrintable(m_FileName)); + qDebug("save %s", qUtf8Printable(m_FileName)); save(); } @@ -40,14 +40,14 @@ void PersistentCookieJar::save() { QFile oldCookies(m_FileName); if (oldCookies.exists()) { if (!oldCookies.remove()) { - qCritical("failed to save cookies: failed to remove %s", qPrintable(m_FileName)); + qCritical("failed to save cookies: failed to remove %s", qUtf8Printable(m_FileName)); return; } } // if it doesn't exists that's fine } if (!file.copy(m_FileName)) { - qCritical("failed to save cookies: failed to write %s", qPrintable(m_FileName)); + qCritical("failed to save cookies: failed to write %s", qUtf8Printable(m_FileName)); } } diff --git a/src/plugincontainer.cpp b/src/plugincontainer.cpp index 8935c472..46a95f0c 100644 --- a/src/plugincontainer.cpp +++ b/src/plugincontainer.cpp @@ -160,12 +160,12 @@ bool PluginContainer::registerPlugin(QObject *plugin, const QString &fileName) for (QObject *proxiedPlugin : matchingPlugins) { if (proxiedPlugin != nullptr) { if (registerPlugin(proxiedPlugin, pluginName)) { - qDebug("loaded plugin \"%s\"", qPrintable(QFileInfo(pluginName).fileName())); + qDebug("loaded plugin \"%s\"", qUtf8Printable(QFileInfo(pluginName).fileName())); } else { qWarning("plugin \"%s\" failed to load. If this plugin is for an older version of MO " "you have to update it or delete it if no update exists.", - qPrintable(pluginName)); + qUtf8Printable(pluginName)); } } } @@ -220,7 +220,7 @@ void PluginContainer::unloadPlugins() QPluginLoader *loader = m_PluginLoaders.back(); m_PluginLoaders.pop_back(); if ((loader != nullptr) && !loader->unload()) { - qDebug("failed to unload %s: %s", qPrintable(loader->fileName()), qPrintable(loader->errorString())); + qDebug("failed to unload %s: %s", qUtf8Printable(loader->fileName()), qUtf8Printable(loader->errorString())); } delete loader; } @@ -275,7 +275,7 @@ void PluginContainer::loadPlugins() while (iter.hasNext()) { iter.next(); if (m_Organizer->settings().pluginBlacklisted(iter.fileName())) { - qDebug("plugin \"%s\" blacklisted", qPrintable(iter.fileName())); + qDebug("plugin \"%s\" blacklisted", qUtf8Printable(iter.fileName())); continue; } loadCheck.write(iter.fileName().toUtf8()); @@ -287,14 +287,14 @@ void PluginContainer::loadPlugins() if (pluginLoader->instance() == nullptr) { m_FailedPlugins.push_back(pluginName); qCritical("failed to load plugin %s: %s", - qPrintable(pluginName), qPrintable(pluginLoader->errorString())); + qUtf8Printable(pluginName), qUtf8Printable(pluginLoader->errorString())); } else { if (registerPlugin(pluginLoader->instance(), pluginName)) { - qDebug("loaded plugin \"%s\"", qPrintable(QFileInfo(pluginName).fileName())); + qDebug("loaded plugin \"%s\"", qUtf8Printable(QFileInfo(pluginName).fileName())); m_PluginLoaders.push_back(pluginLoader.release()); } else { m_FailedPlugins.push_back(pluginName); - qWarning("plugin \"%s\" failed to load (may be outdated)", qPrintable(pluginName)); + qWarning("plugin \"%s\" failed to load (may be outdated)", qUtf8Printable(pluginName)); } } } diff --git a/src/pluginlist.cpp b/src/pluginlist.cpp index 5171bf19..6f417331 100644 --- a/src/pluginlist.cpp +++ b/src/pluginlist.cpp @@ -182,7 +182,7 @@ void PluginList::refresh(const QString &profileName ba2Reg.setPatternSyntax(QRegExp::Wildcard); ba2Reg.setCaseSensitivity(Qt::CaseInsensitive); - //TODO: try QRegularExpression when we move to Qt5.12 + //TODO: try QRegularExpression when we move to Qt5.12 /*QRegularExpression bsaReg = QRegularExpression(); QRegularExpression ba2Reg = QRegularExpression(); bsaReg.setPatternOptions(QRegularExpression::CaseInsensitiveOption); @@ -435,7 +435,7 @@ void PluginList::addInformation(const QString &name, const QString &message) if (iter != m_ESPsByName.end()) { m_AdditionalInfo[name.toLower()].m_Messages.append(message); } else { - qWarning("failed to associate message for \"%s\"", qPrintable(name)); + qWarning("failed to associate message for \"%s\"", qUtf8Printable(name)); } } @@ -499,7 +499,7 @@ void PluginList::writeLockedOrder(const QString &fileName) const file->write(QString("%1|%2\r\n").arg(iter->first).arg(iter->second).toUtf8()); } file.commit(); - qDebug("%s saved", QDir::toNativeSeparators(fileName).toUtf8().constData()); + qDebug("%s saved", qUtf8Printable(QDir::toNativeSeparators(fileName))); } @@ -524,7 +524,7 @@ void PluginList::saveTo(const QString &lockedOrderFileName } } if (deleterFile.commitIfDifferent(m_LastSaveHash[deleterFileName])) { - qDebug("%s saved", qPrintable(QDir::toNativeSeparators(deleterFileName))); + qDebug("%s saved", qUtf8Printable(QDir::toNativeSeparators(deleterFileName))); } } else if (QFile::exists(deleterFileName)) { shellDelete(QStringList() << deleterFileName); @@ -712,7 +712,7 @@ void PluginList::setState(const QString &name, PluginStates state) { m_ESPs[iter->second].m_Enabled = (state == IPluginList::STATE_ACTIVE) || m_ESPs[iter->second].m_ForceEnabled; } else { - qWarning("plugin %s not found", qPrintable(name)); + qWarning("plugin %s not found", qUtf8Printable(name)); } } @@ -1386,7 +1386,7 @@ PluginList::ESPInfo::ESPInfo(const QString &name, bool enabled, m_Masters.insert(QString(iter->c_str())); } } catch (const std::exception &e) { - qCritical("failed to parse plugin file %s: %s", qPrintable(fullPath), e.what()); + qCritical("failed to parse plugin file %s: %s", qUtf8Printable(fullPath), e.what()); m_IsMaster = false; m_IsLight = false; m_IsLightFlagged = false; diff --git a/src/profile.cpp b/src/profile.cpp index 9da1a698..e8ead8e8 100644 --- a/src/profile.cpp +++ b/src/profile.cpp @@ -40,7 +40,7 @@ along with Mod Organizer. If not, see . #include #include // for QStringList #include // for qDebug, qWarning, etc -#include // for qPrintable +#include // for qUtf8Printable #include #include @@ -124,7 +124,7 @@ Profile::Profile(const QDir &directory, IPluginGame const *gamePlugin) findProfileSettings(); if (!QFile::exists(m_Directory.filePath("modlist.txt"))) { - qWarning("missing modlist.txt in %s", qPrintable(directory.path())); + qWarning("missing modlist.txt in %s", qUtf8Printable(directory.path())); touchFile(m_Directory.filePath("modlist.txt")); } @@ -252,7 +252,7 @@ void Profile::doWriteModlist() } if (file.commitIfDifferent(m_LastModlistHash)) { - qDebug("%s saved", QDir::toNativeSeparators(fileName).toUtf8().constData()); + qDebug("%s saved", qUtf8Printable(QDir::toNativeSeparators(fileName))); } } catch (const std::exception &e) { reportError(tr("failed to write mod list: %1").arg(e.what())); @@ -288,7 +288,7 @@ void Profile::createTweakedIniFile() if (error) { reportError(tr("failed to create tweaked ini: %1").arg(getCurrentErrorString().c_str())); } - qDebug("%s saved", qPrintable(QDir::toNativeSeparators(tweakedIni))); + qDebug("%s saved", qUtf8Printable(QDir::toNativeSeparators(tweakedIni))); } // static @@ -303,7 +303,7 @@ void Profile::renameModInAllProfiles(const QString& oldName, const QString& newN if (modList.exists()) renameModInList(modList, oldName, newName); else - qWarning("Profile has no modlist.txt : %s", qPrintable(profileIter.filePath())); + qWarning("Profile has no modlist.txt : %s", qUtf8Printable(profileIter.filePath())); } } @@ -361,7 +361,7 @@ void Profile::renameModInList(QFile &modList, const QString &oldName, const QStr if (renamed) qDebug("Renamed %d \"%s\" mod to \"%s\" in %s", - renamed, qPrintable(oldName), qPrintable(newName), qPrintable(modList.fileName())); + renamed, qUtf8Printable(oldName), qUtf8Printable(newName), qUtf8Printable(modList.fileName())); } void Profile::refreshModStatus() @@ -421,13 +421,13 @@ void Profile::refreshModStatus() } } else { qWarning("no mod state for \"%s\" (profile \"%s\")", - qPrintable(modName), m_Directory.path().toUtf8().constData()); + qUtf8Printable(modName), m_Directory.path().toUtf8().constData()); // need to rewrite the modlist to fix this modStatusModified = true; } } else { qDebug("mod \"%s\" (profile \"%s\") not found", - qPrintable(modName), m_Directory.path().toUtf8().constData()); + qUtf8Printable(modName), m_Directory.path().toUtf8().constData()); // need to rewrite the modlist to fix this modStatusModified = true; } @@ -775,7 +775,7 @@ bool Profile::localSettingsEnabled() const QStringList missingFiles; for (QString file : m_GamePlugin->iniFiles()) { if (!QFile::exists(m_Directory.filePath(file))) { - qWarning("missing %s in %s", qPrintable(file), qPrintable(m_Directory.path())); + qWarning("missing %s in %s", qUtf8Printable(file), qUtf8Printable(m_Directory.path())); missingFiles << file; } } diff --git a/src/profilesdialog.cpp b/src/profilesdialog.cpp index 17844357..f9ea655f 100644 --- a/src/profilesdialog.cpp +++ b/src/profilesdialog.cpp @@ -214,7 +214,7 @@ void ProfilesDialog::on_removeProfileButton_clicked() delete item; } if (!shellDelete(QStringList(profilePath))) { - qWarning("Failed to shell-delete \"%s\" (errorcode %lu), trying regular delete", qPrintable(profilePath), ::GetLastError()); + qWarning("Failed to shell-delete \"%s\" (errorcode %lu), trying regular delete", qUtf8Printable(profilePath), ::GetLastError()); if (!removeDir(profilePath)) { qWarning("regular delete failed too"); } diff --git a/src/selfupdater.cpp b/src/selfupdater.cpp index d26ca96c..cdcbc2f4 100644 --- a/src/selfupdater.cpp +++ b/src/selfupdater.cpp @@ -145,15 +145,15 @@ void SelfUpdater::testForUpdate() if (newestVer > this->m_MOVersion) { m_UpdateCandidate = newest; qDebug("update available: %s -> %s", - qPrintable(this->m_MOVersion.displayString()), - qPrintable(newestVer.displayString())); + qUtf8Printable(this->m_MOVersion.displayString()), + qUtf8Printable(newestVer.displayString())); emit updateAvailable(); } else if (newestVer < this->m_MOVersion) { // this could happen if the user switches from using prereleases to // stable builds. Should we downgrade? qDebug("this version is newer than the newest installed one: %s -> %s", - qPrintable(this->m_MOVersion.displayString()), - qPrintable(newestVer.displayString())); + qUtf8Printable(this->m_MOVersion.displayString()), + qUtf8Printable(newestVer.displayString())); } } }); @@ -224,7 +224,7 @@ void SelfUpdater::closeProgress() void SelfUpdater::openOutputFile(const QString &fileName) { QString outputPath = QDir::fromNativeSeparators(qApp->property("dataPath").toString()) + "/" + fileName; - qDebug("downloading to %s", qPrintable(outputPath)); + qDebug("downloading to %s", qUtf8Printable(outputPath)); m_UpdateFile.setFileName(outputPath); m_UpdateFile.open(QIODevice::WriteOnly); } diff --git a/src/settings.cpp b/src/settings.cpp index 8f768fd2..5cfe427b 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -167,7 +167,7 @@ void Settings::registerPlugin(IPlugin *plugin) QVariant temp = m_Settings.value("Plugins/" + plugin->name() + "/" + setting.key, setting.defaultValue); if (!temp.convert(setting.defaultValue.type())) { qWarning("failed to interpret \"%s\" as correct type for \"%s\" in plugin \"%s\", using default", - qPrintable(temp.toString()), qPrintable(setting.key), qPrintable(plugin->name())); + qUtf8Printable(temp.toString()), qUtf8Printable(setting.key), qUtf8Printable(plugin->name())); temp = setting.defaultValue; } m_PluginSettings[plugin->name()][setting.key] = temp; @@ -574,7 +574,7 @@ void Settings::updateServers(const QList &servers) QVariantMap val = m_Settings.value(key).toMap(); QDate lastSeen = val["lastSeen"].toDate(); if (lastSeen.daysTo(now) > 30) { - qDebug("removing server %s since it hasn't been available for downloads in over a month", qPrintable(key)); + qDebug("removing server %s since it hasn't been available for downloads in over a month", qUtf8Printable(key)); m_Settings.remove(key); } } diff --git a/src/usvfsconnector.cpp b/src/usvfsconnector.cpp index 9c81d0d9..ef7314c0 100644 --- a/src/usvfsconnector.cpp +++ b/src/usvfsconnector.cpp @@ -61,7 +61,7 @@ LogWorker::LogWorker() { m_LogFile.open(QIODevice::WriteOnly); qDebug("usvfs log messages are written to %s", - qPrintable(m_LogFile.fileName())); + qUtf8Printable(m_LogFile.fileName())); } LogWorker::~LogWorker() -- cgit v1.3.1