From bedbeb6384085ca178a4a1d8ac84cc7ab13cb3dc Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sun, 23 Oct 2016 07:08:04 +0800 Subject: [PATCH] Rewrite FilePreferences --- .../filebot/util/prefs/PropertyFileBackingStore.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/source/net/filebot/util/prefs/PropertyFileBackingStore.java b/source/net/filebot/util/prefs/PropertyFileBackingStore.java index 7bd672c7..a7ee6a6a 100644 --- a/source/net/filebot/util/prefs/PropertyFileBackingStore.java +++ b/source/net/filebot/util/prefs/PropertyFileBackingStore.java @@ -19,6 +19,7 @@ import java.util.Properties; public class PropertyFileBackingStore { private Path store; + private int modCount = 0; private Map> nodes = new HashMap>(); @@ -31,6 +32,7 @@ public class PropertyFileBackingStore { } public synchronized String setValue(String node, String key, String value) { + modCount++; return nodes.computeIfAbsent(node, this::newKeyValueMap).put(key, value); } @@ -45,11 +47,13 @@ public class PropertyFileBackingStore { public synchronized void removeValue(String node, String key) { Map values = nodes.get(node); if (values != null) { + modCount++; values.remove(key); } } public synchronized void removeNode(String node) { + modCount++; nodes.remove(node); } @@ -115,6 +119,10 @@ public class PropertyFileBackingStore { } public void flush() throws IOException { + if (modCount == 0) { + return; + } + StringWriter buffer = new StringWriter(); toProperties().store(buffer, null); @@ -126,6 +134,8 @@ public class PropertyFileBackingStore { out.truncate(out.position()); } } + + modCount = 0; // reset } @Override