コード例 #1
0
        // Import individual XML mod
        private static void ImportMod(string path)
        {
            FileStream  fs     = new FileStream(path, FileMode.Open, FileAccess.Read);
            XmlDocument xmldoc = new XmlDocument();
            XmlNodeList xmlnode;
            XmlNode     mod;
            string      name, tyversion, version, authors, description;
            TyVersion   tyversionRange;

            xmldoc.Load(fs);
            xmlnode = xmldoc.GetElementsByTagName("tymod");

            for (int i = 0; i < xmlnode.Count; i++)
            {
                name = null; tyversion = null; version = null; tyversionRange = null; authors = null; description = null;

                mod = xmlnode[i];

                try { name = mod.Attributes.GetNamedItem("name").Value; } catch (Exception e) { Program.Log(path, "Invalid name attribute for tymod \"" + mod.OuterXml + "\"", e); continue; }
                try { version = mod.Attributes.GetNamedItem("version").Value; } catch { }
                try { authors = mod.Attributes.GetNamedItem("authors").Value; } catch { }
                try { description = mod.Attributes.GetNamedItem("description").Value; } catch { }
                try { tyversion = mod.Attributes.GetNamedItem("tyversion").Value; tyversionRange = new TyVersion(tyversion, name + " (" + (version ?? String.Empty) + ";" + (authors ?? String.Empty) + ")"); } catch { }

                if (name != null && name != String.Empty)
                {
                    TyMod tymod = new TyMod(name, tyversionRange, version, authors, description);

                    // Check if tymod already exists
                    if (Mods.Any(x => x.ToString() == tymod.ToString() && x.TyVersion.OverlapsVersion(tymod.TyVersion)))
                    {
                        Log(path, "TyMod with same name, version, authors, and dependency already exists (\"" + tymod.ToString() + "\")");
                        continue;
                    }

                    // Add Elements from node
                    tymod.AddFromNode(mod);

                    // Add to list
                    Mods.Add(tymod);
                }
            }

            fs.Close();
        }
コード例 #2
0
ファイル: TyMod.cs プロジェクト: NotSoCheezyTech/ty-1-tools
        public TyMod(string name, TyVersion tyversion = null, string version = null, string authors = null, string description = null)
        {
            Name        = name;
            TyVersion   = tyversion != null && tyversion.Valid ? tyversion : null;
            ModVersion  = version;
            Authors     = authors ?? String.Empty;
            Description = description ?? String.Empty;

            Edits        = new List <TyModEdit>();
            Imports      = new List <TyModImport>();
            Translations = new List <TyModTranslate>();
            Levels       = new List <TyLevel>();

            if (ModVersion == null)
            {
                ModVersion = String.Empty;
            }

            // Try and read the if enabled
            Enabled = Program.Config.EnabledMods.Any(x => x == ToString());
        }