diff options
| author | isanae <14251494+isanae@users.noreply.github.com> | 2020-02-15 12:25:37 -0500 |
|---|---|---|
| committer | isanae <14251494+isanae@users.noreply.github.com> | 2020-02-18 17:25:04 -0500 |
| commit | 88ef0530001d43be8f18fac43a280169b45db852 (patch) | |
| tree | 0dd2265fae5528e654d780d9bad360e7b82e9456 | |
| parent | 9eeaa88cf5fbed542c05f408982a1492831283ff (diff) | |
error checking in dump()
removed a bunch of "{} saved" in the logs
| -rw-r--r-- | src/directoryrefresher.cpp | 37 | ||||
| -rw-r--r-- | src/filetree.cpp | 39 | ||||
| -rw-r--r-- | src/filetree.h | 4 | ||||
| -rw-r--r-- | src/mainwindow.cpp | 4 | ||||
| -rw-r--r-- | src/pluginlist.cpp | 5 | ||||
| -rw-r--r-- | src/profile.cpp | 6 | ||||
| -rw-r--r-- | src/shared/directoryentry.cpp | 34 |
7 files changed, 50 insertions, 79 deletions
diff --git a/src/directoryrefresher.cpp b/src/directoryrefresher.cpp index f3285cfc..8bf349f1 100644 --- a/src/directoryrefresher.cpp +++ b/src/directoryrefresher.cpp @@ -324,35 +324,34 @@ void DirectoryRefresher::refresh() SetThisThreadName("DirectoryRefresher");
TimeThis tt("refresh");
- for (int i=0; i<1; ++i) {
- QMutexLocker locker(&m_RefreshLock);
- delete m_DirectoryStructure;
+ QMutexLocker locker(&m_RefreshLock);
+ delete m_DirectoryStructure;
- m_DirectoryStructure = new DirectoryEntry(L"data", nullptr, 0);
- m_DirectoryStructure->getFileRegister()->reserve(m_lastFileCount);
+ m_DirectoryStructure = new DirectoryEntry(L"data", nullptr, 0);
+ m_DirectoryStructure->getFileRegister()->reserve(m_lastFileCount);
- IPluginGame *game = qApp->property("managed_game").value<IPluginGame*>();
+ IPluginGame *game = qApp->property("managed_game").value<IPluginGame*>();
- std::wstring dataDirectory =
- QDir::toNativeSeparators(game->dataDirectory().absolutePath()).toStdWString();
+ std::wstring dataDirectory =
+ QDir::toNativeSeparators(game->dataDirectory().absolutePath()).toStdWString();
- {
- DirectoryStats dummy;
- m_DirectoryStructure->addFromOrigin(L"data", dataDirectory, 0, dummy);
- }
+ {
+ DirectoryStats dummy;
+ m_DirectoryStructure->addFromOrigin(L"data", dataDirectory, 0, dummy);
+ }
- std::sort(m_Mods.begin(), m_Mods.end(), [](auto lhs, auto rhs) {
- return lhs.priority < rhs.priority;
- });
+ std::sort(m_Mods.begin(), m_Mods.end(), [](auto lhs, auto rhs) {
+ return lhs.priority < rhs.priority;
+ });
- addMultipleModsFilesToStructure(m_DirectoryStructure, m_Mods, true);
+ addMultipleModsFilesToStructure(m_DirectoryStructure, m_Mods, true);
- m_DirectoryStructure->getFileRegister()->sortOrigins();
+ m_DirectoryStructure->getFileRegister()->sortOrigins();
- cleanStructure(m_DirectoryStructure);
- }
+ cleanStructure(m_DirectoryStructure);
m_lastFileCount = m_DirectoryStructure->getFileRegister()->highestCount();
+ log::debug("refresher saw {} files", m_lastFileCount);
emit progress(100);
emit refreshed();
diff --git a/src/filetree.cpp b/src/filetree.cpp index 45c21c7f..f628dff3 100644 --- a/src/filetree.cpp +++ b/src/filetree.cpp @@ -441,45 +441,6 @@ void FileTree::dumpToFile() const m_core.directoryStructure()->dump(file.toStdWString()); } -void FileTree::dumpToFile( - QFile& out, const QString& parentPath, const DirectoryEntry& entry) const -{ - entry.forEachFile([&](auto&& file) { - bool isArchive = false; - const int originID = file.getOrigin(isArchive); - - if (isArchive) { - // TODO: don't list files from archives. maybe make this an option? - return true; - } - - const auto& origin = m_core.directoryStructure()->getOriginByID(originID); - const auto originName = QString::fromStdWString(origin.getName()); - - const QString path = - parentPath + "\\" + QString::fromStdWString(file.getName()); - - if (out.write(path.toUtf8() + "\t(" + originName.toUtf8() + ")\r\n") == -1) { - QMessageBox::critical( - m_tree->window(), tr("Error"), tr("Failed to write to file %1: %2") - .arg(out.fileName()) - .arg(out.errorString())); - - throw DumpFailed(); - } - - return true; - }); - - entry.forEachDirectory([&](auto&& dir) { - const auto newParentPath = - parentPath + "\\" + QString::fromStdWString(dir.getName()); - - dumpToFile(out, newParentPath, dir); - return true; - }); -} - void FileTree::onExpandedChanged(const QModelIndex& index, bool expanded) { if (auto* item=m_model->itemFromIndex(proxiedIndex(index))) { diff --git a/src/filetree.h b/src/filetree.h index c1458179..2669e53b 100644 --- a/src/filetree.h +++ b/src/filetree.h @@ -65,10 +65,6 @@ private: void toggleVisibility(bool b, FileTreeItem* item=nullptr); QModelIndex proxiedIndex(const QModelIndex& index); - - void dumpToFile( - QFile& out, const QString& parentPath, - const MOShared::DirectoryEntry& entry) const; }; #endif // MODORGANIZER_FILETREE_INCLUDED diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 2145011f..f9f1dfe5 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -4116,9 +4116,7 @@ void MainWindow::saveArchiveList() } } } - if (archiveFile.commitIfDifferent(m_ArchiveListHash)) { - log::debug("{} saved", QDir::toNativeSeparators(m_OrganizerCore.currentProfile()->getArchivesFileName())); - } + archiveFile.commitIfDifferent(m_ArchiveListHash); } else { log::warn("archive list not initialised"); } diff --git a/src/pluginlist.cpp b/src/pluginlist.cpp index 266fe35c..f348f64c 100644 --- a/src/pluginlist.cpp +++ b/src/pluginlist.cpp @@ -507,7 +507,6 @@ void PluginList::writeLockedOrder(const QString &fileName) const file->write(QString("%1|%2\r\n").arg(iter->first).arg(iter->second).toUtf8());
}
file.commit();
- log::debug("{} saved", QDir::toNativeSeparators(fileName));
}
@@ -531,9 +530,7 @@ void PluginList::saveTo(const QString &lockedOrderFileName deleterFile->write("\r\n");
}
}
- if (deleterFile.commitIfDifferent(m_LastSaveHash[deleterFileName])) {
- log::debug("{} saved", QDir::toNativeSeparators(deleterFileName));
- }
+ deleterFile.commitIfDifferent(m_LastSaveHash[deleterFileName]);
} else if (QFile::exists(deleterFileName)) {
shellDelete(QStringList() << deleterFileName);
}
diff --git a/src/profile.cpp b/src/profile.cpp index f041a241..19c0d750 100644 --- a/src/profile.cpp +++ b/src/profile.cpp @@ -250,9 +250,7 @@ void Profile::doWriteModlist() } } - if (file.commitIfDifferent(m_LastModlistHash)) { - log::debug("{} saved", QDir::toNativeSeparators(fileName)); - } + file.commitIfDifferent(m_LastModlistHash); } catch (const std::exception &e) { reportError(tr("failed to write mod list: %1").arg(e.what())); return; @@ -292,8 +290,6 @@ void Profile::createTweakedIniFile() reportError(tr("failed to create tweaked ini: %1") .arg(QString::fromStdWString(formatSystemMessage(e)))); } - - log::debug("{} saved", QDir::toNativeSeparators(tweakedIni)); } // static diff --git a/src/shared/directoryentry.cpp b/src/shared/directoryentry.cpp index 394eda7e..6c5ad9ae 100644 --- a/src/shared/directoryentry.cpp +++ b/src/shared/directoryentry.cpp @@ -1685,14 +1685,33 @@ void DirectoryEntry::addFileToList( // fileNameLower has been moved from this point
}
+struct DumpFailed : public std::runtime_error
+{
+ using runtime_error::runtime_error;
+};
+
void DirectoryEntry::dump(const std::wstring& file) const
{
- std::FILE* f = nullptr;
- auto e = _wfopen_s(&f, file.c_str(), L"wb");
+ try
+ {
+ std::FILE* f = nullptr;
+ auto e = _wfopen_s(&f, file.c_str(), L"wb");
+
+ if (e != 0 || !f) {
+ throw DumpFailed(fmt::format(
+ "failed to open, {} ({})", std::strerror(e), e));
+ }
- dump(f, L"Data");
+ Guard g([&]{ std::fclose(f); });
- std::fclose(f);
+ dump(f, L"Data");
+ }
+ catch(DumpFailed& e)
+ {
+ log::error(
+ "failed to write list to '{}': {}",
+ QString::fromStdWString(file).toStdString(), e.what());
+ }
}
void DirectoryEntry::dump(std::FILE* f, const std::wstring& parentPath) const
@@ -1716,7 +1735,12 @@ void DirectoryEntry::dump(std::FILE* f, const std::wstring& parentPath) const const auto line = path + L"\t(" + o.getName() + L")\r\n";
const auto lineu8 = MOShared::ToString(line, true);
- std::fwrite(lineu8.data(), lineu8.size(), 1, f);
+
+ if (std::fwrite(lineu8.data(), lineu8.size(), 1, f) != 1) {
+ const auto e = errno;
+ throw DumpFailed(fmt::format(
+ "failed to write, {} ({})", std::strerror(e), e));
+ }
}
}
|
