Esempio n. 1
0
 public LocalSettingsData(BackupInterval backupInterval, string backupDirectory,
                          Time backupTime, DayOfWeek backupWeekDay, int backUpDay,
                          DateTime lastBackup)
 {
     BackupInterval  = backupInterval;
     BackupDirectory = backupDirectory;
     BackupTime      = backupTime;
     BackupWeekDay   = backupWeekDay;
     BackUpDay       = backUpDay;
     LastBackup      = lastBackup;
 }
Esempio n. 2
0
        /// <summary>
        /// Saves the backup settings to a xml file.
        /// </summary>
        public static void SaveBackupSettings()
        {
            XmlDocument doc     = new XmlDocument();
            XmlNode     docNode = doc.CreateXmlDeclaration("1.0", "UTF-8", null);

            doc.AppendChild(docNode);

            XmlNode root = doc.CreateElement(ROOT);

            doc.AppendChild(root);

            XmlNode node = ConfigHelper.CreateConfigNode(doc, BACKUPPATH, NAME, BackupPath);

            root.AppendChild(node);

            node = ConfigHelper.CreateConfigNode(doc, AUTOBACKUP, VALUE, AutoBackupOnOff.ToString());
            root.AppendChild(node);

            node = ConfigHelper.CreateConfigNode(doc, BACKUPINTERVAL, VALUE, BackupInterval.ToString());
            root.AppendChild(node);

            node = ConfigHelper.CreateConfigNode(doc, MAXBACKUPFILES, VALUE, MaxBackupFiles.ToString());
            root.AppendChild(node);

            node = ConfigHelper.CreateConfigNode(doc, BACKUPONKSPLAUNCH, VALUE, BackupOnKSPLaunch.ToString());
            root.AppendChild(node);

            node = ConfigHelper.CreateConfigNode(doc, BACKUPONKSPMALAUNCH, VALUE, BackupOnKSPMALaunch.ToString());
            root.AppendChild(node);

            node = doc.CreateElement(BACKUPFILES);
            root.AppendChild(node);

            foreach (BackupNode backupFile in model.Nodes)
            {
                XmlNode columnNode = ConfigHelper.CreateConfigNode(doc, BACKUPFILE, new string[, ]
                {
                    { NAME, backupFile.Name },
                    { NOTE, backupFile.Note }
                });
                node.AppendChild(columnNode);
            }

            doc.Save(FullBackupConfigPath);
        }
Esempio n. 3
0
        public XElement Serialize([NotNull] string elementName)
        {
            if (elementName == null)
            {
                throw new ArgumentNullException("elementName");
            }

            XElement root = new XElement(elementName);

            root.Add(new XAttribute("name", Name));

            if (AccessSecurity.HasRestrictions)
            {
                root.Add(AccessSecurity.Serialize(AccessSecurityXmlTagName));
            }
            if (BuildSecurity.HasRestrictions)
            {
                root.Add(BuildSecurity.Serialize(BuildSecurityXmlTagName));
            }

            if (BackupInterval != BackupIntervalDefault)
            {
                root.Add(new XAttribute("backup", BackupInterval.ToSecondsString()));
            }

            if (Preload)
            {
                root.Add(new XAttribute("noUnload", true));
            }
            if (IsHidden)
            {
                root.Add(new XAttribute("hidden", true));
            }
            root.Add(BlockDB.SaveSettings());

            if (!String.IsNullOrEmpty(LoadedBy))
            {
                root.Add(new XElement("LoadedBy", LoadedBy));
            }
            if (LoadedOn != DateTime.MinValue)
            {
                root.Add(new XElement("LoadedOn", LoadedOn.ToUnixTime()));
            }
            if (!String.IsNullOrEmpty(MapChangedBy))
            {
                root.Add(new XElement("MapChangedBy", MapChangedBy));
            }
            if (MapChangedOn != DateTime.MinValue)
            {
                root.Add(new XElement("MapChangedOn", MapChangedOn.ToUnixTime()));
            }

            XElement elEnv = new XElement(EnvironmentXmlTagName);

            if (CloudColor > -1)
            {
                elEnv.Add(new XAttribute("cloud", CloudColor));
            }
            if (FogColor > -1)
            {
                elEnv.Add(new XAttribute("fog", FogColor));
            }
            if (SkyColor > -1)
            {
                elEnv.Add(new XAttribute("sky", SkyColor));
            }
            if (EdgeLevel > -1)
            {
                elEnv.Add(new XAttribute("level", EdgeLevel));
            }
            if (EdgeBlock != Block.Water)
            {
                elEnv.Add(new XAttribute("edge", EdgeBlock));
            }
            if (elEnv.HasAttributes)
            {
                root.Add(elEnv);
            }
            return(root);
        }
Esempio n. 4
0
        public World([NotNull] string name, [NotNull] XElement el)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (el == null)
            {
                throw new ArgumentNullException("el");
            }
            if (!IsValidName(name))
            {
                throw new ArgumentException("Unacceptable world name.");
            }
            Name    = name;
            BlockDB = new BlockDB(this);
            UpdatePlayerList();

            XAttribute tempAttr;

            // load hidden status
            if ((tempAttr = el.Attribute("hidden")) != null)
            {
                bool isHidden;
                if (Boolean.TryParse(tempAttr.Value, out isHidden))
                {
                    IsHidden = isHidden;
                }
                else
                {
                    Logger.Log(LogType.Warning,
                               "World: Could not parse \"hidden\" attribute of world \"{0}\", assuming NOT hidden.",
                               Name);
                }
            }

            // load access and build security
            XElement tempEl;

            if ((tempEl = el.Element(AccessSecurityXmlTagName)) != null)
            {
                AccessSecurity = new SecurityController(tempEl, true);
            }
            else if ((tempEl = el.Element("accessSecurity")) != null)
            {
                AccessSecurity = new SecurityController(tempEl, true);
            }
            else
            {
                AccessSecurity = new SecurityController();
            }

            if ((tempEl = el.Element(BuildSecurityXmlTagName)) != null)
            {
                BuildSecurity = new SecurityController(tempEl, true);
            }
            else if ((tempEl = el.Element("buildSecurity")) != null)
            {
                BuildSecurity = new SecurityController(tempEl, true);
            }
            else
            {
                BuildSecurity = new SecurityController();
            }

            // load backup interval
            if ((tempAttr = el.Attribute("backup")) != null)
            {
                if (!tempAttr.Value.ToTimeSpan(out backupInterval))
                {
                    backupInterval = BackupIntervalDefault;
                    Logger.Log(LogType.Warning,
                               "WorldManager: Could not parse \"backup\" attribute of world \"{0}\", assuming default ({1}).",
                               Name,
                               BackupInterval.ToMiniString());
                }
            }
            else
            {
                BackupInterval = BackupIntervalDefault;
            }

            // load BlockDB settings
            XElement blockEl = el.Element(BlockDB.XmlRootName);

            if (blockEl != null)
            {
                BlockDB.LoadSettings(blockEl);
            }

            // load map (if needed)
            Preload = (el.Attribute("noUnload") != null);

            // load environment settings
            XElement envEl = el.Element(EnvironmentXmlTagName);

            if (envEl != null)
            {
                if ((tempAttr = envEl.Attribute("cloud")) != null)
                {
                    if (!Int32.TryParse(tempAttr.Value, out CloudColor))
                    {
                        CloudColor = -1;
                        Logger.Log(LogType.Warning,
                                   "WorldManager: Could not parse \"cloud\" attribute of Environment settings for world \"{0}\", assuming default (normal).",
                                   Name);
                    }
                }
                if ((tempAttr = envEl.Attribute("fog")) != null)
                {
                    if (!Int32.TryParse(tempAttr.Value, out FogColor))
                    {
                        FogColor = -1;
                        Logger.Log(LogType.Warning,
                                   "WorldManager: Could not parse \"fog\" attribute of Environment settings for world \"{0}\", assuming default (normal).",
                                   Name);
                    }
                }
                if ((tempAttr = envEl.Attribute("sky")) != null)
                {
                    if (!Int32.TryParse(tempAttr.Value, out SkyColor))
                    {
                        SkyColor = -1;
                        Logger.Log(LogType.Warning,
                                   "WorldManager: Could not parse \"sky\" attribute of Environment settings for world \"{0}\", assuming default (normal).",
                                   Name);
                    }
                }
                if ((tempAttr = envEl.Attribute("level")) != null)
                {
                    if (!Int32.TryParse(tempAttr.Value, out EdgeLevel))
                    {
                        EdgeLevel = -1;
                        Logger.Log(LogType.Warning,
                                   "WorldManager: Could not parse \"level\" attribute of Environment settings for world \"{0}\", assuming default (normal).",
                                   Name);
                    }
                }
                if ((tempAttr = envEl.Attribute("edge")) != null)
                {
                    Block block;
                    if (!Map.GetBlockByName(tempAttr.Value, false, out block))
                    {
                        EdgeBlock = Block.Water;
                        Logger.Log(LogType.Warning,
                                   "WorldManager: Could not parse \"edge\" attribute of Environment settings for world \"{0}\", assuming default (Water).",
                                   Name);
                    }
                    else
                    {
                        if (Map.GetEdgeTexture(block) == null)
                        {
                            EdgeBlock = Block.Water;
                            Logger.Log(LogType.Warning,
                                       "WorldManager: Unacceptable blocktype given for \"edge\" attribute of Environment settings for world \"{0}\", assuming default (Water).",
                                       Name);
                        }
                        else
                        {
                            EdgeBlock = block;
                        }
                    }
                }
            }
        }