示例#1
0
        public static void SaveData()
        {
            EventProcessor.Instance.OnBeforeSave();
            String savePath = SAVE_BASE_FOLDER + Utils.userName + "/";

            Debug.Log("FlightStatistic::SaveData savePath=" + savePath + "statistic_new.json");
            using (StreamWriter sw = new StreamWriter(File.Open(savePath + "statistic_new.json", FileMode.OpenOrCreate), Encoding.UTF8))
            {
                DataHolder dataHolder = new DataHolder();
                dataHolder.crewLaunches = EventProcessor.Instance.crewLaunches;
                dataHolder.launches     = EventProcessor.Instance.launches;
                string json = MyJsonUtil.ObjectToJson(dataHolder);
                sw.WriteLine(json);
            }
            if (System.IO.File.Exists(savePath + "statistic_old.json"))
            {
                System.IO.File.Delete(savePath + "statistic_old.json");
            }
            if (System.IO.File.Exists(savePath + "statistic.json"))
            {
                System.IO.File.Move(savePath + "statistic.json", savePath + "statistic_old.json");
            }
            if (System.IO.File.Exists(savePath + "statistic_new.json"))
            {
                System.IO.File.Move(savePath + "statistic_new.json", savePath + "statistic.json");
            }
        }
示例#2
0
        private void LoadData()
        {
            EventProcessor.Instance.crewLaunches = null;
            EventProcessor.Instance.launches     = null;
            String savePath = SAVE_BASE_FOLDER + Utils.userName + "/";

            if (File.Exists(savePath + "statistic.json"))
            {
                using (StreamReader sr = new StreamReader(File.Open(savePath + "statistic.json", FileMode.Open), Encoding.UTF8))
                {
                    try
                    {
                        string json = sr.ReadToEnd();
                        if (json.Trim().Length > 2)
                        {
                            DataHolder dataHolder = (DataHolder)MyJsonUtil.JsonToObject <DataHolder>(json);
                            EventProcessor.Instance.crewLaunches = dataHolder.crewLaunches;
                            EventProcessor.Instance.launches     = dataHolder.launches;
                            useNativeGui = dataHolder.useNativeGui;
                        }
                        else
                        {
                            EventProcessor.Instance.crewLaunches = new List <LaunchCrewEvent>();
                            EventProcessor.Instance.launches     = new List <LaunchEvent>();
                        }
                    }
                    catch
                    {
                        EventProcessor.Instance.crewLaunches = new List <LaunchCrewEvent>();
                        EventProcessor.Instance.launches     = new List <LaunchEvent>();
                    }
                }
            }
            else
            {
                EventProcessor.Instance.crewLaunches = new List <LaunchCrewEvent>();
                EventProcessor.Instance.launches     = new List <LaunchEvent>();
            }
        }