From 0eb1662a0eaf8eee680cab5b913fff3fcc9b8b2f Mon Sep 17 00:00:00 2001 From: Tannin Date: Mon, 5 May 2014 18:24:15 +0200 Subject: - 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 --- src/safewritefile.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/safewritefile.cpp') 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); +} -- cgit v1.3.1