diff options
Diffstat (limited to 'src/organizercore.cpp')
| -rw-r--r-- | src/organizercore.cpp | 91 |
1 files changed, 73 insertions, 18 deletions
diff --git a/src/organizercore.cpp b/src/organizercore.cpp index a4746ddd..3d996b01 100644 --- a/src/organizercore.cpp +++ b/src/organizercore.cpp @@ -373,11 +373,13 @@ void OrganizerCore::setUserInterface(IUserInterface *userInterface, QWidget *wid m_InstallationManager.setParentWidget(widget);
m_Updater.setUserInterface(widget);
- // this currently wouldn't work reliably if the ui isn't initialized yet to display the result
- if (isOnline() && !m_Settings.offlineMode()) {
- m_Updater.testForUpdate();
- } else {
- qDebug("user doesn't seem to be connected to the internet");
+ if (userInterface != nullptr) {
+ // this currently wouldn't work reliably if the ui isn't initialized yet to display the result
+ if (isOnline() && !m_Settings.offlineMode()) {
+ m_Updater.testForUpdate();
+ } else {
+ qDebug("user doesn't seem to be connected to the internet");
+ }
}
}
@@ -421,21 +423,28 @@ Settings &OrganizerCore::settings() return m_Settings;
}
-bool OrganizerCore::nexusLogin()
+bool OrganizerCore::nexusLogin(bool retry)
{
- QString username, password;
-
NXMAccessManager *accessManager = NexusInterface::instance()->getAccessManager();
- if (!accessManager->loginAttempted()
- && !accessManager->loggedIn()
- && (m_Settings.getNexusLogin(username, password)
- || (m_AskForNexusPW
- && queryLogin(username, password)))) {
- accessManager->login(username, password);
- return true;
- } else {
+ if ((accessManager->loginAttempted()
+ || accessManager->loggedIn())
+ && !retry) {
+ // previous attempt, maybe even successful
return false;
+ } else {
+ QString username, password;
+ 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));
+ accessManager->login(username, password);
+ return true;
+ } else {
+ // no credentials stored and user didn't enter them
+ accessManager->refuseLogin();
+ return false;
+ }
}
}
@@ -1433,9 +1442,15 @@ void OrganizerCore::loginSuccessfulUpdate(bool necessary) void OrganizerCore::loginFailed(const QString &message)
{
+ if (QMessageBox::question(qApp->activeWindow(), tr("Login failed"), tr("Login failed, try again?")) == QMessageBox::Yes) {
+ if (nexusLogin(true)) {
+ return;
+ }
+ }
+
if (!m_PendingDownloads.isEmpty()) {
- MessageDialog::showMessage(tr("login failed: %1. Trying to download anyway").arg(message), qApp->activeWindow());
- foreach (QString url, m_PendingDownloads) {
+ MessageDialog::showMessage(tr("login failed: %1. Download will not be associated with an account").arg(message), qApp->activeWindow());
+ for (QString url : m_PendingDownloads) {
downloadRequestedNXM(url);
}
m_PendingDownloads.clear();
@@ -1555,3 +1570,43 @@ void OrganizerCore::prepareStart() { storeSettings();
}
+std::vector<std::pair<QString, QString>> OrganizerCore::fileMapping()
+{
+ IPluginGame *game = qApp->property("managed_game").value<IPluginGame*>();
+ return fileMapping(game->dataDirectory().absolutePath(),
+ directoryStructure(),
+ directoryStructure());
+}
+
+
+std::vector<std::pair<QString, QString>> OrganizerCore::fileMapping(
+ const QString &dataPath,
+ const DirectoryEntry *base,
+ const DirectoryEntry *directoryEntry)
+{
+ std::vector<std::pair<QString, QString>> result;
+
+ for (FileEntry::Ptr current : directoryEntry->getFiles()) {
+ bool isArchive = false;
+ int origin = current->getOrigin(isArchive);
+ if (isArchive || (origin == 0)) {
+ continue;
+ }
+
+ QString fileName = ToQString(current->getRelativePath());
+ QString source = ToQString(base->getOriginByID(origin).getPath()) + fileName;
+ QString target = QDir::toNativeSeparators(dataPath) + fileName;
+ result.push_back(std::make_pair(source, target));
+ }
+
+ // recurse into subdirectories
+ std::vector<DirectoryEntry*>::const_iterator current, end;
+ directoryEntry->getSubDirectories(current, end);
+ for (; current != end; ++current) {
+ std::vector<std::pair<QString, QString>> subRes = fileMapping(dataPath, base, *current);
+ result.insert(result.end(), subRes.begin(), subRes.end());
+ }
+ return result;
+}
+
+
|
