Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default profile settings #1869

Merged
merged 2 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/createinstancedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ CreateInstanceDialog::CreateInstanceDialog(const PluginContainer& pc, Settings*
m_pages.push_back(std::make_unique<GamePage>(*this));
m_pages.push_back(std::make_unique<VariantsPage>(*this));
m_pages.push_back(std::make_unique<NamePage>(*this));
m_pages.push_back(std::make_unique<ProfilePage>(*this));
m_pages.push_back(std::make_unique<PathsPage>(*this));
m_pages.push_back(std::make_unique<NexusPage>(*this));
m_pages.push_back(std::make_unique<ConfirmationPage>(*this));
Expand Down Expand Up @@ -355,6 +356,10 @@ void CreateInstanceDialog::finish()
s.paths().setOverwrite(ci.paths.overwrite);
}

s.setProfileLocalInis(ci.profileSettings.localInis);
s.setProfileLocalSaves(ci.profileSettings.localSaves);
s.setProfileArchiveInvalidation(ci.profileSettings.archiveInvalidation);

logCreation(tr("Writing %1...").arg(ci.iniPath));

// writing ini
Expand Down Expand Up @@ -475,12 +480,13 @@ CreateInstanceDialog::CreationInfo CreateInstanceDialog::rawCreationInfo() const

CreationInfo ci;

ci.type = getSelected(&cid::Page::selectedInstanceType);
ci.game = getSelected(&cid::Page::selectedGame);
ci.gameLocation = getSelected(&cid::Page::selectedGameLocation);
ci.gameVariant = getSelected(&cid::Page::selectedGameVariant, ci.game);
ci.instanceName = getSelected(&cid::Page::selectedInstanceName);
ci.paths = getSelected(&cid::Page::selectedPaths);
ci.type = getSelected(&cid::Page::selectedInstanceType);
ci.game = getSelected(&cid::Page::selectedGame);
ci.gameLocation = getSelected(&cid::Page::selectedGameLocation);
ci.gameVariant = getSelected(&cid::Page::selectedGameVariant, ci.game);
ci.instanceName = getSelected(&cid::Page::selectedInstanceName);
ci.profileSettings = getSelected(&cid::Page::profileSettings);
ci.paths = getSelected(&cid::Page::selectedPaths);

if (ci.type == Portable) {
ci.dataPath = QDir(InstanceManager::singleton().portablePath()).absolutePath();
Expand Down
10 changes: 10 additions & 0 deletions src/createinstancedialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ class CreateInstanceDialog : public QDialog
auto operator<=>(const Paths&) const = default;
};

struct ProfileSettings
{
bool localInis;
bool localSaves;
bool archiveInvalidation;

auto operator<=>(const ProfileSettings&) const = default;
};

// all the info filled in the various pages
//
struct CreationInfo
Expand All @@ -78,6 +87,7 @@ class CreateInstanceDialog : public QDialog
QString dataPath;
QString iniPath;
Paths paths;
ProfileSettings profileSettings;
};

CreateInstanceDialog(const PluginContainer& pc, Settings* s,
Expand Down
90 changes: 86 additions & 4 deletions src/createinstancedialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
<property name="font">
<font>
<pointsize>14</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
Expand Down Expand Up @@ -294,7 +293,7 @@
<x>0</x>
<y>0</y>
<width>455</width>
<height>286</height>
<height>275</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_26">
Expand Down Expand Up @@ -430,7 +429,7 @@
<x>0</x>
<y>0</y>
<width>455</width>
<height>278</height>
<height>265</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_17">
Expand Down Expand Up @@ -546,6 +545,90 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="page">
<layout class="QVBoxLayout" name="verticalLayout_31">
<item>
<widget class="QWidget" name="widget_24" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_8">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="profileSettingsLabel">
<property name="text">
<string>&lt;h3&gt;Configure your profile settings.&lt;/h3&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="widget_25" native="true">
<layout class="QVBoxLayout" name="verticalLayout_28">
<item>
<widget class="QCheckBox" name="profileInisCheckbox">
<property name="toolTip">
<string extracomment="Enabling this will copy your game's INI files into each profile, which will override the default INI settings"/>
</property>
<property name="text">
<string>Use profile-specific game INI files</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="profileSavesCheckbox">
<property name="toolTip">
<string extracomment="Enabling this will redirect the game's save files into your active profile, allowing you to separate your saves between profiles"/>
</property>
<property name="text">
<string>Use profile-specific save games</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="archiveInvalidationCheckbox">
<property name="toolTip">
<string extracomment="Enabling this will allow MO2 to automatically run necessary INI edits or other steps to allow file overrides in the game."/>
</property>
<property name="text">
<string>Automatic archive invalidation</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_7">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_6">
<layout class="QVBoxLayout" name="verticalLayout_14">
<item>
Expand Down Expand Up @@ -1242,7 +1325,6 @@
<tabstop>showAllGames</tabstop>
<tabstop>gamesFilter</tabstop>
<tabstop>scrollArea_2</tabstop>
<tabstop>instanceName</tabstop>
<tabstop>location</tabstop>
<tabstop>browseLocation</tabstop>
<tabstop>advancedPathOptions</tabstop>
Expand Down
33 changes: 33 additions & 0 deletions src/createinstancedialogpages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ CreateInstanceDialog::Paths Page::selectedPaths() const
return {};
}

CreateInstanceDialog::ProfileSettings Page::profileSettings() const
{
// no-op
return {};
}

IntroPage::IntroPage(CreateInstanceDialog& dlg)
: Page(dlg), m_skip(GlobalSettings::hideCreateInstanceIntro())
{
Expand Down Expand Up @@ -931,6 +937,22 @@ bool NamePage::checkName(QString parentDir, QString name)
return okay;
}

ProfilePage::ProfilePage(CreateInstanceDialog& dlg) : Page(dlg) {}

bool ProfilePage::ready() const
{
return true;
}

CreateInstanceDialog::ProfileSettings ProfilePage::profileSettings() const
{
CreateInstanceDialog::ProfileSettings profileSettings;
profileSettings.localInis = ui->profileInisCheckbox->isChecked();
profileSettings.localSaves = ui->profileSavesCheckbox->isChecked();
profileSettings.archiveInvalidation = ui->archiveInvalidationCheckbox->isChecked();
return profileSettings;
}

PathsPage::PathsPage(CreateInstanceDialog& dlg)
: Page(dlg), m_lastType(CreateInstanceDialog::NoType), m_label(ui->pathsLabel),
m_simpleExists(ui->locationExists), m_simpleInvalid(ui->locationInvalid),
Expand Down Expand Up @@ -1215,6 +1237,17 @@ QString ConfirmationPage::makeReview() const
lines.push_back(QObject::tr("Instance name: %1").arg(ci.instanceName));
}

lines.push_back(QObject::tr("Profile settings:"));
lines.push_back(
QObject::tr(" Local INIs: %1")
.arg(ci.profileSettings.localInis ? QObject::tr("yes") : QObject::tr("no")));
lines.push_back(
QObject::tr(" Local Saves: %1")
.arg(ci.profileSettings.localSaves ? QObject::tr("yes") : QObject::tr("no")));
lines.push_back(QObject::tr(" Automatic Archive Invalidation: %1")
.arg(ci.profileSettings.archiveInvalidation ? QObject::tr("yes")
: QObject::tr("no")));

if (ci.paths.downloads.isEmpty()) {
// simple settings
if (ci.paths.base != ci.dataPath) {
Expand Down
19 changes: 19 additions & 0 deletions src/createinstancedialogpages.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ class Page
//
virtual CreateInstanceDialog::Paths selectedPaths() const;

// returns the profile settings
//
virtual CreateInstanceDialog::ProfileSettings profileSettings() const;

protected:
Ui::CreateInstanceDialog* ui;
CreateInstanceDialog& m_dlg;
Expand Down Expand Up @@ -557,6 +561,21 @@ class PathsPage : public Page
void setIfEmpty(QLineEdit* e, const QString& path, bool force);
};

// default settings for profiles page; allow the user to set their preferred
// defaults for the profile options
//
class ProfilePage : public Page
{
public:
ProfilePage(CreateInstanceDialog& dlg);

// always returns true, options are boolean
//
bool ready() const override;

CreateInstanceDialog::ProfileSettings profileSettings() const override;
};

// nexus connection page; this reuses the ui found in the settings dialog and
// is skipped if there's already an api key in the credentials manager
//
Expand Down
48 changes: 37 additions & 11 deletions src/profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,22 +157,36 @@ void Profile::findProfileSettings()
{
if (setting("", "LocalSaves") == QVariant()) {
if (m_Directory.exists("saves")) {
storeSetting("", "LocalSaves", true);
if (!Settings::instance().profileLocalSaves()) {
m_Directory.rename("saves", "_saves");
storeSetting("", "LocalSaves", false);
} else {
storeSetting("", "LocalSaves", true);
}
} else {
if (m_Directory.exists("_saves")) {
m_Directory.rename("_saves", "saves");
if (Settings::instance().profileLocalSaves()) {
m_Directory.rename("_saves", "saves");
storeSetting("", "LocalSaves", true);
} else {
storeSetting("", "LocalSaves", false);
}
} else {
storeSetting("", "LocalSaves", Settings::instance().profileLocalSaves());
}
storeSetting("", "LocalSaves", false);
}
}

if (setting("", "LocalSettings") == QVariant()) {
QString backupFile = getIniFileName() + "_";
if (m_Directory.exists(backupFile)) {
storeSetting("", "LocalSettings", false);
storeSetting("", "LocalSettings", true);
m_Directory.rename(backupFile, getIniFileName());
} else {
} else if (Settings::instance().profileLocalInis()) {
storeSetting("", "LocalSettings", true);
enableLocalSettings(true);
} else {
storeSetting("", "LocalSettings", false);
}
}

Expand All @@ -183,14 +197,23 @@ void Profile::findProfileSettings()
if ((invalidation != nullptr) && (dataArchives != nullptr)) {
for (const QString& archive : dataArchives->archives(this)) {
if (invalidation->isInvalidationBSA(archive)) {
storeSetting("", "AutomaticArchiveInvalidation", true);
found = true;
break;
}
}
}
if (!found) {
storeSetting("", "AutomaticArchiveInvalidation", false);
if (found) {
if (!Settings::instance().profileArchiveInvalidation()) {
deactivateInvalidation();
} else {
storeSetting("", "AutomaticArchiveInvalidation", true);
}
} else {
if (Settings::instance().profileArchiveInvalidation()) {
activateInvalidation();
} else {
storeSetting("", "AutomaticArchiveInvalidation", false);
}
}
}
}
Expand Down Expand Up @@ -795,7 +818,9 @@ bool Profile::invalidationActive(bool* supported) const
*supported = ((invalidation != nullptr) && (dataArchives != nullptr));
}

return setting("", "AutomaticArchiveInvalidation", false).toBool();
return setting("", "AutomaticArchiveInvalidation",
Settings::instance().profileArchiveInvalidation())
.toBool();
}

void Profile::deactivateInvalidation()
Expand All @@ -822,7 +847,7 @@ void Profile::activateInvalidation()

bool Profile::localSavesEnabled() const
{
return setting("", "LocalSaves", false).toBool();
return setting("", "LocalSaves", Settings::instance().profileLocalSaves()).toBool();
}

bool Profile::enableLocalSaves(bool enable)
Expand Down Expand Up @@ -856,7 +881,8 @@ bool Profile::enableLocalSaves(bool enable)

bool Profile::localSettingsEnabled() const
{
bool enabled = setting("", "LocalSettings", false).toBool();
bool enabled =
setting("", "LocalSettings", Settings::instance().profileLocalInis()).toBool();
if (enabled) {
QStringList missingFiles;
for (QString file : m_GamePlugin->iniFiles()) {
Expand Down
Loading
Loading