Exemplo n.º 1
0
        private static bool ReadXMLDat(string fullname, ReportError ErrorReport, out DatHeader rvDat)
        {
            rvDat = null;
            int errorCode = FileStream.OpenFileRead(fullname, out Stream fs);

            if (errorCode != 0)
            {
                ErrorReport?.Invoke(fullname, errorCode + ": " + new Win32Exception(errorCode).Message);
                return(false);
            }

            XmlDocument doc = new XmlDocument {
                XmlResolver = null
            };

            try
            {
                doc.Load(fs);
            }
            catch (Exception e)
            {
                fs.Close();
                fs.Dispose();
                ErrorReport?.Invoke(fullname, $"Error Occured Reading Dat:\r\n{e.Message}\r\n");
                return(false);
            }
            fs.Close();
            fs.Dispose();

            if (doc.DocumentElement == null)
            {
                return(false);
            }

            XmlNode mame = doc.SelectSingleNode("mame");

            if (mame != null)
            {
                return(DatXmlReader.ReadMameDat(doc, fullname, out rvDat));
            }

            XmlNode head = doc.DocumentElement?.SelectSingleNode("header");

            if (head != null)
            {
                return(DatXmlReader.ReadDat(doc, fullname, out rvDat));
            }

            XmlNodeList headList = doc.SelectNodes("softwarelist");

            if (headList != null)
            {
                return(DatMessXmlReader.ReadDat(doc, fullname, out rvDat));
            }

            return(false);
        }
Exemplo n.º 2
0
        public static bool ReadXMLDatFromStream(Stream fs, string fullname, ReportError ErrorReport, out DatHeader rvDat)
        {
            rvDat = null;
            XmlDocument doc = new XmlDocument {
                XmlResolver = null
            };

            try
            {
                doc.Load(fs);
            }
            catch (Exception e)
            {
                ErrorReport?.Invoke(fullname, $"Error Occured Reading Dat:\r\n{e.Message}\r\n");
                return(false);
            }

            if (doc.DocumentElement == null)
            {
                return(false);
            }

            XmlNode mame = doc.SelectSingleNode("mame");

            if (mame != null)
            {
                return(DatXmlReader.ReadMameDat(doc, fullname, out rvDat));
            }

            XmlNode head = doc.DocumentElement?.SelectSingleNode("header");

            if (head != null)
            {
                return(DatXmlReader.ReadDat(doc, fullname, out rvDat));
            }

            XmlNodeList headList = doc.SelectNodes("softwarelist");

            if (headList != null)
            {
                return(DatMessXmlReader.ReadDat(doc, fullname, out rvDat));
            }

            return(false);
        }