Exemple #1
0
        private static bool ReadXMLDat(ref RvDir tDat, string strFilename)
        {
            System.IO.Stream fs;
            int errorCode = IO.FileStream.OpenFileRead(strFilename, out fs);

            if (errorCode != 0)
            {
                _bgw.ReportProgress(0, new bgwShowError(strFilename, errorCode + ": " + new Win32Exception(errorCode).Message));
                return(false);
            }

            XmlDocument doc = new XmlDocument {
                XmlResolver = null
            };

            try
            {
                doc.Load(fs);
            }
            catch (Exception e)
            {
                fs.Close();
                fs.Dispose();
                string message = string.Format("Error Occured Reading Dat: {0}\r\nSource: {1}\r\nMessage: {2}\r\n", strFilename, e.Source, e.Message);
                if (e.InnerException != null)
                {
                    message += string.Format("\r\nINNER EXCEPTION:\r\nSource: {0}\r\nMessage: {1}\r\n", e.InnerException.Source, e.InnerException.Message);
                }
                ReportError.SendErrorMessageDat(message, strFilename);
                _bgw.ReportProgress(0, new bgwShowError(strFilename, string.Format("Error Occured Reading Dat:\r\n{0}\r\n", e.Message)));
                return(false);
            }
            fs.Close();
            fs.Dispose();

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

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

            if (mame != null)
            {
                return(DatXmlReader.ReadMameDat(ref tDat, doc));
            }

            if (doc.DocumentElement != null)
            {
                XmlNode head = doc.DocumentElement.SelectSingleNode("header");
                if (head != null)
                {
                    return(DatXmlReader.ReadDat(ref tDat, doc));
                }
            }

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

            if (headList != null)
            {
                return(DatMessXmlReader.ReadDat(ref tDat, doc));
            }

            return(false);
        }