示例#1
0
        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);
        }
示例#2
0
        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);
                }
            }
        }