[blam] ItemStore: Co-operate with XmlSerializer



commit bf175ad862a6d654aadd88e287a89ab1371fd8c8
Author: Carlos Martín Nieto <carlos cmartin tk>
Date:   Sat Sep 18 21:51:07 2010 +0100

    ItemStore: Co-operate with XmlSerializer

 src/ItemStore.cs |   15 ++++++++++++---
 1 files changed, 12 insertions(+), 3 deletions(-)
---
diff --git a/src/ItemStore.cs b/src/ItemStore.cs
index 65074d2..0c75e07 100644
--- a/src/ItemStore.cs
+++ b/src/ItemStore.cs
@@ -14,7 +14,9 @@ namespace Imendio.Blam
         static XmlSerializer serializer = new XmlSerializer(typeof(ItemStore));
         static string itemfile = Defines.APP_HOMEDIR + "/" + Defines.APP_ITEMSTORE_FILE;
 
-        [XmlElement("Item", typeof(Item))]
+        public ArrayList _items = new ArrayList();
+
+        [XmlIgnore]
         public Hashtable Items {
             get {
                 return items;
@@ -23,11 +25,13 @@ namespace Imendio.Blam
 
         public void Add(Item item)
         {
+            _items.Add(item);
             items.Add(item.Id, item);
         }
 
         public void Remove(Item item)
         {
+            _items.Remove(item);
             items.Remove(item.Id);
         }
 
@@ -42,8 +46,13 @@ namespace Imendio.Blam
 
         private static void Load()
         {
-            XmlTextReader reader = new XmlTextReader(itemfile);
-            instance = serializer.Deserialize(reader) as ItemStore;
+            try{
+                XmlTextReader reader = new XmlTextReader(itemfile);
+                instance = serializer.Deserialize(reader) as ItemStore;
+            } catch(FileNotFoundException)
+            {
+                instance = new ItemStore();
+            }
         }
 
         private static void Save()



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