Ejemplo n.º 1
0
        public void WriteDefaultConfig()
        {
            ConfigVer5 defaultConfig = new ConfigVer5(true);

            using (var file = new FileStream(_configFile, FileMode.Create, FileAccess.Write))
            {
                ConfigVerion temp = new ConfigVerion()
                {
                    Version = _currentConfigVersion
                };

                Serializer.SerializeWithLengthPrefix(file, temp, PrefixStyle.Base128, 1);
            }

            using (var file = File.Open(_configFile, FileMode.Append, FileAccess.Write))
            {
                Serializer.SerializeWithLengthPrefix(file, defaultConfig, PrefixStyle.Base128, 2);
            }
        }
Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 3
0
        private static ConfigVer5 UpgradeV4ToV5(ConfigVer4 configVer4)
        {
            ConfigVer5 configVer5 = new ConfigVer5
            {
                PreserveWindowPosition   = configVer4.PreserveWindowPosition,
                PreserveWindowSize       = configVer4.PreserveWindowSize,
                WindowPositionX          = configVer4.WindowPositionX,
                WindowPositionY          = configVer4.WindowPositionY,
                WindowSizeX              = configVer4.WindowSizeX,
                WindowSizeY              = configVer4.WindowSizeY,
                PreserveFullScreenStatus = configVer4.PreserveFullScreenStatus,
                IsFullScreen             = configVer4.IsFullScreen,
                PreserveHomeSystem       = configVer4.PreserveHomeSystem,
                HomeSystemId             = configVer4.HomeSystemId,
                MonitorBranch            = configVer4.MonitorBranch,
                MonitorDeklein           = configVer4.MonitorDeklein,
                MonitorTenal             = configVer4.MonitorTenal,
                MonitorVenal             = configVer4.MonitorVenal,
                MonitorFade              = configVer4.MonitorFade,
                MonitorPureBlind         = configVer4.MonitorPureBlind,
                MonitorTribute           = configVer4.MonitorTribute,
                MonitorVale              = configVer4.MonitorVale,
                MonitorProvidence        = configVer4.MonitorProvidence,
                MonitorDelve             = configVer4.MonitorDelve,
                MonitorGameLog           = configVer4.MonitorGameLog,
                AlertBranch              = configVer4.AlertBranch,
                AlertDeklein             = configVer4.AlertDeklein,
                AlertTenal             = configVer4.AlertTenal,
                AlertVenal             = configVer4.AlertVenal,
                AlertFade              = configVer4.AlertFade,
                AlertPureBlind         = configVer4.AlertPureBlind,
                AlertTribute           = configVer4.AlertTribute,
                AlertVale              = configVer4.AlertVale,
                AlertProvidence        = configVer4.AlertProvidence,
                AlertDelve             = configVer4.AlertDelve,
                PreserveCameraDistance = configVer4.PreserveCameraDistance,
                PreserveLookAt         = configVer4.PreserveLookAt,
                CameraDistance         = configVer4.CameraDistance,
                LookAtX                 = configVer4.LookAtX,
                LookAtY                 = configVer4.LookAtY,
                OverrideLogPath         = configVer4.OverrideLogPath,
                LogPath                 = configVer4.LogPath,
                PreserveSelectedSystems = configVer4.PreserveSelectedSystems,
                SelectedSystems         = configVer4.SelectedSystems,
                DisplayNewFileAlerts    = configVer4.DisplayNewFileAlerts,
                DisplayOpenFileAlerts   = configVer4.DisplayOpenFileAlerts,
                AlertTriggers           = configVer4.AlertTriggers,
                IgnoreStrings           = configVer4.IgnoreStrings,
                IgnoreSystems           = configVer4.IgnoreSystems,
                CharacterList           = configVer4.CharacterList,
                DisplayCharacterNames   = configVer4.DisplayCharacterNames,
                ShowCharacterLocations  = configVer4.ShowCharacterLocations,
                CameraFollowCharacter   = configVer4.CameraFollowCharacter,
                CentreOnCharacter       = configVer4.CentreOnCharacter,
                MapRangeFrom            = configVer4.MapRangeFrom,
                AnomalyMonitorSoundId   = -1,
                AnomalyMonitorSoundPath = string.Empty,
                ShowAlertAge            = true,
                ShowAlertAgeSecs        = true,
                ShowReportCount         = false,
                MaxAlertAge             = 15,
                MaxAlerts               = 20
            };

            return(configVer5);
        }