From a2eb3e02665ae4dd2d6029142ac28d27f1cef361 Mon Sep 17 00:00:00 2001 From: LostDragonist Date: Sun, 19 Aug 2018 13:02:30 -0500 Subject: Prevent user from deleting currently active profile --- src/organizer_en.ts | 80 +++++++++++++++++++++++++------------------------- src/profilesdialog.cpp | 14 +++++++-- src/profilesdialog.h | 1 + 3 files changed, 52 insertions(+), 43 deletions(-) (limited to 'src') diff --git a/src/organizer_en.ts b/src/organizer_en.ts index 0d0cae2c..8b8bd101 100644 --- a/src/organizer_en.ts +++ b/src/organizer_en.ts @@ -2886,7 +2886,7 @@ You can also use online editors and converters instead. - + Error @@ -2966,79 +2966,79 @@ You can also use online editors and converters instead. - + loot failed. Exit code was: %1 - + failed to start loot - + failed to run loot: %1 - + Errors occured - + Backup of load order created - + Choose backup to restore - + No Backups - + There are no backups to restore - - + + Restore failed - - + + Failed to restore the backup. Errorcode: %1 - + Backup of modlist created - + A file with the same name has already been downloaded. What would you like to do? - + Overwrite - + Rename new file - + Ignore file @@ -4199,108 +4199,108 @@ p, li { white-space: pre-wrap; } - + Error - + Windows Event Log Error - + The Windows Event Log service is disabled and/or not running. This prevents USVFS from running properly. Your mods may not be working in the executable that you are launching. Note that you may have to restart MO and/or your PC after the service is fixed. Continue launching %1? - + No profile set - + Failed to refresh list of esps: %1 - + Multiple esps/esls activated, please check that they don't conflict. - + Download? - + A download has been started but no installed page plugin recognizes it. If you download anyway no information (i.e. version) will be associated with the download. Continue? - + failed to update mod list: %1 - - + + login successful - + Login failed - + Login failed, try again? - + login failed: %1. Download will not be associated with an account - + login failed: %1 - + login failed: %1. You need to log-in with Nexus to update MO. - + MO1 "Script Extender" load mechanism has left hook.dll in your game folder - - + + Description missing - + <a href="%1">hook.dll</a> has been found in your game folder (right click to copy the full path). This is most likely a leftover of setting the ModOrganizer 1 load mechanism to "Script Extender", in which case you must remove this file either by changing the load mechanism in ModOrganizer 1 or manually removing the file, otherwise the game is likely to crash and burn. - + failed to save load order: %1 - + The designated write target "%1" is not enabled. diff --git a/src/profilesdialog.cpp b/src/profilesdialog.cpp index 04c1876d..f0bbe6ed 100644 --- a/src/profilesdialog.cpp +++ b/src/profilesdialog.cpp @@ -53,6 +53,7 @@ ProfilesDialog::ProfilesDialog(const QString &profileName, MOBase::IPluginGame c , ui(new Ui::ProfilesDialog) , m_FailState(false) , m_Game(game) + , m_ActiveProfileName("") { ui->setupUi(this); @@ -66,6 +67,7 @@ ProfilesDialog::ProfilesDialog(const QString &profileName, MOBase::IPluginGame c QListWidgetItem *item = addItem(profileIter.filePath()); if (profileName == profileIter.fileName()) { ui->profilesList->setCurrentItem(item); + m_ActiveProfileName = profileName; } } @@ -182,13 +184,19 @@ void ProfilesDialog::on_copyProfileButton_clicked() void ProfilesDialog::on_removeProfileButton_clicked() { + Profile::Ptr profileToDelete = ui->profilesList->currentItem()->data(Qt::UserRole).value(); + if (profileToDelete->name() == m_ActiveProfileName) { + QMessageBox::warning(this, tr("Deleting active profile"), + tr("Unable to delete active profile. Please change to a different profile first.")); + return; + } + QMessageBox confirmBox(QMessageBox::Question, tr("Confirm"), tr("Are you sure you want to remove this profile (including local savegames if any)?"), QMessageBox::Yes | QMessageBox::No); if (confirmBox.exec() == QMessageBox::Yes) { - Profile::Ptr currentProfile = ui->profilesList->currentItem()->data(Qt::UserRole).value(); QString profilePath; - if (currentProfile.get() == nullptr) { + if (profileToDelete.get() == nullptr) { profilePath = Settings::instance().getProfileDirectory() + "/" + ui->profilesList->currentItem()->text(); if (QMessageBox::question(this, tr("Profile broken"), @@ -199,7 +207,7 @@ void ProfilesDialog::on_removeProfileButton_clicked() } else { // on destruction, the profile object would write the profile.ini file again, so // we have to get rid of the it before deleting the directory - profilePath = currentProfile->absolutePath(); + profilePath = profileToDelete->absolutePath(); } QListWidgetItem* item = ui->profilesList->takeItem(ui->profilesList->currentRow()); if (item != nullptr) { diff --git a/src/profilesdialog.h b/src/profilesdialog.h index cab25f6a..a328ce40 100644 --- a/src/profilesdialog.h +++ b/src/profilesdialog.h @@ -95,6 +95,7 @@ private: QListWidget *m_ProfilesList; bool m_FailState; MOBase::IPluginGame const *m_Game; + QString m_ActiveProfileName; }; #endif // PROFILESDIALOG_H -- cgit v1.3.1