summaryrefslogtreecommitdiff
path: root/src/safewritefile.cpp
diff options
context:
space:
mode:
authorTannin <devnull@localhost>2014-05-05 18:24:15 +0200
committerTannin <devnull@localhost>2014-05-05 18:24:15 +0200
commit0eb1662a0eaf8eee680cab5b913fff3fcc9b8b2f (patch)
tree4cccf64266f73d9acabc15e517abd510da79b582 /src/safewritefile.cpp
parent164ec25a75a9d5b5fcbafbe321935ba37fe0885c (diff)
- very effective optimization to findfirstfile-calls
- several configuration files are now only saved to disk if the content actually changed. This should also get rid of a problem where plugins.txt was re-written immediately after starting the game (causing a conflict with the game) - reduced "noise" from hook.dll - removed some debugging messages
Diffstat (limited to 'src/safewritefile.cpp')
-rw-r--r--src/safewritefile.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/safewritefile.cpp b/src/safewritefile.cpp
index 6df8c2b8..626413dd 100644
--- a/src/safewritefile.cpp
+++ b/src/safewritefile.cpp
@@ -46,3 +46,23 @@ void SafeWriteFile::commit() {
m_TempFile.setAutoRemove(false);
m_TempFile.close();
}
+
+bool SafeWriteFile::commitIfDifferent(uint &inHash) {
+ uint newHash = hash();
+ if (newHash != inHash) {
+ commit();
+ inHash = newHash;
+ return true;
+ } else {
+ return false;
+ }
+}
+
+uint SafeWriteFile::hash()
+{
+ qint64 pos = m_TempFile.pos();
+ m_TempFile.seek(0);
+ QByteArray data = m_TempFile.readAll();
+ m_TempFile.seek(pos);
+ return qHash(data);
+}