Exemple #1
0
        /// @param savable
        ///     The savable to deserialize from file
        ///
        /// @return Whether the data was successfully loaded
        ///
        public static void Load(this ISavable savable)
        {
            var    jsonData = new Dictionary <string, object>();
            string filePath = string.Format(k_filePathFormat, savable.GetType().ToString());

            if (FileSystem.DoesFileExist(filePath, FileSystem.Location.Persistent))
            {
                jsonData = JsonWrapper.ParseJsonFile(filePath, FileSystem.Location.Persistent);
                if (jsonData == null)
                {
                    // Delete the corrupted file
                    FileSystem.DeleteFile(filePath, FileSystem.Location.Persistent);

                    // Load a backup
                    string backup = string.Format(k_filePathBackupFormat, savable.GetType().ToString());
                    jsonData = JsonWrapper.ParseJsonFile(backup, FileSystem.Location.Persistent);
                }
            }
            else if (FileSystem.DoesFileExist(filePath, FileSystem.Location.Cache))
            {
                // Legacy file in cache
                jsonData = JsonWrapper.ParseJsonFile(filePath, FileSystem.Location.Cache);
            }
            savable.Deserialize(jsonData);
        }