Skip to content

Commit

Permalink
Merge pull request #156 from erasmux/vs_usvfs_plus_various_fixes
Browse files Browse the repository at this point in the history
Vs usvfs plus various fixes
  • Loading branch information
LePresidente authored Dec 21, 2017
2 parents b157ebb + a24a1cb commit 28a68cf
Show file tree
Hide file tree
Showing 14 changed files with 274 additions and 123 deletions.
17 changes: 12 additions & 5 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ SET(organizer_SRCS
instancemanager.cpp
usvfsconnector.cpp
eventfilter.cpp
moshortcut.cpp

shared/windows_error.cpp
shared/error_report.cpp
Expand Down Expand Up @@ -179,6 +180,7 @@ SET(organizer_HDRS
usvfsconnector.h
eventfilter.h
descriptionpage.h
moshortcut.h

shared/windows_error.h
shared/error_report.h
Expand Down Expand Up @@ -282,7 +284,7 @@ INCLUDE_DIRECTORIES(${project_path}/uibase/src
${project_path}/bsatk/src
${project_path}/esptk/src
${project_path}/archive/src
${project_path}/../usvfs/usvfs
${project_path}/../usvfs/include
${project_path}/game_gamebryo/src
${project_path}/game_features/src
${project_path}/githubpp/src)
Expand All @@ -299,7 +301,7 @@ EXECUTE_PROCESS(
OUTPUT_STRIP_TRAILING_WHITESPACE
)

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

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

INSTALL(TARGETS ModOrganizer
RUNTIME DESTINATION bin)
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/ModOrganizer.pdb
INSTALL(FILES $<TARGET_PDB_FILE:ModOrganizer>
DESTINATION pdb)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/dlls.manifest.qt5
DESTINATION bin/dlls
RENAME dlls.manifest)

# use windeployqt.exe to install all required libraries
SET(windeploy_parameters --no-translations --no-plugins --libdir dlls --release-with-debug-info --no-compiler-runtime)
SET(windeploy_parameters "--no-translations --plugindir qtplugins --libdir dlls --release-with-debug-info --no-compiler-runtime")
INSTALL(
CODE
"EXECUTE_PROCESS(
Expand All @@ -351,7 +353,12 @@ INSTALL(
COMMAND
${qt5bin}/windeployqt.exe uibase.dll ${windeploy_parameters}
WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/bin
)"
)
file(REMOVE_RECURSE ${CMAKE_INSTALL_PREFIX}/bin/platforms)
file(REMOVE_RECURSE ${CMAKE_INSTALL_PREFIX}/bin/dlls/imageformats)
file(RENAME ${CMAKE_INSTALL_PREFIX}/bin/qtplugins/platforms ${CMAKE_INSTALL_PREFIX}/bin/platforms)
file(RENAME ${CMAKE_INSTALL_PREFIX}/bin/qtplugins/imageformats ${CMAKE_INSTALL_PREFIX}/bin/dlls/imageformats)
file(REMOVE_RECURSE ${CMAKE_INSTALL_PREFIX}/bin/qtplugins)"
)

INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/stylesheets
Expand Down
2 changes: 1 addition & 1 deletion src/executableslist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Executable &ExecutablesList::find(const QString &title)
return exe;
}
}
throw std::runtime_error(QString("invalid name %1").arg(title).toLocal8Bit().constData());
throw std::runtime_error(QString("invalid executable name %1").arg(title).toLocal8Bit().constData());
}


Expand Down
20 changes: 15 additions & 5 deletions src/instancemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,19 @@ InstanceManager &InstanceManager::instance()
return s_Instance;
}

void InstanceManager::overrideInstance(const QString& instanceName)
{
m_overrideInstanceName = instanceName;
m_overrideInstance = true;
}


QString InstanceManager::currentInstance() const
{
return m_AppSettings.value(INSTANCE_KEY, "").toString();
if (m_overrideInstance)
return m_overrideInstanceName;
else
return m_AppSettings.value(INSTANCE_KEY, "").toString();
}

void InstanceManager::clearCurrentInstance()
Expand Down Expand Up @@ -177,7 +187,8 @@ void InstanceManager::createDataPath(const QString &dataPath) const
QString InstanceManager::determineDataPath()
{
QString instanceId = currentInstance();
if (instanceId.isEmpty() && portableInstall() && !m_Reset) {
if (instanceId.isEmpty() && !m_Reset && (m_overrideInstance || portableInstall()))
{
// startup, apparently using portable mode before
return qApp->applicationDirPath();
}
Expand All @@ -187,8 +198,9 @@ QString InstanceManager::determineDataPath()
+ "/" + instanceId);


if (instanceId.isEmpty() || !QFileInfo::exists(dataPath)) {
if (!m_overrideInstance && (instanceId.isEmpty() || !QFileInfo::exists(dataPath))) {
instanceId = chooseInstance(instances());
setCurrentInstance(instanceId);
if (!instanceId.isEmpty()) {
dataPath = QDir::fromNativeSeparators(
QStandardPaths::writableLocation(QStandardPaths::DataLocation)
Expand All @@ -199,8 +211,6 @@ QString InstanceManager::determineDataPath()
if (instanceId.isEmpty()) {
return qApp->applicationDirPath();
} else {
setCurrentInstance(instanceId);

createDataPath(dataPath);

return dataPath;
Expand Down
8 changes: 6 additions & 2 deletions src/instancemanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@ class InstanceManager {
QString determineDataPath();
void clearCurrentInstance();

void overrideInstance(const QString& instanceName);

QString currentInstance() const;

private:

InstanceManager();

QString currentInstance() const;
QString instancePath() const;

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

QSettings m_AppSettings;
bool m_Reset {false};

bool m_overrideInstance{false};
QString m_overrideInstanceName;
};
30 changes: 16 additions & 14 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include "tutorialmanager.h"
#include "nxmaccessmanager.h"
#include "instancemanager.h"
#include "moshortcut.h"

#include <eh.h>
#include <windows_error.h>
Expand Down Expand Up @@ -367,8 +368,6 @@ int runApplication(MOApplication &application, SingleInstance &instance,
const QString &splashPath)
{
qDebug("start main application");
QPixmap pixmap(splashPath);
QSplashScreen splash(pixmap);

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

try {
qDebug("Working directory: %s", qPrintable(QDir::toNativeSeparators(QDir::currentPath())));
splash.show();
} catch (const std::exception &e) {
reportError(e.what());
return 1;
}

try {
QSettings settings(dataPath + "/"
+ QString::fromStdWString(AppConfig::iniFileName()),
QSettings::IniFormat);
Expand Down Expand Up @@ -458,9 +451,9 @@ int runApplication(MOApplication &application, SingleInstance &instance,
// if we have a command line parameter, it is either a nxm link or
// a binary to start
if (arguments.size() > 1) {
if (OrganizerCore::isMoShortcut(arguments.at(1))) {
if (MOShortcut shortcut{ arguments.at(1) }) {
try {
organizer.runShortcut(OrganizerCore::moShortcutName(arguments.at(1)));
organizer.runShortcut(shortcut);
return 0;
} catch (const std::exception &e) {
reportError(
Expand Down Expand Up @@ -488,6 +481,10 @@ int runApplication(MOApplication &application, SingleInstance &instance,
}
}

QPixmap pixmap(splashPath);
QSplashScreen splash(pixmap);
splash.show();

NexusInterface::instance()->getAccessManager()->startLoginCheck();

qDebug("initializing tutorials");
Expand Down Expand Up @@ -556,10 +553,12 @@ int main(int argc, char *argv[])
forcePrimary = true;
}

MOShortcut moshortcut{ arguments.size() > 1 ? arguments.at(1) : "" };

SingleInstance instance(forcePrimary);
if (!instance.primaryInstance()) {
if ((arguments.size() == 2)
&& (OrganizerCore::isMoShortcut(arguments.at(1)) || OrganizerCore::isNxmLink(arguments.at(1))))
if (moshortcut ||
arguments.size() > 1 && OrganizerCore::isNxmLink(arguments.at(1)))
{
qDebug("not primary instance, sending shortcut/download message");
instance.sendMessage(arguments.at(1));
Expand All @@ -576,7 +575,10 @@ int main(int argc, char *argv[])
QString dataPath;

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

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

QString splash = dataPath + "/splash.png";
if (!QFile::exists(dataPath + "/splash.png")) {
Expand Down
75 changes: 7 additions & 68 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1958,7 +1958,7 @@ void MainWindow::modorder_changed()
}
}
m_OrganizerCore.refreshBSAList();
m_OrganizerCore.currentProfile()->modlistWriter().write();
m_OrganizerCore.currentProfile()->writeModlist();
m_ArchiveListWriter.write();
m_OrganizerCore.directoryStructure()->getFileRegister()->sortOrigins();

Expand Down Expand Up @@ -2019,71 +2019,9 @@ void MainWindow::installMod_clicked()
installMod();
}

void MainWindow::renameModInList(QFile &modList, const QString &oldName, const QString &newName)
{
//TODO this code needs to be merged with ModList::readFrom
if (!modList.open(QIODevice::ReadWrite)) {
reportError(tr("failed to open %1").arg(modList.fileName()));
return;
}

QBuffer outBuffer;
outBuffer.open(QIODevice::WriteOnly);

while (!modList.atEnd()) {
QByteArray line = modList.readLine();

if (line.length() == 0) {
// ignore empty lines
qWarning("mod list contained invalid data: empty line");
continue;
}

char spec = line.at(0);
if (spec == '#') {
// don't touch comments
outBuffer.write(line);
continue;
}

QString modName = QString::fromUtf8(line).mid(1).trimmed();

if (modName.isEmpty()) {
// file broken?
qWarning("mod list contained invalid data: missing mod name");
continue;
}

outBuffer.write(QByteArray(1, spec));
if (modName == oldName) {
modName = newName;
}
outBuffer.write(modName.toUtf8().constData());
outBuffer.write("\r\n");
}

modList.resize(0);
modList.write(outBuffer.buffer());
modList.close();
}


void MainWindow::modRenamed(const QString &oldName, const QString &newName)
{
// fix the profiles directly on disc
for (int i = 0; i < ui->profileBox->count(); ++i) {
QString profileName = ui->profileBox->itemText(i);

//TODO this functionality should be in the Profile class
QString modlistName = QString("%1/%2/modlist.txt")
.arg(qApp->property("dataPath").toString() + "/" + QString::fromStdWString(AppConfig::profilesPath()))
.arg(profileName);

QFile modList(modlistName);
if (modList.exists()) {
renameModInList(modList, oldName, newName);
}
}
Profile::renameModInAllProfiles(oldName, newName);

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

void MainWindow::modlistChanged(const QModelIndex&, int)
{
m_OrganizerCore.currentProfile()->modlistWriter().write();
m_OrganizerCore.currentProfile()->writeModlist();
}

void MainWindow::modlistSelectionChanged(const QModelIndex &current, const QModelIndex&)
Expand Down Expand Up @@ -3307,7 +3245,7 @@ void MainWindow::fixMods_clicked(SaveGameInfo::MissingAssets const &missingAsset
}
}

m_OrganizerCore.currentProfile()->modlistWriter().write();
m_OrganizerCore.currentProfile()->writeModlist();
m_OrganizerCore.refreshLists();

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

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

void MainWindow::on_saveModsButton_clicked()
{
m_OrganizerCore.currentProfile()->modlistWriter().writeImmediately(true);
m_OrganizerCore.currentProfile()->writeModlistNow(true);
QDateTime now = QDateTime::currentDateTime();
if (createBackup(m_OrganizerCore.currentProfile()->getModlistFileName(), now)) {
MessageDialog::showMessage(tr("Backup of modlist created"), this);
Expand Down
2 changes: 0 additions & 2 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,6 @@ private slots:

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

void renameModInList(QFile &modList, const QString &oldName, const QString &newName);

void refreshFilters();

/**
Expand Down
Loading

0 comments on commit 28a68cf

Please sign in to comment.