Compare commits

..
Author SHA1 Message Date
isanae 08e0d85d85 added DownloadInfo for headers and user agent 2021-03-02 19:14:14 -05:00
isanae 2094d7d15f added IPluginRepository to container
downloads now have an IRepositoryDownload to manage the actual downloads
curl downloader uses IDownload and IDownloader
download stats, allow downloading to buffer
2021-03-02 17:15:52 -05:00
isanae 25a69bccd3 split queue back into manager 2021-02-17 14:16:55 -05:00
isanae a39a80ec4c log wrapper, verbose log
log curl version
2021-02-17 11:18:28 -05:00
isanae 42d432e5aa moved to curldownloader 2021-02-16 04:53:49 -05:00
isanae acb55d431c fixed output file staying opened when moving to queue
refactored removing from queue
2021-02-16 04:43:26 -05:00
isanae 95a2cc93b9 queue management 2021-02-16 04:23:20 -05:00
isanae 35a0474ac1 initial new download manager 2021-02-16 02:33:20 -05:00
58 changed files with 3953 additions and 2507 deletions
@@ -2,7 +2,7 @@
name: Game support Request
about: Request support for a new game
title: Add support for game [GAME NAME]
labels: 'Feature Request, additional games support, area: mo2 game plugins'
labels: 'additional games support, Feature Request, area: mo2 game plugins'
assignees: ''
---
@@ -18,7 +18,7 @@ assignees: ''
- **Nexus ID [optional]:** ID of the game on Nexus (you can usually find this in Nexus URL).
- **Executable:** Name of the main executable for the game (relative to the game folder).
- **Launcher [optional]:** Name of the game launcher (relative to the game folder).
- **Data path:** Path to the data folder of the game (relative to the game folder). Please note that the Virtual Files System often does not work for top level dlls or exe files.
- **Data path:** Path to the data folder of the game (relative to the game folder).
- **Documents path:** Path to folder containing INI files, etc., for the game (usually under "My Games", or the game folder itself).
- **Saves directory [optional]:** Path to the folder containing save games (this default to the path above).
- **Save extension [optional]:** Extension of the saves
+1
View File
@@ -65,6 +65,7 @@ add_filter(NAME src/downloads GROUPS
downloadlist
downloadlistview
downloadmanager
downloadmanager2
)
add_filter(NAME src/env GROUPS
-5
View File
@@ -469,11 +469,6 @@
<string notr="true">Drew Warwick</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">foresto</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">GamerPoet</string>
+6 -13
View File
@@ -158,14 +158,14 @@ protected:
currentName = std::get<0>(p)[0];
}
// If the name is different, we need to create a directory from what we have
// If the name is different, we need to create a directory from what we have
// accumulated:
if (currentName != std::get<0>(p)[0]) {
// We may or may not have an index here, it depends on the type of archive (some archives list
// intermediate non-empty folders, some don't):
entries.push_back(std::make_shared<ArchiveFileTreeImpl>(parent, currentName, currentIndex, std::move(currentFiles)));
currentFiles.clear(); // Back to a valid state.
// Reset the index:
@@ -200,7 +200,7 @@ protected:
if (currentName != "") {
entries.push_back(std::make_shared<ArchiveFileTreeImpl>(parent, currentName, currentIndex, std::move(currentFiles)));
}
// Let the parent class sort the entries:
return false;
}
@@ -214,7 +214,7 @@ private:
mutable std::vector<File> m_Files;
};
std::shared_ptr<ArchiveFileTree> ArchiveFileTree::makeTree(Archive const& archive)
std::shared_ptr<ArchiveFileTree> ArchiveFileTree::makeTree(Archive const& archive)
{
auto const& data = archive.getFileList();
@@ -222,16 +222,9 @@ std::shared_ptr<ArchiveFileTree> ArchiveFileTree::makeTree(Archive const& archiv
files.reserve(data.size());
for (size_t i = 0; i < data.size(); ++i) {
// Ignore "." and ".." as they're useless and muck things up
if (data[i]->getArchiveFilePath().compare(L".") == 0 ||
data[i]->getArchiveFilePath().compare(L"..") == 0)
{
continue;
}
files.push_back(std::make_tuple(
QString::fromStdWString(data[i]->getArchiveFilePath()).replace("\\", "/").split("/", Qt::SkipEmptyParts),
data[i]->isDirectory(),
QString::fromStdWString(data[i]->getArchiveFilePath()).replace("\\", "/").split("/", Qt::SkipEmptyParts),
data[i]->isDirectory(),
(int) i));
}
+4 -49
View File
@@ -8,7 +8,6 @@
#include <iplugingame.h>
#include <report.h>
#include <utility.h>
#include "filesystemutilities.h"
namespace cid
{
@@ -293,7 +292,7 @@ void GamePage::select(IPluginGame* game, const QString& dir)
Game* checked = findGame(game);
if (checked) {
if (!checked->installed || (detectMicrosoftStore(checked->dir) && !confirmMicrosoftStore(checked->dir, checked->game))) {
if (!checked->installed) {
if (dir.isEmpty()) {
// the selected game has no installation directory and none was given,
// ask the user
@@ -305,9 +304,6 @@ void GamePage::select(IPluginGame* game, const QString& dir)
if (path.isEmpty()) {
// cancelled
checked = nullptr;
} else if (detectMicrosoftStore(path) && !confirmMicrosoftStore(path, game)) {
// cancelled
checked = nullptr;
} else {
// check whether a plugin supports the given directory; this can
// return the same plugin, a different one, or null
@@ -357,13 +353,6 @@ void GamePage::selectCustom()
return;
}
// Microsoft store games are not supported
if (detectMicrosoftStore(path) && !confirmMicrosoftStore(path, nullptr)) {
// reselect the previous button
selectButton(m_selection);
return;
}
// try to find a plugin that likes this directory
for (auto& g : m_games) {
if (g->game->looksValid(path)) {
@@ -604,11 +593,6 @@ GamePage::Game* GamePage::checkInstallation(const QString& path, Game* g)
return g;
}
if (detectMicrosoftStore(path) && confirmMicrosoftStore(path, g->game)) {
// okay
return g;
}
// the selected game can't use that folder, find another one
IPluginGame* otherGame = nullptr;
@@ -655,35 +639,6 @@ GamePage::Game* GamePage::checkInstallation(const QString& path, Game* g)
return g;
}
bool GamePage::detectMicrosoftStore(const QString& path)
{
return path.contains("/ModifiableWindowsApps/") ||
path.contains("/WindowsApps/");
}
bool GamePage::confirmMicrosoftStore(const QString& path, IPluginGame* game)
{
const auto r = TaskDialog(&m_dlg)
.title(QObject::tr("Microsoft Store game"))
.main(QObject::tr("Microsoft Store game"))
.content(QObject::tr(
"The folder %1 seems to be a Microsoft Store game install. Games"
" installed through the Microsoft Store are not supported by Mod Organizer"
" and will not work properly.")
.arg(path))
.button({
game ? QObject::tr("Use this folder for %1").arg(game->gameName())
: QObject::tr("Use this folder"),
QObject::tr("I know what I'm doing"),
QMessageBox::Ignore})
.button({
QObject::tr("Cancel"),
QMessageBox::Cancel})
.exec();
return (r == QMessageBox::Ignore);
}
bool GamePage::confirmUnknown(const QString& path, IPluginGame* game)
{
const auto r = TaskDialog(&m_dlg)
@@ -901,7 +856,7 @@ QString NamePage::selectedInstanceName() const
}
const auto text = ui->instanceName->text().trimmed();
return MOBase::sanitizeFileName(text);
return InstanceManager::singleton().sanitizeInstanceName(text);
}
void NamePage::onChanged()
@@ -928,7 +883,7 @@ bool NamePage::checkName(QString parentDir, QString name)
if (name.isEmpty()) {
empty = true;
} else {
if (MOBase::validFileName(name)) {
if (InstanceManager::singleton().validInstanceName(name)) {
exists = QDir(parentDir).exists(name);
} else {
invalid = true;
@@ -1153,7 +1108,7 @@ bool PathsPage::checkPath(
} else {
const QDir d(path);
if (MOBase::validFileName(d.dirName())) {
if (m.validInstanceName(d.dirName())) {
if (m_dlg.rawCreationInfo().type == CreateInstanceDialog::Portable) {
// the default data path for a portable instance is the application
// directory, so it's not an error if it exists
-9
View File
@@ -354,15 +354,6 @@ private:
MOBase::IPluginGame* confirmOtherGame(
const QString& path,
MOBase::IPluginGame* selectedGame, MOBase::IPluginGame* guessedGame);
// detects if the given path likely contains a Microsoft Store game
//
bool detectMicrosoftStore(const QString& path);
// tells the user that the path probably contains a Microsoft Store game that
// is not supported, returns true if the user decides to accept anyway.
//
bool confirmMicrosoftStore(const QString& path, MOBase::IPluginGame* game);
};
File diff suppressed because it is too large Load Diff
+212
View File
@@ -0,0 +1,212 @@
#ifndef MODORGANIZER_CURLDOWNLOADER_INCLUDED
#define MODORGANIZER_CURLDOWNLOADER_INCLUDED
#include <ipluginrepository.h>
namespace dm::curl
{
namespace fs = std::filesystem;
using hr_clock = std::chrono::high_resolution_clock;
struct defer_t {};
extern const defer_t defer;
class GlobalHandle
{
public:
GlobalHandle();
~GlobalHandle();
GlobalHandle(const GlobalHandle&) = delete;
GlobalHandle& operator=(const GlobalHandle) = delete;
};
class EasyHandle
{
public:
EasyHandle();
EasyHandle(defer_t);
~EasyHandle();
EasyHandle(const EasyHandle&) = delete;
EasyHandle& operator=(const EasyHandle&) = delete;
bool create();
CURL* get() const;
private:
CURL* m_handle;
};
class MultiHandle
{
public:
MultiHandle();
MultiHandle(defer_t);
~MultiHandle();
MultiHandle(const MultiHandle&) = delete;
MultiHandle& operator=(const MultiHandle&) = delete;
bool create();
CURLM* get() const;
private:
CURLM* m_handle;
};
class FileHandle
{
public:
FileHandle();
~FileHandle();
FileHandle(const FileHandle&) = delete;
FileHandle& operator=(const FileHandle&) = delete;
bool opened() const;
std::size_t open(fs::path p, bool append);
void close();
bool write(std::string_view sv);
private:
HANDLE m_handle;
fs::path m_path;
bool doOpen(bool append);
};
struct SListDeleter
{
void operator()(curl_slist* p)
{
if (p) {
curl_slist_free_all(p);
}
}
};
using SList = std::unique_ptr<curl_slist, SListDeleter>;
class Download : public MOBase::IDownload
{
public:
Download(std::string url, Info info);
CURL* setup(curl_off_t maxSpeed);
CURL* handle() const;
States state() const override;
Stats stats() const override;
std::string stealBuffer();
QByteArray buffer() const override;
int httpCode() const override;
std::string error() const;
std::string debugName() const;
void start();
void stop() override;
bool finish(CURLcode code);
bool xfer(
curl_off_t dltotal, curl_off_t dlnow,
curl_off_t ultotal, curl_off_t ulnow);
bool header(std::string_view sv);
bool write(std::string_view data);
void debug(curl_infotype t, std::string_view data);
private:
std::string m_url;
Info m_info;
EasyHandle m_handle;
FileHandle m_out;
SList m_headers;
std::string m_buffer;
States m_state;
std::string m_error;
hr_clock::time_point m_lastCheck;
std::size_t m_bytes;
std::atomic<double> m_bytesPerSecond;
std::atomic<double> m_progress;
std::size_t resumeFrom();
bool rename();
fs::path outputFile() const;
static int s_xfer(
void* p,
curl_off_t dltotal, curl_off_t dlnow,
curl_off_t ultotal, curl_off_t ulnow);
static size_t s_header(char* data, size_t size, size_t n, void* p);
static size_t s_write(char* data, size_t size, size_t n, void* p);
static int s_debug(CURL* h, curl_infotype t, char* data, size_t n, void *p);
};
class Downloader : public MOBase::IDownloader
{
public:
static const std::size_t NoLimit =
std::numeric_limits<std::size_t>::max();
Downloader();
~Downloader();
void cancel();
void stop();
void join();
void maxSpeed(std::size_t bytesPerSecond);
bool finished() const;
std::shared_ptr<MOBase::IDownload> add(
const QUrl& url, const MOBase::IDownload::Info& info={}) override;
private:
using DownloadList = std::list<std::shared_ptr<Download>>;
std::shared_ptr<GlobalHandle> m_global;
MultiHandle m_handle;
std::vector<std::shared_ptr<Download>> m_temp;
std::mutex m_tempMutex;
std::thread m_thread;
std::atomic<bool> m_cancel, m_stop, m_finished;
std::condition_variable m_cv;
DownloadList m_list;
std::map<CURL*, DownloadList::iterator> m_map;
std::atomic<std::size_t> m_maxSpeed;
void run();
void checkTemp();
void perform();
void poll();
bool start(std::shared_ptr<Download> d);
void setLimits();
void checkCancel();
void checkQueue();
bool cleanupActive();
DownloadList::iterator removeFromActive(DownloadList::iterator itor);
void stopOverMax(std::size_t max);
bool addFromQueue(std::size_t max);
curl_off_t maxSpeedPer() const;
};
} // namespace
#endif // MODORGANIZER_CURLDOWNLOADER_INCLUDED
+2 -2
View File
@@ -226,7 +226,7 @@ bool DownloadList::lessThanPredicate(const QModelIndex &left, const QModelIndex
if ((leftIndex < m_manager.numTotalDownloads())
&& (rightIndex < m_manager.numTotalDownloads())) {
if (left.column() == DownloadList::COL_NAME) {
return left.data(Qt::DisplayRole).toString().compare(right.data(Qt::DisplayRole).toString(), Qt::CaseInsensitive) < 0;
return m_manager.getFileName(left.row()).compare(m_manager.getFileName(right.row()), Qt::CaseInsensitive) < 0;
} else if (left.column() == DownloadList::COL_MODNAME) {
QString leftName, rightName;
@@ -275,7 +275,7 @@ bool DownloadList::lessThanPredicate(const QModelIndex &left, const QModelIndex
if (leftState == rightState)
return m_manager.getFileTime(left.row()) < m_manager.getFileTime(right.row());
else
return leftState < rightState;
return leftState > rightState;
} else if (left.column() == DownloadList::COL_SIZE) {
return m_manager.getFileSize(left.row()) < m_manager.getFileSize(right.row());
} else if (left.column() == DownloadList::COL_FILETIME) {
+2 -3
View File
@@ -33,7 +33,6 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include "shared/util.h"
#include <utility.h>
#include <report.h>
#include "filesystemutilities.h"
#include <QTimer>
#include <QFileInfo>
@@ -1457,7 +1456,7 @@ void DownloadManager::markUninstalled(QString fileName)
QString DownloadManager::getDownloadFileName(const QString &baseName, bool rename) const
{
QString fullPath = m_OutputDirectory + "/" + MOBase::sanitizeFileName(baseName);
QString fullPath = m_OutputDirectory + "/" + baseName;
if (QFile::exists(fullPath) && rename) {
int i = 1;
while (QFile::exists(QString("%1/%2_%3").arg(m_OutputDirectory).arg(i).arg(baseName))) {
@@ -1477,7 +1476,7 @@ QString DownloadManager::getFileNameFromNetworkReply(QNetworkReply *reply)
std::cmatch result;
if (std::regex_search(reply->rawHeader("Content-Disposition").constData(), result, exp)) {
return MOBase::sanitizeFileName(QString::fromUtf8(result.str(1).c_str()));
return QString::fromUtf8(result.str(1).c_str());
}
}
File diff suppressed because it is too large Load Diff
+114
View File
@@ -0,0 +1,114 @@
#ifndef MODORGANIZER_DOWNLOADEDMANAGER2_INCLUDED
#define MODORGANIZER_DOWNLOADEDMANAGER2_INCLUDED
#include <ipluginrepository.h>
class PluginContainer;
namespace dm::curl { class Downloader; class Download; }
namespace dm
{
namespace fs = std::filesystem;
class DownloadManager2;
class Download
{
public:
enum States
{
None = 0,
Queueing,
Queued,
Finished,
Errored,
Running,
Pausing,
Paused,
Cancelling,
Cancelled
};
Download(DownloadManager2& dm, MOBase::IPluginRepository& repo, QString what);
const QString& what() const;
const QString& error() const;
States state() const;
bool start();
void cancel();
void pause();
void queue();
void tick();
QString debugName() const;
private:
DownloadManager2& m_dm;
MOBase::IPluginRepository& m_repo;
std::unique_ptr<MOBase::IRepositoryDownload> m_download;
QString m_what;
States m_state;
QString m_error;
void setState(States s);
void next();
};
class DownloadManager2
{
public:
static const std::size_t NoLimit =
std::numeric_limits<std::size_t>::max();
DownloadManager2(PluginContainer& pc);
~DownloadManager2();
void add(QString what);
void maxActive(std::size_t n);
void maxSpeed(std::size_t bytesPerSecond);
bool hasActive() const;
curl::Downloader& downloader();
private:
using DownloadList = std::list<std::shared_ptr<Download>>;
PluginContainer& m_pc;
std::thread m_thread;
std::atomic<bool> m_stop;
std::unique_ptr<curl::Downloader> m_downloader;
std::vector<std::shared_ptr<Download>> m_temp;
std::mutex m_tempMutex;
std::condition_variable m_cv;
DownloadList m_queued, m_active, m_inactive;
std::atomic<std::size_t> m_maxActive, m_maxSpeed;
std::atomic<bool> m_hasActive;
void run();
void checkTemp();
void checkQueue();
void cleanupActive();
void stopOverMax(std::size_t max);
void addFromQueue(std::size_t max);
};
} // namespace
#endif // MODORGANIZER_DOWNLOADEDMANAGER2_INCLUDED
+5 -23
View File
@@ -232,8 +232,8 @@ void forEachEntryImpl(
if (status < 0) {
log::error(
"failed to open directory '{}': {}",
toString(poa), formatNtMessage(status));
"NtOpenFile() failed for '{}', {}",
toString(poa), formatSystemMessage(status));
return;
}
@@ -264,9 +264,8 @@ void forEachEntryImpl(
break;
} else if (status < 0) {
log::error(
"failed to read directory '{}': {}",
toString(poa), formatNtMessage(status));
"NtQueryDirectoryFile() failed for '{}', {}",
toString(poa), formatSystemMessage(status));
break;
}
@@ -322,23 +321,6 @@ void forEachEntryImpl(
}
}
std::wstring makeNtPath(const std::wstring& path)
{
constexpr const wchar_t* nt_prefix = L"\\??\\";
constexpr const wchar_t* nt_unc_prefix = L"\\??\\UNC\\";
constexpr const wchar_t* share_prefix = L"\\\\";
if (path.starts_with(nt_prefix)) {
// already an nt path
return path;
} else if (path.starts_with(share_prefix)) {
// network shared need \??\UNC\ as a prefix
return nt_unc_prefix + path.substr(2);
} else {
// prepend the \??\ prefix
return nt_prefix + path;
}
}
void DirectoryWalker::forEachEntry(
const std::wstring& path, void* cx,
@@ -353,7 +335,7 @@ void DirectoryWalker::forEachEntry(
NtClose = (NtClose_type)::GetProcAddress(m.get(), "NtClose");
}
const std::wstring ntpath = makeNtPath(path);
const std::wstring ntpath = std::wstring(L"\\??\\") + path;
UNICODE_STRING ObjectName = {};
ObjectName.Buffer = const_cast<wchar_t*>(ntpath.c_str());
+2 -2
View File
@@ -130,7 +130,7 @@ Module::FileInfo Module::getFileInfo() const
return {};
}
log::debug(
log::error(
"GetFileVersionInfoSizeW() failed on '{}', {}",
m_path, formatSystemMessage(e));
@@ -268,7 +268,7 @@ QDateTime Module::getTimestamp(const VS_FIXEDFILEINFO& fi) const
if (h.get() == INVALID_HANDLE_VALUE) {
const auto e = GetLastError();
log::debug(
log::error(
"can't open file '{}' for timestamp, {}",
m_path, formatSystemMessage(e));
+1 -1
View File
@@ -21,7 +21,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include "installationmanager.h"
#include "filesystemutilities.h"
#include "utility.h"
#include "report.h"
#include "categories.h"
#include "questionboxmemory.h"
+30 -2
View File
@@ -32,7 +32,6 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include <iplugingame.h>
#include <utility.h>
#include <log.h>
#include "filesystemutilities.h"
#include <QCoreApplication>
#include <QDir>
@@ -722,7 +721,7 @@ const MOBase::IPluginGame* InstanceManager::gamePluginForDirectory(
QString InstanceManager::makeUniqueName(const QString& instanceName) const
{
const QString sanitized = MOBase::sanitizeFileName(instanceName);
const QString sanitized = sanitizeInstanceName(instanceName);
// trying "name (N)"
QString name = sanitized;
@@ -743,6 +742,35 @@ bool InstanceManager::instanceExists(const QString& instanceName) const
return root.exists(instanceName);
}
QString InstanceManager::sanitizeInstanceName(const QString &name) const
{
QString new_name = name;
// Restrict the allowed characters
new_name = new_name.remove(QRegExp("[^A-Za-z0-9 _=+;!@#$%^'\\-\\.\\[\\]\\{\\}\\(\\)]"));
// Don't end in spaces and periods
new_name = new_name.remove(QRegExp("\\.*$"));
new_name = new_name.remove(QRegExp(" *$"));
// Recurse until stuff stops changing
if (new_name != name) {
return sanitizeInstanceName(new_name);
}
return new_name;
}
bool InstanceManager::validInstanceName(const QString& instanceName) const
{
if (instanceName.isEmpty()) {
return false;
}
return (instanceName == sanitizeInstanceName(instanceName));
}
std::unique_ptr<Instance> selectInstance()
{
auto& m = InstanceManager::singleton();
+10
View File
@@ -305,6 +305,10 @@ public:
//
std::vector<QString> globalInstancePaths() const;
// returns `name` modified so that it is a valid instance name
//
QString sanitizeInstanceName(const QString &name) const;
// sanitizes the given instance name and either
// 1) returns it if there is no instance with this name
// 2) tries to add " (N)" at the end until it works
@@ -317,6 +321,12 @@ public:
//
bool instanceExists(const QString& instanceName) const;
// returns whether the given instance name would be a valid name; this does
// not check whether the instance already exists, it's basiscally just a check
// against what sanitizeInstanceName() returns
//
bool validInstanceName(const QString& instanceName) const;
// returns the absolute path of a global instance with the given name; this
// does not check if the name is valid or if exists
//
+3 -4
View File
@@ -10,7 +10,6 @@
#include <utility.h>
#include <report.h>
#include <iplugingame.h>
#include "filesystemutilities.h"
using namespace MOBase;
@@ -110,10 +109,10 @@ QString getInstanceName(
if (text->text().isEmpty()) {
error->setText("");
} else if (!MOBase::validFileName(text->text())) {
} else if (!m.validInstanceName(text->text())) {
error->setText(QObject::tr("The instance name must be a valid folder name."));
} else {
const auto name = MOBase::sanitizeFileName(text->text());
const auto name = m.sanitizeInstanceName(text->text());
if ((name != oldName) && m.instanceExists(text->text())) {
error->setText(QObject::tr("An instance with this name already exists."));
@@ -137,7 +136,7 @@ QString getInstanceName(
return {};
}
return MOBase::sanitizeFileName(text->text());
return m.sanitizeInstanceName(text->text());
}
+1
View File
@@ -7,6 +7,7 @@
#include "instancemanager.h"
#include "thread_utils.h"
#include "shared/util.h"
#include "downloadmanager2.h"
#include <report.h>
#include <log.h>
+23 -74
View File
@@ -351,7 +351,6 @@ MainWindow::MainWindow(Settings &settings
}
settings.geometry().restoreState(ui->downloadView->header());
settings.geometry().restoreState(ui->savegameList->header());
ui->splitter->setStretchFactor(0, 3);
ui->splitter->setStretchFactor(1, 2);
@@ -513,8 +512,6 @@ void MainWindow::setupModList()
connect(&ui->modList->actions(), &ModListViewActions::overwriteCleared, [=]() { scheduleCheckForProblems(); });
connect(&ui->modList->actions(), &ModListViewActions::originModified, this, &MainWindow::originModified);
connect(&ui->modList->actions(), &ModListViewActions::modInfoDisplayed, this, &MainWindow::modInfoDisplayed);
connect(m_OrganizerCore.modList(), &ModList::modPrioritiesChanged, [&]() { m_ArchiveListWriter.write(); });
}
@@ -1440,36 +1437,12 @@ void MainWindow::registerModPage(IPluginModPage *modPage)
ui->actionModPage->menu()->addAction(action);
}
bool MainWindow::registerNexusPage(const QString& gameName)
{
// Get the plugin
IPluginGame* plugin = m_OrganizerCore.getGame(gameName);
if (plugin == nullptr)
return false;
// Create an action
QAction* action = new QAction(
plugin->gameIcon(),
QObject::tr("Visit %1 on Nexus").arg(plugin->gameName()),
this);
// Bind the action
connect(action, &QAction::triggered, this, [this, gameName]() {
shell::Open(QUrl(NexusInterface::instance().getGameURL(gameName)));
}, Qt::QueuedConnection);
// Add the action
ui->actionModPage->menu()->addAction(action);
return true;
}
void MainWindow::updateModPageMenu()
{
// Clear the menu:
ui->actionModPage->menu()->clear();
ui->actionModPage->menu()->addAction(ui->actionNexus);
// Determine the loaded mod page plugins
std::vector<IPluginModPage*> modPagePlugins = m_PluginContainer.plugins<IPluginModPage>();
// Sort the plugins by display name
@@ -1490,30 +1463,14 @@ void MainWindow::updateModPageMenu()
registerModPage(modPagePlugin);
}
// Add the primary game (with a separator)
registerNexusPage(m_OrganizerCore.managedGame()->gameShortName());
ui->actionModPage->menu()->addSeparator();
// Add the secondary games (sorted)
bool secondaryGameAdded = false;
QStringList secondaryGames = m_OrganizerCore.managedGame()->validShortNames();
secondaryGames.sort(Qt::CaseInsensitive);
for (auto gameName : secondaryGames)
{
if (registerNexusPage(gameName)) {
secondaryGameAdded = true;
}
}
// No mod page plugin and the menu was visible:
bool keepOriginalAction = modPagePlugins.size() == 0 && !secondaryGameAdded;
if (keepOriginalAction) {
if (modPagePlugins.empty()) {
ui->toolBar->insertAction(ui->actionAdd_Profile, ui->actionNexus);
}
else {
ui->toolBar->removeAction(ui->actionNexus);
}
ui->actionModPage->setVisible(!keepOriginalAction);
ui->actionModPage->setVisible(!modPagePlugins.empty());
}
void MainWindow::startExeAction()
@@ -2046,7 +2003,6 @@ void MainWindow::storeSettings()
s.geometry().saveState(ui->espList->header());
s.geometry().saveState(ui->downloadView->header());
s.geometry().saveState(ui->savegameList->header());
s.widgets().saveIndex(ui->executablesListBox);
s.widgets().saveIndex(ui->tabWidget);
@@ -2188,15 +2144,6 @@ void MainWindow::on_actionAdd_Profile_triggered()
profilesDialog.exec();
m_SavesTab->refreshSaveList(); // since the save list may now be outdated we have to refresh it completely
if (profilesDialog.selectedProfile())
{
// Change profile while blocking signals to prevent extra signals being sent
// Doesn't matter much as refreshProfiles() is being called after this
ui->profileBox->blockSignals(true);
ui->profileBox->setCurrentText(profilesDialog.selectedProfile().value());
ui->profileBox->blockSignals(false);
}
if (refreshProfiles() && !profilesDialog.failed()) {
break;
}
@@ -2872,37 +2819,41 @@ void MainWindow::nxmUpdateInfoAvailable(QString gameName, QVariant userData, QVa
}
QVariantList resultList = resultData.toList();
auto* watcher = new QFutureWatcher<NxmUpdateInfoData>();
QObject::connect(watcher, &QFutureWatcher<NxmUpdateInfoData>::finished, [this, watcher]() {
finishUpdateInfo(watcher->result());
watcher->deleteLater();
});
auto future = QtConcurrent::run([=]() {
return NxmUpdateInfoData{ gameNameReal, ModInfo::filteredMods(gameNameReal, resultList, userData.toBool(), true) };
QFutureWatcher<std::pair<QString, std::set<QSharedPointer<ModInfo>>>> *watcher = new QFutureWatcher<std::pair<QString, std::set<QSharedPointer<ModInfo>>>>();
QObject::connect(watcher, &QFutureWatcher<std::set<QSharedPointer<ModInfo>>>::finished, this, &MainWindow::finishUpdateInfo);
QFuture<std::pair<QString, std::set<QSharedPointer<ModInfo>>>> future = QtConcurrent::run([=]() -> std::pair<QString, std::set<QSharedPointer<ModInfo>>> {
return std::make_pair(gameNameReal, ModInfo::filteredMods(gameNameReal, resultList, userData.toBool(), true));
});
watcher->setFuture(future);
ui->modList->invalidateFilter();
}
void MainWindow::finishUpdateInfo(const NxmUpdateInfoData& data)
void MainWindow::finishUpdateInfo()
{
if (data.finalMods.empty()) {
log::info("{}", tr("None of your %1 mods appear to have had recent file updates.").arg(data.game));
QFutureWatcher<std::pair<QString, std::set<QSharedPointer<ModInfo>>>> *watcher = static_cast<QFutureWatcher<std::pair<QString, std::set<QSharedPointer<ModInfo>>>> *>(sender());
QString game = watcher->result().first;
auto finalMods = watcher->result().second;
if (finalMods.empty()) {
log::info("{}", tr("None of your %1 mods appear to have had recent file updates.").arg(game));
}
std::set<std::pair<QString, int>> organizedGames;
for (auto& mod : data.finalMods) {
for (auto mod : finalMods) {
if (mod->canBeUpdated()) {
organizedGames.insert(std::make_pair<QString, int>(mod->gameName().toLower(), mod->nexusId()));
}
m_OrganizerCore.modList()->notifyChange(ModInfo::getIndex(mod->name()));
}
if (!data.finalMods.empty() && organizedGames.empty())
if (!finalMods.empty() && organizedGames.empty())
log::warn("{}", tr("All of your mods have been checked recently. We restrict update checks to help preserve your available API requests."));
for (const auto& game : organizedGames) {
for (auto game : organizedGames)
NexusInterface::instance().requestUpdates(game.second, this, QVariant(), game.first, QString());
}
disconnect(sender());
delete sender();
}
void MainWindow::nxmUpdatesAvailable(QString gameName, int modID, QVariant userData, QVariant resultData, int requestID)
@@ -2977,15 +2928,13 @@ void MainWindow::nxmUpdatesAvailable(QString gameName, int modID, QVariant userD
if (foundUpdate) {
// Just get the standard data updates for endorsements and descriptions
mod->setLastNexusUpdate(QDateTime::currentDateTimeUtc());
m_OrganizerCore.modList()->notifyChange(ModInfo::getIndex(mod->name()));
} else {
// Scrape mod data here so we can use the mod version if no file update was located
requiresInfo = true;
}
}
// invalidate the filter to display mods with an update
ui->modList->invalidateFilter();
if (requiresInfo)
NexusInterface::instance().requestModInfo(gameNameReal, modID, this, QVariant(), QString());
}

Some files were not shown because too many files have changed in this diff Show More