コード例 #1
0
        private void createModStructure2(string databaseFilePath)
        {
            XmlDocument doc = new XmlDocument();

            try
            {
                doc.Load(databaseFilePath);
            }
            catch (XmlException)
            {
                Settings.appendToLog("CRITICAL: Failed to read database!");
                MessageBox.Show("CRITICAL: Failed to read database!");
                Application.Exit();
            }
            //add the global dependencies
            globalDependencies = new List <Dependency>();
            XmlNodeList globalDependenciesList = doc.SelectNodes("//modInfoAlpha.xml/globaldependencies/globaldependency");

            foreach (XmlNode dependencyNode in globalDependenciesList)
            {
                Dependency d = new Dependency();
                foreach (XmlNode globs in dependencyNode.ChildNodes)
                {
                    switch (globs.Name)
                    {
                    case "dependencyZipFile":
                        d.dependencyZipFile = globs.InnerText;
                        break;

                    case "dependencyZipCRC":
                        d.dependencyZipCRC = globs.InnerText;
                        break;

                    case "startAddress":
                        d.startAddress = globs.InnerText;
                        break;

                    case "endAddress":
                        d.endAddress = globs.InnerText;
                        break;

                    case "dependencyenabled":
                        try
                        {
                            d.enabled = bool.Parse(globs.InnerText);
                        }
                        catch (FormatException)
                        {
                            d.enabled = false;
                        }
                        break;
                    }
                }
                globalDependencies.Add(d);
            }

            XmlNodeList catagoryList = doc.SelectNodes("//modInfoAlpha.xml/catagories/catagory");

            parsedCatagoryList = new List <Catagory>();
            foreach (XmlNode nnnnn in catagoryList)
            {
                Catagory cat = new Catagory();
                foreach (XmlNode nnnnnn in nnnnn.ChildNodes)
                {
                    switch (nnnnnn.Name)
                    {
                    case "name":
                        cat.name = nnnnnn.InnerText;
                        break;

                    case "selectionType":
                        cat.selectionType = nnnnnn.InnerText;
                        break;

                    case "mods":
                        foreach (XmlNode n in nnnnnn.ChildNodes)
                        {
                            Mod m = new Mod();
                            foreach (XmlNode nn in n.ChildNodes)
                            {
                                switch (nn.Name)
                                {
                                case "name":
                                    m.name = nn.InnerText;
                                    break;

                                case "version":
                                    m.version = nn.InnerText;
                                    break;

                                case "size":
                                    try
                                    {
                                        m.size = float.Parse(nn.InnerText);
                                    }
                                    catch (FormatException)
                                    {
                                        m.size = (float)0.0;
                                    }
                                    break;

                                case "modzipfile":
                                    m.modZipFile = nn.InnerText;
                                    break;

                                case "startAddress":
                                    m.startAddress = nn.InnerText;
                                    break;

                                case "endAddress":
                                    m.endAddress = nn.InnerText;
                                    break;

                                case "modzipcrc":
                                    m.crc = nn.InnerText;
                                    break;

                                case "enabled":
                                    try
                                    {
                                        m.enabled = bool.Parse(nn.InnerText);
                                    }
                                    catch (FormatException)
                                    {
                                        m.enabled = false;
                                    }
                                    break;

                                case "description":
                                    m.description = nn.InnerText;
                                    break;

                                case "updateComment":
                                    m.updateComment = nn.InnerText;
                                    break;

                                case "devURL":
                                    m.devURL = nn.InnerText;
                                    break;

                                case "userDatas":
                                    foreach (XmlNode nnnnnnn in nn.ChildNodes)
                                    {
                                        switch (nnnnnnn.Name)
                                        {
                                        case "userData":
                                            string innerText = nnnnnnn.InnerText;
                                            if (innerText == null)
                                            {
                                                continue;
                                            }
                                            if (innerText.Equals(""))
                                            {
                                                continue;
                                            }
                                            m.userFiles.Add(innerText);
                                            break;
                                        }
                                    }
                                    break;

                                case "pictures":
                                    //parse every picture
                                    foreach (XmlNode nnnnnnn in nn.ChildNodes)
                                    {
                                        foreach (XmlNode nnnnnnnn in nnnnnnn.ChildNodes)
                                        {
                                            switch (nnnnnnnn.Name)
                                            {
                                            case "URL":
                                                string innerText = nnnnnnnn.InnerText;
                                                if (innerText == null)
                                                {
                                                    continue;
                                                }
                                                if (innerText.Equals(""))
                                                {
                                                    continue;
                                                }
                                                m.picList.Add(new Picture("Mod: " + m.name, nnnnnnnn.InnerText));
                                                break;
                                            }
                                        }
                                    }
                                    break;

                                case "dependencies":
                                    //parse all dependencies
                                    foreach (XmlNode nnnnnnn in nn.ChildNodes)
                                    {
                                        Dependency d = new Dependency();
                                        foreach (XmlNode nnnnnnnn in nnnnnnn.ChildNodes)
                                        {
                                            switch (nnnnnnnn.Name)
                                            {
                                            case "dependencyZipFile":
                                                d.dependencyZipFile = nnnnnnnn.InnerText;
                                                break;

                                            case "startAddress":
                                                d.startAddress = nnnnnnnn.InnerText;
                                                break;

                                            case "endAddress":
                                                d.endAddress = nnnnnnnn.InnerText;
                                                break;

                                            case "dependencyZipCRC":
                                                d.dependencyZipCRC = nnnnnnnn.InnerText;
                                                break;

                                            case "dependencyenabled":
                                                try
                                                {
                                                    d.enabled = bool.Parse(nnnnnnnn.InnerText);
                                                }
                                                catch (FormatException)
                                                {
                                                    d.enabled = false;
                                                }
                                                break;
                                            }
                                        }
                                        m.modDependencies.Add(d);
                                    }
                                    break;

                                case "configs":
                                    //parse every config for that mod
                                    foreach (XmlNode nnn in nn.ChildNodes)
                                    {
                                        Config c = new Config();
                                        foreach (XmlNode nnnn in nnn.ChildNodes)
                                        {
                                            switch (nnnn.Name)
                                            {
                                            case "name":
                                                c.name = nnnn.InnerText;
                                                break;

                                            case "configzipfile":
                                                c.zipConfigFile = nnnn.InnerText;
                                                break;

                                            case "startAddress":
                                                c.startAddress = nnnn.InnerText;
                                                break;

                                            case "endAddress":
                                                c.endAddress = nnnn.InnerText;
                                                break;

                                            case "configzipcrc":
                                                c.crc = nnnn.InnerText;
                                                break;

                                            case "configenabled":
                                                try
                                                {
                                                    c.enabled = bool.Parse(nnnn.InnerText);
                                                }
                                                catch (FormatException)
                                                {
                                                    c.enabled = false;
                                                }
                                                break;

                                            case "size":
                                                try
                                                {
                                                    c.size = float.Parse(nnnn.InnerText);
                                                }
                                                catch (FormatException)
                                                {
                                                    c.size = (float)0.0;
                                                }
                                                break;

                                            case "configtype":
                                                c.type = nnnn.InnerText;
                                                break;

                                            case "dependencies":
                                                //parse all dependencies
                                                foreach (XmlNode nnnnnnn in nnnn.ChildNodes)
                                                {
                                                    Dependency d = new Dependency();
                                                    foreach (XmlNode nnnnnnnn in nnnnnnn.ChildNodes)
                                                    {
                                                        switch (nnnnnnnn.Name)
                                                        {
                                                        case "dependencyZipFile":
                                                            d.dependencyZipFile = nnnnnnnn.InnerText;
                                                            break;

                                                        case "startAddress":
                                                            d.startAddress = nnnnnnnn.InnerText;
                                                            break;

                                                        case "endAddress":
                                                            d.endAddress = nnnnnnnn.InnerText;
                                                            break;

                                                        case "dependencyZipCRC":
                                                            d.dependencyZipCRC = nnnnnnnn.InnerText;
                                                            break;

                                                        case "dependencyenabled":
                                                            try
                                                            {
                                                                d.enabled = bool.Parse(nnnnnnnn.InnerText);
                                                            }
                                                            catch (FormatException)
                                                            {
                                                                d.enabled = false;
                                                            }
                                                            break;
                                                        }
                                                    }
                                                    m.modDependencies.Add(d);
                                                }
                                                break;

                                            case "pictures":
                                                //parse every picture
                                                foreach (XmlNode nnnnnnnn in nnnn.ChildNodes)
                                                {
                                                    foreach (XmlNode nnnnnnnnnn in nnnnnnnn.ChildNodes)
                                                    {
                                                        switch (nnnnnnnnnn.Name)
                                                        {
                                                        case "URL":
                                                            string innerText = nnnnnnnn.InnerText;
                                                            if (innerText == null)
                                                            {
                                                                continue;
                                                            }
                                                            if (innerText.Equals(""))
                                                            {
                                                                continue;
                                                            }
                                                            c.pictureList.Add(nnnnnnnn.InnerText);
                                                            //m.picList.Add(new Picture("Config: " + c.name, nnnnnnnn.InnerText));
                                                            break;
                                                        }
                                                    }
                                                }
                                                break;
                                            }
                                        }
                                        m.configs.Add(c);
                                    }
                                    break;
                                }
                            }
                            cat.mods.Add(m);
                        }
                        break;

                    case "dependencies":
                        //parse every config for that mod
                        foreach (XmlNode nnn in nnnnnn.ChildNodes)
                        {
                            Dependency d = new Dependency();
                            foreach (XmlNode nnnn in nnn.ChildNodes)
                            {
                                switch (nnnn.Name)
                                {
                                case "dependencyZipFile":
                                    d.dependencyZipFile = nnnn.InnerText;
                                    break;

                                case "startAddress":
                                    d.startAddress = nnnn.InnerText;
                                    break;

                                case "endAddress":
                                    d.endAddress = nnnn.InnerText;
                                    break;

                                case "dependencyZipCRC":
                                    d.dependencyZipCRC = nnnn.InnerText;
                                    break;

                                case "dependencyenabled":
                                    try
                                    {
                                        d.enabled = bool.Parse(nnnn.InnerText);
                                    }
                                    catch (FormatException)
                                    {
                                        d.enabled = false;
                                    }
                                    break;
                                }
                            }
                            cat.dependencies.Add(d);
                        }
                        break;
                    }
                }
                parsedCatagoryList.Add(cat);
            }
        }
コード例 #2
0
 //sorts the catagories
 public static int CompareCatagories(Catagory x, Catagory y)
 {
     return(x.name.CompareTo(y.name));
 }