Exemple #1
0
        private static void AddDevice(string device, List <DatDir> devices, DatDir tDat)
        {
            if (tDat.ChildNameSearch(new DatDir(tDat.DatFileType)
            {
                Name = device
            }, out int index) != 0)
            {
                return;
            }
            DatDir devChild = (DatDir)tDat.Child(index);

            if (devChild == null)
            {
                return;
            }

            if (devices.Contains(devChild))
            {
                return;
            }

            devices.Add(devChild);

            List <string> childDev = devChild.DGame?.device_ref;

            if (childDev == null)
            {
                return;
            }

            foreach (string deviceChild in childDev)
            {
                AddDevice(deviceChild, devices, tDat);
            }
        }
        public static void FindParentSet(DatDir searchGame, DatDir parentDir, bool includeBios, ref List <DatDir> lstParentGames)
        {
            if (searchGame.DGame == null)
            {
                return;
            }

            string parentName = searchGame.DGame.RomOf;

            if (string.IsNullOrEmpty(parentName) || (parentName == searchGame.Name))
            {
                parentName = searchGame.DGame.CloneOf;
            }
            if (string.IsNullOrEmpty(parentName) || (parentName == searchGame.Name))
            {
                return;
            }

            int intResult = parentDir.ChildNameSearch(new DatDir(searchGame.DatFileType)
            {
                Name = parentName
            }, out int intIndex);

            if (intResult != 0)
            {
                return;
            }

            DatDir parentGame = (DatDir)parentDir.Child(intIndex);

            if (!includeBios && parentGame.DGame?.IsBios == "yes")
            {
                return;
            }

            lstParentGames.Add(parentGame);
            FindParentSet(parentGame, parentDir, includeBios, ref lstParentGames);
        }
Exemple #3
0
        public static void DirectoryExpand(DatDir dDir)
        {
            DatBase[] arrDir      = dDir.ToArray();
            bool      foundSubDir = false;

            foreach (DatBase db in arrDir)
            {
                if (CheckDir(db))
                {
                    if (db.Name.Contains("\\"))
                    {
                        foundSubDir = true;
                        break;
                    }
                }
            }

            if (foundSubDir)
            {
                dDir.ChildrenClear();
                foreach (DatBase db in arrDir)
                {
                    if (CheckDir(db))
                    {
                        if (db.Name.Contains("\\"))
                        {
                            string dirName = db.Name;
                            int    split   = dirName.IndexOf("\\", StringComparison.Ordinal);
                            string part0   = dirName.Substring(0, split);
                            string part1   = dirName.Substring(split + 1);

                            db.Name = part1;
                            DatDir dirFind = new DatDir(DatFileType.Dir)
                            {
                                Name = part0
                            };
                            if (dDir.ChildNameSearch(dirFind, out int index) != 0)
                            {
                                dDir.ChildAdd(dirFind);
                            }
                            else
                            {
                                dirFind = (DatDir)dDir.Child(index);
                            }

                            if (part1.Length > 0)
                            {
                                dirFind.ChildAdd(db);
                            }
                            continue;
                        }
                    }
                    dDir.ChildAdd(db);
                }

                arrDir = dDir.ToArray();
            }

            foreach (DatBase db in arrDir)
            {
                if (db is DatDir dbDir)
                {
                    DirectoryExpand(dbDir);
                }
            }
        }
Exemple #4
0
        public static void MakeDatSingleLevel(DatHeader tDatHeader, bool useDescription, RemoveSubType subDirType, bool isFiles)
        {
            // KeepAllSubDirs, just does what it says
            // RemoveAllSubDirs, just does what it says
            // RemoveallIfNoConflicts, does the conflict precheck and if a conflict is found switches to KeepAllSubDirs
            // RemoveSubIfNameMatches, will remove the subdir if the rom and game name match (without extentions) and there is only one rom in the game


            DatBase[] db = tDatHeader.BaseDir.ToArray();
            tDatHeader.Dir = "noautodir";

            string rootDirName = "";

            if (string.IsNullOrEmpty(rootDirName) && useDescription &&
                !string.IsNullOrWhiteSpace(tDatHeader.Description))
            {
                rootDirName = tDatHeader.Description;
            }
            if (string.IsNullOrEmpty(rootDirName))
            {
                rootDirName = tDatHeader.Name;
            }


            // do a pre check to see if removing all the sub-dirs will give any name conflicts
            if (subDirType == RemoveSubType.RemoveAllIfNoConflicts)
            {
                bool   foundRepeatFilename = false;
                DatDir rootTest            = new DatDir(DatFileType.UnSet)
                {
                    Name  = rootDirName,
                    DGame = new DatGame {
                        Description = tDatHeader.Description
                    }
                };
                foreach (DatBase set in db)
                {
                    string dirName = set.Name;
                    if (!(set is DatDir romSet))
                    {
                        continue;
                    }
                    DatBase[] dbr = romSet.ToArray();
                    foreach (DatBase rom in dbr)
                    {
                        int f = rootTest.ChildNameSearch(rom, out int _);
                        if (f == 0)
                        {
                            foundRepeatFilename = true;
                            subDirType          = RemoveSubType.KeepAllSubDirs;
                            break;
                        }
                        rootTest.ChildAdd(rom);
                    }

                    if (foundRepeatFilename)
                    {
                        break;
                    }
                }
            }

            tDatHeader.BaseDir.ChildrenClear();

            DatDir root;

            if (isFiles)
            {
                root = tDatHeader.BaseDir;
            }
            else
            {
                root = new DatDir(DatFileType.UnSet)
                {
                    Name  = rootDirName,
                    DGame = new DatGame {
                        Description = tDatHeader.Description
                    }
                };
                tDatHeader.BaseDir.ChildAdd(root);
            }

            foreach (DatBase set in db)
            {
                string dirName = set.Name;
                if (!(set is DatDir romSet))
                {
                    continue;
                }
                DatBase[] dbr = romSet.ToArray();
                foreach (DatBase rom in dbr)
                {
                    if (subDirType == RemoveSubType.RemoveSubIfNameMatches)
                    {
                        if (dbr.Length != 1 || Path.GetFileNameWithoutExtension(rom.Name) != dirName)
                        {
                            rom.Name = dirName + "\\" + rom.Name;
                        }
                    }
                    else if (subDirType == RemoveSubType.KeepAllSubDirs)
                    {
                        rom.Name = dirName + "\\" + rom.Name;
                    }
                    root.ChildAdd(rom);
                }
            }
        }
        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);
        }
        public static void SetZip(DatBase inDat, bool is7Zip = false)
        {
            int parentCount = _parents.Count;

            if (inDat is DatFile dFile)
            {
                if (dFile.isDisk)
                {
                    //go up 2 levels to find the directory of the game
                    DatDir dir    = _parents[parentCount - 2];
                    DatDir zipDir = _parents[parentCount - 1];

                    DatDir tmpFile = new DatDir(DatFileType.Dir)
                    {
                        Name = zipDir.Name, DGame = zipDir.DGame
                    };

                    if (dir.ChildNameSearch(tmpFile, out int index) != 0)
                    {
                        dir.ChildAdd(tmpFile);
                    }
                    else
                    {
                        tmpFile = (DatDir)dir.Child(index);
                    }
                    dFile.DatFileType = DatFileType.File;
                    tmpFile.ChildAdd(dFile);
                }
                else
                {
                    dFile.Name        = dFile.Name.Replace("\\", "/");
                    dFile.DatFileType = is7Zip ? DatFileType.File7Zip : DatFileType.FileTorrentZip;
                    _parents[parentCount - 1].ChildAdd(dFile);
                }
                return;
            }

            if (!(inDat is DatDir dDir))
            {
                return;
            }

            if (_parents.Count > 0)
            {
                _parents[parentCount - 1].ChildAdd(inDat);
            }

            dDir.DatFileType = dDir.DGame == null ?
                               DatFileType.Dir :
                               (is7Zip ? DatFileType.Dir7Zip : DatFileType.DirTorrentZip);

            DatBase[] children = dDir.ToArray();
            if (children == null)
            {
                return;
            }

            dDir.ChildrenClear();

            _parents.Add(dDir);
            foreach (DatBase child in children)
            {
                SetZip(child, is7Zip);
            }
            _parents.RemoveAt(parentCount);
        }
Exemple #7
0
        private static void SetZip(DatBase inDat, bool is7Zip, List <DatDir> parents)
        {
            if (parents == null)
            {
                parents = new List <DatDir>();
            }

            int parentCount = parents.Count;

            if (inDat is DatFile dFile)
            {
                if (dFile.isDisk)
                {
                    //go up 2 levels to find the directory of the game
                    DatDir dir    = parents[parentCount - 2];
                    DatDir zipDir = parents[parentCount - 1];

                    DatDir tmpFile = new DatDir(DatFileType.Dir)
                    {
                        Name = zipDir.Name, DGame = zipDir.DGame
                    };

                    if (dir.ChildNameSearch(tmpFile, out int index) != 0)
                    {
                        dir.ChildAdd(tmpFile);
                    }
                    else
                    {
                        tmpFile = (DatDir)dir.Child(index);
                    }
                    dFile.DatFileType = DatFileType.File;
                    tmpFile.ChildAdd(dFile);
                }
                else
                {
                    dFile.Name        = dFile.Name.Replace("\\", "/");
                    dFile.DatFileType = is7Zip ? DatFileType.File7Zip : DatFileType.FileTorrentZip;
                    parents[parentCount - 1].ChildAdd(dFile);
                }
                return;
            }

            if (!(inDat is DatDir dDir))
            {
                return;
            }

            if (inDat.Name != null)
            {
                inDat.Name = inDat.Name.TrimStart(new[] { ' ' });
                inDat.Name = inDat.Name.TrimEnd(new[] { ' ' });
                if (string.IsNullOrWhiteSpace(inDat.Name))
                {
                    inDat.Name = "_";
                }
            }

            if (parents.Count > 0)
            {
                parents[parentCount - 1].ChildAdd(inDat);
            }

            dDir.DatFileType = dDir.DGame == null ?
                               DatFileType.Dir :
                               (is7Zip ? DatFileType.Dir7Zip : DatFileType.DirTorrentZip);

            DatBase[] children = dDir.ToArray();
            if (children == null)
            {
                return;
            }

            dDir.ChildrenClear();

            parents.Add(dDir);
            foreach (DatBase child in children)
            {
                SetZip(child, is7Zip, parents);
            }
            parents.RemoveAt(parentCount);
        }