示例#1
0
        internal static GCTNode IsParsable(string path)
        {
            FileMap map = FileMap.FromFile(path, FileMapProtect.ReadWrite);

            GCTCodeLine *data = (GCTCodeLine *)map.Address;

            if (GCTCodeLine.Tag._1 != data->_1 || GCTCodeLine.Tag._2 != data->_2)
            {
                map.Dispose();
                return(null);
            }

            data = (GCTCodeLine *)(map.Address + (uint)Helpers.RoundDown((uint)map.Length, 8) - GCTCodeLine.Size);
            bool endFound = false;
            int  i        = 0;

            while (!endFound)
            {
                GCTCodeLine line = *data--;
                if (line._1 == GCTCodeLine.End._1 && line._2 == GCTCodeLine.End._2)
                {
                    endFound = true;
                    break;
                }

                i++;
            }

            if (endFound && i <= 0)
            {
                data = (GCTCodeLine *)map.Address + 1;

                string s = "";
                while (true)
                {
                    GCTCodeLine line = *data++;
                    if (line._1 == GCTCodeLine.End._1 && line._2 == GCTCodeLine.End._2)
                    {
                        break;
                    }

                    s += line.ToStringNoSpace();
                }

                GCTNode g = new GCTNode();

                List <string> _unrecognized = new List <string>();

                foreach (CodeStorage c in Properties.Settings.Default.Codes)
                {
                    int index = -1;
                    if ((index = s.IndexOf(c._code)) >= 0)
                    {
                        g.AddChild(new GCTCodeEntryNode()
                        {
                            _name = c._name, _description = c._description, LinesNoSpaces = s.Substring(index, c._code.Length)
                        });
                        s = s.Remove(index, c._code.Length);
                    }
                }

                if (g.Children.Count > 0)
                {
                    if (s.Length > 0)
                    {
                        MessageBox.Show(String.Format("{0} code{1} w{2} recognized.", g.Children.Count.ToString(), g.Children.Count > 1 ? "s" : "", g.Children.Count > 1 ? "ere" : "as"));
                    }
                }
                else
                {
                    MessageBox.Show("This GCT does not contain any recognizable codes.");
                }

                if (s.Length > 0)
                {
                    g.AddChild(new GCTCodeEntryNode()
                    {
                        _name = "Unrecognized Code(s)", LinesNoSpaces = s
                    });
                }

                return(g);
            }
            else if (endFound && i > 0)
            {
                GCTNode g = new GCTNode();
                g.Initialize(null, new DataSource(map));
                return(g);
            }

            map.Dispose();
            return(null);
        }
        public static GCTNode FromTXT(string path)
        {
            GCTNode node = new GCTNode();

            if (File.Exists(path))
            {
                bool anyEnabled = false;

                using (StreamReader sr = new StreamReader(path))
                {
                    for (int i = 0; !sr.EndOfStream; i++)
                    {
                        string lastLine;
                        while (String.IsNullOrEmpty(lastLine = sr.ReadLine()))
                        {
                            ;
                        }

                        if (!String.IsNullOrEmpty(lastLine))
                        {
                            node._name = lastLine;
                        }

                        lastLine = sr.ReadLine();
                        if (!String.IsNullOrEmpty(lastLine))
                        {
                            node._gameName = lastLine;
                        }

                        while (!sr.EndOfStream)
                        {
                            while (String.IsNullOrEmpty(lastLine = sr.ReadLine()))
                            {
                                ;
                            }

                            GCTCodeEntryNode   e = new GCTCodeEntryNode();
                            List <GCTCodeLine> g = new List <GCTCodeLine>();

                            if (!String.IsNullOrEmpty(lastLine))
                            {
                                e._name = lastLine;
                            }
                            else
                            {
                                break;
                            }

                            bool?codeEnabled = null;
                            while (true)
                            {
                                lastLine = sr.ReadLine();
                                if (String.IsNullOrEmpty(lastLine))
                                {
                                    break;
                                }

                                bool lineEnabled = lastLine.StartsWith("* ");
                                if (lineEnabled)
                                {
                                    anyEnabled = true;
                                    lastLine   = lastLine.Substring(2);
                                }

                                if (codeEnabled == null)
                                {
                                    codeEnabled = lineEnabled;
                                }
                                else if (codeEnabled != lineEnabled)
                                {
                                    break;
                                }

                                string[] lines = lastLine.Split(' ');
                                if (lines.Length < 2)
                                {
                                    break;
                                }

                                uint val1, val2;
                                if (uint.TryParse(lines[0], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out val1))
                                {
                                    if (uint.TryParse(lines[1], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out val2))
                                    {
                                        GCTCodeLine l = new GCTCodeLine(val1, val2);
                                        g.Add(l);
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                                else
                                {
                                    break;
                                }
                            }

                            List <string> description = new List <string>();
                            while (!String.IsNullOrEmpty(lastLine))
                            {
                                description.Add(lastLine);
                                lastLine = sr.ReadLine();
                            }

                            e._enabled     = codeEnabled ?? false;
                            e._lines       = g.ToArray();
                            e._description = String.Join(Environment.NewLine, description);
                            node.AddChild(e, false);
                        }
                    }
                }
                if (anyEnabled == false)
                {
                    // No codes enabled in file - enable all codes
                    foreach (GCTCodeEntryNode e in node.Children)
                    {
                        e._enabled = true;
                    }
                }
            }
            return(node);
        }
示例#3
0
        public static GCTNode FromTXT(string path)
        {
            GCTNode node = new GCTNode();

            if (File.Exists(path))
            {
                using (StreamReader sr = new StreamReader(path))
                    for (int i = 0; !sr.EndOfStream; i++)
                    {
                        string lastLine;
                        while (String.IsNullOrEmpty(lastLine = sr.ReadLine()))
                        {
                            ;
                        }

                        if (!String.IsNullOrEmpty(lastLine))
                        {
                            node._name = lastLine;
                        }

                        lastLine = sr.ReadLine();
                        if (!String.IsNullOrEmpty(lastLine))
                        {
                            node._gameName = lastLine;
                        }

                        while (!sr.EndOfStream)
                        {
                            while (String.IsNullOrEmpty(lastLine = sr.ReadLine()))
                            {
                                ;
                            }

                            GCTCodeEntryNode   e = new GCTCodeEntryNode();
                            List <GCTCodeLine> g = new List <GCTCodeLine>();

                            if (!String.IsNullOrEmpty(lastLine))
                            {
                                e._name = lastLine;
                            }
                            else
                            {
                                break;
                            }

                            while (true)
                            {
                                lastLine = sr.ReadLine();
                                if (String.IsNullOrEmpty(lastLine))
                                {
                                    break;
                                }

                                string[] lines = lastLine.Split(' ');
                                if (lines.Length < 2)
                                {
                                    break;
                                }

                                uint val1, val2;
                                if (uint.TryParse(lines[0], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out val1))
                                {
                                    if (uint.TryParse(lines[1], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out val2))
                                    {
                                        GCTCodeLine l = new GCTCodeLine(val1, val2);
                                        g.Add(l);
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                                else
                                {
                                    break;
                                }
                            }
                            e._lines       = g.ToArray();
                            e._description = lastLine;
                            node.AddChild(e);
                        }
                    }
            }

            return(node);
        }
        private void saveAllRememberedCodesToGCTToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GCTNode g = new GCTNode();
            foreach (CodeStorage w in BrawlLib.Properties.Settings.Default.Codes)
            {
                GCTCodeEntryNode r = new GCTCodeEntryNode();

                r.LinesNoSpaces = w._code;
                r._name = w._name;
                r._description = w._description;

                g.AddChild(r);
            }
            SaveAs(g, true);
        }
        private void txtName_TextChanged(object sender, EventArgs e)
        {
            if (_updating)
                return;

            string s = txtName.Text;

            bool temp = false;
            if (TargetNode == null)
            {
                TargetNode = new GCTNode();
                temp = true;
            }

            TargetNode.GameName = txtName.Text = s;
            if (temp)
                txtName.Select(txtName.Text.Length, 0);
        }
        private void btnNewCode_Click(object sender, EventArgs e)
        {
            if (_updating)
                return;

            if (TargetNode == null)
                TargetNode = new GCTNode();

            GCTCodeEntryNode n = new GCTCodeEntryNode() { _name = "New Code" };
            TargetNode.AddChild(n);
            lstCodes.Items.Add(new ListViewItem() { Text = n.Name, Checked = true, Tag = n });
        }
 private void loadRememberedCodesAsNewFileToolStripMenuItem_Click(object sender, EventArgs e)
 {
     GCTNode node = new GCTNode();
     node._name = "CODE";
     node._gameName = "Code List";
     foreach (CodeStorage w in BrawlLib.Properties.Settings.Default.Codes)
         node.AddChild(new GCTCodeEntryNode() { _name = w._name, _description = w._description, LinesNoSpaces = w._code });
     TargetNode = node;
 }
 private void btnBrowse_Click(object sender, EventArgs e)
 {
     GCTNode node = LoadGCT(); if (node != null) TargetNode = node;
 }
 private void btnClose_Click(object sender, EventArgs e)
 {
     TargetNode = null;
 }
        protected override void OnClosing(CancelEventArgs e)
        {
            TargetNode = null;

            if (TargetNode != null)
                e.Cancel = true;

            BrawlLib.Properties.Settings.Default.Save();

            base.OnClosing(e);
        }
        public bool SaveAs(GCTNode node, bool writeInfo)
        {
            if (dlgSave.ShowDialog(this) != DialogResult.OK)
                return false;

            string path = dlgSave.FileName;
            if (!String.IsNullOrEmpty(path))
            {
                try
                {
                    node.Children.Clear();
                    foreach (ListViewItem e in lstCodes.Items)
                        if (e.Checked)
                            node.Children.Add(e.Tag as GCTCodeEntryNode);

                    if (Path.GetExtension(path).ToUpper() == ".TXT")
                        node.ToTXT(path);
                    else
                    {
                        node._writeInfo = writeInfo;
                        node.Merge();
                        node.Export(node._origPath = path);
                        node.IsDirty = false;
                        txtPath.Text = path;
                    }
                    return true;
                }
                catch { return false; }
            }
            return false;
        }
        public bool Save(GCTNode node, bool writeInfo)
        {
            try
            {
                if (String.IsNullOrEmpty(node._origPath))
                    return SaveAs(node, writeInfo);

                node.Children.Clear();
                foreach (ListViewItem e in lstCodes.Items)
                    if (e.Checked)
                        node.Children.Add(e.Tag as GCTCodeEntryNode);

                node._writeInfo = writeInfo;
                node.Merge();
                node.Export(TargetNode._origPath);
                node.IsDirty = false;
                return true;
            }
            catch
            {
                return false;
            }
        }
示例#13
0
        internal static GCTNode IsParsable(string path)
        {
            FileMap map = FileMap.FromFile(path, FileMapProtect.ReadWrite);

            GCTCodeLine* data = (GCTCodeLine*)map.Address;
            if (GCTCodeLine.Tag._1 != data->_1 || GCTCodeLine.Tag._2 != data->_2)
            {
                map.Dispose();
                return null;
            }

            data = (GCTCodeLine*)(map.Address + (uint)Helpers.RoundDown((uint)map.Length, 8) - GCTCodeLine.Size);
            bool endFound = false;
            int i = 0;
            while (!endFound)
            {
                GCTCodeLine line = *data--;
                if (line._1 == GCTCodeLine.End._1 && line._2 == GCTCodeLine.End._2)
                {
                    endFound = true;
                    break;
                }

                i++;
            }

            if (endFound && i <= 0)
            {
                data = (GCTCodeLine*)map.Address + 1;

                string s = "";
                while (true)
                {
                    GCTCodeLine line = *data++;
                    if (line._1 == GCTCodeLine.End._1 && line._2 == GCTCodeLine.End._2)
                        break;

                    s += line.ToStringNoSpace();
                }

                GCTNode g = new GCTNode();

                List<string> _unrecognized = new List<string>();

                foreach (CodeStorage c in Properties.Settings.Default.Codes)
                {
                    int index = -1;
                    if ((index = s.IndexOf(c._code)) >= 0)
                    {
                        g.AddChild(new GCTCodeEntryNode() { _name = c._name, _description = c._description, LinesNoSpaces = s.Substring(index, c._code.Length) });
                        s = s.Remove(index, c._code.Length);
                    }
                }

                if (g.Children.Count > 0)
                {
                    if (s.Length > 0)
                        MessageBox.Show(String.Format("{0} code{1} w{2} recognized.", g.Children.Count.ToString(), g.Children.Count > 1 ? "s" : "", g.Children.Count > 1 ? "ere" : "as"));
                }
                else
                    MessageBox.Show("This GCT does not contain any recognizable codes.");

                if (s.Length > 0)
                    g.AddChild(new GCTCodeEntryNode() { _name = "Unrecognized Code(s)", LinesNoSpaces = s });

                return g;
            }
            else if (endFound && i > 0)
            {
                GCTNode g = new GCTNode();
                g.Initialize(null, new DataSource(map));
                return g;
            }

            map.Dispose();
            return null;
        }
示例#14
0
        public static GCTNode FromTXT(string path)
        {
            GCTNode node = new GCTNode();

            if (File.Exists(path))
                using (StreamReader sr = new StreamReader(path))
                    for (int i = 0; !sr.EndOfStream; i++)
                    {
                        string lastLine;
                        while (String.IsNullOrEmpty(lastLine = sr.ReadLine())) ;

                        if (!String.IsNullOrEmpty(lastLine))
                            node._name = lastLine;

                        lastLine = sr.ReadLine();
                        if (!String.IsNullOrEmpty(lastLine))
                            node._gameName = lastLine;

                        while (!sr.EndOfStream)
                        {
                            while (String.IsNullOrEmpty(lastLine = sr.ReadLine())) ;

                            GCTCodeEntryNode e = new GCTCodeEntryNode();
                            List<GCTCodeLine> g = new List<GCTCodeLine>();

                            if (!String.IsNullOrEmpty(lastLine))
                                e._name = lastLine;
                            else
                                break;

                            while (true)
                            {
                                lastLine = sr.ReadLine();
                                if (String.IsNullOrEmpty(lastLine))
                                    break;

                                string[] lines = lastLine.Split(' ');
                                if (lines.Length < 2)
                                    break;

                                uint val1, val2;
                                if (uint.TryParse(lines[0], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out val1))
                                    if (uint.TryParse(lines[1], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out val2))
                                    {
                                        GCTCodeLine l = new GCTCodeLine(val1, val2);
                                        g.Add(l);
                                    }
                                    else
                                        break;
                                else
                                    break;
                            }
                            e._lines = g.ToArray();
                            e._description = lastLine;
                            node.AddChild(e);
                        }
                    }

            return node;
        }