diff options
| author | Tannin <devnull@localhost> | 2014-02-12 21:00:49 +0100 |
|---|---|---|
| committer | Tannin <devnull@localhost> | 2014-02-12 21:00:49 +0100 |
| commit | 9c8e43853dfeb6ac80faffe0960222ff0f087fd3 (patch) | |
| tree | a08077f950ac1c77b33900f4724c11be6a43e877 /src/modinfo.cpp | |
| parent | 7aadb476376db1d23ad333abb439639552bb6e19 (diff) | |
- a few hooks will now somewhat handle file names starting with \\?\
- mod meta information is now (also) saved by a timer to reduce the likelyhood
of a data loss in case of a crash
- mod meta files are now written to a temporary file and then renamed to real name to
reduce chance of breaking the file
- updated minimum compatible nmm version to 0.47.0
- bugfix: defaults for newestVersion, version and installationFile when creating
an empty mod were integers instead of strings
- bugfix: "Plugins" and "Archives" weren't translatable
Diffstat (limited to 'src/modinfo.cpp')
| -rw-r--r-- | src/modinfo.cpp | 62 |
1 files changed, 44 insertions, 18 deletions
diff --git a/src/modinfo.cpp b/src/modinfo.cpp index 85612b32..ff44b392 100644 --- a/src/modinfo.cpp +++ b/src/modinfo.cpp @@ -373,26 +373,48 @@ void ModInfoRegular::saveMeta() { // only write meta data if the mod directory exists if (m_MetaInfoChanged && QFile::exists(absolutePath())) { - QSettings metaFile(absolutePath().append("/meta.ini"), QSettings::IniFormat); - if (metaFile.status() == QSettings::NoError) { - std::set<int> temp = m_Categories; - temp.erase(m_PrimaryCategory); - metaFile.setValue("category", QString("%1").arg(m_PrimaryCategory) + "," + SetJoin(temp, ",")); - metaFile.setValue("newestVersion", m_NewestVersion.canonicalString()); - metaFile.setValue("ignoredVersion", m_IgnoredVersion.canonicalString()); - metaFile.setValue("version", m_Version.canonicalString()); - metaFile.setValue("modid", m_NexusID); - metaFile.setValue("notes", m_Notes); - metaFile.setValue("nexusDescription", m_NexusDescription); - metaFile.setValue("lastNexusQuery", m_LastNexusQuery.toString(Qt::ISODate)); - if (m_EndorsedState != ENDORSED_UNKNOWN) { - metaFile.setValue("endorsed", m_EndorsedState); + bool success = false; + { + QSettings metaFile(absolutePath().append("/meta.ini.new"), QSettings::IniFormat); + if (metaFile.status() == QSettings::NoError) { + std::set<int> temp = m_Categories; + temp.erase(m_PrimaryCategory); + metaFile.setValue("category", QString("%1").arg(m_PrimaryCategory) + "," + SetJoin(temp, ",")); + metaFile.setValue("newestVersion", m_NewestVersion.canonicalString()); + metaFile.setValue("ignoredVersion", m_IgnoredVersion.canonicalString()); + metaFile.setValue("version", m_Version.canonicalString()); + if (m_NexusID != -1) { + metaFile.setValue("modid", m_NexusID); + } + metaFile.setValue("notes", m_Notes); + metaFile.setValue("nexusDescription", m_NexusDescription); + metaFile.setValue("lastNexusQuery", m_LastNexusQuery.toString(Qt::ISODate)); + if (m_EndorsedState != ENDORSED_UNKNOWN) { + metaFile.setValue("endorsed", m_EndorsedState); + } + metaFile.sync(); // sync needs to be called to ensure the file is created + + if (metaFile.status() == QSettings::NoError) { + success = true; + m_MetaInfoChanged = false; + } else { + reportError(tr("failed to write %1/meta.ini: error %2").arg(absolutePath()).arg(metaFile.status())); + } + } else { + reportError(tr("failed to write %1/meta.ini: error %2").arg(absolutePath()).arg(metaFile.status())); + } + } + if (success) { + if (!QFile::remove(absolutePath().append("/meta.ini"))) { + qCritical("failed to remove %s", qPrintable(absolutePath().append("/meta.ini"))); + return; + } + if (QFile::rename(absolutePath().append("/meta.ini.new"), absolutePath().append("/meta.ini"))) { + qDebug("%s written", qPrintable(absolutePath().append("/meta.ini"))); + } else { + qCritical("writing %s failed", qPrintable(absolutePath().append("/meta.ini"))); } - metaFile.sync(); // sync needs to be called to ensure the file is created - } else { - reportError(tr("failed to write %1/meta.ini: %2").arg(absolutePath()).arg(metaFile.status())); } - m_MetaInfoChanged = false; } } @@ -556,6 +578,10 @@ void ModInfoRegular::setVersion(const VersionInfo &version) m_MetaInfoChanged = true; } +void ModInfoRegular::setNewestVersion(const VersionInfo &version) { + m_NewestVersion = version; +} + void ModInfoRegular::setNexusDescription(const QString &description) { m_NexusDescription = description; |
