public static void populate()
 {
     if (pluginInfo.Names.Count < 1)
     {
         RegistryAccess ra = new RegistryAccess(Microsoft.Win32.Registry.CurrentUser,
                                  RegistryAccess.RegPaths.Halo2 + "PluginSets\\");
         if (ra.isOpen)
         {
             pluginInfo.Names = new List<string>(ra.getNames());
             pluginInfo.Paths = new List<string>(Array.ConvertAll(ra.getValues(),new Converter<object,string>(Convert)));
             int i = pluginInfo.Names.IndexOf("");
             if (i != -1)
             {
                 pluginInfo.Names.RemoveAt(i);
                 pluginInfo.Paths.RemoveAt(i);
             }
         }
         else
         {
             pluginInfo.Names.Add("Default");
             pluginInfo.Paths.Add(Prefs.pathPluginsFolder);
         }
         ra.CloseReg();
     }
 }
Beispiel #2
0
        /// <summary>
        /// Adds a file to the Halo 2 recently used list
        /// </summary>
        /// <param name="pos">The position in which to add the fileName (0-9)</param>
        /// <param name="fileName">The location and name of the file</param>
        public static void AddRecentFile(int pos, string fileName)
        {
            int found = -1;
            int count = 0;
            string[] files = new string[10];
            // Load recently used files list
            RegistryAccess ra = new RegistryAccess(Registry.CurrentUser, RegPaths.Halo2RecentFiles);
            for (int i = 0; i < files.Length; i++)
            {
                files[i] = ra.getValue(i.ToString());
                if (files[i] != null) count++;
                if (files[i] == fileName) found = i;
            }
            ra.CloseReg();

            if (found == -1) found = count;
            if (found < pos)
            {
                int z = found;
                found = pos;
                pos = z;
            }

            for (int i = found; i > pos; i--)
                setValue(Registry.CurrentUser, RegistryAccess.RegPaths.Halo2RecentFiles, i.ToString(), files[i-1]);
            setValue(Registry.CurrentUser, RegistryAccess.RegPaths.Halo2RecentFiles, pos.ToString(), fileName);
        }
 public static string getActivePlugin()
 {
     RegistryAccess ra = new RegistryAccess(Microsoft.Win32.Registry.CurrentUser,
                              RegistryAccess.RegPaths.Halo2 + "PluginSets\\");
     string s = ra.getValue("");
     ra.CloseReg();
     return s;
 }
Beispiel #4
0
        /// <summary>
        /// Returns true if file was loaded
        /// </summary>
        /// <returns></returns>
        /// <remarks></remarks>
        public static bool Load()
        {
            // check for settings file
            bool settingsFileExists = File.Exists(FilePath);

                // Parse the settings file
            if (settingsFileExists)
            {
                XmlDocument doc = new XmlDocument();

                try
                {
                    // load settings into document
                    doc.Load(FilePath);

                    // loop rootnode's nodes, and depending on what node we find
                    // do a different action.
                    foreach (XmlNode node in doc.DocumentElement.ChildNodes)
                    {
                        switch (node.Name)
                        {
                            case XML_NODE_MAINMENUFILE:
                                {
                                    pathMainmenu = node.InnerText;
                                    break;
                                }
                            case XML_NODE_MPSHAREDFILE:
                                {
                                    pathShared = node.InnerText;
                                    break;
                                }
                            case XML_NODE_SPSHAREDFILE:
                                {
                                    pathSPShared = node.InnerText;
                                    break;
                                }
                            case XML_NODE_BITMAPSFILE:
                                {
                                    pathBitmaps = node.InnerText;
                                    break;
                                }

                            case XML_NODE_MAPSFOLDER:
                                {
                                    pathMapsFolder = node.InnerText;
                                    break;
                                }
                            case XML_NODE_CLEANMAPSFOLDER:
                                {
                                    pathCleanMaps = node.InnerText;
                                    break;
                                }
                            case XML_NODE_PLUGINSFOLDER:
                                {
                                    pathPluginsFolder = node.InnerText;
                                    break;
                                }
                            case XML_NODE_BITMAPSFOLDER:
                                {
                                    pathBitmapsFolder = node.InnerText;
                                    break;
                                }
                            case XML_NODE_EXTRACTSFOLDER:
                                {
                                    pathExtractsFolder = node.InnerText;
                                    break;
                                }
                            case XML_NODE_PATCHFOLDER:
                                {
                                    pathPatchFolder = node.InnerText;
                                    break;
                                }

                            case XML_NODE_USEDEFMAPS:
                                {
                                    useDefaultMaps = bool.Parse(node.InnerText);
                                    break;
                                }
                            case XML_NODE_USEREGISTRY:
                                {
                                    useRegistryEntries = bool.Parse(node.InnerText);
                                    break;
                                }
                            case XML_NODE_CHECKUPDATE:
                                {
                                    checkUpdate = (updateFrequency)Enum.Parse(typeof(updateFrequency), node.InnerText);
                                    break;
                                }
                            case XML_NODE_LASTUPDATECHECK:
                                {
                                    lastCheck = DateTime.Parse(node.InnerText);
                                    break;
                                }

                            case XML_NODE_RECENTMAPSLIST:
                                {
                                    foreach (XmlNode recentMapNode in node)
                                    {
                                        RecentFile rf = new RecentFile();
                                        rf.Path = recentMapNode.InnerText;
                                        RecentOpenedMaps.Add(rf);
                                    }
                                    break;
                                }
                            case XML_NODE_QUICKACCESSTAGSLIST:
                                {
                                    foreach (XmlNode quickAccessNode in node)
                                    {
                                        QuickAccessTagType quickAcess = new QuickAccessTagType();
                                        quickAcess.TagType = quickAccessNode.Attributes[XML_ATTR_TAGTYPENAME].InnerText;
                                        foreach (XmlNode tagPathNode in quickAccessNode)
                                        {
                                            //switch (tagPathNode.Name)
                                            //{
                                            //    case XML_NODE_QUICKACCESSTAGPATH:
                                            //        {
                                            quickAcess.TagPaths.Add(tagPathNode.InnerText);
                                            //            break;
                                            //        }

                                            //}
                                        }
                                        QuickAccessTagTypes.Add(quickAcess);
                                    }
                                    break;
                                }
                            case XML_NODE_USERPLUGINMASKS:
                                {
                                    foreach (XmlNode pluginMaskNode in node)
                                    {
                                        CustomPluginMask mask = new CustomPluginMask();
                                        mask.Name = pluginMaskNode.Attributes[XML_ATTR_PLUGINMASKNAME].InnerText;

                                        foreach (XmlNode maskNode in pluginMaskNode)
                                        {
                                            //switch (maskNode.Name)
                                            //{
                                            //    case XML_NODE_PLUGINMASK_VISIBLETAGTYPE:
                                            //        {
                                            mask.VisibleTagTypes.Add(
                                                maskNode.Attributes[XML_ATTR_TAGTYPENAME].InnerText);
                                            //            break;
                                            //        }

                                            //}
                                        }

                                        CustomPluginMasks.Add(mask);
                                    }
                                    break;
                                }
                        }
                    }
                }
                catch
                {
                    settingsFileExists = false;
                }
            }

            // If useRegistryEntires is set to false & the settings file exists, then the
            // user doesn't wish to use the registry, so we are good to exit
            if (settingsFileExists && !useRegistryEntries)
                return true;

            // If enabled, load the settings from the registry
            if (useRegistryEntries)
            {
                // Used for accessing the registry
                RegistryAccess Reg;

                try
                {
                    // UseSettingsFile contains a list of Entity directories that wish to use the settings file instead of
                    // the registry. Check if our path is in the list for using the settings file.
                    Reg = new RegistryAccess(Registry.CurrentUser, RegistryAccess.RegPaths.Halo2 + @"Entity\UseSettingsFile\");

                    // If Entry exists in list, use settings file if it exists
                    if (Reg.getValue(Globals.Global.StartupPath) != null)
                        return settingsFileExists;

                    // Try to open the settings for Halo 2, if it doesn't exist, Reg.isOpen == false
                    Reg = new RegistryAccess(Registry.CurrentUser, RegistryAccess.RegPaths.Halo2Paths);
                    if (Reg.isOpen)
                    {
                        string tempS = string.Empty;
                        #region General Halo2 paths in registry
                        tempS = Reg.getValue(RegistryAccess.RegNames.MainMenuFile);
                        if (tempS != null) Prefs.pathMainmenu = tempS;
                        tempS = Reg.getValue(RegistryAccess.RegNames.SharedFile);
                        if (tempS != null) Prefs.pathShared = tempS;
                        tempS = Reg.getValue(RegistryAccess.RegNames.SinglePlayerSharedFile);
                        if (tempS != null) Prefs.pathSPShared = tempS;
                        tempS = Reg.getValue(RegistryAccess.RegNames.BitmapsFile);
                        if (tempS != null) Prefs.pathBitmaps = tempS;
                        tempS = Reg.getValue(RegistryAccess.RegNames.MapsPath);
                        if (tempS != null) Prefs.pathMapsFolder = tempS;
                        tempS = Reg.getValue(RegistryAccess.RegNames.FontsPath);
                        if (tempS != null) Prefs.pathFontsFolder = tempS;
                        tempS = Reg.getValue(RegistryAccess.RegNames.BitmapsPath);
                        if (tempS != null) Prefs.pathBitmapsFolder = tempS;
                        tempS = Reg.getValue(RegistryAccess.RegNames.ExtractsPath);
                        if (tempS != null) Prefs.pathExtractsFolder = tempS;
                        tempS = Reg.getValue(RegistryAccess.RegNames.PluginsPath);
                        if (tempS != null) Prefs.pathPluginsFolder = tempS;
                        tempS = Reg.getValue(RegistryAccess.RegNames.CleanMapsPath);
                        if (tempS != null) Prefs.pathCleanMaps = tempS;
                        #endregion
                        #region Entity specific paths & settings
                        Reg = new RegistryAccess(Registry.CurrentUser, RegistryAccess.RegPaths.Halo2 + @"Entity\");
                        tempS = Reg.getValue("PatchFolder");
                        if (tempS != null) Prefs.pathPatchFolder = tempS;
                        tempS = Reg.getValue("UseDefaultMaps");
                        if (tempS != null) Prefs.useDefaultMaps = bool.Parse(tempS);
                        Prefs.useRegistryEntries = true;
                        #region Automatic Update
                        tempS = Reg.getValue("lastCheck");
                        if (tempS != null)
                            try
                            {
                                Prefs.lastCheck = DateTime.Parse(tempS);
                            }
                            catch
                            {
                                Prefs.lastCheck = DateTime.MinValue;
                            }
                        tempS = Reg.getValue("checkUpdate");
                        try
                        {
                            Prefs.updateFrequency updateFreq = (Prefs.updateFrequency)Enum.Parse(typeof(Prefs.updateFrequency), tempS);
                            Prefs.checkUpdate = updateFreq;
                        }
                        catch
                        {
                            Prefs.checkUpdate = Prefs.updateFrequency.Daily;
                        }
                        #endregion;

                        // Check for recent files in the registry
                        Reg = new RegistryAccess(Registry.CurrentUser, RegistryAccess.RegPaths.Halo2RecentFiles);
                        if (Reg.isOpen)
                        {
                            for (int count = Prefs.MaxRecentFiles - 1; count >= 0; count--)
                            {
                                tempS = Reg.getValue(count.ToString());
                                if (tempS != null)
                                {
                                    RecentFile rf = new RecentFile();
                                    rf.Path = tempS;
                                    RecentOpenedMaps.Insert(0, rf);
                                }
                            }
                        }

                        #endregion
                        #region Load Quick Access Tags
                        if (Prefs.useRegistryEntries)
                        {
                            try
                            {
                                RegistryAccess ra = new RegistryAccess(Microsoft.Win32.Registry.CurrentUser, RegistryAccess.RegPaths.Halo2 + @"Entity\ME\Tags\");
                                string[] tags = ra.getKeys();
                                foreach (string tagType in tags)
                                {
                                    QuickAccessTagType qatt = new QuickAccessTagType();
                                    qatt.TagType = tagType;
                                    ra.setKey(Microsoft.Win32.Registry.CurrentUser, RegistryAccess.RegPaths.Halo2 + @"Entity\ME\Tags\" + tagType + @"\");
                                    foreach (string tagName in ra.getNames())
                                    {
                                        if (ra.getValue(tagName).ToLower() == "true")
                                            qatt.TagPaths.Add(tagName);
                                    }
                                    if (qatt.TagPaths.Count > 0)
                                        QuickAccessTagTypes.Add(qatt);
                                }
                            }
                            catch
                            {
                                // Ignore errors regarding to Quick keys
                            }
                        }
                        #endregion
                        Reg.CloseReg();
                        return true;
                    }
                }
                catch (Exception e)
                {
                    Global.ShowErrorMsg("Prefs Load Exception", e);
                    return settingsFileExists;
                }

            }

            return false;
        }