示例#1
0
        private static bool LoadGameFromDat(DatFileLoader dfl, DatDir parentDir, ReportError errorReport)
        {
            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":
                    string description = dfl.GnRestQ();
                    int    idx1        = description.IndexOf("\"");
                    if (idx1 != -1)
                    {
                        int idx2 = description.IndexOf("\"", idx1 + 1);
                        if (idx2 != -1)
                        {
                            description = description.Substring(idx1 + 1, idx2 - idx1 - 1);
                        }
                    }
                    dGame.Description = description;
                    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 "isdevice":
                    dGame.IsDevice = dfl.GnRest();
                    break;

                case "serial":
                case "rebuildto":
                case "sample":
                case "biosset":
                case "chip":
                case "video":
                case "sound":
                case "input":
                case "dipswitch":
                case "driver":
                case "display":
                case "comment":
                case "releaseyear":
                case "releasemonth":
                case "releaseday":
                case "genre":
                case "developer":
                case "publisher":
                case "homepage":
                case "users":
                case "version":
                case "license":
                case "device_ref":
                case "driverstatus":
                case "ismechanical":
                case "#":     // comments

                    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, errorReport))
                    {
                        return(false);
                    }
                    break;

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

                case "archive":
                    if (!LoadArchiveFromDat(dfl, errorReport))
                    {
                        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);
        }