Skip to content

Commit 28a68cf

Browse files
authored
Merge pull request #156 from erasmux/vs_usvfs_plus_various_fixes
Vs usvfs plus various fixes
2 parents b157ebb + a24a1cb commit 28a68cf

14 files changed

+274
-123
lines changed

src/CMakeLists.txt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ SET(organizer_SRCS
8888
instancemanager.cpp
8989
usvfsconnector.cpp
9090
eventfilter.cpp
91+
moshortcut.cpp
9192

9293
shared/windows_error.cpp
9394
shared/error_report.cpp
@@ -179,6 +180,7 @@ SET(organizer_HDRS
179180
usvfsconnector.h
180181
eventfilter.h
181182
descriptionpage.h
183+
moshortcut.h
182184

183185
shared/windows_error.h
184186
shared/error_report.h
@@ -282,7 +284,7 @@ INCLUDE_DIRECTORIES(${project_path}/uibase/src
282284
${project_path}/bsatk/src
283285
${project_path}/esptk/src
284286
${project_path}/archive/src
285-
${project_path}/../usvfs/usvfs
287+
${project_path}/../usvfs/include
286288
${project_path}/game_gamebryo/src
287289
${project_path}/game_features/src
288290
${project_path}/githubpp/src)
@@ -299,7 +301,7 @@ EXECUTE_PROCESS(
299301
OUTPUT_STRIP_TRAILING_WHITESPACE
300302
)
301303

302-
ADD_DEFINITIONS(-D_UNICODE -DUNICODE -DNOMINMAX -D_CRT_SECURE_NO_WARNINGS -DGITID="${GIT_COMMIT_HASH}")
304+
ADD_DEFINITIONS(-D_UNICODE -DUNICODE -DNOMINMAX -D_CRT_SECURE_NO_WARNINGS -DBOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE -DGITID="${GIT_COMMIT_HASH}")
303305

304306
IF("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
305307
SET(usvfs_name usvfs_x64)
@@ -335,14 +337,14 @@ FIND_PROGRAM(WINDEPLOYQT_COMMAND windeployqt PATHS ${qt5bin} NO_DEFAULT_PATH)
335337

336338
INSTALL(TARGETS ModOrganizer
337339
RUNTIME DESTINATION bin)
338-
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/ModOrganizer.pdb
340+
INSTALL(FILES $<TARGET_PDB_FILE:ModOrganizer>
339341
DESTINATION pdb)
340342
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/dlls.manifest.qt5
341343
DESTINATION bin/dlls
342344
RENAME dlls.manifest)
343345

344346
# use windeployqt.exe to install all required libraries
345-
SET(windeploy_parameters --no-translations --no-plugins --libdir dlls --release-with-debug-info --no-compiler-runtime)
347+
SET(windeploy_parameters "--no-translations --plugindir qtplugins --libdir dlls --release-with-debug-info --no-compiler-runtime")
346348
INSTALL(
347349
CODE
348350
"EXECUTE_PROCESS(
@@ -351,7 +353,12 @@ INSTALL(
351353
COMMAND
352354
${qt5bin}/windeployqt.exe uibase.dll ${windeploy_parameters}
353355
WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/bin
354-
)"
356+
)
357+
file(REMOVE_RECURSE ${CMAKE_INSTALL_PREFIX}/bin/platforms)
358+
file(REMOVE_RECURSE ${CMAKE_INSTALL_PREFIX}/bin/dlls/imageformats)
359+
file(RENAME ${CMAKE_INSTALL_PREFIX}/bin/qtplugins/platforms ${CMAKE_INSTALL_PREFIX}/bin/platforms)
360+
file(RENAME ${CMAKE_INSTALL_PREFIX}/bin/qtplugins/imageformats ${CMAKE_INSTALL_PREFIX}/bin/dlls/imageformats)
361+
file(REMOVE_RECURSE ${CMAKE_INSTALL_PREFIX}/bin/qtplugins)"
355362
)
356363

357364
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/stylesheets

src/executableslist.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ Executable &ExecutablesList::find(const QString &title)
8686
return exe;
8787
}
8888
}
89-
throw std::runtime_error(QString("invalid name %1").arg(title).toLocal8Bit().constData());
89+
throw std::runtime_error(QString("invalid executable name %1").arg(title).toLocal8Bit().constData());
9090
}
9191

9292

src/instancemanager.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,19 @@ InstanceManager &InstanceManager::instance()
4747
return s_Instance;
4848
}
4949

50+
void InstanceManager::overrideInstance(const QString& instanceName)
51+
{
52+
m_overrideInstanceName = instanceName;
53+
m_overrideInstance = true;
54+
}
55+
56+
5057
QString InstanceManager::currentInstance() const
5158
{
52-
return m_AppSettings.value(INSTANCE_KEY, "").toString();
59+
if (m_overrideInstance)
60+
return m_overrideInstanceName;
61+
else
62+
return m_AppSettings.value(INSTANCE_KEY, "").toString();
5363
}
5464

5565
void InstanceManager::clearCurrentInstance()
@@ -177,7 +187,8 @@ void InstanceManager::createDataPath(const QString &dataPath) const
177187
QString InstanceManager::determineDataPath()
178188
{
179189
QString instanceId = currentInstance();
180-
if (instanceId.isEmpty() && portableInstall() && !m_Reset) {
190+
if (instanceId.isEmpty() && !m_Reset && (m_overrideInstance || portableInstall()))
191+
{
181192
// startup, apparently using portable mode before
182193
return qApp->applicationDirPath();
183194
}
@@ -187,8 +198,9 @@ QString InstanceManager::determineDataPath()
187198
+ "/" + instanceId);
188199

189200

190-
if (instanceId.isEmpty() || !QFileInfo::exists(dataPath)) {
201+
if (!m_overrideInstance && (instanceId.isEmpty() || !QFileInfo::exists(dataPath))) {
191202
instanceId = chooseInstance(instances());
203+
setCurrentInstance(instanceId);
192204
if (!instanceId.isEmpty()) {
193205
dataPath = QDir::fromNativeSeparators(
194206
QStandardPaths::writableLocation(QStandardPaths::DataLocation)
@@ -199,8 +211,6 @@ QString InstanceManager::determineDataPath()
199211
if (instanceId.isEmpty()) {
200212
return qApp->applicationDirPath();
201213
} else {
202-
setCurrentInstance(instanceId);
203-
204214
createDataPath(dataPath);
205215

206216
return dataPath;

src/instancemanager.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,14 @@ class InstanceManager {
3434
QString determineDataPath();
3535
void clearCurrentInstance();
3636

37+
void overrideInstance(const QString& instanceName);
38+
39+
QString currentInstance() const;
40+
3741
private:
3842

3943
InstanceManager();
4044

41-
QString currentInstance() const;
4245
QString instancePath() const;
4346

4447
QStringList instances() const;
@@ -55,5 +58,6 @@ class InstanceManager {
5558

5659
QSettings m_AppSettings;
5760
bool m_Reset {false};
58-
61+
bool m_overrideInstance{false};
62+
QString m_overrideInstanceName;
5963
};

src/main.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
4545
#include "tutorialmanager.h"
4646
#include "nxmaccessmanager.h"
4747
#include "instancemanager.h"
48+
#include "moshortcut.h"
4849

4950
#include <eh.h>
5051
#include <windows_error.h>
@@ -367,8 +368,6 @@ int runApplication(MOApplication &application, SingleInstance &instance,
367368
const QString &splashPath)
368369
{
369370
qDebug("start main application");
370-
QPixmap pixmap(splashPath);
371-
QSplashScreen splash(pixmap);
372371

373372
QString dataPath = application.property("dataPath").toString();
374373
qDebug("data path: %s", qPrintable(dataPath));
@@ -382,13 +381,7 @@ int runApplication(MOApplication &application, SingleInstance &instance,
382381

383382
try {
384383
qDebug("Working directory: %s", qPrintable(QDir::toNativeSeparators(QDir::currentPath())));
385-
splash.show();
386-
} catch (const std::exception &e) {
387-
reportError(e.what());
388-
return 1;
389-
}
390384

391-
try {
392385
QSettings settings(dataPath + "/"
393386
+ QString::fromStdWString(AppConfig::iniFileName()),
394387
QSettings::IniFormat);
@@ -458,9 +451,9 @@ int runApplication(MOApplication &application, SingleInstance &instance,
458451
// if we have a command line parameter, it is either a nxm link or
459452
// a binary to start
460453
if (arguments.size() > 1) {
461-
if (OrganizerCore::isMoShortcut(arguments.at(1))) {
454+
if (MOShortcut shortcut{ arguments.at(1) }) {
462455
try {
463-
organizer.runShortcut(OrganizerCore::moShortcutName(arguments.at(1)));
456+
organizer.runShortcut(shortcut);
464457
return 0;
465458
} catch (const std::exception &e) {
466459
reportError(
@@ -488,6 +481,10 @@ int runApplication(MOApplication &application, SingleInstance &instance,
488481
}
489482
}
490483

484+
QPixmap pixmap(splashPath);
485+
QSplashScreen splash(pixmap);
486+
splash.show();
487+
491488
NexusInterface::instance()->getAccessManager()->startLoginCheck();
492489

493490
qDebug("initializing tutorials");
@@ -556,10 +553,12 @@ int main(int argc, char *argv[])
556553
forcePrimary = true;
557554
}
558555

556+
MOShortcut moshortcut{ arguments.size() > 1 ? arguments.at(1) : "" };
557+
559558
SingleInstance instance(forcePrimary);
560559
if (!instance.primaryInstance()) {
561-
if ((arguments.size() == 2)
562-
&& (OrganizerCore::isMoShortcut(arguments.at(1)) || OrganizerCore::isNxmLink(arguments.at(1))))
560+
if (moshortcut ||
561+
arguments.size() > 1 && OrganizerCore::isNxmLink(arguments.at(1)))
563562
{
564563
qDebug("not primary instance, sending shortcut/download message");
565564
instance.sendMessage(arguments.at(1));
@@ -576,7 +575,10 @@ int main(int argc, char *argv[])
576575
QString dataPath;
577576

578577
try {
579-
dataPath = InstanceManager::instance().determineDataPath();
578+
InstanceManager& instanceManager = InstanceManager::instance();
579+
if (moshortcut && moshortcut.hasInstance())
580+
instanceManager.overrideInstance(moshortcut.instance());
581+
dataPath = instanceManager.determineDataPath();
580582
} catch (const std::exception &e) {
581583
if (strcmp(e.what(),"Canceled"))
582584
QMessageBox::critical(nullptr, QObject::tr("Failed to set up instance"), e.what());
@@ -587,7 +589,7 @@ int main(int argc, char *argv[])
587589
// initialize dump collection only after "dataPath" since the crashes are stored under it
588590
prevUnhandledExceptionFilter = SetUnhandledExceptionFilter(MyUnhandledExceptionFilter);
589591

590-
LogBuffer::init(100, QtDebugMsg, qApp->property("dataPath").toString() + "/logs/mo_interface.log");
592+
LogBuffer::init(1000, QtDebugMsg, qApp->property("dataPath").toString() + "/logs/mo_interface.log");
591593

592594
QString splash = dataPath + "/splash.png";
593595
if (!QFile::exists(dataPath + "/splash.png")) {

src/mainwindow.cpp

Lines changed: 7 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,7 +1958,7 @@ void MainWindow::modorder_changed()
19581958
}
19591959
}
19601960
m_OrganizerCore.refreshBSAList();
1961-
m_OrganizerCore.currentProfile()->modlistWriter().write();
1961+
m_OrganizerCore.currentProfile()->writeModlist();
19621962
m_ArchiveListWriter.write();
19631963
m_OrganizerCore.directoryStructure()->getFileRegister()->sortOrigins();
19641964

@@ -2019,71 +2019,9 @@ void MainWindow::installMod_clicked()
20192019
installMod();
20202020
}
20212021

2022-
void MainWindow::renameModInList(QFile &modList, const QString &oldName, const QString &newName)
2023-
{
2024-
//TODO this code needs to be merged with ModList::readFrom
2025-
if (!modList.open(QIODevice::ReadWrite)) {
2026-
reportError(tr("failed to open %1").arg(modList.fileName()));
2027-
return;
2028-
}
2029-
2030-
QBuffer outBuffer;
2031-
outBuffer.open(QIODevice::WriteOnly);
2032-
2033-
while (!modList.atEnd()) {
2034-
QByteArray line = modList.readLine();
2035-
2036-
if (line.length() == 0) {
2037-
// ignore empty lines
2038-
qWarning("mod list contained invalid data: empty line");
2039-
continue;
2040-
}
2041-
2042-
char spec = line.at(0);
2043-
if (spec == '#') {
2044-
// don't touch comments
2045-
outBuffer.write(line);
2046-
continue;
2047-
}
2048-
2049-
QString modName = QString::fromUtf8(line).mid(1).trimmed();
2050-
2051-
if (modName.isEmpty()) {
2052-
// file broken?
2053-
qWarning("mod list contained invalid data: missing mod name");
2054-
continue;
2055-
}
2056-
2057-
outBuffer.write(QByteArray(1, spec));
2058-
if (modName == oldName) {
2059-
modName = newName;
2060-
}
2061-
outBuffer.write(modName.toUtf8().constData());
2062-
outBuffer.write("\r\n");
2063-
}
2064-
2065-
modList.resize(0);
2066-
modList.write(outBuffer.buffer());
2067-
modList.close();
2068-
}
2069-
2070-
20712022
void MainWindow::modRenamed(const QString &oldName, const QString &newName)
20722023
{
2073-
// fix the profiles directly on disc
2074-
for (int i = 0; i < ui->profileBox->count(); ++i) {
2075-
QString profileName = ui->profileBox->itemText(i);
2076-
2077-
//TODO this functionality should be in the Profile class
2078-
QString modlistName = QString("%1/%2/modlist.txt")
2079-
.arg(qApp->property("dataPath").toString() + "/" + QString::fromStdWString(AppConfig::profilesPath()))
2080-
.arg(profileName);
2081-
2082-
QFile modList(modlistName);
2083-
if (modList.exists()) {
2084-
renameModInList(modList, oldName, newName);
2085-
}
2086-
}
2024+
Profile::renameModInAllProfiles(oldName, newName);
20872025

20882026
// immediately refresh the active profile because the data in memory is invalid
20892027
m_OrganizerCore.currentProfile()->refreshModStatus();
@@ -2264,7 +2202,7 @@ void MainWindow::restoreBackup_clicked()
22642202

22652203
void MainWindow::modlistChanged(const QModelIndex&, int)
22662204
{
2267-
m_OrganizerCore.currentProfile()->modlistWriter().write();
2205+
m_OrganizerCore.currentProfile()->writeModlist();
22682206
}
22692207

22702208
void MainWindow::modlistSelectionChanged(const QModelIndex &current, const QModelIndex&)
@@ -3307,7 +3245,7 @@ void MainWindow::fixMods_clicked(SaveGameInfo::MissingAssets const &missingAsset
33073245
}
33083246
}
33093247

3310-
m_OrganizerCore.currentProfile()->modlistWriter().write();
3248+
m_OrganizerCore.currentProfile()->writeModlist();
33113249
m_OrganizerCore.refreshLists();
33123250

33133251
std::set<QString> espsToActivate = dialog.getESPsToActivate();
@@ -3393,7 +3331,8 @@ void MainWindow::addWindowsLink(const ShortcutType mapping)
33933331
QString executable = QDir::toNativeSeparators(selectedExecutable.m_BinaryInfo.absoluteFilePath());
33943332

33953333
std::wstring targetFile = ToWString(exeInfo.absoluteFilePath());
3396-
std::wstring parameter = ToWString(QString("\"moshortcut://%1\"").arg(selectedExecutable.m_Title));
3334+
std::wstring parameter = ToWString(
3335+
QString("\"moshortcut://%1:%2\"").arg(InstanceManager::instance().currentInstance(),selectedExecutable.m_Title));
33973336
std::wstring description = ToWString(QString("Run %1 with ModOrganizer").arg(selectedExecutable.m_Title));
33983337
std::wstring iconFile = ToWString(executable);
33993338
std::wstring currentDirectory = ToWString(QDir::toNativeSeparators(qApp->applicationDirPath()));
@@ -4678,7 +4617,7 @@ void MainWindow::on_restoreButton_clicked()
46784617

46794618
void MainWindow::on_saveModsButton_clicked()
46804619
{
4681-
m_OrganizerCore.currentProfile()->modlistWriter().writeImmediately(true);
4620+
m_OrganizerCore.currentProfile()->writeModlistNow(true);
46824621
QDateTime now = QDateTime::currentDateTime();
46834622
if (createBackup(m_OrganizerCore.currentProfile()->getModlistFileName(), now)) {
46844623
MessageDialog::showMessage(tr("Backup of modlist created"), this);

src/mainwindow.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,6 @@ private slots:
220220

221221
void writeDataToFile(QFile &file, const QString &directory, const MOShared::DirectoryEntry &directoryEntry);
222222

223-
void renameModInList(QFile &modList, const QString &oldName, const QString &newName);
224-
225223
void refreshFilters();
226224

227225
/**

0 commit comments

Comments
 (0)