示例#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);
        }
        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;
        }