Esempio n. 1
0
        public static ModListBoxItem Load(string path)
        {
            if (File.Exists(path))
            {
                ModListBoxItem modItem = new ModListBoxItem();
                XDocument      doc     = XDocument.Load(path);
                XElement       root    = doc.Root;
                modItem.ModPath = root.Element("ModPath").Value;
                XElement category = root.Element("Category");
                switch (category.Value)
                {
                case "Internal":
                    modItem.Category = ModCategory.Internal;
                    break;

                case "Workshop":
                    modItem.Category = ModCategory.Workshop;
                    break;

                default:
                    modItem.Category = ModCategory.Custom;
                    break;
                }
                XElement generateOption = root.Element("GenerateOption");
                switch (generateOption.Value)
                {
                case "Special":
                    modItem.GenerateOption = GenerateMode.Special;
                    break;

                case "Core":
                    modItem.GenerateOption = GenerateMode.Core;
                    break;

                default:
                    modItem.GenerateOption = GenerateMode.Standard;
                    break;
                }
                XElement languages = root.Element("Languages");
                foreach (XElement li in languages.Elements())
                {
                    LanguageListBoxItem langItem = new LanguageListBoxItem();
                    langItem.LangPath   = li.Element("LangPath").Value;
                    langItem.RealName   = li.Element("RealName").Value;
                    langItem.NativeName = li.Element("NativeName").Value;
                    langItem.IsCustom   = (string.Compare(li.Element("IsCustom").Value, "true", true) == 0);
                    langItem.CustomPath = li.Element("CustomPath").Value;
                    langItem.IsChecked  = (string.Compare(li.Element("IsChecked").Value, "true", true) == 0);
                    modItem.Languages.Add(langItem);
                }
                modItem.ProjectFileName = Path.GetFileName(path);
                modItem.ModName         = GetModName(modItem.ModPath);
                return(modItem);
            }
            else
            {
                throw new Exception("The File dose not exist: " + path);
            }
        }
Esempio n. 2
0
        public static IEnumerable <ModListBoxItem> GetModItems(string path, ModCategory category)
        {
            foreach (string subDir in Directory.GetDirectories(path))
            {
                ModListBoxItem modItem = new ModListBoxItem();

                modItem.ModPath  = subDir;
                modItem.Category = category;
                modItem.ModName  = GetModName(subDir);
                //modItem.IsCleanMode = false;
                if (System.IO.Path.GetFileName(subDir) == "Core")
                {
                    modItem.GenerateOption = GenerateMode.Core;
                }
                else
                {
                    modItem.GenerateOption = GenerateMode.Standard;
                }

                yield return(modItem);
            }
        }