コード例 #1
0
ファイル: CategoryList.cs プロジェクト: oxysoft/cairoshell
        public static CategoryList Deserialize(string ConfigFile)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(ConfigFile);
            XmlElement   root    = doc.ChildNodes[0] as XmlElement;
            CategoryList catList = new CategoryList();

            foreach (XmlElement catElement in root.ChildNodes)
            {
                // get category
                Category cat = new Category();
                cat.Name = catElement.Attributes["Name"].Value;
                if (catElement.Attributes["Type"] != null)
                {
                    cat.Type = Convert.ToInt32(catElement.Attributes["Type"].Value);
                }
                else
                {
                    // migration
                    if (cat.Name == "Uncategorized")
                    {
                        cat.Type = 2;
                    }
                    else if (cat.Name == "Quick Launch")
                    {
                        cat.Type = 3;
                    }
                }
                if (catElement.Attributes["ShowInMenu"] != null)
                {
                    cat.ShowInMenu = Convert.ToBoolean(catElement.Attributes["ShowInMenu"].Value);
                }
                else
                {
                    // force hide quick launch and uncategorized
                    if (cat.Type > 1)
                    {
                        cat.ShowInMenu = false;
                    }
                }

                catList.Add(cat);

                foreach (XmlElement appElement in catElement.ChildNodes)
                {
                    // get application
                    ApplicationInfo app = new ApplicationInfo();
                    app.Name = appElement.ChildNodes[0].InnerText;
                    app.Path = appElement.ChildNodes[1].InnerText;
                    if (appElement.Attributes["AskAlwaysAdmin"] != null)
                    {
                        app.AskAlwaysAdmin = Convert.ToBoolean(appElement.Attributes["AskAlwaysAdmin"].Value);
                    }
                    if (appElement.Attributes["AlwaysAdmin"] != null)
                    {
                        app.AlwaysAdmin = Convert.ToBoolean(appElement.Attributes["AlwaysAdmin"].Value);
                    }
                    if (appElement.ChildNodes.Count > 2)
                    {
                        app.Target = appElement.ChildNodes[2].InnerText;
                    }
                    if (!app.IsStoreApp && !Interop.Shell.Exists(app.Path))
                    {
                        System.Diagnostics.Debug.WriteLine(app.Path + " does not exist");
                        continue;
                    }

                    cat.Add(app);
                }
            }
            return(catList);
        }