[mistelix] Save Preferences only when they are dirty
- From: Jordi Mas <jmas src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [mistelix] Save Preferences only when they are dirty
- Date: Tue, 9 Feb 2010 18:45:28 +0000 (UTC)
commit 2a25cf93f976208b45008935db2e2c9682fd7279
Author: Jordi Mas <jmas softcatala org>
Date: Tue Feb 9 19:45:38 2010 +0100
Save Preferences only when they are dirty
src/Core/Preferences.cs | 26 +++++++++++++++++++++++---
1 files changed, 23 insertions(+), 3 deletions(-)
---
diff --git a/src/Core/Preferences.cs b/src/Core/Preferences.cs
index b1769bf..27bd40a 100644
--- a/src/Core/Preferences.cs
+++ b/src/Core/Preferences.cs
@@ -1,5 +1,5 @@
//
-// Copyright (C) 2009 Jordi Mas i Hernandez, jmas softcatala org
+// Copyright (C) 2009-2010 Jordi Mas i Hernandez, jmas softcatala org
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
@@ -135,17 +135,22 @@ namespace Mistelix.Core
Load ();
}
+ public bool IsDirty { get; set;}
+
public void Save ()
{
try {
+ if (IsDirty == false)
+ return;
+
if (!Directory.Exists (config_path))
Directory.CreateDirectory (config_path);
XmlTextWriter writer = new XmlTextWriter (file, Encoding.UTF8);
writer.Formatting = Formatting.Indented;
-
properties.WriteXml (writer);
writer.Close ();
+ IsDirty = false;
}
catch (Exception e)
{
@@ -170,17 +175,29 @@ namespace Mistelix.Core
public void SetIntValue (string key, int value)
{
+ if (properties[key] == value.ToString ())
+ return;
+
properties[key] = value.ToString ();
+ IsDirty = true;
}
public void SetBoolValue (string key, bool value)
{
+ if (properties [key] == value.ToString ())
+ return;
+
properties [key] = value.ToString ();
+ IsDirty = true;
}
public void SetStringValue (string key, string value)
{
+ if (properties[key] == value)
+ return;
+
properties[key] = value;
+ IsDirty = true;
}
void LoadDefaultValues ()
@@ -220,12 +237,15 @@ namespace Mistelix.Core
try {
LoadDefaultValues ();
- if (File.Exists (file) == false)
+ if (File.Exists (file) == false) {
+ IsDirty = true;
return;
+ }
XmlTextReader reader = new XmlTextReader (file);
properties.ReadXml (reader);
reader.Close ();
+ IsDirty = false;
}
catch (Exception e)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]