@@ -27,6 +27,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
27
27
#include < QStandardPaths>
28
28
#include < QInputDialog>
29
29
#include < QMessageBox>
30
+ #include < cstdint>
30
31
31
32
32
33
static const char COMPANY_NAME[] = " Tannin" ;
@@ -40,6 +41,11 @@ InstanceManager::InstanceManager()
40
41
{
41
42
}
42
43
44
+ InstanceManager &InstanceManager::instance ()
45
+ {
46
+ static InstanceManager s_Instance;
47
+ return s_Instance;
48
+ }
43
49
44
50
QString InstanceManager::currentInstance () const
45
51
{
@@ -49,6 +55,7 @@ QString InstanceManager::currentInstance() const
49
55
void InstanceManager::clearCurrentInstance ()
50
56
{
51
57
setCurrentInstance (" " );
58
+ m_Reset = true ;
52
59
}
53
60
54
61
void InstanceManager::setCurrentInstance (const QString &name)
@@ -81,26 +88,51 @@ QString InstanceManager::queryInstanceName() const
81
88
82
89
QString InstanceManager::chooseInstance (const QStringList &instanceList) const
83
90
{
84
- SelectionDialog selection (QObject::tr (" Choose Instance" ), nullptr );
91
+ enum class Special : uint8_t {
92
+ NewInstance,
93
+ Portable
94
+ };
95
+
96
+ SelectionDialog selection (
97
+ QString (" <h3>%1</h3><br>%2" )
98
+ .arg (QObject::tr (" Choose Instance" ))
99
+ .arg (QObject::tr (
100
+ " Each Instance is a full set of MO data files (mods, "
101
+ " downloads, profiles, configuration, ...). Use multiple "
102
+ " instances for different games. If your MO folder is "
103
+ " writable, you can also store a single instance locally (called "
104
+ " a portable install)." )),
105
+ nullptr );
85
106
selection.disableCancel ();
86
107
for (const QString &instance : instanceList) {
87
108
selection.addChoice (instance, " " , instance);
88
109
}
89
110
90
- selection.addChoice (QObject::tr (" New" ),
111
+ selection.addChoice (QIcon ( " :/MO/gui/add " ), QObject::tr (" New" ),
91
112
QObject::tr (" Create a new instance." ),
92
- " " );
113
+ static_cast <uint8_t >(Special::NewInstance));
114
+
115
+ if (QFileInfo (qApp->applicationDirPath ()).isWritable ()) {
116
+ selection.addChoice (QIcon (" :/MO/gui/package" ), QObject::tr (" Portable" ),
117
+ QObject::tr (" Use MO folder for data." ),
118
+ static_cast <uint8_t >(Special::Portable));
119
+ }
120
+
93
121
if (selection.exec () == QDialog::Rejected) {
94
122
qDebug (" rejected" );
95
123
throw MOBase::MyException (QObject::tr (" Canceled" ));
96
124
}
97
125
98
- QString choice = selection.getChoiceData (). toString ();
126
+ QVariant choice = selection.getChoiceData ();
99
127
100
- if (choice.isEmpty () ) {
101
- return queryInstanceName ();
128
+ if (choice.type () == QVariant::String ) {
129
+ return choice. toString ();
102
130
} else {
103
- return choice;
131
+ switch (choice.value <uint8_t >()) {
132
+ case Special::NewInstance: return queryInstanceName ();
133
+ case Special::Portable: return QString ();
134
+ default : throw std::runtime_error (" invalid selection" );
135
+ }
104
136
}
105
137
}
106
138
@@ -125,27 +157,6 @@ bool InstanceManager::portableInstall() const
125
157
}
126
158
127
159
128
- InstanceManager::InstallationMode InstanceManager::queryInstallMode () const
129
- {
130
- SelectionDialog selection (QObject::tr (" Installation Mode" ), nullptr );
131
- selection.disableCancel ();
132
- selection.addChoice (QObject::tr (" Portable" ),
133
- QObject::tr (" Everything in one directory, only one game per installation." ),
134
- 0 );
135
- selection.addChoice (QObject::tr (" Regular" ),
136
- QObject::tr (" Data in separate directory, multiple games supported." ),
137
- 1 );
138
- if (selection.exec () == QDialog::Rejected) {
139
- throw MOBase::MyException (QObject::tr (" Canceled" ));
140
- }
141
-
142
- switch (selection.getChoiceData ().toInt ()) {
143
- case 0 : return InstallationMode::PORTABLE;
144
- default : return InstallationMode::REGULAR;
145
- }
146
- }
147
-
148
-
149
160
void InstanceManager::createDataPath (const QString &dataPath) const
150
161
{
151
162
if (!QDir (dataPath).exists ()) {
@@ -166,31 +177,22 @@ void InstanceManager::createDataPath(const QString &dataPath) const
166
177
QString InstanceManager::determineDataPath ()
167
178
{
168
179
QString instanceId = currentInstance ();
180
+ if (instanceId.isEmpty () && portableInstall () && !m_Reset) {
181
+ // startup, apparently using portable mode before
182
+ return qApp->applicationDirPath ();
183
+ }
184
+
169
185
QString dataPath = QDir::fromNativeSeparators (
170
186
QStandardPaths::writableLocation (QStandardPaths::DataLocation)
171
187
+ " /" + instanceId);
172
188
173
- if ((instanceId.isEmpty () || !QFileInfo::exists (dataPath)) && !portableInstall ()) {
174
- // no portable install and no selected instance
175
-
176
- QStringList instanceList = instances ();
177
-
178
- if (instanceList.size () == 0 ) {
179
- if (QFileInfo (qApp->applicationDirPath ()).isWritable ()) {
180
- switch (queryInstallMode ()) {
181
- case InstallationMode::PORTABLE: {
182
- instanceId = QString ();
183
- } break ;
184
- case InstallationMode::REGULAR: {
185
- instanceId = queryInstanceName ();
186
- } break ;
187
- }
188
- } else {
189
- instanceId = queryInstanceName ();
190
- }
191
- } else {
192
- // don't offer portable instance if we can't set one up.
193
- instanceId = chooseInstance (instanceList);
189
+
190
+ if (instanceId.isEmpty () || !QFileInfo::exists (dataPath)) {
191
+ instanceId = chooseInstance (instances ());
192
+ if (!instanceId.isEmpty ()) {
193
+ dataPath = QDir::fromNativeSeparators (
194
+ QStandardPaths::writableLocation (QStandardPaths::DataLocation)
195
+ + " /" + instanceId);
194
196
}
195
197
}
196
198
0 commit comments