Пример #1
0
        public static bool ReadDat(string strFilename, ReportError errorReport, out DatHeader datHeader)
        {
            using (DatFileLoader dfl = new DatFileLoader())
            {
                datHeader = new DatHeader {
                    BaseDir = new DatDir(DatFileType.UnSet)
                };
                int errorCode = dfl.LoadDat(strFilename, DatRead.Enc);
                if (errorCode != 0)
                {
                    errorReport?.Invoke(strFilename, new Win32Exception(errorCode).Message);
                    return(false);
                }

                dfl.Gn();
                if (dfl.EndOfStream())
                {
                    return(false);
                }
                if (dfl.Next.ToLower() == "clrmamepro" || dfl.Next.ToLower() == "clrmame")
                {
                    if (!LoadHeaderFromDat(dfl, strFilename, datHeader, errorReport))
                    {
                        return(false);
                    }
                    dfl.Gn();
                }
                if (dfl.Next.ToLower() == "raine")
                {
                    while (dfl.Next.ToLower() != "emulator")
                    {
                        dfl.Gn();
                    }
                    if (!LoadHeaderFromDat(dfl, strFilename, datHeader, errorReport))
                    {
                        return(false);
                    }
                    dfl.Gn();
                }
                if (dfl.Next.ToLower() == "romvault")
                {
                    if (!LoadHeaderFromDat(dfl, strFilename, datHeader, errorReport))
                    {
                        return(false);
                    }
                    dfl.Gn();
                }

                while (!dfl.EndOfStream())
                {
                    bool res = ReadNextBlock(dfl, datHeader.BaseDir, errorReport);
                    if (!res)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Пример #2
0
        public bool ReadDat(string strFilename, out DatHeader datHeader)
        {
            _filename = strFilename;

            using (DatFileLoader dfl = new DatFileLoader())
            {
                datHeader = new DatHeader {
                    BaseDir = new DatDir(DatFileType.UnSet)
                };
                int errorCode = dfl.LoadDat(strFilename, System.Text.Encoding.UTF8);
                if (errorCode != 0)
                {
                    _errorReport?.Invoke(strFilename, new Win32Exception(errorCode).Message);
                    return(false);
                }

                dfl.Gn();
                if (dfl.EndOfStream())
                {
                    return(false);
                }
                if (dfl.Next.ToLower() == "doscenter")
                {
                    dfl.Gn();
                    if (!LoadHeaderFromDat(dfl, datHeader))
                    {
                        return(false);
                    }
                    dfl.Gn();
                }

                while (!dfl.EndOfStream())
                {
                    switch (dfl.Next.ToLower())
                    {
                    case "game":
                        dfl.Gn();
                        if (!LoadGameFromDat(dfl, datHeader.BaseDir))
                        {
                            return(false);
                        }
                        dfl.Gn();
                        break;

                    default:
                        _errorReport?.Invoke(dfl.Filename, "Error: key word '" + dfl.Next + "' not known, on line " + dfl.LineNumber);
                        dfl.Gn();
                        break;
                    }
                }
            }

            return(true);
        }
Пример #3
0
        public bool ReadDat(string strFilename, out DatHeader datHeader)
        {
            _filename = strFilename;

            using (DatFileLoader dfl = new DatFileLoader())
            {
                datHeader = new DatHeader {
                    BaseDir = new DatDir(DatFileType.UnSet)
                };
                int errorCode = dfl.LoadDat(strFilename);
                if (errorCode != 0)
                {
                    _errorReport?.Invoke(strFilename, new Win32Exception(errorCode).Message);
                    return(false);
                }

                dfl.Gn();
                if (dfl.EndOfStream())
                {
                    return(false);
                }
                if (dfl.Next.ToLower() == "clrmamepro" || dfl.Next.ToLower() == "clrmame")
                {
                    dfl.Gn();
                    if (!LoadHeaderFromDat(dfl, datHeader))
                    {
                        return(false);
                    }
                    dfl.Gn();
                }
                if (dfl.Next.ToLower() == "romvault")
                {
                    dfl.Gn();
                    if (!LoadHeaderFromDat(dfl, datHeader))
                    {
                        return(false);
                    }
                    dfl.Gn();
                }

                while (!dfl.EndOfStream())
                {
                    bool res = ReadNextBlock(dfl, datHeader.BaseDir);
                    if (!res)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Пример #4
0
        private static bool LoadCredits(DatFileLoader dfl, DatHeader datHeader, ReportError errorReport)
        {
            if (dfl.Next.ToLower() != "[credits]")
            {
                errorReport?.Invoke(dfl.Filename, "Looking for [CREDITS] but found " + dfl.Next + " , " + dfl.LineNumber);
                return(false);
            }

            while (!dfl.EndOfStream())
            {
                string line = dfl.Gn();
                if (line.Substring(0, 1) == "[")
                {
                    return(true);
                }

                string element;
                string value;
                if (!splitLine(line, out element, out value))
                {
                    return(false);
                }

                switch (element.ToLower())
                {
                case "author":
                    datHeader.Author = value;
                    break;

                case "email":
                    datHeader.Email = value;
                    break;

                case "homepage":
                    datHeader.URL = value;
                    break;

                case "url":
                    datHeader.URL = value;
                    break;

                case "version":
                    datHeader.Version = value;
                    break;

                case "date":
                    datHeader.Date = value;
                    break;

                case "comment":
                    datHeader.Comment = value;
                    break;

                default:
                    errorReport?.Invoke(dfl.Filename, "Unknown Line " + dfl.Next + " found in [CREDITS], " + dfl.LineNumber);
                    return(false);
                }
            }
            return(true);
        }
Пример #5
0
        private static bool LoadEmulator(DatFileLoader dfl, DatHeader datHeader, ReportError errorReport)
        {
            if (dfl.Next.ToLower() != "[emulator]")
            {
                errorReport?.Invoke(dfl.Filename, "Looking for [EMULATOR] but found " + dfl.Next + " , " + dfl.LineNumber);
                return(false);
            }

            while (!dfl.EndOfStream())
            {
                string line = dfl.Gn();
                if (line.Substring(0, 1) == "[")
                {
                    return(true);
                }

                string element;
                string value;
                if (!splitLine(line, out element, out value))
                {
                    return(false);
                }

                switch (element.ToLower())
                {
                case "refname":
                    datHeader.Name = value;
                    break;

                case "version":
                    datHeader.Description = value;
                    break;

                case "category":
                    datHeader.Category = value;
                    break;

                case "exe":
                    break;

                case "runcmd":
                    break;

                case "romspaths":
                    break;

                default:
                    errorReport?.Invoke(dfl.Filename, "Unknown Line " + dfl.Next + " found in [EMULATOR], " + dfl.LineNumber);
                    return(false);
                }
            }
            return(true);
        }
Пример #6
0
        private static bool LoadDat(DatFileLoader dfl, DatHeader datHeader, ReportError errorReport)
        {
            if (dfl.Next.ToLower() != "[dat]")
            {
                errorReport?.Invoke(dfl.Filename, "Looking for [DAT] but found " + dfl.Next + " , " + dfl.LineNumber);
                return(false);
            }

            while (!dfl.EndOfStream())
            {
                string line = dfl.Gn();
                if (line.Substring(0, 1) == "[")
                {
                    return(true);
                }

                string element;
                string value;
                if (!splitLine(line, out element, out value))
                {
                    return(false);
                }

                switch (element.ToLower())
                {
                case "version":
                    //datVersion = value;
                    break;

                case "plugin":
                    //plugin = value;
                    break;

                case "split":
                    datHeader.Split = value;
                    break;

                case "merge":
                    datHeader.MergeType = value;
                    break;

                default:
                    errorReport?.Invoke(dfl.Filename, "Unknown Line " + dfl.Next + " found in [DAT], " + dfl.LineNumber);
                    return(false);
                }
            }
            return(true);
        }
Пример #7
0
        private bool LoadGameFromDat(DatFileLoader dfl, DatDir parentDir)
        {
            dfl.Gn();
            if (dfl.Next != "(")
            {
                _errorReport?.Invoke(dfl.Filename, "( not found after game, on line " + dfl.LineNumber);
                return(false);
            }

            dfl.Gn();
            string snext = dfl.Next.ToLower();

            string pathextra = "";

            if (snext == "rebuildto")
            {
                pathextra = dfl.Gn();
                dfl.Gn();
                snext = dfl.Next.ToLower();
            }

            if (snext != "name")
            {
                _errorReport?.Invoke(dfl.Filename, "Name not found as first object in ( ), on line " + dfl.LineNumber);
                return(false);
            }

            string name = dfl.GnRest();

            name = Path.Combine(pathextra, name);

            dfl.Gn();
            DatDir dDir = new DatDir(DatFileType.UnSet)
            {
                Name = name, DGame = new DatGame()
            };
            DatGame dGame = dDir.DGame;

            while (dfl.Next != ")" && !dfl.EndOfStream())
            {
                switch (dfl.Next.ToLower())
                {
                case "romof":
                    dGame.RomOf = dfl.GnRest();
                    break;

                case "description":
                    dGame.Description = dfl.GnRest();
                    break;

                case "sourcefile":
                    dGame.SourceFile = dfl.GnRest();
                    break;

                case "cloneof":
                    dGame.CloneOf = dfl.GnRest();
                    break;

                case "sampleof":
                    dGame.SampleOf = dfl.GnRest();
                    break;

                case "board":
                    dGame.Board = dfl.GnRest();
                    break;

                case "year":
                    dGame.Year = dfl.GnRest();
                    break;

                case "manufacturer":
                    dGame.Manufacturer = dfl.GnRest();
                    break;

                case "history":
                    dGame.History = dfl.GnRest();
                    break;

                case "serial":
                    dfl.GnRest();
                    break;

                case "rebuildto":
                    dfl.GnRest();
                    break;

                case "sample":
                    dfl.GnRest();
                    break;

                case "biosset":
                    dfl.GnRest();
                    break;

                case "chip":
                    dfl.GnRest();
                    break;

                case "video":
                    dfl.GnRest();
                    break;

                case "sound":
                    dfl.GnRest();
                    break;

                case "input":
                    dfl.GnRest();
                    break;

                case "dipswitch":
                    dfl.GnRest();
                    break;

                case "driver":
                    dfl.GnRest();
                    break;

                case "display":
                    dfl.GnRest();
                    break;

                case "comment":
                case "releaseyear":
                case "releasemonth":
                case "releaseday":
                case "genre":
                case "developer":
                case "publisher":
                case "homepage":
                case "users":
                case "version":
                case "license":
                    dfl.GnRest();
                    break;

                case "name":
                    string tmpName = dfl.GnRest();
                    _errorReport?.Invoke(dfl.Filename, "Error: multiple names found in one game '" + tmpName + "' will be ignored, on line " + dfl.LineNumber);
                    break;

                case "rom":
                    if (!LoadRomFromDat(dfl, dDir))
                    {
                        return(false);
                    }
                    break;

                case "disk":
                    if (!LoadDiskFromDat(dfl, dDir))
                    {
                        return(false);
                    }
                    break;

                case "archive":
                    if (!LoadArchiveFromDat(dfl))
                    {
                        return(false);
                    }
                    break;

                default:
                    _errorReport?.Invoke(dfl.Filename, "Error: key word '" + dfl.Next + "' not known in game, on line " + dfl.LineNumber);
                    break;
                }
                dfl.Gn();
            }
            parentDir.ChildAdd(dDir);
            return(true);
        }
Пример #8
0
        public static bool ReadDat(string strFilename, ReportError errorReport, out DatHeader datHeader)
        {
            datHeader = new DatHeader
            {
                BaseDir  = new DatDir(DatFileType.UnSet),
                Filename = strFilename
            };

            using (DatFileLoader dfl = new DatFileLoader())
            {
                dfl.LoadDat(strFilename);
                dfl.Gn();

                while (!dfl.EndOfStream())
                {
                    switch (dfl.Next.ToLower())
                    {
                    case "[credits]":
                        //getcredits
                        if (!LoadCredits(dfl, datHeader, errorReport))
                        {
                            return(false);
                        }
                        break;

                    case "[dat]":
                        //getdat
                        if (!LoadDat(dfl, datHeader, errorReport))
                        {
                            return(false);
                        }
                        break;

                    case "[emulator]":
                        //emulator
                        if (!LoadEmulator(dfl, datHeader, errorReport))
                        {
                            return(false);
                        }
                        break;

                    case "[games]":
                        //games
                        if (!LoadGame(dfl, datHeader.BaseDir, errorReport))
                        {
                            return(false);
                        }
                        break;

                    case "[resources]":
                        //resources
                        if (!LoadGame(dfl, datHeader.BaseDir, errorReport))
                        {
                            return(false);
                        }
                        break;

                    case "[disks]":
                        //games
                        if (!LoadDisks(dfl, datHeader.BaseDir, errorReport))
                        {
                            return(false);
                        }
                        break;

                    default:
                        errorReport?.Invoke(dfl.Filename, "Unknown Line " + dfl.Next + " , " + dfl.LineNumber);
                        return(false);
                    }
                }
            }

            return(true);
        }
Пример #9
0
        private static bool LoadDisks(DatFileLoader dfl, DatDir parentDir, ReportError errorReport)
        {
            if (dfl.Next.ToLower() != "[disks]")
            {
                errorReport?.Invoke(dfl.Filename, "Looking for [DISKS] but found " + dfl.Next + " , " + dfl.LineNumber);
                return(false);
            }

            while (!dfl.EndOfStream())
            {
                string line = dfl.Gn();

                if (line.Substring(0, 1) == "[")
                {
                    return(true);
                }

                string[] parts = line.Split('¬');

                // 1 parent name         = clone of
                // 2 parent description  = description (from parent)
                // 3 game name           = name (game)
                // 4 game description    = description
                // 5 rom name            = name (rom)
                // 6 rom crc             = crc
                // 7 rom size            = size
                // 8 romof name          = romof
                // 9 merge name          = merge

                string ParentName        = parts[1];
                string ParentDescription = parts[2];
                string GameName          = parts[3];
                string GameDescription   = parts[4];
                string romName           = parts[5];
                string romCRC            = parts[6];
                string romSize           = parts[7];
                string romOf             = parts[8];
                string merge             = parts[9];

                int    index;
                DatDir dDir;
                DatDir searchDir = new DatDir(DatFileType.Dir)
                {
                    Name = GameName
                };
                if (parentDir.ChildNameSearch(searchDir, out index) != 0)
                {
                    dDir = new DatDir(DatFileType.UnSet)
                    {
                        Name = GameName, DGame = new DatGame()
                    };
                    DatGame dGame = dDir.DGame;
                    dGame.Description = GameDescription;
                    if (ParentName != GameName)
                    {
                        dGame.CloneOf = ParentName;
                    }
                    parentDir.ChildAdd(dDir);
                }
                else
                {
                    dDir = (DatDir)parentDir.Child(index);
                    // need to check everything matches
                }

                DatFile dRom = new DatFile(DatFileType.UnSet)
                {
                    isDisk = true,
                    Name   = VarFix.CleanCHD(romName),
                    SHA1   = VarFix.CleanMD5SHA1(romCRC, 40),
                    Merge  = merge
                };
                // dRom.Size = VarFix.ULong(romSize);
                // check romof=ParentName

                dDir.ChildAdd(dRom);
            }
            return(true);
        }