private static ConfigVer3 UpgradeV2ToV3(ConfigVer2 configVer2) { ConfigVer3 configVer3 = new ConfigVer3 { PreserveWindowPosition = configVer2.PreserveWindowPosition, PreserveWindowSize = configVer2.PreserveWindowSize, WindowPositionX = configVer2.WindowPositionX, WindowPositionY = configVer2.WindowPositionY, WindowSizeX = configVer2.WindowSizeX, WindowSizeY = configVer2.WindowSizeY, PreserveFullScreenStatus = configVer2.PreserveFullScreenStatus, IsFullScreen = configVer2.IsFullScreen, PreserveHomeSystem = configVer2.PreserveHomeSystem, HomeSystemId = configVer2.HomeSystemId, MonitorBranch = configVer2.MonitorBranch, MonitorDeklein = configVer2.MonitorDeklein, MonitorTenal = configVer2.MonitorTenal, MonitorVenal = configVer2.MonitorVenal, MonitorFade = configVer2.MonitorFade, MonitorPureBlind = configVer2.MonitorPureBlind, MonitorTribute = configVer2.MonitorTribute, MonitorVale = configVer2.MonitorVale, MonitorProvidence = configVer2.MonitorProvidence, MonitorDelve = configVer2.MonitorDelve, MonitorGameLog = configVer2.MonitorGameLog, AlertBranch = configVer2.AlertBranch, AlertDeklein = configVer2.AlertDeklein, AlertTenal = configVer2.AlertTenal, AlertVenal = configVer2.AlertVenal, AlertFade = configVer2.AlertFade, AlertPureBlind = configVer2.AlertPureBlind, AlertTribute = configVer2.AlertTribute, AlertVale = configVer2.AlertVale, AlertProvidence = configVer2.AlertProvidence, AlertDelve = configVer2.AlertDelve, PreserveCameraDistance = configVer2.PreserveCameraDistance, PreserveLookAt = configVer2.PreserveLookAt, CameraDistance = configVer2.CameraDistance, LookAtX = configVer2.LookAtX, LookAtY = configVer2.LookAtY, OverrideLogPath = configVer2.OverrideLogPath, LogPath = configVer2.LogPath, PreserveSelectedSystems = configVer2.PreserveSelectedSystems, SelectedSystems = configVer2.SelectedSystems, DisplayNewFileAlerts = configVer2.DisplayNewFileAlerts, DisplayOpenFileAlerts = configVer2.DisplayOpenFileAlerts, AlertTriggers = configVer2.AlertTriggers, IgnoreStrings = configVer2.IgnoreStrings, IgnoreSystems = configVer2.IgnoreSystems, CharacterList = configVer2.CharacterList, DisplayCharacterNames = true, ShowCharacterLocations = true, CameraFollowCharacter = false, CentreOnCharacter = -1, MapRangeFrom = 0 }; return(configVer3); }
public TacoConfig(string basePath) { _configFile = basePath + @"\taco.conf"; if (!File.Exists(_configFile)) { WriteDefaultConfig(); } // ReSharper disable once JoinDeclarationAndInitializer bool configCorrupt, oldConfig, upgradeConfig; configCorrupt = oldConfig = upgradeConfig = false; using (var file = new FileStream(_configFile, FileMode.Open, FileAccess.Read)) { var configVersion = Serializer.DeserializeWithLengthPrefix <ConfigVerion>(file, PrefixStyle.Base128, 1); if (configVersion.Version == 5) { try { _config = Serializer.DeserializeWithLengthPrefix <ConfigVer5>(file, PrefixStyle.Base128, 2); } catch { configCorrupt = true; } } else if (configVersion.Version == 4) { try { if (File.Exists(_configFile + ".v4.bak")) { File.Delete(_configFile + ".v4.bak"); } File.Copy(_configFile, _configFile + ".v4.bak"); ConfigVer4 configVer4 = Serializer.DeserializeWithLengthPrefix <ConfigVer4>(file, PrefixStyle.Base128, 2); _config = UpgradeV4ToV5(configVer4); upgradeConfig = true; } catch { configCorrupt = true; } } else if (configVersion.Version == 3) { try { if (File.Exists(_configFile + ".v3.bak")) { File.Delete(_configFile + ".v3.bak"); } File.Copy(_configFile, _configFile + ".v3.bak"); ConfigVer3 configVer3 = Serializer.DeserializeWithLengthPrefix <ConfigVer3>(file, PrefixStyle.Base128, 2); ConfigVer4 configVer4 = UpgradeV3ToV4(configVer3); _config = UpgradeV4ToV5(configVer4); upgradeConfig = true; } catch { configCorrupt = true; } } else if (configVersion.Version == 2) { try { if (File.Exists(_configFile + ".v2.bak")) { File.Delete(_configFile + ".v2.bak"); } File.Copy(_configFile, _configFile + ".v2.bak"); ConfigVer2 configVer2 = Serializer.DeserializeWithLengthPrefix <ConfigVer2>(file, PrefixStyle.Base128, 2); ConfigVer3 configVer3 = UpgradeV2ToV3(configVer2); ConfigVer4 configVer4 = UpgradeV3ToV4(configVer3); _config = UpgradeV4ToV5(configVer4); upgradeConfig = true; } catch { configCorrupt = true; } } else { oldConfig = true; } } if (upgradeConfig) { var messageText = new StringBuilder(); messageText.AppendLine("Your config file has been upgraded."); messageText.AppendLine("It has been backed up in your Taco directory."); messageText.AppendLine("You can delete it if you wish, or keep it, up to you really."); MessageBox.Show(messageText.ToString(), "Config Upgraded", MessageBoxButtons.OK, MessageBoxIcon.Information); WriteConfig(); } if (configCorrupt) { var messageText = new StringBuilder(); messageText.AppendLine("It looks like your config file is corrupt."); messageText.AppendLine("It will now be backed up, and a new default config created."); messageText.AppendLine("Please send taco.conf.corrupt to mcnubblet AT gmail.com so I can try and figure out why."); MessageBox.Show(messageText.ToString(), "Corrupt Config Detected", MessageBoxButtons.OK, MessageBoxIcon.Error); File.Move(_configFile, _configFile + ".corrupt"); WriteDefaultConfig(); using (var file = new FileStream(_configFile, FileMode.Open, FileAccess.Read)) { //configVersion = Serializer.DeserializeWithLengthPrefix<ConfigVerion>(file, PrefixStyle.Base128, 1); _config = Serializer.DeserializeWithLengthPrefix <ConfigVer5>(file, PrefixStyle.Base128, 2); } } if (oldConfig) { var messageText = new StringBuilder(); messageText.AppendLine("It looks like you have an older (v1) config."); messageText.AppendLine("Unfortunately, this can't be imported, sorry."); messageText.AppendLine("Your old config will now be backed up, and a new default config created."); MessageBox.Show(messageText.ToString(), "Old Config Detected", MessageBoxButtons.OK, MessageBoxIcon.Information); if (File.Exists(_configFile + ".v1.bak")) { File.Delete(_configFile + ".v1.bak"); } File.Move(_configFile, _configFile + ".v1.bak"); WriteDefaultConfig(); using (var file = new FileStream(_configFile, FileMode.Open, FileAccess.Read)) { //configVersion = Serializer.DeserializeWithLengthPrefix<ConfigVerion>(file, PrefixStyle.Base128, 1); _config = Serializer.DeserializeWithLengthPrefix <ConfigVer5>(file, PrefixStyle.Base128, 2); } } }
private static ConfigVer4 UpgradeV3ToV4(ConfigVer3 configVer3) { ConfigVer4 configVer4 = new ConfigVer4 { PreserveWindowPosition = configVer3.PreserveWindowPosition, PreserveWindowSize = configVer3.PreserveWindowSize, WindowPositionX = configVer3.WindowPositionX, WindowPositionY = configVer3.WindowPositionY, WindowSizeX = configVer3.WindowSizeX, WindowSizeY = configVer3.WindowSizeY, PreserveFullScreenStatus = configVer3.PreserveFullScreenStatus, IsFullScreen = configVer3.IsFullScreen, PreserveHomeSystem = configVer3.PreserveHomeSystem, HomeSystemId = configVer3.HomeSystemId, MonitorBranch = configVer3.MonitorBranch, MonitorDeklein = configVer3.MonitorDeklein, MonitorTenal = configVer3.MonitorTenal, MonitorVenal = configVer3.MonitorVenal, MonitorFade = configVer3.MonitorFade, MonitorPureBlind = configVer3.MonitorPureBlind, MonitorTribute = configVer3.MonitorTribute, MonitorVale = configVer3.MonitorVale, MonitorProvidence = configVer3.MonitorProvidence, MonitorDelve = configVer3.MonitorDelve, MonitorGameLog = configVer3.MonitorGameLog, AlertBranch = configVer3.AlertBranch, AlertDeklein = configVer3.AlertDeklein, AlertTenal = configVer3.AlertTenal, AlertVenal = configVer3.AlertVenal, AlertFade = configVer3.AlertFade, AlertPureBlind = configVer3.AlertPureBlind, AlertTribute = configVer3.AlertTribute, AlertVale = configVer3.AlertVale, AlertProvidence = configVer3.AlertProvidence, AlertDelve = configVer3.AlertDelve, PreserveCameraDistance = configVer3.PreserveCameraDistance, PreserveLookAt = configVer3.PreserveLookAt, CameraDistance = configVer3.CameraDistance, LookAtX = configVer3.LookAtX, LookAtY = configVer3.LookAtY, OverrideLogPath = configVer3.OverrideLogPath, LogPath = configVer3.LogPath, PreserveSelectedSystems = configVer3.PreserveSelectedSystems, SelectedSystems = configVer3.SelectedSystems, DisplayNewFileAlerts = configVer3.DisplayNewFileAlerts, DisplayOpenFileAlerts = configVer3.DisplayOpenFileAlerts, AlertTriggers = configVer3.AlertTriggers, IgnoreStrings = configVer3.IgnoreStrings, IgnoreSystems = configVer3.IgnoreSystems, CharacterList = configVer3.CharacterList, DisplayCharacterNames = configVer3.DisplayCharacterNames, ShowCharacterLocations = configVer3.ShowCharacterLocations, CameraFollowCharacter = configVer3.CameraFollowCharacter, CentreOnCharacter = configVer3.CentreOnCharacter, MapRangeFrom = configVer3.MapRangeFrom, AnomalyMonitorSoundId = -1, AnomalyMonitorSoundPath = String.Empty }; return(configVer4); }