Exemplo n.º 1
0
 private static void SetExpandedRecurse(RvDir pTree, bool expanded)
 {
     for (int i = 0; i < pTree.ChildCount; i++)
     {
         RvBase b = pTree.Child(i);
         if (b is RvDir)
         {
             RvDir d = (RvDir)b;
             if (d.Tree != null)
             {
                 d.Tree.TreeExpanded = expanded;
                 SetExpandedRecurse(d, expanded);
             }
         }
     }
 }
Exemplo n.º 2
0
 private static void SetChecked(RvDir pTree, RvTreeRow.TreeSelect nSelection)
 {
     pTree.Tree.Checked = nSelection;
     for (int i = 0; i < pTree.ChildCount; i++)
     {
         RvBase b = pTree.Child(i);
         if (b is RvDir)
         {
             RvDir d = (RvDir)b;
             if (d.Tree != null)
             {
                 SetChecked(d, nSelection);
             }
         }
     }
 }
Exemplo n.º 3
0
        public static bool ReadDat(ref RvDir tDat, string strFilename)
        {
            RvDir    tNow         = tDat;
            FileType thisFileType = FileType.Unknown;

            int errorCode = DatFileLoader.LoadDat(strFilename);

            if (errorCode != 0)
            {
                DatUpdate.ShowDat(new Win32Exception(errorCode).Message, strFilename);
                return(false);
            }

            DatFileLoader.Gn();
            while (!DatFileLoader.EndOfStream())
            {
                switch (DatFileLoader.Next.ToLower())
                {
                case "doscenter":
                    _cleanFileNames = true;
                    DatFileLoader.Gn();
                    if (!LoadHeaderFromDat(ref tNow, ref thisFileType))
                    {
                        return(false);
                    }
                    DatFileLoader.Gn();
                    break;

                case "game":
                    DatFileLoader.Gn();
                    if (!LoadGameFromDat(ref tNow, thisFileType))
                    {
                        return(false);
                    }
                    DatFileLoader.Gn();
                    break;

                default:
                    DatUpdate.SendAndShowDat(Resources.DatCmpReader_ReadDat_Error_keyword + DatFileLoader.Next + Resources.DatCmpReader_ReadDat_not_known, DatFileLoader.Filename);
                    DatFileLoader.Gn();
                    break;
                }
            }

            DatFileLoader.Close();
            return(true);
        }
Exemplo n.º 4
0
        private static EFile RemoveOldDatsCleanUpFiles(RvBase dbDir)
        {
            if (dbDir.Dat != null)
            {
                if (dbDir.Dat.Status == DatUpdateStatus.Correct)
                {
                    return(EFile.Keep);
                }

                if (dbDir.Dat.Status == DatUpdateStatus.Delete)
                {
                    if (dbDir.DatRemove() == EFile.Delete)
                    {
                        return(EFile.Delete); //delete
                    }
                }
            }

            FileType ft = dbDir.FileType;

            // if we are checking a dir or zip recurse into it.
            if (ft != FileType.Zip && ft != FileType.Dir)
            {
                return(EFile.Keep);
            }
            RvDir tDir = dbDir as RvDir;

            // remove all DATStatus's here they will get set back correctly when adding dats back in below.
            dbDir.DatStatus = DatStatus.NotInDat;

            for (int i = 0; i < tDir.ChildCount; i++)
            {
                if (RemoveOldDatsCleanUpFiles(tDir.Child(i)) == EFile.Keep)
                {
                    continue;
                }
                tDir.ChildRemove(i);
                i--;
            }
            if (ft == FileType.Zip && dbDir.GotStatus == GotStatus.Corrupt)
            {
                return(EFile.Keep);
            }

            // if this directory is now empty it should be deleted
            return(tDir.ChildCount == 0 ? EFile.Delete : EFile.Keep);
        }
Exemplo n.º 5
0
        public static bool ReadMameDat(ref RvDir tDat, XmlDocument doc)
        {
            FileType thisFileType = FileType.Unknown;

            if (!LoadMameHeaderFromDat(ref tDat, ref doc, ref thisFileType))
            {
                return(false);
            }

            if (doc.DocumentElement == null)
            {
                return(false);
            }

            XmlNodeList dirNodeList = doc.DocumentElement.SelectNodes("dir");

            if (dirNodeList != null)
            {
                foreach (XmlNode dirNode in dirNodeList)
                {
                    LoadDirFromDat(ref tDat, dirNode, thisFileType);
                }
            }

            XmlNodeList gameNodeList = doc.DocumentElement.SelectNodes("game");

            if (gameNodeList != null)
            {
                foreach (XmlNode gameNode in gameNodeList)
                {
                    LoadGameFromDat(ref tDat, gameNode, thisFileType);
                }
            }

            XmlNodeList machineNodeList = doc.DocumentElement.SelectNodes("machine");

            if (machineNodeList != null)
            {
                foreach (XmlNode machineNode in machineNodeList)
                {
                    LoadGameFromDat(ref tDat, machineNode, thisFileType);
                }
            }


            return(true);
        }
Exemplo n.º 6
0
        private static void MatchFound(RvBase dbChild, RvBase fileChild)
        {
            // only check a zip if the filestamp has changed, we asume it is the same if the filestamp has not changed.
            switch (dbChild.FileType)
            {
            case FileType.Zip:
                if (dbChild.TimeStamp != fileChild.TimeStamp || EScanLevel == eScanLevel.Level3 ||
                    (EScanLevel == eScanLevel.Level2 && !IsDeepScanned((RvDir)dbChild)))
                {
                    // this is done first as the CheckADir could change this value if the zip turns out to be corrupt
                    dbChild.FileAdd(fileChild);
                    CheckADir((RvDir)dbChild, false);
                }
                else
                {
                    // this is still needed incase the filenames case (upper/lower characters) have changed, but nothing else
                    dbChild.FileCheckName(fileChild);
                }
                break;

            case FileType.Dir:
                RvDir tDir = (RvDir)dbChild;
                if (tDir.Tree == null)     // do not recurse into directories that are in the tree, as they are processed by the top level code.
                {
                    CheckADir(tDir, true);
                }
                if (_fileErrorAbort)
                {
                    return;
                }
                dbChild.FileAdd(fileChild);
                break;

            case FileType.File:
            case FileType.ZipFile:
                if (dbChild.TimeStamp == fileChild.TimeStamp && dbChild.GotStatus == GotStatus.Corrupt)
                {
                    fileChild.GotStatus = GotStatus.Corrupt;
                }

                dbChild.FileAdd(fileChild);
                break;

            default:
                throw new Exception("Unsuported file type " + dbChild.FileType);
            }
        }
Exemplo n.º 7
0
        // returns number of CHD files in a RvDir
        // will be confused if there are any RvDirs as well as CHD files in 'dir'
        // does not check sub-dirs of 'dir'
        private static int numDisks(RvDir dir)
        {
            int retVal = 0;

            if (dir != null)
            {
                for (int i = 0; i < dir.ChildCount; i++)
                {
                    RvFile chd = dir.Child(i) as RvFile;
                    if ((chd != null) && (chd.FileType == FileType.File) && chd.Name.EndsWith(".chd"))
                    {
                        retVal++;
                    }
                }
            }
            return(retVal);
        }
Exemplo n.º 8
0
        private static bool LoadHeaderFromDat(ref RvDir tDir, ref XmlDocument doc)
        {
            XmlNodeList head = doc.SelectNodes("softwarelist");

            if (head == null)
            {
                return(false);
            }

            if (head.Count == 0)
            {
                return(false);
            }

            if (head[0].Attributes == null)
            {
                return(false);
            }

            RvDat tDat = new RvDat();

            tDat.AddData(RvDat.DatData.DatName, VarFix.CleanFileName(head[0].Attributes.GetNamedItem("name")));
            tDat.AddData(RvDat.DatData.Description, VarFix.String(head[0].Attributes.GetNamedItem("description")));

            string val = VarFix.String(head[0].Attributes.GetNamedItem("forcemerging")).ToLower();

            switch (val.ToLower())
            {
            case "split":
                tDat.AddData(RvDat.DatData.MergeType, "split");
                break;

            case "full":
                tDat.AddData(RvDat.DatData.MergeType, "full");
                break;

            default:
                tDat.AddData(RvDat.DatData.MergeType, "split");
                break;
            }



            tDir.Dat = tDat;
            return(true);
        }
Exemplo n.º 9
0
        public static void ReportStatusReset(RvBase tBase)
        {
            tBase.RepStatusReset();

            FileType ftBase = tBase.FileType;

            if ((ftBase != FileType.Zip) && (ftBase != FileType.SevenZip) && (ftBase != FileType.Dir))
            {
                return;
            }

            RvDir tDir = (RvDir)tBase;

            for (int i = 0; i < tDir.ChildCount; i++)
            {
                ReportStatusReset(tDir.Child(i));
            }
        }
Exemplo n.º 10
0
        private static void LoadRomFromDat(ref RvDir tGame, XmlNode romNode, FileType thisFileType)
        {
            if (romNode.Attributes == null)
            {
                return;
            }

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

            if (name != null)
            {
                RvFile tRom = new RvFile(thisFileType) // changed
                {
                    Name   = VarFix.CleanFullFileName(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")),

                    Dat = tGame.Dat
                };

                if (tRom.Size != null)
                {
                    tRom.FileStatusSet(FileStatus.SizeFromDAT);
                }
                if (tRom.CRC != null)
                {
                    tRom.FileStatusSet(FileStatus.CRCFromDAT);
                }
                if (tRom.SHA1 != null)
                {
                    tRom.FileStatusSet(FileStatus.SHA1FromDAT);
                }

                _indexContinue = tGame.ChildAdd(tRom);
            }
            else if (loadflag.ToLower() == "continue")
            {
                RvFile tZippedFile = (RvFile)tGame.Child(_indexContinue);
                tZippedFile.Size += VarFix.ULong(romNode.Attributes.GetNamedItem("size"));
            }
        }
Exemplo n.º 11
0
        private static void ReportMissingFindSizes(RvDir dir, RvDat dat, ReportType rt)
        {
            for (int i = 0; i < dir.ChildCount; i++)
            {
                RvBase b = dir.Child(i);
                if (b.Dat != null && b.Dat != dat)
                {
                    continue;
                }

                RvFile f = b as RvFile;

                if (f != null)
                {
                    if (
                        (rt == ReportType.PartialMissing && Partial.Contains(f.RepStatus)) ||
                        (rt == ReportType.Fixing && Fixing.Contains(f.RepStatus))
                        )
                    {
                        int fileNameLength  = f.FileNameInsideGame().Length;
                        int fileSizeLength  = f.Size.ToString().Length;
                        int repStatusLength = f.RepStatus.ToString().Length;

                        if (fileNameLength > _fileNameLength)
                        {
                            _fileNameLength = fileNameLength;
                        }
                        if (fileSizeLength > _fileSizeLength)
                        {
                            _fileSizeLength = fileSizeLength;
                        }
                        if (repStatusLength > _repStatusLength)
                        {
                            _repStatusLength = repStatusLength;
                        }
                    }
                }
                RvDir d = b as RvDir;
                if (d != null)
                {
                    ReportMissingFindSizes(d, dat, rt);
                }
            }
        }
Exemplo n.º 12
0
        private static void RemoveOldTree(RvBase dbBase)
        {
            RvDir dbDir = dbBase as RvDir;

            if (dbDir == null)
            {
                return;
            }

            if (dbDir.DatStatus == DatStatus.NotInDat && dbDir.Tree != null)
            {
                dbDir.Tree = null;
            }

            for (int i = 0; i < dbDir.ChildCount; i++)
            {
                RemoveOldTree(dbDir.Child(i));
            }
        }
Exemplo n.º 13
0
        private static void DatSetRemoveUnneededDirs(RvDir tDat)
        {
            for (int g = 0; g < tDat.ChildCount; g++)
            {
                RvDir tGame = (RvDir)tDat.Child(g);
                if (tGame.Game == null)
                {
                    DatSetRemoveUnneededDirs(tGame);
                }
                else
                {
                    for (int r = 0; r < tGame.ChildCount - 1; r++)
                    {
                        // first find any directories, zero length with filename ending in a '/'
                        // there are RvFiles that are really directories (probably inside a zip file)
                        RvFile f0 = (RvFile)tGame.Child(r);
                        if (f0.Name.Length == 0)
                        {
                            continue;
                        }
                        if (f0.Name.Substring(f0.Name.Length - 1, 1) != "/")
                        {
                            continue;
                        }

                        // if the next file contains that found directory, then the directory file can be deleted
                        RvFile f1 = (RvFile)tGame.Child(r + 1);
                        if (f1.Name.Length <= f0.Name.Length)
                        {
                            continue;
                        }

                        if (f0.Name != f1.Name.Substring(0, f0.Name.Length))
                        {
                            continue;
                        }

                        tGame.ChildRemove(r);
                        r--;
                    }
                }
            }
        }
Exemplo n.º 14
0
        private static void WriteDatFile(RvDir dir, bool CHDsAreDisk)
        {
            WriteLine("<?xml version=\"1.0\"?>");
            WriteLine("");
            WriteLine("<datafile>");
            WriteHeader(CHDsAreDisk ? "CHDs as disk - if you see lots of status=nodump, try the other way" :
                        "CHD as rom - if you see lots of empty double-quotes, try the other way");

            /* write Games/Dirs */
            if (CHDsAreDisk)
            {
                ProcessDir(dir);
            }
            else
            {
                PlainProcessDir(dir);
            }

            WriteLine("</datafile>");
        }
Exemplo n.º 15
0
        private static void SetMissingStatus(RvBase dbChild)
        {
            if (dbChild.FileRemove() == EFile.Delete)
            {
                ReportError.SendAndShow("Error is Set Mssing Status in DatUpdate");
                return;
            }


            FileType ft = dbChild.FileType;

            if (ft == FileType.Zip || ft == FileType.Dir)
            {
                RvDir dbDir = (RvDir)dbChild;
                for (int i = 0; i < dbDir.ChildCount; i++)
                {
                    SetMissingStatus(dbDir.Child(i));
                }
            }
        }
Exemplo n.º 16
0
        // CHDs as rom
        private static void PlainProcessDir(RvDir dir, int depth = 1)
        {
            string indent = new string('\t', depth);

            for (int i = 0; i < dir.ChildCount; i++)
            {
                RvDir item = dir.Child(i) as RvDir;
                if ((item != null) && ((item.FileType == FileType.Zip) || (item.FileType == FileType.Dir)))
                {
                    WriteLine(indent + "<game name=\"" + clean(item.Name) + "\">");
                    WriteLine(indent + "\t<description>" + clean(item.Game == null ? item.Name : item.Game.GetData(RvGame.GameData.Description)) + "</description>");

                    for (int j = 0; j < item.ChildCount; j++)
                    {
                        RvFile file = item.Child(j) as RvFile;
                        if (file != null)
                        {
                            WriteLine(indent + "\t<rom name=\"" + clean(file.Name) + "\" size=\"" + file.Size + "\" crc=\"" + ArrByte.ToString(file.CRC) + "\" md5=\"" + ArrByte.ToString(file.MD5) + "\" sha1=\"" + ArrByte.ToString(file.SHA1) + "\"/>");
                        }
                        RvDir aDir = item.Child(j) as RvDir;
                        if (aDir != null)
                        {
                            string dName = aDir.Name;
                            for (int k = 0; k < aDir.ChildCount; k++)
                            {
                                RvFile subFile = aDir.Child(k) as RvFile;
                                WriteLine(indent + "\t<rom name=\"" + dName + "\\" + clean(subFile.Name) + "\" size=\"" + subFile.Size + "\" crc=\"" + ArrByte.ToString(subFile.CRC) + "\" md5=\"" + ArrByte.ToString(subFile.MD5) + "\" sha1=\"" + ArrByte.ToString(subFile.SHA1) + "\"/>");
                            }
                        }
                    }
                    WriteLine(indent + "</game>");
                }
                // only recurse when grandchildren are not CHDs
                if ((item != null) && (item.FileType == FileType.Dir) && !hasChdGrandChildren(item))
                {
                    WriteLine(indent + "<dir name=\"" + clean(item.Name) + "\">");
                    PlainProcessDir(item, depth + 1);
                    WriteLine(indent + "</dir>");
                }
            }
        }
Exemplo n.º 17
0
        private static void DatSetRenameAndRemoveDups(RvDir tDat)
        {
            for (int g = 0; g < tDat.ChildCount; g++)
            {
                RvDir tDir = (RvDir)tDat.Child(g);
                if (tDir.Game == null)
                {
                    DatSetRenameAndRemoveDups(tDir);
                }
                else
                {
                    for (int r = 0; r < tDir.ChildCount - 1; r++)
                    {
                        RvFile f0 = (RvFile)tDir.Child(r);
                        RvFile f1 = (RvFile)tDir.Child(r + 1);

                        if (f0.Name != f1.Name)
                        {
                            continue;
                        }

                        if (f0.Size != f1.Size || !ArrByte.bCompare(f0.CRC, f1.CRC))
                        {
                            tDir.ChildRemove(r + 1);                            // remove F1
                            f1.Name = f1.Name + "_" + ArrByte.ToString(f1.CRC); // rename F1;
                            int pos = tDir.ChildAdd(f1);
                            if (pos < r)
                            {
                                r = pos;
                            }
                            // if this rename moved the File back up the list, start checking again from that file.
                        }
                        else
                        {
                            tDir.ChildRemove(r + 1);
                        }
                        r--;
                    }
                }
            }
        }
Exemplo n.º 18
0
        private static bool LoadMameHeaderFromDat(ref RvDir tDir, ref XmlDocument doc, ref FileType thisFileType)
        {
            if (doc.DocumentElement == null)
            {
                return(false);
            }
            XmlNode head = doc.SelectSingleNode("mame");

            if (head == null || head.Attributes == null)
            {
                return(false);
            }
            RvDat tDat = new RvDat();

            tDat.AddData(RvDat.DatData.DatName, VarFix.CleanFileName(head.Attributes.GetNamedItem("build")));
            tDat.AddData(RvDat.DatData.Description, VarFix.String(head.Attributes.GetNamedItem("build")));

            thisFileType = FileType.ZipFile;
            tDir.Dat     = tDat;
            return(true);
        }
Exemplo n.º 19
0
        private static void LoadRomFromDat(ref RvDir tGame, XmlNode romNode, FileType thisFileType)
        {
            if (romNode.Attributes == null)
            {
                return;
            }


            RvFile tRom = new RvFile(thisFileType)
            {
                Dat    = tGame.Dat,
                Size   = VarFix.ULong(romNode.Attributes.GetNamedItem("size")),
                Name   = VarFix.CleanFullFileName(romNode.Attributes.GetNamedItem("name")),
                CRC    = VarFix.CleanMD5SHA1(romNode.Attributes.GetNamedItem("crc"), 8),
                SHA1   = VarFix.CleanMD5SHA1(romNode.Attributes.GetNamedItem("sha1"), 40),
                MD5    = VarFix.CleanMD5SHA1(romNode.Attributes.GetNamedItem("md5"), 32),
                Merge  = VarFix.CleanFullFileName(romNode.Attributes.GetNamedItem("merge")),
                Status = VarFix.ToLower(romNode.Attributes.GetNamedItem("status"))
            };

            if (tRom.Size != null)
            {
                tRom.FileStatusSet(FileStatus.SizeFromDAT);
            }
            if (tRom.CRC != null)
            {
                tRom.FileStatusSet(FileStatus.CRCFromDAT);
            }
            if (tRom.SHA1 != null)
            {
                tRom.FileStatusSet(FileStatus.SHA1FromDAT);
            }
            if (tRom.MD5 != null)
            {
                tRom.FileStatusSet(FileStatus.MD5FromDAT);
            }

            tGame.ChildAdd(tRom);
        }
Exemplo n.º 20
0
 private static bool hasChdGrandChildren(RvDir aDir)
 {
     if (aDir == null)
     {
         return(false);
     }
     for (int i = 0; i < aDir.ChildCount; i++)
     {
         RvDir item = aDir.Child(i) as RvDir;
         if (item == null)
         {
             continue;
         }
         for (int j = 0; j < item.ChildCount; j++)
         {
             if (item.Child(j).Name.ToLower().EndsWith(".chd"))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Exemplo n.º 21
0
        private static void LoadDiskFromDat(ref RvDir tGame, XmlNode romNode)
        {
            if (romNode.Attributes == null)
            {
                return;
            }

            XmlNode name = romNode.Attributes.GetNamedItem("name");
            RvFile  tRom = new RvFile(FileType.File)
            {
                Name    = VarFix.CleanFullFileName(name) + ".chd",
                SHA1CHD = VarFix.CleanMD5SHA1(romNode.Attributes.GetNamedItem("sha1"), 40),
                Status  = VarFix.ToLower(romNode.Attributes.GetNamedItem("status")),
                Dat     = tGame.Dat
            };

            if (tRom.SHA1CHD != null)
            {
                tRom.FileStatusSet(FileStatus.SHA1CHDFromDAT);
            }

            tGame.ChildAdd(tRom);
        }
Exemplo n.º 22
0
        private static void ScanDirs(uint dirId, string datRoot, string subPath)
        {
            DirectoryInfo di = new DirectoryInfo(Path.Combine(datRoot, subPath));

            DirectoryInfo[] dis = di.GetDirectories();
            foreach (DirectoryInfo d in dis)
            {
                uint nextDirId = RvDir.FindOrInsertIntoDir(dirId, d.Name, Path.Combine(subPath, d.Name) + "\\");
                ScanDirs(nextDirId, datRoot, Path.Combine(subPath, d.Name));
                if (_bgw.CancellationPending)
                {
                    return;
                }
            }

            FileInfo[] fisDat   = di.GetFiles("*.DAT");
            FileInfo[] fisXml   = di.GetFiles("*.XML");
            int        datCount = fisDat.Length + fisXml.Length;

            ReadDat(fisDat, subPath, dirId, datCount > 1);

            ReadDat(fisXml, subPath, dirId, datCount > 1);
        }
Exemplo n.º 23
0
        private static void SetExpanded(RvDir pTree, bool rightClick)
        {
            if (!rightClick)
            {
                pTree.Tree.TreeExpanded = !pTree.Tree.TreeExpanded;
                return;
            }

            // Find the value of the first child node.
            for (int i = 0; i < pTree.ChildCount; i++)
            {
                RvBase b = pTree.Child(i);
                if (b is RvDir)
                {
                    RvDir d = (RvDir)b;
                    if (d.Tree != null)
                    {
                        //Recusivly Set All Child Nodes to this value
                        SetExpandedRecurse(pTree, !d.Tree.TreeExpanded);
                        break;
                    }
                }
            }
        }
Exemplo n.º 24
0
        public static bool ReadMameDat(ref RvDir tDat, XmlDocument doc)
        {
            FileType thisFileType = FileType.Unknown;

            if (!LoadMameHeaderFromDat(ref tDat, ref doc, ref thisFileType))
            {
                return(false);
            }

            if (doc.DocumentElement == null)
            {
                return(false);
            }

            XmlNodeList dirNodeList = doc.DocumentElement.SelectNodes("dir");

            if (dirNodeList != null)
            {
                for (int i = 0; i < dirNodeList.Count; i++)
                {
                    LoadDirFromDat(ref tDat, dirNodeList[i], thisFileType);
                }
            }

            XmlNodeList gameNodeList = doc.DocumentElement.SelectNodes("game");

            if (gameNodeList != null)
            {
                for (int i = 0; i < gameNodeList.Count; i++)
                {
                    LoadGameFromDat(ref tDat, gameNodeList[i], thisFileType);
                }
            }

            return(true);
        }
Exemplo n.º 25
0
        public void SetSelected(RvDir selected)
        {
            bool found = false;

            RvDir t = selected;

            while (t != null)
            {
                if (t.Tree != null)
                {
                    if (!found)
                    {
                        _lSelected = t;
                        found      = true;
                    }
                    else
                    {
                        t.Tree.TreeExpanded = true;
                    }
                }
                t = t.Parent;
            }
            SetupInt();
        }
Exemplo n.º 26
0
        public static bool ReadDat(ref RvDir tDat, XmlDocument doc)
        {
            if (!LoadHeaderFromDat(ref tDat, ref doc))
            {
                return(false);
            }

            if (doc.DocumentElement == null)
            {
                return(false);
            }
            XmlNodeList gameNodeList = doc.DocumentElement.SelectNodes("software");

            if (gameNodeList == null)
            {
                return(false);
            }
            for (int i = 0; i < gameNodeList.Count; i++)
            {
                LoadGameFromDat(ref tDat, gameNodeList[i]);
            }

            return(true);
        }
Exemplo n.º 27
0
        private static bool LoadGameFromDat(ref RvDir tDat, FileType thisFileType)
        {
            if (DatFileLoader.Next != "(")
            {
                DatUpdate.SendAndShowDat(Resources.DatCmpReader_LoadGameFromDat_not_found_after_game, DatFileLoader.Filename);
                return(false);
            }
            DatFileLoader.Gn();

            string snext = DatFileLoader.Next.ToLower();

            if (snext != "name")
            {
                DatUpdate.SendAndShowDat(Resources.DatCmpReader_LoadGameFromDat_Name_not_found_as_first_object_in, DatFileLoader.Filename);
                return(false);
            }

            RvDir parent = tDat;

            string fullname = VarFix.CleanFullFileName(DatFileLoader.GnRest());

            if (_cleanFileNames)
            {
                fullname = fullname.Replace("/", "-");
            }

            while (fullname.Contains("/"))
            {
                int    firstSlash = fullname.IndexOf("/", StringComparison.Ordinal);
                string dir        = fullname.Substring(0, firstSlash);
                fullname = fullname.Substring(firstSlash + 1);
                int index;
                if (parent.ChildNameSearch(new RvDir(FileType.Dir)
                {
                    Name = dir
                }, out index) == 0)
                {
                    parent = (RvDir)parent.Child(index);
                }
                else
                {
                    RvDir tpDir = new RvDir(FileType.Dir)
                    {
                        Name      = dir,
                        DatStatus = DatStatus.InDatCollect,
                        Dat       = tDat.Dat,
                        Tree      = new RvTreeRow()
                    };
                    parent.ChildAdd(tpDir, index);
                    parent = tpDir;
                }
            }

            if (fullname.Length > 4 && fullname.ToLower().Substring(fullname.Length - 4, 4) == ".zip")
            {
                fullname = fullname.Substring(0, fullname.Length - 4);
            }

            RvDir tDir = new RvDir(thisFileType == FileType.File ? FileType.Dir : FileType.Zip)
            {
                Name = fullname
            };

            DatFileLoader.Gn();
            tDir.Game      = new RvGame();
            tDir.DatStatus = DatStatus.InDatCollect;
            tDir.Dat       = tDat.Dat;
            int index1;

            string testName  = tDir.Name;
            int    nameCount = 0;

            while (parent.ChildNameSearch(tDir, out index1) == 0)
            {
                tDir.Name = testName + "_" + nameCount;
                nameCount++;
            }
            parent.ChildAdd(tDir, index1);


            while (DatFileLoader.Next != ")")
            {
                switch (DatFileLoader.Next.ToLower())
                {
                case "file":
                    DatFileLoader.Gn();
                    if (!LoadRomFromDat(ref tDir, thisFileType))
                    {
                        return(false);
                    }
                    DatFileLoader.Gn();
                    break;

                default:
                    DatUpdate.SendAndShowDat(Resources.DatCmpReader_ReadDat_Error_keyword + DatFileLoader.Next + Resources.DatCmpReader_LoadGameFromDat_not_known_in_game, DatFileLoader.Filename);
                    DatFileLoader.Gn();
                    break;
                }
            }


            return(true);
        }
Exemplo n.º 28
0
        private static void UpdateDirs(RvDir dbDir, RvDir fileDir)
        {
            int dbIndex   = 0;
            int scanIndex = 0;

            dbDir.DatStatus = DatStatus.InDatCollect;
            if (dbDir.Tree == null)
            {
                Debug.WriteLine("Adding Tree View to " + dbDir.Name);
                dbDir.Tree = new RvTreeRow();
            }


            Debug.WriteLine("");
            Debug.WriteLine("Now scanning dirs");

            while (dbIndex < dbDir.ChildCount || scanIndex < fileDir.ChildCount)
            {
                RvBase dbChild   = null;
                RvBase fileChild = null;
                int    res       = 0;

                if (dbIndex < dbDir.ChildCount && scanIndex < fileDir.ChildCount)
                {
                    dbChild   = dbDir.Child(dbIndex);
                    fileChild = fileDir.Child(scanIndex);
                    res       = DBHelper.CompareName(dbChild, fileChild);
                    Debug.WriteLine("Checking " + dbChild.Name + " : and " + fileChild.Name + " : " + res);
                }
                else if (scanIndex < fileDir.ChildCount)
                {
                    fileChild = fileDir.Child(scanIndex);
                    res       = 1;
                    Debug.WriteLine("Checking : and " + fileChild.Name + " : " + res);
                }
                else if (dbIndex < dbDir.ChildCount)
                {
                    dbChild = dbDir.Child(dbIndex);
                    res     = -1;
                }
                switch (res)
                {
                case 0:
                    // found a matching directory in DatRoot So recurse back into it

                    if (dbChild.GotStatus == GotStatus.Got)
                    {
                        if (dbChild.Name != fileChild.Name)              // check if the case of the Item in the DB is different from the Dat Root Actual filename
                        {
                            if (!string.IsNullOrEmpty(dbChild.FileName)) // if we do not already have a different case name stored
                            {
                                dbChild.FileName = dbChild.Name;         // copy the DB filename to the FileName
                            }
                            else                                         // We already have a different case filename found in RomRoot
                            {
                                if (dbChild.FileName == fileChild.Name)  // check if the Datroot name does now match the name in the DB Filename
                                {
                                    dbChild.FileName = null;             // if it does undo the BadCase Flag
                                }
                            }
                            dbChild.Name = fileChild.Name;     // Set the db Name to match the Datroot Name.
                        }
                    }
                    else
                    {
                        dbChild.Name = fileChild.Name;
                    }

                    UpdateDatList((RvDir)dbChild, (RvDir)fileChild);
                    dbIndex++;
                    scanIndex++;
                    break;

                case 1:
                    // found a new directory in Dat
                    RvDir tDir = new RvDir(FileType.Dir)
                    {
                        Name      = fileChild.Name,
                        Tree      = new RvTreeRow(),
                        DatStatus = DatStatus.InDatCollect,
                    };
                    dbDir.ChildAdd(tDir, dbIndex);
                    Debug.WriteLine("Adding new Dir and Calling back in to check this DIR " + tDir.Name);
                    UpdateDatList(tDir, (RvDir)fileChild);

                    dbIndex++;
                    scanIndex++;
                    break;

                case -1:
                    // all files
                    dbIndex++;
                    break;
                }
            }
        }
Exemplo n.º 29
0
        /*
         * private static void SetInDat(RvDir tDir)
         * {
         *  tDir.DatStatus = DatStatus.InDatCollect;
         *  if (tDir.Parent != null)
         *      SetInDat(tDir.Parent);
         * }
         */

        private static Boolean MergeInDat(RvDir dbDat, RvDir newDat, out RvDat conflict, bool checkOnly)
        {
            conflict = null;
            int dbIndex  = 0;
            int newIndex = 0;

            while (dbIndex < dbDat.ChildCount || newIndex < newDat.ChildCount)
            {
                RvBase dbChild     = null;
                RvBase newDatChild = null;
                int    res         = 0;

                if (dbIndex < dbDat.ChildCount && newIndex < newDat.ChildCount)
                {
                    dbChild     = dbDat.Child(dbIndex);   // are files
                    newDatChild = newDat.Child(newIndex); // is from a dat item
                    res         = DBHelper.CompareName(dbChild, newDatChild);
                }
                else if (newIndex < newDat.ChildCount)
                {
                    newDatChild = newDat.Child(newIndex);
                    res         = 1;
                }
                else if (dbIndex < dbDat.ChildCount)
                {
                    dbChild = dbDat.Child(dbIndex);
                    res     = -1;
                }

                if (res == 0)
                {
                    if (dbChild == null || newDatChild == null)
                    {
                        SendAndShowDat(Resources.DatUpdate_MergeInDat_Error_in_Logic, dbDat.FullName);
                        break;
                    }


                    List <RvBase> dbDats       = new List <RvBase>();
                    List <RvBase> newDats      = new List <RvBase>();
                    int           dbDatsCount  = 1;
                    int           newDatsCount = 1;


                    dbDats.Add(dbChild);
                    newDats.Add(newDatChild);

                    while (dbIndex + dbDatsCount < dbDat.ChildCount && DBHelper.CompareName(dbChild, dbDat.Child(dbIndex + dbDatsCount)) == 0)
                    {
                        dbDats.Add(dbDat.Child(dbIndex + dbDatsCount));
                        dbDatsCount += 1;
                    }
                    while (newIndex + newDatsCount < newDat.ChildCount && DBHelper.CompareName(newDatChild, newDat.Child(newIndex + newDatsCount)) == 0)
                    {
                        newDats.Add(newDat.Child(newIndex + newDatsCount));
                        newDatsCount += 1;
                    }

                    if (dbDatsCount > 1 || newDatsCount > 1)
                    {
                        ReportError.SendAndShow("Double Name Found");
                    }

                    for (int indexdb = 0; indexdb < dbDatsCount; indexdb++)
                    {
                        if (dbDats[indexdb].DatStatus == DatStatus.NotInDat)
                        {
                            continue;
                        }

                        if (checkOnly)
                        {
                            conflict = dbChild.Dat;
                            return(true);
                        }

                        SendAndShowDat(Resources.DatUpdate_MergeInDat_Unkown_Update_Dat_Status + dbChild.DatStatus, dbDat.FullName);
                        break;
                    }

                    if (!checkOnly)
                    {
                        for (int indexNewDats = 0; indexNewDats < newDatsCount; indexNewDats++)
                        {
                            if (newDats[indexNewDats].SearchFound)
                            {
                                continue;
                            }

                            for (int indexDbDats = 0; indexDbDats < dbDatsCount; indexDbDats++)
                            {
                                if (dbDats[indexDbDats].SearchFound)
                                {
                                    continue;
                                }

                                bool matched = FullCompare(dbDats[indexDbDats], newDats[indexNewDats]);
                                if (!matched)
                                {
                                    continue;
                                }

                                dbDats[indexDbDats].DatAdd(newDats[indexNewDats]);

                                FileType ft = dbChild.FileType;

                                if (ft == FileType.Zip || ft == FileType.Dir)
                                {
                                    RvDir dChild    = (RvDir)dbChild;
                                    RvDir dNewChild = (RvDir)newDatChild;
                                    MergeInDat(dChild, dNewChild, out conflict, checkOnly);
                                }

                                dbDats[indexDbDats].SearchFound   = true;
                                newDats[indexNewDats].SearchFound = true;
                            }
                        }

                        for (int indexNewDats = 0; indexNewDats < newDatsCount; indexNewDats++)
                        {
                            if (newDats[indexNewDats].SearchFound)
                            {
                                continue;
                            }

                            dbDat.ChildAdd(newDats[indexNewDats], dbIndex);
                            dbChild = dbDat.Child(dbIndex);
                            SetMissingStatus(dbChild);

                            dbIndex++;
                        }
                    }

                    dbIndex  += dbDatsCount;
                    newIndex += newDatsCount;
                }

                if (res == 1)
                {
                    if (!checkOnly)
                    {
                        dbDat.ChildAdd(newDatChild, dbIndex);
                        dbChild = dbDat.Child(dbIndex);
                        SetMissingStatus(dbChild);

                        dbIndex++;
                    }
                    newIndex++;
                }

                if (res == -1)
                {
                    dbIndex++;
                }
            }
            return(false);
        }
Exemplo n.º 30
0
        // CHDs as disk
        private static void ProcessDir(RvDir dir, int depth = 1)
        {
            string        indent = new string('\t', depth); // recursive indent
            List <string> disks  = new List <string> {
                string.Empty
            };

            for (int i = 0; i < dir.ChildCount; i++)
            {
                RvDir item = dir.Child(i) as RvDir;
                if ((item != null) && (item.FileType == FileType.Dir))
                {
                    if ((disks.Count > 2) && (item.Name != disks[0])) // flush the last one if there were only CHDs in it
                    {
                        justCHDs(indent, disks);
                        disks.Clear();
                    }
                    // tabulate next disk list, if any
                    disks = new List <string> {
                        item.Name, item.Game == null ? item.Name : item.Game.GetData(RvGame.GameData.Description)
                    };
                    for (int j = 0; j < item.ChildCount; j++)
                    {
                        RvFile chd = item.Child(j) as RvFile;
                        if ((chd != null) && (chd.FileType == FileType.File) && chd.Name.EndsWith(".chd"))
                        {
                            if (!string.IsNullOrEmpty(ArrByte.ToString(chd.SHA1CHD)))
                            {
                                disks.Add(indent + "\t<disk name=\"" + clean(chd.Name).Replace(".chd", "") + "\" sha1=\"" + ArrByte.ToString(chd.SHA1CHD) + "\"/>");
                            }
                            else
                            {
                                disks.Add(indent + "\t<disk name=\"" + clean(chd.Name).Replace(".chd", "") + "\" status=\"nodump\"/>");
                            }
                        }
                    }
                }
                if ((item != null) && (item.FileType == FileType.Zip))
                {
                    WriteLine(indent + "<game name=\"" + clean(item.Name) + "\">");
                    string desc = item.Game == null ? item.Name : item.Game.GetData(RvGame.GameData.Description);
                    WriteLine(indent + "\t<description>" + clean(desc) + "</description>");

                    for (int j = 0; j < item.ChildCount; j++)
                    {
                        RvFile file = item.Child(j) as RvFile;
                        if (file != null)
                        {
                            WriteLine(indent + "\t<rom name=\"" + clean(file.Name) + "\" size=\"" + file.Size + "\" crc=\"" + ArrByte.ToString(file.CRC) + "\" md5=\"" + ArrByte.ToString(file.MD5) + "\" sha1=\"" + ArrByte.ToString(file.SHA1) + "\"/>");
                        }
                    }

                    if (disks.Count > 2) // take care of previous list of CHDs now
                    {
                        for (int j = 2; j < disks.Count; j++)
                        {
                            WriteLine(disks[j]);
                        }
                        disks.Clear();
                    }

                    WriteLine(indent + "</game>");
                }

                if ((item != null) && (item.FileType == FileType.Dir))
                {
                    if (numDisks(item) == 0) // only recurse when children are not CHDs
                    {
                        WriteLine(indent + "<dir name=\"" + clean(item.Name) + "\">");
                        ProcessDir(item, depth + 1);
                        WriteLine(indent + "</dir>");
                    }
                }
            }
            // check for one last CHDs-only game
            if (disks.Count > 2)
            {
                justCHDs(indent, disks);
            }
        }