Ejemplo n.º 1
0
        private void LoadRomFromDat(DatDir parentDir, XmlNode romNode)
        {
            if (romNode.Attributes == null)
            {
                return;
            }

            XmlNode name     = romNode.Attributes.GetNamedItem("name");
            string  loadflag = VarFix.String(romNode.Attributes.GetNamedItem("loadflag"));

            if (name != null)
            {
                DatFile dRom = new DatFile(DatFileType.UnSet)
                {
                    Name   = VarFix.String(name),
                    Size   = VarFix.ULong(romNode.Attributes.GetNamedItem("size")),
                    CRC    = VarFix.CleanMD5SHA1(romNode.Attributes.GetNamedItem("crc"), 8),
                    SHA1   = VarFix.CleanMD5SHA1(romNode.Attributes.GetNamedItem("sha1"), 40),
                    Status = VarFix.ToLower(romNode.Attributes.GetNamedItem("status"))
                };

                _indexContinue = parentDir.ChildAdd(dRom);
            }
            else if (loadflag.ToLower() == "continue")
            {
                DatFile tRom = (DatFile)parentDir.Child(_indexContinue);
                tRom.Size += VarFix.ULong(romNode.Attributes.GetNamedItem("size"));
            }
            else if (loadflag.ToLower() == "ignore")
            {
                DatFile tRom = (DatFile)parentDir.Child(_indexContinue);
                tRom.Size += VarFix.ULong(romNode.Attributes.GetNamedItem("size"));
            }
        }
Ejemplo n.º 2
0
        public static bool HasRomOf(DatDir tDat)
        {
            for (int g = 0; g < tDat.ChildCount; g++)
            {
                if (!(tDat.Child(g) is DatDir mGame))
                {
                    continue;
                }

                if (mGame.DGame == null)
                {
                    bool res = HasRomOf(mGame);
                    if (res)
                    {
                        return(true);
                    }
                }
                else
                {
                    if (!String.IsNullOrWhiteSpace(mGame.DGame.RomOf))
                    {
                        return(true);
                    }
                    if (!String.IsNullOrWhiteSpace(mGame.DGame.CloneOf))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
0
        public static void RemoveNonCHD(DatDir tDat)
        {
            for (int g = 0; g < tDat.ChildCount; g++)
            {
                DatDir mGame = (DatDir)tDat.Child(g);

                if (mGame.DGame == null)
                {
                    RemoveNonCHD(mGame);
                }
                else
                {
                    for (int r = 0; r < mGame.ChildCount; r++)
                    {
                        DatFile df1 = (DatFile)mGame.Child(r);
                        if (df1.isDisk)
                        {
                            continue;
                        }
                        mGame.ChildRemove(df1);
                        r--;
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public static void RemoveNoDumps(DatDir tDat)
        {
            for (int g = 0; g < tDat.ChildCount; g++)
            {
                if (!(tDat.Child(g) is DatDir mGame))
                {
                    continue;
                }

                if (mGame.DGame == null)
                {
                    RemoveNoDumps(mGame);
                }
                else
                {
                    DatBase[] tGame = mGame.ToArray();
                    foreach (DatBase t in tGame)
                    {
                        if (((DatFile)t).Status == "nodump")
                        {
                            mGame.ChildRemove(t);
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public static void DatSetMakeNonMergeSet(DatDir tDat)
        {
            // look for merged roms, check if a rom exists in a parent set where the Name,Size and CRC all match.

            for (int g = 0; g < tDat.ChildCount; g++)
            {
                DatDir mGame = (DatDir)tDat.Child(g);

                if (mGame.DGame == null)
                {
                    DatSetMakeNonMergeSet(mGame);
                }
                else
                {
                    DatGame dGame = mGame.DGame;

                    if (dGame?.device_ref == null)
                    {
                        continue;
                    }

                    List <DatDir> devices = new List <DatDir> {
                        mGame
                    };

                    foreach (string device in dGame.device_ref)
                    {
                        AddDevice(device, devices, tDat);
                    }
                    devices.RemoveAt(0);


                    foreach (DatDir device in devices)
                    {
                        for (int i = 0; i < device.ChildCount; i++)
                        {
                            DatFile df0      = (DatFile)device.Child(i);
                            bool    crcFound = false;
                            for (int j = 0; j < mGame.ChildCount; j++)
                            {
                                DatFile df1 = (DatFile)mGame.Child(j);
                                if (ArrByte.bCompare(df0.SHA1, df1.SHA1))
                                {
                                    crcFound = true;
                                    break;
                                }
                            }
                            if (!crcFound)
                            {
                                mGame.ChildAdd(device.Child(i));
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 7
0
        private void ProcessDir(DatDir dd, int depth, bool inGame)
        {
            bool dirIsGame = dd.DGame != null;

            inGame |= dirIsGame;

            if (dd.DGame != null)
            {
                if (!string.IsNullOrWhiteSpace(dd.DGame.CloneOf))
                {
                    cloneOf = true;
                }
                if (!string.IsNullOrWhiteSpace(dd.DGame.RomOf))
                {
                    romOf = true;
                }
            }

            if (!inGame && depth > 0)
            {
                subDirFound        = true;
                subDirContainsDir |= dd.Name.Contains(@"/") || dd.Name.Contains(@"\");
            }
            if (dirIsGame)
            {
                gameContainsdir |= dd.Name.Contains(@"/") || dd.Name.Contains(@"\");
            }
            if (inGame && !dirIsGame)
            {
                subDirFoundInGame        = true;
                subDirInGameContainsDir |= dd.Name.Contains(@"/") || dd.Name.Contains(@"\");
            }

            //  Debug.WriteLine(depth + " " + dd.Name + "  " + inGame);
            int iCount = dd.ChildCount;

            for (int i = 0; i < iCount; i++)
            {
                DatBase db = dd.Child(i);

                DatDir ddc = db as DatDir;
                if (ddc != null)
                {
                    ProcessDir(ddc, depth + 1, inGame);
                }
                DatFile dfc = db as DatFile;
                if (dfc != null)
                {
                    ProcessFile(dfc);
                }
            }
        }
Ejemplo n.º 8
0
        public static void RemoveUnNeededDirectoriesFromZip(DatDir mGame)
        {
            for (int r = 0; r < mGame.ChildCount; r++)
            {
                DatFile df1 = (DatFile)mGame.Child(r);
                if (df1.Size != 0 || df1.Name.Length == 0 || df1.Name.Substring(df1.Name.Length - 1) != "/")
                {
                    continue;
                }
                bool found = false;
                for (int r1 = 0; r1 < mGame.ChildCount; r1++)
                {
                    if (r == r1)
                    {
                        continue;
                    }
                    string compName = mGame.Child(r1).Name;
                    if (compName.Length <= df1.Name.Length)
                    {
                        continue;
                    }

                    if (compName.Substring(0, df1.Name.Length) == df1.Name)
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    continue;
                }

                mGame.ChildRemove(df1);
                r--;
            }
        }
Ejemplo n.º 9
0
        public static void RemoveUnNeededDirectories(DatDir tDat)
        {
            for (int g = 0; g < tDat.ChildCount; g++)
            {
                DatDir mGame = (DatDir)tDat.Child(g);

                if (mGame.DGame == null)
                {
                    RemoveUnNeededDirectories(mGame);
                }
                else
                {
                    RemoveUnNeededDirectoriesFromZip(mGame);
                }
            }
        }
Ejemplo n.º 10
0
        public static void RemoveUnNeededDirectories(DatDir tDat)
        {
            for (int g = 0; g < tDat.ChildCount; g++)
            {
                if (!(tDat.Child(g) is DatDir mGame))
                {
                    continue;
                }

                if (mGame.DGame == null)
                {
                    RemoveUnNeededDirectories(mGame);
                }
                else
                {
                    RemoveUnNeededDirectoriesFromZip(mGame);
                }
            }
        }
Ejemplo n.º 11
0
        public static void RemoveEmptyDirectories(DatDir tDat)
        {
            for (int g = 0; g < tDat.ChildCount; g++)
            {
                DatDir mGame = (DatDir)tDat.Child(g);

                if (mGame.DGame == null)
                {
                    RemoveEmptyDirectories(mGame);
                }
                else
                {
                    if (mGame.ChildCount == 0)
                    {
                        tDat.ChildRemove(mGame);
                        g--;
                    }
                }
            }
        }
Ejemplo n.º 12
0
        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);
        }
Ejemplo n.º 13
0
        public static void DatSetMakeMergeSet(DatDir tDat, bool mergeWithGameName = true)
        {
            // look for merged roms, check if a rom exists in a parent set where the Name,Size and CRC all match.

            for (int g = 0; g < tDat.ChildCount; g++)
            {
                DatDir mGame = (DatDir)tDat.Child(g);

                if (mGame.DGame == null)
                {
                    DatSetMakeMergeSet(mGame, mergeWithGameName);
                    continue;
                }

                // find all parents of this game
                List <DatDir> lstParentGames = new List <DatDir>();
                DatFindParentSets.FindParentSet(mGame, tDat, true, ref lstParentGames);

                // if no parents are found then just set all children as kept
                if (lstParentGames.Count == 0)
                {
                    for (int r = 0; r < mGame.ChildCount; r++)
                    {
                        if (mGame.Child(r) is DatFile dfGame)
                        {
                            RomCheckCollect(dfGame, false);
                        }
                    }

                    continue;
                }

                List <DatDir> pGames = new List <DatDir>();
                List <DatDir> pBios  = new List <DatDir>();
                foreach (DatDir dd in lstParentGames)
                {
                    if (dd.DGame.IsBios?.ToLower() == "yes")
                    {
                        pBios.Add(dd);
                    }
                    else
                    {
                        pGames.Add(dd);
                    }
                }

                DatBase[]      mGameTest = mGame.ToArray();
                List <DatBase> mGameKeep = new List <DatBase>();

                foreach (DatBase tGame in mGameTest)
                {
                    if (((DatFile)tGame).Status == "nodump")
                    {
                        mGame.ChildAdd(tGame);
                        continue;
                    }

                    // first remove any file that is in a parent BIOS set
                    bool found = false;
                    foreach (DatDir romofGame in pBios)
                    {
                        for (int r1 = 0; r1 < romofGame.ChildCount; r1++)
                        {
                            // size/checksum compare, so name does not need to match
                            // if (!string.Equals(mGame[r].Name, romofGame.Child(r1).Name, StringComparison.OrdinalIgnoreCase))
                            // {
                            //     continue;
                            // }

                            ulong?size0 = ((DatFile)tGame).Size;
                            ulong?size1 = ((DatFile)romofGame.Child(r1)).Size;
                            if ((size0 != null) && (size1 != null) && (size0 != size1))
                            {
                                continue;
                            }

                            byte[] crc0 = ((DatFile)tGame).CRC;
                            byte[] crc1 = ((DatFile)romofGame.Child(r1)).CRC;
                            if ((crc0 != null) && (crc1 != null) && !ArrByte.bCompare(crc0, crc1))
                            {
                                continue;
                            }

                            byte[] sha0 = ((DatFile)tGame).SHA1;
                            byte[] sha1 = ((DatFile)romofGame.Child(r1)).SHA1;
                            if ((sha0 != null) && (sha1 != null) && !ArrByte.bCompare(sha0, sha1))
                            {
                                continue;
                            }

                            byte[] md50 = ((DatFile)tGame).MD5;
                            byte[] md51 = ((DatFile)romofGame.Child(r1)).MD5;
                            if ((md50 != null) && (md51 != null) && !ArrByte.bCompare(md50, md51))
                            {
                                continue;
                            }

                            if (((DatFile)tGame).isDisk != ((DatFile)romofGame.Child(r1)).isDisk)
                            {
                                continue;
                            }

                            // not needed as we are now checking for nodumps at the top of this code
                            // don't merge if only one of the ROM is nodump
                            //if (((DatFile)romofGame.Child(r1)).Status == "nodump" != (((DatFile)mGame[r]).Status == "nodump"))
                            //{
                            //    continue;
                            //}

                            found = true;
                            break;
                        }

                        if (found)
                        {
                            break;
                        }
                    }

                    if (!found)
                    {
                        mGameKeep.Add(tGame);
                    }
                }

                mGame.ChildrenClear();

                if (pGames.Count == 0)
                {
                    foreach (DatBase tGame in mGameKeep)
                    {
                        mGame.ChildAdd(tGame);
                    }

                    continue;
                }

                DatDir romOfTopParent = pGames[pGames.Count - 1];

                foreach (DatBase tGame in mGameKeep)
                {
                    if (mergeWithGameName && !((DatFile)tGame).isDisk)
                    {
                        tGame.Name = mGame.Name + "\\" + tGame.Name;
                    }
                    romOfTopParent.ChildAdd(tGame);
                }
            }
        }
Ejemplo n.º 14
0
        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);
        }
Ejemplo n.º 15
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);
        }
Ejemplo n.º 16
0
        public static void RemoveDupes(DatDir tDat)
        {
            for (int g = 0; g < tDat.ChildCount; g++)
            {
                DatDir mGame = (DatDir)tDat.Child(g);

                if (mGame.DGame == null)
                {
                    RemoveDupes(mGame);
                }
                else
                {
                    bool found = true;
                    while (found)
                    {
                        found = false;


                        for (int r = 0; r < mGame.ChildCount; r++)
                        {
                            DatFile df0 = (DatFile)mGame.Child(r);
                            for (int t = r + 1; t < mGame.ChildCount; t++)
                            {
                                DatFile df1 = (DatFile)mGame.Child(t);

                                if (!ArrByte.bCompare(df0.CRC, df1.CRC))
                                {
                                    continue;
                                }

                                found = true;

                                string name0 = df0.Name;
                                string name1 = df1.Name;

                                bool nS0 = name0.Contains("\\");
                                bool ns1 = name1.Contains("\\");

                                if (nS0 && !ns1)
                                {
                                    mGame.ChildRemove(df0);
                                }
                                else if (!nS0 && ns1)
                                {
                                    mGame.ChildRemove(df1);
                                }
                                else if (nS0 && ns1)
                                {
                                    string s0 = name0.Substring(0, name0.IndexOf("\\", StringComparison.Ordinal));
                                    string s1 = name1.Substring(0, name1.IndexOf("\\", StringComparison.Ordinal));
                                    if (s0 != s1)
                                    {
                                        mGame.ChildRemove(df1);
                                    }
                                    else
                                    {
                                        int res = AlphanumComparatorFast.Compare(name0, name1);
                                        mGame.ChildRemove(res >= 0 ? df0 : df1);
                                    }
                                }
                                else if (name0 == name1)
                                {
                                    mGame.ChildRemove(df1);
                                }
                                else
                                {
                                    found = false;
                                    continue;
                                }
                                r = mGame.ChildCount;
                                t = mGame.ChildCount;
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 17
0
        public static void DatSetMakeSplitSet(DatDir tDat)
        {
            // look for merged roms, check if a rom exists in a parent set where the Name,Size and CRC all match.

            for (int g = 0; g < tDat.ChildCount; g++)
            {
                DatDir mGame = (DatDir)tDat.Child(g);

                if (mGame.DGame == null)
                {
                    DatSetMakeSplitSet(mGame);
                }
                else
                {
                    // find all parents of this game
                    List <DatDir> lstParentGames = new List <DatDir>();
                    DatFindParentSets.FindParentSet(mGame, tDat, true, ref lstParentGames);

                    // if no parents are found then just set all children as kept
                    if (lstParentGames.Count == 0)
                    {
                        for (int r = 0; r < mGame.ChildCount; r++)
                        {
                            if (mGame.Child(r) is DatFile dfGame)
                            {
                                RomCheckCollect(dfGame, false);
                            }
                        }
                    }
                    else
                    {
                        for (int r = 0; r < mGame.ChildCount; r++)
                        {
                            if (((DatFile)mGame.Child(r)).Status == "nodump")
                            {
                                RomCheckCollect((DatFile)mGame.Child(r), false);
                                continue;
                            }

                            bool found = false;
                            foreach (DatDir romofGame in lstParentGames)
                            {
                                for (int r1 = 0; r1 < romofGame.ChildCount; r1++)
                                {
                                    // size/checksum compare, so name does not need to match
                                    // if (!string.Equals(mGame.Child(r).Name, romofGame.Child(r1).Name, StringComparison.OrdinalIgnoreCase))
                                    // {
                                    //     continue;
                                    // }

                                    ulong?size0 = ((DatFile)mGame.Child(r)).Size;
                                    ulong?size1 = ((DatFile)romofGame.Child(r1)).Size;
                                    if ((size0 != null) && (size1 != null) && (size0 != size1))
                                    {
                                        continue;
                                    }

                                    byte[] crc0 = ((DatFile)mGame.Child(r)).CRC;
                                    byte[] crc1 = ((DatFile)romofGame.Child(r1)).CRC;
                                    if ((crc0 != null) && (crc1 != null) && !ArrByte.bCompare(crc0, crc1))
                                    {
                                        continue;
                                    }

                                    byte[] sha0 = ((DatFile)mGame.Child(r)).SHA1;
                                    byte[] sha1 = ((DatFile)romofGame.Child(r1)).SHA1;
                                    if ((sha0 != null) && (sha1 != null) && !ArrByte.bCompare(sha0, sha1))
                                    {
                                        continue;
                                    }

                                    byte[] md50 = ((DatFile)mGame.Child(r)).MD5;
                                    byte[] md51 = ((DatFile)romofGame.Child(r1)).MD5;
                                    if ((md50 != null) && (md51 != null) && !ArrByte.bCompare(md50, md51))
                                    {
                                        continue;
                                    }

                                    if (((DatFile)mGame.Child(r)).isDisk != ((DatFile)romofGame.Child(r1)).isDisk)
                                    {
                                        continue;
                                    }

                                    // not needed as we are now checking for nodumps at the top of this code
                                    // don't merge if only one of the ROM is nodump
                                    //if (((DatFile)romofGame.Child(r1)).Status == "nodump" != (((DatFile)mGame.Child(r)).Status == "nodump"))
                                    //{
                                    //    continue;
                                    //}

                                    found = true;
                                    break;
                                }
                                if (found)
                                {
                                    break;
                                }
                            }

                            RomCheckCollect((DatFile)mGame.Child(r), found);
                        }
                    }
                }
            }
        }
Ejemplo n.º 18
0
        public static void RemoveDupes(DatDir tDat, bool testName = true, bool testWithMergeName = false)
        {
            for (int g = 0; g < tDat.ChildCount; g++)
            {
                DatDir mGame = (DatDir)tDat.Child(g);

                if (mGame.DGame == null)
                {
                    RemoveDupes(mGame, testName);
                }
                else
                {
                    bool found = true;
                    while (found)
                    {
                        found = false;


                        for (int r = 0; r < mGame.ChildCount; r++)
                        {
                            DatFile df0 = (DatFile)mGame.Child(r);
                            for (int t = r + 1; t < mGame.ChildCount; t++)
                            {
                                DatFile df1 = (DatFile)mGame.Child(t);

                                if (testName && df0.Name != df1.Name)
                                {
                                    continue;
                                }
                                bool hasCRC = df0.CRC != null && df1.CRC != null;
                                if (hasCRC && !ArrByte.bCompare(df0.CRC, df1.CRC))
                                {
                                    continue;
                                }
                                bool hasSHA1 = df0.SHA1 != null && df1.SHA1 != null;
                                if (hasSHA1 && !ArrByte.bCompare(df0.SHA1, df1.SHA1))
                                {
                                    continue;
                                }
                                bool hasMD5 = df0.MD5 != null && df1.MD5 != null;
                                if (hasMD5 && !ArrByte.bCompare(df0.MD5, df1.MD5))
                                {
                                    continue;
                                }
                                if (!hasCRC && !hasSHA1 && !hasMD5)
                                {
                                    continue;
                                }

                                found = true;

                                string name0 = df0.Name;
                                string name1 = df1.Name;

                                bool nS0 = name0.Contains("\\");
                                bool ns1 = name1.Contains("\\");

                                if (nS0 && !ns1)
                                {
                                    mGame.ChildRemove(df0);
                                }
                                else if (!nS0 && ns1)
                                {
                                    mGame.ChildRemove(df1);
                                }
                                else if (nS0 && ns1)
                                {
                                    string s0 = name0.Substring(0, name0.IndexOf("\\", StringComparison.Ordinal));
                                    string s1 = name1.Substring(0, name1.IndexOf("\\", StringComparison.Ordinal));
                                    if (s0 != s1)
                                    {
                                        mGame.ChildRemove(df1);
                                    }
                                    else
                                    {
                                        int res = AlphanumComparatorFast.Compare(name0, name1);
                                        mGame.ChildRemove(res >= 0 ? df0 : df1);
                                    }
                                }
                                else if ((name0 == name1) || (testWithMergeName && (name0 == df1.Merge)))
                                {
                                    mGame.ChildRemove(df1);
                                }
                                else
                                {
                                    found = false;
                                    continue;
                                }
                                r = mGame.ChildCount;
                                t = mGame.ChildCount;
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 19
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);
                }
            }
        }
Ejemplo n.º 20
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);
        }