Пример #1
0
        private void Config_Changed(object sender, FileSystemEventArgs e)
        {
            if (!e.Name.Contains("SpaceEngineers-Dedicated.cfg") || e.Name.Contains("SpaceEngineers-Dedicated.cfg.restart"))
            {
                return;
            }

            if (!_serverRan)
            {
                return;
            }

            if (e.ChangeType == WatcherChangeTypes.Changed)
            {
                try
                {
                    if (!File.Exists(Path + @"\SpaceEngineers-Dedicated.cfg.restart"))
                    {
                        ApplicationLog.BaseLog.Info("SpaceEngineers-Dedicated.cfg has changed updating configuration settings.");

                        MyConfigDedicatedData <MyObjectBuilder_SessionSettings> changedConfig = DedicatedConfigDefinition.Load(new FileInfo(e.FullPath));
                        Config = new DedicatedConfigDefinition(changedConfig);
                    }
                    else
                    {
                        ApplicationLog.BaseLog.Info("SpaceEngineers-Dedicated.cfg has changed with existing restart file.");

                        MyConfigDedicatedData <MyObjectBuilder_SessionSettings> restartConfig = DedicatedConfigDefinition.Load(new FileInfo(Path + @"\SpaceEngineers-Dedicated.cfg.restart"));
                        MyConfigDedicatedData <MyObjectBuilder_SessionSettings> changedConfig = DedicatedConfigDefinition.Load(new FileInfo(e.FullPath));

                        restartConfig.Mods           = restartConfig.Mods.Union(changedConfig.Mods).ToList( );
                        restartConfig.Banned         = changedConfig.Banned.Union(changedConfig.Banned).ToList( );
                        restartConfig.Administrators = changedConfig.Administrators.Union(changedConfig.Administrators).ToList( );
                        DedicatedConfigDefinition config = new DedicatedConfigDefinition(restartConfig);
                        config.Save(new FileInfo(Path + @"\SpaceEngineers-Dedicated.cfg.restart"));
                        Config = config;
                    }
                }
                catch (Exception ex)
                {
                    ApplicationLog.BaseLog.Error("Error on configuration change ({1})", e.FullPath);
                    ApplicationLog.BaseLog.Error(ex);
                }
            }
        }
Пример #2
0
        private void Config_Changed(object sender, FileSystemEventArgs e)
        {
            if (!e.Name.Contains("SpaceEngineers-Dedicated.cfg") || e.Name.Contains("SpaceEngineers-Dedicated.cfg.restart"))
            {
                return;
            }

            if (!m_serverRan)
            {
                return;
            }

            if (e.ChangeType == WatcherChangeTypes.Changed)
            {
                try
                {
                    if (!File.Exists(Path + @"\SpaceEngineers-Dedicated.cfg.restart"))
                    {
                        LogManager.APILog.WriteLineAndConsole(string.Format("SpaceEngineers-Dedicated.cfg has changed updating configuration settings."));

                        MyConfigDedicatedData changedConfig = DedicatedConfigDefinition.Load(new FileInfo(e.FullPath));
                        Config = new DedicatedConfigDefinition(changedConfig);
                    }
                    else
                    {
                        LogManager.APILog.WriteLineAndConsole(string.Format("SpaceEngineers-Dedicated.cfg has changed with existing restart file."));

                        MyConfigDedicatedData restartConfig = DedicatedConfigDefinition.Load(new FileInfo(Path + @"\SpaceEngineers-Dedicated.cfg.restart"));
                        MyConfigDedicatedData changedConfig = DedicatedConfigDefinition.Load(new FileInfo(e.FullPath));

                        restartConfig.Mods           = restartConfig.Mods.Union(changedConfig.Mods).ToList();
                        restartConfig.Banned         = changedConfig.Banned.Union(changedConfig.Banned).ToList();
                        restartConfig.Administrators = changedConfig.Administrators.Union(changedConfig.Administrators).ToList();
                        DedicatedConfigDefinition config = new DedicatedConfigDefinition(restartConfig);
                        config.Save(new FileInfo(Path + @"\SpaceEngineers-Dedicated.cfg.restart"));
                        Config = config;
                    }
                }
                catch (Exception ex)
                {
                    LogManager.APILog.WriteLineAndConsole(string.Format("Error on configuration change ({1}): {0}", e.FullPath, ex.ToString()));
                }
            }
        }