Ejemplo n.º 1
0
        /// <summary>
        /// Write a SubKey
        /// </summary>
        /// <param name="sw"></param>
        /// <param name="key"></param>
        void WriteKey(System.IO.StreamWriter sw, XmlRegistryKey key)
        {
            if (key != root)
            {
                sw.WriteLine("<key name=\"" + key.Name + "\">");
            }

            string[] keys = key.GetSubKeyNames();
            foreach (string s in keys)
            {
                WriteKey(sw, key.OpenSubKey(s, false));
            }

            string[] values = key.GetValueNames();
            foreach (string s in values)
            {
                WriteValue(sw, s, key.GetValue(s));
            }


            if (key != root)
            {
                sw.WriteLine("</key>");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Parse a certain SubNode Level of the XML File
        /// </summary>
        /// <param name="node">The current Node</param>
        /// <param name="key">The current SubTree</param>
        void ParseSubNode(XmlNode node, XmlRegistryKey key)
        {
            XmlRegistryKey subkey = key;

            //Remember the Name of the Node
            if (node.Name == "key")
            {
                subkey = key.CreateSubKey(node.Attributes["name"].Value);
            }

            foreach (XmlNode subnode in node)
            {
                if (subnode.Name == "key")
                {
                    ParseSubNode(subnode, subkey);
                }
                ParseValues(subnode, subkey);
                if (subnode.Name == "list")
                {
                    ParseListNode(subnode, subkey, false);
                }
                if (subnode.Name == "cilist")
                {
                    ParseListNode(subnode, subkey, true);
                }
            }
        }
Ejemplo n.º 3
0
        protected static void Load()
        {
            ArrayList list = new ArrayList();

            XmlRegistryKey rk = Helper.WindowsRegistry.RegistryKey.CreateSubKey("ExtTools");

            string[] names = rk.GetSubKeyNames();

            foreach (string name in names)
            {
                string         rname = ToolLoaderItemExt.SplitName(name);
                XmlRegistryKey srk   = rk.CreateSubKey(name);

                ToolLoaderItemExt tli = new ToolLoaderItemExt(rname);
                tli.Type = Convert.ToUInt32(srk.GetValue("type"));
                //tli.Name = Convert.ToString(srk.GetValue("name"));
                tli.FileName   = Convert.ToString(srk.GetValue("filename"));
                tli.Attributes = Convert.ToString(srk.GetValue("attributes"));

                list.Add(tli);
            }

            items = new ToolLoaderItemExt[list.Count];
            list.CopyTo(items);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Parse a certain SubNode Level of the XML File
        /// </summary>
        /// <param name="node">The current Node</param>
        /// <param name="key">The current SubTree</param>
        /// <param name="caseinvariant">true if you want a case Invariant List</param>
        void ParseListNode(XmlNode node, XmlRegistryKey key, bool caseinvariant)
        {
            XmlRegistryKey subkey = new XmlRegistryKey();
            ArrayList      names  = new ArrayList();

            foreach (XmlNode subnode in node)
            {
                if (subnode.Attributes == null)
                {
                    continue;
                }
                names.Add(subnode.Attributes["name"].Value);
                ParseValues(subnode, subkey);
            }

            ArrayList list = null;

            if (!caseinvariant)
            {
                list = new ArrayList();
            }
            else
            {
                list = new Ambertation.CaseInvariantArrayList();
            }

            foreach (string s in names)
            {
                list.Add(subkey.GetValue(s));
            }

            key.SetValue(node.Attributes["name"].Value, list);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Parse the passed Values
 /// </summary>
 /// <param name="subnode"></param>
 /// <param name="subkey"></param>
 void ParseValues(XmlNode subnode, XmlRegistryKey subkey)
 {
     if (subnode.Name == "string")
     {
         ParseStringValue(subnode, subkey);
     }
     if (subnode.Name == "int")
     {
         ParseIntValue(subnode, subkey);
     }
     if (subnode.Name == "uint")
     {
         ParseUIntValue(subnode, subkey);
     }
     if (subnode.Name == "long")
     {
         ParseLongValue(subnode, subkey);
     }
     if (subnode.Name == "ulong")
     {
         ParseULongValue(subnode, subkey);
     }
     if (subnode.Name == "bool")
     {
         ParseBoolValue(subnode, subkey);
     }
     if (subnode.Name == "float")
     {
         ParseFloatValue(subnode, subkey);
     }
     if (subnode.Name == "datetime")
     {
         ParseDateTimeValue(subnode, subkey);
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Load the Registry from the passed File
        /// </summary>
        /// <param name="xmlfilename">Name of the Registry</param>
        /// <param name="create">true, if you want to create the File if it does not exist</param>
        public XmlRegistry(string infilename, string outfilename, bool create)
        {
#if MAC
            Console.WriteLine("Loading Settings from \"" + xmlfilename + "\".");
#endif
            root = new XmlRegistryKey();
            if (create)
            {
                if (!System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(outfilename)))
                {
                    System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(outfilename));
                }
                if (!System.IO.File.Exists(outfilename))
                {
                    Flush(outfilename);
                }
            }

            this.filename = outfilename;

            //read XML File
            System.Xml.XmlDocument xmlfile = new XmlDocument();
            xmlfile.Load(infilename);

            //seek Root Node
            XmlNodeList XMLData = xmlfile.GetElementsByTagName("registry");

            //Process all Root Node Entries
            for (int i = 0; i < XMLData.Count; i++)
            {
                XmlNode node = XMLData.Item(i);
                ParseSubNode(node, root);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Open the SubKey with the given Name
        /// </summary>
        /// <param name="name">Name of the Key</param>
        /// <param name="create">create it if it does not exist</param>
        /// <returns>the opened/created subKey (null if created is false and the key does not exist)</returns>
        /// <exception cref="Exception">Thrown if the passed Element is not a Key but a value</exception>
        XmlRegistryKey OpenLocalSubKey(string name, bool create)
        {
            if (tree.ContainsKey(name))
            {
                object o = tree[name];
                if (o != null)
                {
                    if (o.GetType() != typeof(XmlRegistryKey))
                    {
                        throw new Exception("The SubElement " + name + " is not a Key!");
                    }
                }

                return((XmlRegistryKey)o);
            }

            if (create)
            {
                XmlRegistryKey xrk = new XmlRegistryKey();
                xrk.name   = name;
                tree[name] = xrk;
                return(CreateSubKey(name));
            }

            return(null);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Add an LongInteger Value
        /// </summary>
        /// <param name="node">The current Node</param>
        /// <param name="key">The current SubTree</param>
        void ParseULongValue(XmlNode node, XmlRegistryKey key)
        {
            ulong val = 0;

            try
            {
                val = Convert.ToUInt64(node.InnerText);
            }
            catch {}
            key.SetValue(node.Attributes["name"].Value, val);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Add an Integer Value
        /// </summary>
        /// <param name="node">The current Node</param>
        /// <param name="key">The current SubTree</param>
        void ParseIntValue(XmlNode node, XmlRegistryKey key)
        {
            int val = 0;

            try
            {
                val = Convert.ToInt32(node.InnerText);
            }
            catch {}
            key.SetValue(node.Attributes["name"].Value, val);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Add an Date Value
        /// </summary>
        /// <param name="node">The current Node</param>
        /// <param name="key">The current SubTree</param>
        void ParseDateTimeValue(XmlNode node, XmlRegistryKey key)
        {
            DateTime val = DateTime.Now;

            try
            {
                val = Convert.ToDateTime(node.InnerText);
            }
            catch {}
            key.SetValue(node.Attributes["name"].Value, val);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Put the Settings to the Registry
        /// </summary>
        public void SaveSettings()
        {
            XmlRegistryKey rk = Helper.WindowsRegistry.RegistryKey.CreateSubKey("ExtTools");

            rk = rk.CreateSubKey(Helper.HexString(type) + "-" + name);

            rk.SetValue("name", Name);
            rk.SetValue("type", Type);
            rk.SetValue("filename", FileName);
            rk.SetValue("attributes", Attributes);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Add an Float Value
        /// </summary>
        /// <param name="node">The current Node</param>
        /// <param name="key">The current SubTree</param>
        void ParseFloatValue(XmlNode node, XmlRegistryKey key)
        {
            float val = 0;

            try
            {
                val = Convert.ToSingle(node.InnerText);
            }
            catch {}
            key.SetValue(node.Attributes["name"].Value, val);
        }
Ejemplo n.º 13
0
        private PathProvider()
        {
            reg         = new XmlRegistry(ExpansionFile, ExpansionFile, true);
            xrk         = reg.CurrentUser.CreateSubKey("Expansions");
            exps        = new List <ExpansionItem>();
            map         = new Dictionary <Expansions, ExpansionItem>();
            savgamemap  = new Dictionary <long, Ambertation.CaseInvariantArrayList>();
            censorfiles = new List <string>();
            avlgrp      = 0;

            Load();
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Open the SubKey with the given Name
        /// </summary>
        /// <param name="name">Name of the Key</param>
        /// <param name="create">create it if it does not exist</param>
        /// <returns>the opened/created subKey (null if created is false and the key does not exist)</returns>
        /// <exception cref="Exception">Thrown if the passed Element is not a Key but a value</exception>
        XmlRegistryKey OpenSubKey(string[] path, bool create)
        {
            XmlRegistryKey key = this;

            string curkey = "";

            for (int i = 0; i < path.Length; i++)
            {
                key     = key.OpenLocalSubKey(path[i], create);
                curkey += "\\" + path[i];
                if (key == null)
                {
                    return(null);                           //throw new Exception("The Key "+curkey+" was not found!");
                }
            }

            return(key);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Add an Boolean Value
        /// </summary>
        /// <param name="node">The current Node</param>
        /// <param name="key">The current SubTree</param>
        void ParseBoolValue(XmlNode node, XmlRegistryKey key)
        {
            bool val = false;

            try
            {
                string s = node.InnerText.Trim().ToLower();
                if (s == "false" || s == "no" || s == "off" || s == "0")
                {
                    val = false;
                }
                else
                {
                    val = true;
                }
            }
            catch {}
            key.SetValue(node.Attributes["name"].Value, val);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Save the Toollist
        /// </summary>
        public static void StoreTools()
        {
            if (items == null)
            {
                return;
            }

            string[] names = Helper.WindowsRegistry.RegistryKey.CreateSubKey("ExtTools").GetSubKeyNames();

            foreach (string name in names)
            {
                Helper.WindowsRegistry.RegistryKey.CreateSubKey("ExtTools").DeleteSubKey(name, false);
            }
            Helper.WindowsRegistry.RegistryKey.DeleteSubKey("ExtTools", false);
            XmlRegistryKey rk = Helper.WindowsRegistry.RegistryKey.CreateSubKey("ExtTools");

            foreach (ToolLoaderItemExt tli in items)
            {
                tli.SaveSettings();
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Remove a SubKey
        /// </summary>
        /// <param name="path"></param>
        /// <param name="throwOnException"></param>
        void DeleteSubKey(string[] path, bool throwOnException)
        {
            if (path.Length < 1)
            {
                return;
            }

            XmlRegistryKey key = this;

            string curkey = "";

            for (int i = 0; i < path.Length - 1; i++)
            {
                key     = key.OpenLocalSubKey(path[i], false);
                curkey += "\\" + path[i];
                if (key == null)
                {
                    if (throwOnException)
                    {
                        throw new Exception("The Key " + curkey + " was not found!");
                    }
                    else
                    {
                        return;
                    }
                }
            }

            string name = path[path.Length - 1];

            if (!key.tree.Contains(name) && throwOnException)
            {
                throw new Exception("The Key " + curkey + " was not found!");
            }
            if (key.tree.Contains(name))
            {
                key.tree.Remove(name);
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Add an String Value
        /// </summary>
        /// <param name="node">The current Node</param>
        /// <param name="key">The current SubTree</param>
        void ParseStringValue(XmlNode node, XmlRegistryKey key)
        {
            string val = node.InnerText;

            key.SetValue(node.Attributes["name"].Value, val);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Remove the Registry Settings
        /// </summary>
        public void DeleteSettings()
        {
            XmlRegistryKey rk = Helper.WindowsRegistry.RegistryKey.CreateSubKey("ExtTools");

            rk.DeleteSubKey(Helper.HexString(type) + "-" + name, false);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Add a new SubKey
        /// </summary>
        /// <param name="name">Name of the SubKey</param>
        /// <returns>the created SubKey</returns>
        public XmlRegistryKey CreateSubKey(string name)
        {
            XmlRegistryKey xrk = OpenSubKey(name, true);

            return(xrk);
        }
Ejemplo n.º 21
0
        internal ExpansionItem(XmlRegistryKey key)
        {
            filtablefolders          = new Ambertation.CaseInvariantArrayList();
            preobjectfiltablefolders = new Ambertation.CaseInvariantArrayList();


            shortname   = "Unk.";
            shortername = "Unknown";
            longname    = "The Sims 2 - Unknown";
            namelistnr  = "0";
            if (key != null)
            {
                name = key.Name;
                ;
                XmlRegistryKey lang = key.OpenSubKey(System.Threading.Thread.CurrentThread.CurrentUICulture.Name.ToLower(), false);
                if (lang == null)
                {
                    lang = key.OpenSubKey(System.Threading.Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName.ToLower(), false);
                }


                version        = (int)key.GetValue("Version", 0);
                runtimeversion = (int)key.GetValue("PreferedRuntimeVersion", version);
                exp            = (Expansions)(Math.Pow(2, version));

                int    isnum = -1;
                object o     = key.GetValue("RegKey", null);
                if (o is string)
                {
                    rk = Microsoft.Win32.Registry.LocalMachine.OpenSubKey((string)o, false);
                }
                else if (o is Ambertation.CaseInvariantArrayList)
                {
                    foreach (string s in (Ambertation.CaseInvariantArrayList)o)
                    {
                        isnum++;
                        rk = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(s, false);
                        if (rk != null)
                        {
                            break;
                        }
                    }
                }
                if (rk == null)
                {
                    isnum = -1;
                }
                o = key.GetValue("InstallSuffix", null);
                if (o is string)
                {
                    installsuffix = (string)o;
                }
                else if (o is Ambertation.CaseInvariantArrayList && isnum >= 0 && isnum < ((Ambertation.CaseInvariantArrayList)o).Count)
                {
                    installsuffix = (string)((Ambertation.CaseInvariantArrayList)o)[isnum];
                }

                exe       = (string)key.GetValue("ExeName", "Sims2.exe");
                flag      = new Flags((int)key.GetValue("Flag", 0));
                censor    = (string)key.GetValue("Censor", "");
                group     = (int)key.GetValue("Group", 1);
                objfolder = (string)key.GetValue("ObjectsFolder", "TSData" + Helper.PATH_SEP + "Res" + Helper.PATH_SEP + "Objects");

                simnamedeep = (Ambertation.CaseInvariantArrayList)key.GetValue("SimNameDeepSearch", new Ambertation.CaseInvariantArrayList());
                savegames   = (Ambertation.CaseInvariantArrayList)key.GetValue("SaveGameLocationsForGroup", new Ambertation.CaseInvariantArrayList());
                if (savegames.Count == 0)
                {
                    savegames.Add(PathProvider.SimSavegameFolder);
                }

                Ambertation.CaseInvariantArrayList ftf = (Ambertation.CaseInvariantArrayList)key.GetValue("FileTableFolders", new Ambertation.CaseInvariantArrayList());
                if (ftf.Count == 0)
                {
                    SetDefaultFileTableFolders();
                }
                else
                {
                    foreach (string folder in ftf)
                    {
                        AddFileTableFolder(folder);
                    }
                }

                ftf = (Ambertation.CaseInvariantArrayList)key.GetValue("AdditionalFileTableFolders", new Ambertation.CaseInvariantArrayList());
                foreach (string folder in ftf)
                {
                    AddFileTableFolder(folder);
                }

                System.Diagnostics.Debug.WriteLine(this.ToString());

                namelistnr = (string)key.GetValue("namelistnr", "0");
                string dname = name;
                if (lang != null)
                {
                    shortname   = (string)lang.GetValue("short", name);
                    shortername = (string)lang.GetValue("name", shortname);
                    if (rk != null)
                    {
                        dname = (string)rk.GetValue("DisplayName", shortername);
                    }
                    longname = (string)lang.GetValue("long", dname);
                }
                else //1. check the resource files, then try default language, then set to defaults
                {
                    if (lang == null)
                    {
                        lang = key.OpenSubKey("en", false);
                    }
                    shortname   = SimPe.Localization.GetString("EP SNAME " + version);
                    shortername = shortname;

                    if (shortname == "EP SNAME " + version && lang != null)
                    {
                        shortname   = (string)lang.GetValue("short", name);
                        shortername = (string)lang.GetValue("name", shortname);
                    }
                    if (shortname == "EP SNAME " + version)
                    {
                        shortname = name;
                    }

                    if (rk != null)
                    {
                        dname = (string)rk.GetValue("DisplayName", shortername);
                    }

                    longname = SimPe.Localization.GetString("EP NAME " + version);
                    if (longname == "EP NAME " + version && lang != null)
                    {
                        longname = (string)lang.GetValue("long", dname);
                    }
                    if (longname == "EP NAME " + version)
                    {
                        longname = dname;
                    }
                }
            }
            else
            {
                name           = "NULL";
                flag           = new Flags(0);
                censor         = "";
                exe            = "";
                exp            = (Expansions)0;
                version        = -1;
                runtimeversion = -1;
                simnamedeep    = new Ambertation.CaseInvariantArrayList();
                savegames      = new Ambertation.CaseInvariantArrayList();
                savegames.Add(PathProvider.SimSavegameFolder);


                SetDefaultFileTableFolders();
                objfolder = "TSData" + Helper.PATH_SEP + "Res" + Helper.PATH_SEP + "Objects";
                group     = 0;
            }



            BuildGroupList();
            sname = GetShortName();
        }
Ejemplo n.º 22
0
 /// <summary>
 /// Creates a new Instance
 /// </summary>
 /// <param name="layoutkey">Key to the Layout</param>
 internal LayoutRegistry(XmlRegistryKey layoutkey)
 {
     reg = new XmlRegistry(Helper.DataFolder.Layout2XREG, Helper.DataFolder.Layout2XREGW, true);
     xrk = reg.CurrentUser.CreateSubKey(@"Software\Ambertation\SimPe\Layout");
 }