コード例 #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedItem == null)
            {
                MessageBox.Show("You gotta select the rom you want to delete, Dawg!");
                return;
            }

            SystemStruct.Rom[] roms = new SystemStruct.Rom[sysstruct[sysCount].roms.Length - 1];
            int naughty             = 0;

            for (int i = 0; i < sysstruct[sysCount].roms.Length; i++)
            {
                if (listBox1.SelectedItem.ToString() == sysstruct[sysCount].roms[i].name)
                {
                    naughty = sysstruct[sysCount].roms[i].count;
                }
            }
            int orange = 0;

            for (int i = 0; i < sysstruct[sysCount].roms.Length; i++)
            {
                if (sysstruct[sysCount].roms[i].count != naughty)
                {
                    roms[orange] = sysstruct[sysCount].roms[i];
                    orange++;
                }
            }

            sysstruct[sysCount].roms = new SystemStruct.Rom[roms.Length];
            sysstruct[sysCount].roms = roms;

            // and delete the selected index, finally
            fIsRemoving = true;
            try
            {
                listBox1.Items.RemoveAt(listBox1.SelectedIndex);
                listBox2.Items.Clear();
                if (listBox1.Items.Count != 0)
                {
                    fIsRemoving            = true;
                    listBox1.SelectedIndex = 0;
                    ReadXMLData(listBox1.SelectedItem.ToString(), currentSystem);
                }
            }
            catch
            {
                MessageBox.Show("ItemRemove Parse fail, Dawg!");
                return;
            }

            finally
            {
                if (listBox1.Items.Count == 0 && currentSystem == comboBox1.Text)
                {
                    listBox3.Visible = true;
                    label4.Visible   = true;
                    listBox3.Items.Add(comboBox1.Text);
                    comboBox1.Items.RemoveAt(comboBox1.SelectedIndex);
                    currentSystem = "";
                    sysCount++;
                }
            }
        }
コード例 #2
0
        public void ReadXML()
        {
            String endelementfield = "";
            String elementfield    = "";
            {
                XmlDocument xml = new XmlDocument();
                xml.Load(Application.StartupPath + filename);
                XmlNodeList NodesCount = xml.GetElementsByTagName("System");
                sysstruct = new SystemStruct[NodesCount.Count];

                XmlTextReader xliff = new XmlTextReader(Application.StartupPath + filename);
                try
                {
                    int count    = 0;
                    int romcount = 0;
                    while (xliff.Read())
                    {
                        switch (xliff.NodeType)
                        {
                        case XmlNodeType.Element:     // The node is an element.
                            elementfield = xliff.Name;

                            while (xliff.MoveToNextAttribute())                              // Read the attributes.
                            {
                                SystemStruct.Rom[] newRoms = new SystemStruct.Rom[romcount]; // reset the rom list to the right size
                                newRoms = sysstruct[count].roms;
                                sysstruct[count].roms = new SystemStruct.Rom[romcount];
                                sysstruct[count].roms = newRoms;

                                sysstruct[count].systemname = xliff.Name;
                                comboBox1.Items.Remove(sysstruct[count].systemname);
                                listBox3.Visible = true;
                                label4.Visible   = true;
                                listBox3.Items.Add(sysstruct[count].systemname);
                                count++;
                                romcount = 0;
                            }
                            break;

                        case XmlNodeType.EndElement:     //The node is an element's end
                            endelementfield = xliff.Name;
                            break;

                        case XmlNodeType.Text:     //Display the text in each element.
                            switch (elementfield)
                            {
                            case "FilePath":
                                sysstruct[count].filepath = xliff.Value;
                                break;

                            case "RomPath":
                                sysstruct[count].rompath = xliff.Value;
                                sysstruct[count].roms    = new SystemStruct.Rom[200];
                                break;

                            case "Name":
                                sysstruct[count].roms[romcount].name = xliff.Value;
                                break;

                            case "Alias":
                                sysstruct[count].roms[romcount].alias = xliff.Value;
                                break;

                            case "Count":
                                int result = 0;
                                if (!Int32.TryParse(xliff.Value, out result))
                                {
                                    MessageBox.Show("Parse Error, Dawg!");
                                }
                                sysstruct[count].roms[romcount].count = result;
                                break;

                            case "Path":
                                sysstruct[count].roms[romcount].path = xliff.Value;
                                romcount++;
                                break;
                            }
                            break;
                        }
                    }
                }

                catch (Exception ex)
                {
                    MessageBox.Show("Error parsing inbound XML file:" + ex.Message, "inbound parse error");
                }

                finally
                {
                    xliff.Close();
                }
            }
        }