public static bool Deserialize()
        {
            if (File.Exists("data.dat"))
            {
                BinaryFormatter    bf   = new BinaryFormatter();
                FileStream         fs   = new FileStream("data.dat", FileMode.Open, FileAccess.Read, FileShare.Read);
                DataSerializeClass data = new DataSerializeClass();

                try
                {
                    using (fs)
                    {
                        data = (DataSerializeClass)bf.Deserialize(fs);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                    return(false);
                }
                Data.LoadDeserializedData(data);
                return(true);
            }
            return(false);
        }
Exemple #2
0
        public static DataSerializeClass PrepareToSerialize()
        {
            DataSerializeClass data = new DataSerializeClass();

            data.Icons            = Icons;
            data.Items            = Items;
            data.Fluids           = Fluids;
            data.Locale           = Locale;
            data.Recipes          = Recipes;
            data.ItemCategories   = ItemCategories;
            data.ItemSubgroups    = ItemSubgroups;
            data.RecipeCategories = RecipeCategories;
            data.RecipeSubgroups  = RecipeSubgroups;

            Console.WriteLine("");
            Console.WriteLine("Preparing:");
            Console.WriteLine("\tNumber of icons: {0}", data.Icons.Count);
            Console.WriteLine("\tNumber of items: {0}", data.Items.Count);
            Console.WriteLine("\tNumber of fluids: {0}", data.Fluids.Count);
            Console.WriteLine("\tNumber of recipes: {0}", data.Recipes.Count);
            Console.WriteLine("\tNumber of locale strings: {0}", data.Locale.Length);
            Console.WriteLine("\tNumber of item categories: {0}", data.ItemCategories.Count);
            Console.WriteLine("\tNumber of item subgroups: {0}", data.ItemSubgroups.Count);
            Console.WriteLine("\tNumber of recipe categories: {0}", data.RecipeCategories.Count);
            Console.WriteLine("\tNumber of recipe subgroups: {0}", data.RecipeSubgroups.Count);
            Console.WriteLine("\tTotal: {0}", data.RecipeSubgroups.Count + data.Items.Count + data.Fluids.Count + data.Recipes.Count + data.Locale.Length + data.ItemCategories.Count + data.ItemSubgroups.Count + data.RecipeCategories.Count + data.RecipeSubgroups.Count);
            Console.WriteLine("");

            return(data);
        }
Exemple #3
0
        static void SerializeData()
        {
            DataSerializeClass data = Data.PrepareToSerialize();

            Serialization.Serialize(data);
            backgroundWorker.ReportProgress(1);
        }
Exemple #4
0
 public static void LoadDeserializedData(DataSerializeClass inData)
 {
     Icons            = inData.Icons;
     Items            = inData.Items;
     Fluids           = inData.Fluids;
     Locale           = inData.Locale;
     Recipes          = inData.Recipes;
     ItemCategories   = inData.ItemCategories;
     ItemSubgroups    = inData.ItemSubgroups;
     RecipeCategories = inData.RecipeCategories;
     RecipeSubgroups  = inData.RecipeSubgroups;
 }
        public static void Serialize(DataSerializeClass inData)
        {
            BinaryFormatter bf = new BinaryFormatter();
            FileStream      fs = new FileStream("data.dat", FileMode.CreateNew, FileAccess.Write);

            try
            {
                using (fs)
                {
                    bf.Serialize(fs, inData);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }