Ejemplo n.º 1
0
 public void SetParam2(string propertyName, string paramValue)
 {
     if (properties.ContainsKey(propertyName))
     {
         ModDataProperty prop = properties [propertyName];
         prop.param2 = paramValue;
         properties [propertyName] = prop;
     }
     else
     {
         ModDataProperty prop = new ModDataProperty();
         prop.name   = propertyName;
         prop.param2 = paramValue;
         prop.param1 = "";
         prop.value  = "";
         properties.Add(propertyName, prop);
     }
 }
Ejemplo n.º 2
0
        public bool Save()
        {
            string modDataPath = SDTM.API.configDataPath;

            string[] splitter   = { "/" };
            string[] parts      = dataName.Split(splitter, StringSplitOptions.RemoveEmptyEntries);
            string   dataFolder = modDataPath;

            if (parts.Length > 1)
            {
                dataFolder += "/" + parts [0];
            }

            if (FileUtils.ensureDirectoryExists(dataFolder))
            {
                modDataPath = modDataPath + "/" + dataName + ".xml";
                StreamWriter sw = new StreamWriter(modDataPath);

                sw.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
                sw.WriteLine("<ModData>");

                foreach (string key in properties.Keys)
                {
                    ModDataProperty prop  = properties[key];
                    string          entry = string.Format("<{0} param1=\"{1}\" param2=\"{2}\">{3}</{0}>", prop.name, prop.param1, prop.param2, prop.value);
                    sw.WriteLine("\t" + entry);
                }

                sw.WriteLine("</ModData>");
                sw.Flush();
                sw.Close();

                return(true);
            }

            return(false);
        }
Ejemplo n.º 3
0
        public bool Load()
        {
            string modDataPath = SDTM.API.configDataPath;

            string[] splitter   = { "/" };
            string[] parts      = dataName.Split(splitter, StringSplitOptions.RemoveEmptyEntries);
            string   dataFolder = modDataPath;

            if (parts.Length > 1)
            {
                dataFolder += "/" + parts [0];
            }

            if (FileUtils.ensureDirectoryExists(dataFolder))
            {
                modDataPath = modDataPath + "/" + dataName + ".xml";

                if (!File.Exists(modDataPath))
                {
                    if (!Save())
                    {
                        Log.Error(string.Format("[SDTMLib] Could not Create Initial Data: {0}", modDataPath));
                        return(false);
                    }
                }

                XmlDocument xmlDoc = new XmlDocument();
                try{
                    xmlDoc.Load(modDataPath);
                }
                catch (XmlException e) {
                    Log.Error(string.Format("[SDTMLib] Could not Load Config: {0}", e.Message));
                    return(false);
                }

                XmlNode rootNode = xmlDoc.DocumentElement;

                foreach (XmlNode configNode in rootNode.ChildNodes)
                {
                    ModDataProperty prop = new ModDataProperty();
                    prop.name  = configNode.Name.ToLower();
                    prop.value = configNode.InnerText;

                    if (configNode.Attributes.Count > 0)
                    {
                        foreach (XmlAttribute attr in configNode.Attributes)
                        {
                            switch (attr.Name.ToLower())
                            {
                            case "param1":
                                prop.param1 = attr.Value;
                                break;

                            case "param2":
                                prop.param2 = attr.Value;
                                break;
                            }
                        }
                    }
                    properties.Add(configNode.Name.ToLower(), prop);
                }

                return(true);
            }

            return(false);
        }