Inheritance: Pluton.CountedInstance
Exemple #1
0
 public bool AddFromIni(string inipath)
 {
     if (File.Exists(inipath))
     {
         IniParser ini = new IniParser(inipath);
         foreach (string section in ini.Sections)
         {
             foreach (string setting in ini.EnumSection(section))
             {
                 this.Add(section, setting, ini.GetSetting(section, setting));
             }
         }
         return true;
     }
     return false;
 }
Exemple #2
0
        public LoadOut(string name)
        {
            path = Path.Combine(Util.GetLoadoutFolder(), name + ".ini");
            bool nu = false;
            if (!File.Exists(path)) {
                File.AppendAllText(path, "");
                nu = true;
            }
            var ini = new IniParser(path);
            Name = ini.Name;
            if (!nu) {
                itemCount = Int32.Parse(ini.GetSetting("Def", "itemCount"));
                OwnerUse = ini.GetBoolSetting("Def", "ownerCanUse");
                ModeratorUse = ini.GetBoolSetting("Def", "modCanUse");
                NormalUse = ini.GetBoolSetting("Def", "normalCanUse");
            } else {
                itemCount = 0;
                OwnerUse = true;
                NormalUse = true;
                ModeratorUse = true;
            }
            items = new Dictionary<int, LoadOutItem>(30);

            if (itemCount != 0) {
                LoadOutItem current;
                for (var i = 0; i < itemCount; i++) {
                    string namee = ini.GetSetting(i.ToString(), "Name");
                    int amount;
                    if (!Int32.TryParse(ini.GetSetting(i.ToString(), "Amount"), out amount))
                        amount = Int32.MaxValue;
                    current = new LoadOutItem(namee, amount);
                    items.Add(i, current);
                }
            }
            ini = null;
            if (Server.GetInstance().LoadOuts.ContainsKey(Name))
                Server.GetInstance().LoadOuts.Remove(Name);
            Server.GetInstance().LoadOuts.Add(Name, this);
        }
Exemple #3
0
        public bool ToIni(string inifilename = "DataStore")
        {
            string inipath = Path.Combine(Util.GetPublicFolder(), RemoveChars(inifilename).Trim() + ".ini");
            File.WriteAllText(inipath, "");
            IniParser ini = new IniParser(inipath);
            ini.Save();

            foreach (string section in this.datastore.Keys) {
                Hashtable ht = (Hashtable)this.datastore[section];
                foreach (object setting in ht.Keys) {
                    try {
                        string key = "NullReference";
                        string val = "NullReference";
                        if (setting != null) {
                            if (setting.GetType().GetMethod("ToString", Type.EmptyTypes) == null) {
                                key = "type:" + setting.GetType().ToString();
                            } else {
                                key = setting.ToString();
                            }
                        }

                        if (ht[setting] != null) {
                            if (ht[setting].GetType().GetMethod("ToString", Type.EmptyTypes) == null) {
                                val = "type:" + ht[setting].GetType().ToString();
                            } else {
                                val = ht[setting].ToString();
                            }            
                        }

                        ini.AddSetting(section, key, val);
                    } catch (Exception ex) {
                        Logger.LogException(ex);
                    }
                }
            }
            ini.Save();
            return true;           
        }
Exemple #4
0
        public bool TableToIni(string tablename, string inipath)
        {
            Hashtable hashtable = (Hashtable)this.datastore[tablename];
            if (hashtable != null)
            {
                if (!Path.HasExtension(inipath))
                    inipath += ".ini";
                File.WriteAllText(inipath, "");
                IniParser ini = new IniParser(inipath);
                ini.Save();

                foreach (string setting in hashtable.Keys)
                {
                    ini.AddSetting(tablename, setting, hashtable[setting].ToString());
                }
                ini.Save();
                return true;
            }
            return false;
        }
Exemple #5
0
 public void ToIni()
 {
     var ini = new IniParser(path);
     ini.AddSetting("Def", "itemCount", itemCount.ToString());
     ini.AddSetting("Def", "ownerCanUse", OwnerUse.ToString());
     ini.AddSetting("Def", "modCanUse", ModeratorUse.ToString());
     ini.AddSetting("Def", "normalCanUse", NormalUse.ToString());
     for (var i = 0; i < itemCount; i++) {
         ini.AddSetting(i.ToString(), "Name", items[i].Name);
         ini.AddSetting(i.ToString(), "Amount", items[i].Amount.ToString());
     }
     ini.Save();
 }