[blam] ItemStore: Implement saving



commit 01081ce765dd0c75dbd9e211d2652cd228c0ea59
Author: Carlos Martín Nieto <carlos cmartin tk>
Date:   Wed Sep 15 17:09:08 2010 +0100

    ItemStore: Implement saving

 src/ItemStore.cs |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)
---
diff --git a/src/ItemStore.cs b/src/ItemStore.cs
index 2a487f9..f6a74bd 100644
--- a/src/ItemStore.cs
+++ b/src/ItemStore.cs
@@ -1,4 +1,5 @@
 using System;
+using System.IO;
 using System.Collections;
 using System.ServiceModel.Syndication;
 using System.Xml;
@@ -11,6 +12,7 @@ namespace Imendio.Blam
         Hashtable items;
         ItemStore instance = null;
         static XmlSerializer serializer = new XmlSerializer(typeof(ItemStore));
+        static string itemfile = Defines.APP_HOMEDIR + "/" + Defines.APP_ITEMSTORE_FILE;
 
         [XmlElement("Item", typeof(Item))]
         public Hashtable Items {
@@ -27,18 +29,24 @@ namespace Imendio.Blam
         public ItemStore GetInstance()
         {
             if(instance == null){
-                Load(Defines.APP_HOMEDIR + "/" + Defines.APP_ITEMSTORE_FILE);
+                Load();
             }
 
             return instance;
         }
 
-        private void Load(string filename)
+        private void Load()
         {
-            XmlTextReader reader = new XmlTextReader(filename);
+            XmlTextReader reader = new XmlTextReader(itemfile);
             instance = serializer.Deserialize(reader) as ItemStore;
         }
 
+        private void Save()
+        {
+            Stream writer = new FileStream(itemfile, FileMode.Create);
+            serializer.Serialize(writer, instance);
+        }
+
        private ItemStore ()
        {
             items = new Hashtable();



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]