Ejemplo n.º 1
0
        static public void LoadData()
        {
            string path = Path.GetDirectoryName(Path.GetDirectoryName(Directory.GetCurrentDirectory())) + @"\Saves";


            string datePath = path + @"\date.json";

            if (File.Exists(datePath))
            {
                using (StreamReader streamReader = new StreamReader(datePath))
                {
                    try
                    {
                        string dateJson = streamReader.ReadToEnd();
                        SerializationCurrentDate serializationCurrentDate = SerializationCurrentDate.Deserialize(dateJson);
                        Date.SetCurrentDateData(serializationCurrentDate);
                    }
                    catch (Exception) { }
                }
            }


            if (Directory.Exists(path + @"\Banks"))
            {
                string[] bankPathArray = Directory.GetDirectories(path + @"\Banks");
                foreach (string bankPath in bankPathArray)
                {
                    Bank bank = LoadBank(bankPath);
                    Bank.Banks.Add(bank);
                }
            }
        }
Ejemplo n.º 2
0
        static public void SaveData()
        {
            string path      = Path.GetDirectoryName(Path.GetDirectoryName(Directory.GetCurrentDirectory())) + @"\Saves";
            string datePath  = path + @"\date.json";
            string banksPath = path + @"\banks";

            ClearDirectory(path);


            using (StreamWriter streamWriter = new StreamWriter(datePath))
            {
                SerializationCurrentDate serializationCurrentDate = new SerializationCurrentDate();
                string dateJson = JsonSerializer.Serialize <SerializationCurrentDate>(serializationCurrentDate);
                streamWriter.Write(dateJson);
            }


            Directory.CreateDirectory(banksPath);
            foreach (Bank bank in Bank.Banks)
            {
                SaveBank(banksPath + @"\" + bank.Title, bank);
            }
        }