示例#1
0
        public static bool ReadDat(string fullname, long fileTimeStamp, BackgroundWorker bgw, out RvDat rvDat)
        {
            _bgw = bgw;

            rvDat = null;

            Console.WriteLine("Reading " + fullname);

            Stream fs;
            int    errorCode = IO.FileStream.OpenFileRead(fullname, out fs);

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



            StreamReader myfile  = new StreamReader(fs, Program.Enc);
            string       strLine = myfile.ReadLine();

            myfile.Close();
            fs.Close();
            fs.Dispose();

            if (strLine == null)
            {
                return(false);
            }


            if (strLine.ToLower().IndexOf("xml", StringComparison.Ordinal) >= 0)
            {
                if (!ReadXMLDat(fullname, fileTimeStamp, out rvDat))
                {
                    return(false);
                }
            }

            else if (strLine.ToLower().IndexOf("clrmamepro", StringComparison.Ordinal) >= 0 || strLine.ToLower().IndexOf("romvault", StringComparison.Ordinal) >= 0 || strLine.ToLower().IndexOf("game", StringComparison.Ordinal) >= 0)
            {
                if (!DatCmpReader.ReadDat(fullname, fileTimeStamp, out rvDat))
                {
                    return(false);
                }
            }
            else if (strLine.ToLower().IndexOf("doscenter", StringComparison.Ordinal) >= 0)
            {
                //    if (!DatDOSReader.ReadDat(datFullName))
                //        return;
            }
            else
            {
                _bgw.ReportProgress(0, new bgwShowError(fullname, "Invalid DAT File"));
                return(false);
            }

            return(true);
        }
示例#2
0
        public static bool ReadDat(string fullname, BackgroundWorker bgw, out RvDat rvDat)
        {
            _bgw = bgw;

            rvDat = null;

            Console.WriteLine("Reading " + fullname);

            int errorCode = FileStream.OpenFileRead(fullname, out Stream fs);

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

            // If the file could be read, read the first line
            StreamReader myfile  = new StreamReader(fs, Program.Enc);
            string       strLine = myfile.ReadLine();

            myfile.Close();
            fs.Close();
            fs.Dispose();

            // If there's no first line, we don't have a readable file
            if (strLine == null)
            {
                return(false);
            }

            // XML-based DATs
            if (strLine.IndexOf("xml", StringComparison.OrdinalIgnoreCase) >= 0)
            {
                return(ReadXMLDat(fullname, out rvDat));
            }

            // ClrMamePro DATs
            else if (strLine.IndexOf("clrmamepro", StringComparison.OrdinalIgnoreCase) >= 0 ||
                     strLine.IndexOf("romvault", StringComparison.OrdinalIgnoreCase) >= 0 ||
                     strLine.IndexOf("game", StringComparison.OrdinalIgnoreCase) >= 0)
            {
                return(DatCmpReader.ReadDat(fullname, out rvDat));
            }

            // DOSCenter DATs
            else if (strLine.IndexOf("doscenter", StringComparison.OrdinalIgnoreCase) >= 0)
            {
                return(DatDOSReader.ReadDat(fullname, out rvDat));
            }

            // RomCenter DATs
            else if (strLine.IndexOf("[", StringComparison.OrdinalIgnoreCase) >= 0 &&
                     strLine.IndexOf("]", StringComparison.OrdinalIgnoreCase) >= 0)
            {
                return(DatRcReader.ReadDat(fullname, out rvDat));
            }

            // Unknown file / DAT type
            else
            {
                _bgw.ReportProgress(0, new bgwShowError(fullname, "Invalid DAT File"));
                return(false);
            }
        }