Skip to content

Commit 22b1695

Browse files
Install manager metadata updates
* Fix missing author and uploader when installing mods * Refactor doInstall parameters into a struct
1 parent 3efaf7c commit 22b1695

2 files changed

Lines changed: 47 additions & 28 deletions

File tree

src/installationmanager.cpp

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -480,28 +480,23 @@ bool InstallationManager::ensureValidModName(GuessedValue<QString>& name) const
480480
return true;
481481
}
482482

483-
InstallationResult InstallationManager::doInstall(GuessedValue<QString>& modName,
484-
QString gameName, int modID,
485-
const QString& version,
486-
const QString& newestVersion,
487-
int categoryID, int fileCategoryID,
488-
const QString& repository)
483+
InstallationResult InstallationManager::doInstall(ModInstallationInfo& info)
489484
{
490-
if (!ensureValidModName(modName)) {
485+
if (!ensureValidModName(info.modName)) {
491486
return {IPluginInstaller::RESULT_FAILED};
492487
}
493488

494489
// determine target directory
495-
InstallationResult result = testOverwrite(modName);
490+
InstallationResult result = testOverwrite(info.modName);
496491
if (!result) {
497492
return result;
498493
}
499494

500495
const bool merge = result.merged();
501496

502-
result.m_name = modName;
497+
result.m_name = info.modName;
503498

504-
QString targetDirectory = QDir(m_ModsDirectory + "/" + modName).canonicalPath();
499+
QString targetDirectory = QDir(m_ModsDirectory + "/" + info.modName).canonicalPath();
505500
QString targetDirectoryNative = QDir::toNativeSeparators(targetDirectory);
506501

507502
log::debug("installing to \"{}\"", targetDirectoryNative);
@@ -532,28 +527,31 @@ InstallationResult InstallationManager::doInstall(GuessedValue<QString>& modName
532527

533528
// overwrite settings only if they are actually are available or haven't been set
534529
// before
535-
if ((gameName != "") || !settingsFile.contains("gameName")) {
536-
settingsFile.setValue("gameName", gameName);
530+
if ((info.gameName != "") || !settingsFile.contains("gameName")) {
531+
settingsFile.setValue("gameName", info.gameName);
537532
}
538-
if ((modID != 0) || !settingsFile.contains("modid")) {
539-
settingsFile.setValue("modid", modID);
533+
if ((info.modID != 0) || !settingsFile.contains("modid")) {
534+
settingsFile.setValue("modid", info.modID);
540535
}
541536
if (!settingsFile.contains("version") ||
542-
(!version.isEmpty() &&
543-
(!merge || (VersionInfo(version) >=
537+
(!info.version.isEmpty() &&
538+
(!merge || (VersionInfo(info.version) >=
544539
VersionInfo(settingsFile.value("version").toString()))))) {
545-
settingsFile.setValue("version", version);
540+
settingsFile.setValue("version", info.version);
546541
}
547-
if (!newestVersion.isEmpty() || !settingsFile.contains("newestVersion")) {
548-
settingsFile.setValue("newestVersion", newestVersion);
542+
if (!info.newestVersion.isEmpty() || !settingsFile.contains("newestVersion")) {
543+
settingsFile.setValue("newestVersion", info.newestVersion);
549544
}
550545
// issue #51 used to overwrite the manually set categories
551546
if (!settingsFile.contains("category")) {
552-
settingsFile.setValue("category", QString::number(categoryID));
547+
settingsFile.setValue("category", QString::number(info.categoryID));
553548
}
554-
settingsFile.setValue("nexusFileStatus", fileCategoryID);
549+
settingsFile.setValue("nexusFileStatus", info.fileCategoryID);
555550
settingsFile.setValue("installationFile", m_CurrentFile);
556-
settingsFile.setValue("repository", repository);
551+
settingsFile.setValue("repository", info.repository);
552+
settingsFile.setValue("author", info.author);
553+
settingsFile.setValue("uploader", info.uploader);
554+
settingsFile.setValue("uploaderUrl", info.uploaderUrl);
557555

558556
if (!merge) {
559557
// this does not clear the list we have in memory but the mod is going to have to be
@@ -650,6 +648,9 @@ InstallationResult InstallationManager::install(const QString& fileName,
650648
int categoryID = 0;
651649
int fileCategoryID = 1;
652650
QString repository = "Nexus";
651+
QString author = "";
652+
QString uploader = "";
653+
QString uploaderUrl = "";
653654

654655
QString metaName = fileName + ".meta";
655656
if (QFile(metaName).exists()) {
@@ -690,6 +691,9 @@ InstallationResult InstallationManager::install(const QString& fileName,
690691
}
691692
repository = metaFile.value("repository", "").toString();
692693
fileCategoryID = metaFile.value("fileCategory", 1).toInt();
694+
author = metaFile.value("author", "").toString();
695+
uploader = metaFile.value("uploader", "").toString();
696+
uploaderUrl = metaFile.value("uploaderUrl", "").toString();
693697
}
694698

695699
if (version.isEmpty()) {
@@ -807,8 +811,11 @@ InstallationResult InstallationManager::install(const QString& fileName,
807811

808812
// the simple installer only prepares the installation, the rest
809813
// works the same for all installers
810-
installResult = doInstall(modName, gameName, modID, version, newestVersion,
811-
categoryID, fileCategoryID, repository);
814+
ModInstallationInfo info{
815+
modName, gameName, modID, version, newestVersion, categoryID,
816+
fileCategoryID, repository, author, uploader, uploaderUrl};
817+
818+
installResult = doInstall(info);
812819
}
813820
}
814821
}

src/installationmanager.h

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,13 +263,25 @@ class InstallationManager : public QObject, public MOBase::IInstallationManager
263263
QString generateBackupName(const QString& directoryName) const;
264264

265265
private:
266+
struct ModInstallationInfo
267+
{
268+
MOBase::GuessedValue<QString> modName;
269+
const QString gameName;
270+
const int modID;
271+
const QString version;
272+
const QString newestVersion;
273+
const int categoryID;
274+
const int fileCategoryID;
275+
const QString repository;
276+
const QString author;
277+
const QString uploader;
278+
const QString uploaderUrl;
279+
};
280+
266281
// actually perform the installation (write files to the disk, etc.), returns the
267282
// installation result
268283
//
269-
InstallationResult doInstall(MOBase::GuessedValue<QString>& modName, QString gameName,
270-
int modID, const QString& version,
271-
const QString& newestVersion, int categoryID,
272-
int fileCategoryID, const QString& repository);
284+
InstallationResult doInstall(ModInstallationInfo& info);
273285

274286
/**
275287
* @brief Clean the list of created files by removing all entries that are not

0 commit comments

Comments
 (0)