Esempio n. 1
0
        public static bool Save <T>(string path, byte[] data) where T : class
        {
            string handle = UserIO.GetHandle(path);
            bool   flag   = false;

            try
            {
                string        backupHandle = UserIO.GetBackupHandle(path);
                DirectoryInfo directory    = new FileInfo(handle).Directory;
                if (!directory.Exists)
                {
                    directory.Create();
                }
                directory = new FileInfo(backupHandle).Directory;
                if (!directory.Exists)
                {
                    directory.Create();
                }
                using (FileStream fileStream = File.Open(backupHandle, FileMode.Create, FileAccess.Write))
                {
                    fileStream.Write(data, 0, data.Length);
                }

                //Try loading the save file to test if save was good.
                if (UserIO.Load <T>(path, true) != null)
                {
                    File.Copy(backupHandle, handle, true);
                    flag = true;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR: " + ex.ToString());
            }
            if (!flag)
            {
                Console.WriteLine("Save Failed");
            }
            return(flag);
        }
Esempio n. 2
0
 public static TimeTable LoadStorage(string name)
 {
     return(UserIO.Load <TimeTable>(name));
 }