コード例 #1
0
        /// <summary>
        /// Creates and returns an uninitialized <see cref="IPersistentData"/> instance.
        /// </summary>
        /// <param name="importedBuildPath">Optional path to a build file that should be imported.</param>
        public static IPersistentData CreatePersistentData(string importedBuildPath)
        {
            if (!File.Exists(FilePath))
            {
                var deserializer = new PersistentDataDeserializerCurrent();
                return(new PersistentData(deserializer, importedBuildPath));
            }

            try
            {
                return(Deserialize(FilePath, importedBuildPath));
            }
            catch (Exception ex)
            {
                if (File.Exists(BackupPath))
                {
                    return(Deserialize(BackupPath, importedBuildPath));
                }

                var badFilePath = AppData.GetFolder(true) + FileName + "_Bad.xml";
                File.Copy(FilePath, badFilePath, true);

                FileEx.DeleteIfExists(FilePath);
                FileEx.DeleteIfExists(BackupPath);

                Log.Error("Could not deserialize PeristentData file", ex);
                throw new Exception(ex.Message +
                                    "\nYour PersistentData file could not be loaded correctly. It has been moved to " +
                                    badFilePath);
            }
        }