Exemplo n.º 1
0
        private static void Add7Zip(FileInfo f, DatDir thisDir)
        {
            DatDir ZipDir = new DatDir(DatFileType.Dir7Zip)
            {
                Name  = Path.GetFileNameWithoutExtension(f.Name),
                DGame = new DatGame()
            };

            ZipDir.DGame.Description = ZipDir.Name;
            thisDir.ChildAdd(ZipDir);

            SevenZ zf1 = new SevenZ();

            zf1.ZipFileOpen(f.FullName, -1, true);
            FileScan fs = new FileScan();
            List <FileScan.FileResults> fr = fs.Scan(zf1, true, true);

            for (int i = 0; i < fr.Count; i++)
            {
                if (zf1.IsDirectory(i))
                {
                    continue;
                }
                DatFile df = new DatFile(DatFileType.File7Zip)
                {
                    Name = zf1.Filename(i),
                    Size = fr[i].Size,
                    CRC  = fr[i].CRC,
                    SHA1 = fr[i].SHA1
                           //df.MD5 = zf.MD5(i)
                };
                ZipDir.ChildAdd(df);
            }
            zf1.ZipFileClose();
        }
Exemplo n.º 2
0
        public static bool RemoveEmptySets(DatBase inDat)
        {
            if (inDat is DatFile)
            {
                return(true);
            }

            DatDir dDir = inDat as DatDir;

            DatBase[] children = dDir?.ToArray();
            if (children == null || children.Length == 0)
            {
                return(false);
            }

            dDir.ChildrenClear();

            bool found = false;

            foreach (DatBase child in children)
            {
                bool keep = RemoveEmptySets(child);
                if (keep)
                {
                    found = true;
                    dDir.ChildAdd(child);
                }
            }

            return(found);
        }
Exemplo n.º 3
0
        public static void CleanFilenamesFixDupes(DatDir dDir)
        {
            DatBase[] arrDir     = dDir.ToArray();
            string    lastName   = "";
            int       matchCount = 0;

            foreach (DatBase db in arrDir)
            {
                string thisName = db.Name;
                if (lastName == thisName)
                {
                    string path0 = Path.GetFileNameWithoutExtension(thisName);
                    string path1 = Path.GetExtension(thisName);
                    db.Name     = path0 + "_" + matchCount + path1;
                    matchCount += 1;
                }
                else
                {
                    matchCount = 0;
                    lastName   = thisName;
                }

                if (db is DatDir ddir)
                {
                    CleanFilenamesFixDupes(ddir);
                }
            }
        }
Exemplo 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--;
                    }
                }
            }
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
        private static void ProcessDir(DirectoryInfo di, DatDir thisDir)
        {
            DirectoryInfo[] dia = di.GetDirectories();
            foreach (DirectoryInfo d in dia)
            {
                DatDir nextDir = new DatDir(DatFileType.Dir)
                {
                    Name = d.Name
                };
                thisDir.ChildAdd(nextDir);
                ProcessDir(d, nextDir);
            }
            FileInfo[] fia = di.GetFiles();

            foreach (FileInfo f in fia)
            {
                Console.WriteLine(f.FullName);
                string ext = Path.GetExtension(f.Name).ToLower();

                switch (ext)
                {
                case ".zip":
                    AddZip(f, thisDir);
                    break;

                case ".7z":
                    Add7Zip(f, thisDir);
                    break;

                default:
                    AddFile(f, thisDir);
                    break;
                }
            }
        }
        public static void RemoveDevices(DatDir tDat)
        {
            DatBase[] children = tDat.ToArray();

            tDat.ChildrenClear();
            foreach (DatBase child in children)
            {
                DatDir mGame = (DatDir)child;

                if (mGame.DGame == null)
                {
                    RemoveDevices(mGame);
                    tDat.ChildAdd(mGame);
                }
                else
                {
                    DatGame dGame = mGame.DGame;

                    if (dGame != null && dGame.IsDevice == "yes" && dGame.Runnable == "no")
                    {
                        continue;
                    }

                    tDat.ChildAdd(mGame);
                }
            }
        }
Exemplo n.º 8
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);
            }
        }
Exemplo n.º 9
0
        private bool LoadDirFromDat(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();
            if (dfl.Next.ToLower() != "name")
            {
                _errorReport?.Invoke(dfl.Filename, "Name not found as first object in ( ), on line " + dfl.LineNumber);
                return(false);
            }
            DatDir dir = new DatDir(DatFileType.UnSet)
            {
                Name = dfl.GnRest()
            };

            dfl.Gn();
            parentDir.ChildAdd(dir);

            while (dfl.Next != ")")
            {
                bool res = ReadNextBlock(dfl, dir);
                if (!res)
                {
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 10
0
        public static bool RemoveNotCollected(DatBase inDat)
        {
            if (inDat is DatFile dFile)
            {
                return(dFile.DatStatus == DatFileStatus.InDatCollect || dFile.DatStatus == DatFileStatus.InDatBad);
            }

            DatDir dDir = inDat as DatDir;

            DatBase[] children = dDir?.ToArray();
            if (children == null || children.Length == 0)
            {
                return(false);
            }

            dDir.ChildrenClear();

            bool found = false;

            foreach (DatBase child in children)
            {
                bool keep = RemoveNotCollected(child);
                if (keep)
                {
                    found = true;
                    dDir.ChildAdd(child);
                }
            }

            return(found);
        }
Exemplo n.º 11
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);
                        }
                    }
                }
            }
        }
Exemplo n.º 12
0
        public static void MakeDatSingleLevel(DatHeader tDatHeader)
        {
            DatBase[] db = tDatHeader.BaseDir.ToArray();
            tDatHeader.Dir = "noautodir";

            tDatHeader.BaseDir.ChildrenClear();
            DatDir root = new DatDir(DatFileType.UnSet)
            {
                Name  = tDatHeader.Name,
                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)
                {
                    rom.Name = dirName + "\\" + rom.Name;
                    root.ChildAdd(rom);
                }
            }
        }
Exemplo n.º 13
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"));
            }
        }
Exemplo n.º 14
0
        private static void AddDirAsGame(DirectoryInfo di, DatDir thisDir)
        {
            DatDir fDir = new DatDir(DatFileType.Dir)
            {
                Name  = Path.GetFileNameWithoutExtension(di.Name),
                DGame = new DatGame()
            };

            fDir.DGame.Description = fDir.Name;
            thisDir.ChildAdd(fDir);

            FileInfo[] fia = di.GetFiles();

            int fCount = 0;

            foreach (FileInfo f in fia)
            {
                Console.WriteLine(f.FullName);
                AddFile(f, fDir);

                //fCount++;
                if (fCount > 10)
                {
                    break;
                }
            }
        }
Exemplo n.º 15
0
        private bool LoadGameFromDat(DatFileLoader dfl, DatDir parentDir)
        {
            if (dfl.Next != "(")
            {
                _errorReport?.Invoke(dfl.Filename, "( not found after game, on line " + dfl.LineNumber);
                return(false);
            }
            dfl.Gn();

            string 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();

            dfl.Gn();

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

            while (dfl.Next != ")")
            {
                switch (dfl.Next.ToLower())
                {
                case "file":
                    dfl.Gn();
                    if (!LoadFileFromDat(dfl, dDir))
                    {
                        return(false);
                    }
                    dfl.Gn();
                    break;

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

                default:
                    _errorReport?.Invoke(dfl.Filename, "Error: key word '" + dfl.Next + "' not known in game, on line " + dfl.LineNumber);
                    dfl.Gn();
                    break;
                }
            }
            parentDir.ChildAdd(dDir);
            return(true);
        }
Exemplo n.º 16
0
        private static void AddZip(FileInfo f, DatDir thisDir)
        {
            ZipFile zf1 = new ZipFile();

            zf1.ZipFileOpen(f.FullName, -1, true);
            zf1.ZipStatus = ZipStatus.TrrntZip;

            DatDir ZipDir = new DatDir(zf1.ZipStatus == ZipStatus.TrrntZip ? DatFileType.DirTorrentZip : DatFileType.DirRVZip)
            {
                Name  = Path.GetFileNameWithoutExtension(f.Name),
                DGame = new DatGame()
            };

            ZipDir.DGame.Description = ZipDir.Name;
            thisDir.ChildAdd(ZipDir);



            FileScan fs = new FileScan();
            List <FileScan.FileResults> fr = fs.Scan(zf1, true, true);
            bool isTorrentZipDate          = true;

            for (int i = 0; i < fr.Count; i++)
            {
                if (fr[i].FileStatus != Compress.ZipReturn.ZipGood)
                {
                    Console.WriteLine("File Error :" + zf1.Filename(i) + " : " + fr[i].FileStatus);
                    continue;
                }

                DatFile df = new DatFile(DatFileType.FileTorrentZip)
                {
                    Name = zf1.Filename(i),
                    Size = fr[i].Size,
                    CRC  = fr[i].CRC,
                    SHA1 = fr[i].SHA1,
                    Date = zf1.LastModified(i).ToString("yyyy/MM/dd HH:mm:ss")
                           //df.MD5 = zf.MD5(i)
                };
                if (zf1.LastModified(i).Ticks != 629870671200000000)
                {
                    isTorrentZipDate = false;
                }

                ZipDir.ChildAdd(df);
            }
            zf1.ZipFileClose();
            if (isTorrentZipDate && ZipDir.DatFileType == DatFileType.DirRVZip)
            {
                ZipDir.DatFileType = DatFileType.DirTorrentZip;
            }

            if (ZipDir.DatFileType == DatFileType.DirTorrentZip)
            {
                DatSetCompressionType.SetZip(ZipDir);
                DatClean.RemoveUnNeededDirectoriesFromZip(ZipDir);
            }
        }
Exemplo n.º 17
0
        private static void ProcessDir(DirectoryInfo di, DatDir thisDir, bool newStyle)
        {
            DirectoryInfo[] dia = di.GetDirectories();
            foreach (DirectoryInfo d in dia)
            {
                bool procAsGame = CheckAddDir(d);
                if (procAsGame)
                {
                    Console.WriteLine(d.FullName + "\\ need to add as game");
                    AddDirAsGame(d, thisDir);
                }
                else
                {
                    DatDir nextDir = new DatDir(DatFileType.Dir)
                    {
                        Name = d.Name
                    };
                    thisDir.ChildAdd(nextDir);
                    ProcessDir(d, nextDir, newStyle);
                }
            }
            FileInfo[] fia = di.GetFiles();

            int fCount = 0;

            foreach (FileInfo f in fia)
            {
                //Console.WriteLine(f.FullName);
                string ext = Path.GetExtension(f.Name).ToLower();

                switch (ext)
                {
                case ".zip":
                    AddZip(f, thisDir);
                    break;

                case ".7z":
                    Add7Zip(f, thisDir);
                    break;

                default:
                    if (newStyle)
                    {
                        AddFile(f, thisDir);
                    }
                    break;
                }

                if (testMode)
                {
                    fCount++;
                    if (fCount > 10)
                    {
                        break;
                    }
                }
            }
        }
Exemplo n.º 18
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));
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 19
0
        private bool LoadFileFromDat(DatFileLoader dfl, DatDir parentDir)
        {
            if (dfl.Next != "(")
            {
                _errorReport?.Invoke(dfl.Filename, "( not found after file, on line " + dfl.LineNumber);
                return(false);
            }
            dfl.Gn();

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

            DatFile dRom = new DatFile(DatFileType.UnSet)
            {
                Name = dfl.GnNameToSize()
            };

            dfl.Gn();


            while (dfl.Next != ")")
            {
                switch (dfl.Next.ToLower())
                {
                case "size":
                    dRom.Size = VarFix.ULong(dfl.Gn());
                    dfl.Gn();
                    break;

                case "crc":
                    dRom.CRC = VarFix.CleanMD5SHA1(dfl.Gn(), 8);
                    dfl.Gn();
                    break;

                case "date":
                    dRom.Date = dfl.Gn() + " " + dfl.Gn();
                    dfl.Gn();
                    break;

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

            parentDir.ChildAdd(dRom);

            return(true);
        }
Exemplo n.º 20
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);
                }
            }
        }
Exemplo n.º 21
0
        public static void CleanFilenames(DatDir dDir)
        {
            DatBase[] arrDir = dDir.ToArray();
            foreach (DatBase db in arrDir)
            {
                CleanFilename(db);

                if (db is DatDir ddir)
                {
                    CleanFilenames(ddir);
                }
            }
        }
Exemplo n.º 22
0
        private bool ReadNextBlock(DatFileLoader dfl, DatDir parentDir)
        {
            switch (dfl.Next.ToLower())
            {
            case "dir":
                dfl.Gn();
                if (!LoadDirFromDat(dfl, parentDir))
                {
                    return(false);
                }
                dfl.Gn();
                break;

            case "game":
            case "machine":
                dfl.Gn();
                if (!LoadGameFromDat(dfl, parentDir))
                {
                    return(false);
                }
                dfl.Gn();
                break;

            case "resource":
                dfl.Gn();
                if (!LoadGameFromDat(dfl, parentDir))
                {
                    return(false);
                }
                dfl.Gn();
                break;

            case "emulator":
                dfl.Gn();
                if (!LoadEmulator(dfl))
                {
                    return(false);
                }
                dfl.Gn();
                break;

            default:
                _errorReport?.Invoke(dfl.Filename, "Error Keyword " + dfl.Next + " not know in dir, on line " + dfl.LineNumber);
                dfl.Gn();
                break;
            }
            return(true);
        }
Exemplo n.º 23
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);
                }
            }
        }
Exemplo n.º 24
0
        private static void LoadDiskFromDat(DatDir parentDir, XmlNode romNode)
        {
            if (romNode.Attributes == null)
            {
                return;
            }

            DatFile dRom = new DatFile(DatFileType.UnSet)
            {
                Name   = VarFix.CleanCHD(romNode.Attributes.GetNamedItem("name")),
                SHA1   = VarFix.CleanMD5SHA1(romNode.Attributes.GetNamedItem("sha1"), 40),
                Status = VarFix.ToLower(romNode.Attributes.GetNamedItem("status")),
                isDisk = true
            };

            parentDir.ChildAdd(dRom);
        }
Exemplo n.º 25
0
        public static void MakeDatSingleLevel(DatHeader tDatHeader, bool useDescription, bool removeSubDir)
        {
            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;
            }

            tDatHeader.BaseDir.ChildrenClear();

            DatDir 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 (!removeSubDir)
                    {
                        rom.Name = dirName + "\\" + rom.Name;
                    }
                    root.ChildAdd(rom);
                }
            }
        }
Exemplo n.º 26
0
        private static bool ReadNextBlock(DatFileLoader dfl, DatDir parentDir, ReportError errorReport)
        {
            switch (dfl.Next.ToLower())
            {
            case "dir":
                if (!LoadDirFromDat(dfl, parentDir, errorReport))
                {
                    return(false);
                }
                break;

            case "game":
            case "machine":
                if (!LoadGameFromDat(dfl, parentDir, errorReport))
                {
                    return(false);
                }
                break;

            case "resource":
                if (!LoadGameFromDat(dfl, parentDir, errorReport))
                {
                    return(false);
                }
                break;

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

            case "#":     // comments

                dfl.GnRest();
                break;

            default:
                errorReport?.Invoke(dfl.Filename, "Error Keyword " + dfl.Next + " not know in dir, on line " + dfl.LineNumber);
                break;
            }
            dfl.Gn();
            return(true);
        }
Exemplo n.º 27
0
        private static void AddFile(FileInfo f, DatDir thisDir)
        {
            Compress.File.File zf1 = new Compress.File.File();
            zf1.ZipFileOpen(f.FullName, -1, true);
            FileScan fs = new FileScan();
            List <FileScan.FileResults> fr = fs.Scan(zf1, true, true);

            DatFile df = new DatFile(DatFileType.File)
            {
                Name = f.Name,
                Size = fr[0].Size,
                CRC  = fr[0].CRC,
                SHA1 = fr[0].SHA1
            };

            thisDir.ChildAdd(df);
            zf1.ZipFileClose();
        }
Exemplo n.º 28
0
        public static void MakeDatSingleLevel(DatHeader tDatHeader, bool useDescription)
        {
            DatBase[] db = tDatHeader.BaseDir.ToArray();
            tDatHeader.Dir = "noautodir";


            // if we are auto adding extra directories then create a new directory.
            string extraDirName = "";

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

            tDatHeader.BaseDir.ChildrenClear();
            DatDir root = new DatDir(DatFileType.UnSet)
            {
                Name  = extraDirName,
                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)
                {
                    rom.Name = dirName + "\\" + rom.Name;
                    root.ChildAdd(rom);
                }
            }
        }
Exemplo n.º 29
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);
                }
            }
        }
Exemplo n.º 30
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--;
                    }
                }
            }
        }