Пример #1
0
        private static void GetSelectedFilesSortSHA1CHD(ref List <RvFile> lstFiles, RvBase val, bool selected)
        {
            if (selected)
            {
                RvFile rvFile = val as RvFile;
                if (rvFile != null)
                {
                    if (rvFile.SHA1CHD != null)
                    {
                        lstFiles.Add(rvFile);
                    }
                }
            }

            RvDir rvVal = val as RvDir;

            if (rvVal == null)
            {
                return;
            }

            for (int i = 0; i < rvVal.ChildCount; i++)
            {
                bool nextSelect = selected;
                if (rvVal.Tree != null)
                {
                    nextSelect = rvVal.Tree.Checked == RvTreeRow.TreeSelect.Selected;
                }
                GetSelectedFilesSortSHA1CHD(ref lstFiles, rvVal.Child(i), nextSelect);
            }
        }
Пример #2
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;
         }
         else
         {
             for (int j = 0; j < item.ChildCount; j++)
             {
                 if (item.Child(j).Name.ToLower().EndsWith(".chd"))
                 {
                     return(true);
                 }
             }
         }
     }
     return(false);
 }
Пример #3
0
        private static void MarkAsMissing(RvDir dbDir)
        {
            for (int i = 0; i < dbDir.ChildCount; i++)
            {
                RvBase dbChild = dbDir.Child(i);

                if (dbChild.FileRemove() == EFile.Delete)
                {
                    dbDir.ChildRemove(i);
                    i--;
                }
                else
                {
                    switch (dbChild.FileType)
                    {
                    case FileType.Zip:
                        MarkAsMissing((RvDir)dbChild);
                        break;

                    case FileType.Dir:
                        RvDir tDir = (RvDir)dbChild;
                        if (tDir.Tree == null)
                        {
                            MarkAsMissing(tDir);
                        }
                        break;
                    }
                }
            }
        }
Пример #4
0
        private static void ReportMissing(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))
                        )
                    {
                        string filename = f.FileNameInsideGame();
                        string crc      = ArrByte.ToString(f.CRC);
                        _ts.WriteLine("| " + filename + new string(' ', _fileNameLength + 1 - filename.Length) + "| "
                                      + f.Size + new string(' ', _fileSizeLength + 1 - f.Size.ToString().Length) + "| "
                                      + crc + new string(' ', 9 - crc.Length) + "| "
                                      + f.RepStatus + new string(' ', _repStatusLength + 1 - f.RepStatus.ToString().Length) + "|");
                    }
                }
                RvDir d = b as RvDir;
                if (d != null)
                {
                    ReportMissing(d, dat, rt);
                }
            }
        }
Пример #5
0
        private static void GetSelectedDirList(ref List <RvDir> lstDir, RvDir thisDir)
        {
            for (int i = 0; i < thisDir.ChildCount; i++)
            {
                if (thisDir.DatStatus != DatStatus.InDatCollect)
                {
                    continue;
                }
                RvDir tDir = thisDir.Child(i) as RvDir;
                if (tDir == null)
                {
                    continue;
                }
                if (tDir.Tree == null)
                {
                    continue;
                }
                if (tDir.Tree.Checked == RvTreeRow.TreeSelect.Selected)
                {
                    lstDir.Add(tDir);
                }

                GetSelectedDirList(ref lstDir, tDir);
            }
        }
Пример #6
0
        private static void DatSetRemoveGameDir(RvDir newDir)
        {
            if (newDir.ChildCount != 1)
            {
                return;
            }

            RvDir child = newDir.Child(0) as RvDir;

            if (child.FileType != FileType.Dir)
            {
                return;
            }

            if (child.Game == null)
            {
                return;
            }

            newDir.ChildRemove(0);
            newDir.Game = child.Game;
            for (int i = 0; i < child.ChildCount; i++)
            {
                newDir.ChildAdd(child.Child(i), i);
            }
        }
Пример #7
0
        private static void FindParentSet(RvDir searchGame, RvDir parentDir, ref List <RvDir> lstParentGames)
        {
            if (searchGame.Game == null)
            {
                return;
            }

            string parentName = searchGame.Game.GetData(RvGame.GameData.RomOf);

            if (String.IsNullOrEmpty(parentName) || parentName == searchGame.Name)
            {
                parentName = searchGame.Game.GetData(RvGame.GameData.CloneOf);
            }
            if (String.IsNullOrEmpty(parentName) || parentName == searchGame.Name)
            {
                return;
            }

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

            if (intResult == 0)
            {
                RvDir parentGame = (RvDir)parentDir.Child(intIndex);
                lstParentGames.Add(parentGame);
                FindParentSet(parentGame, parentDir, ref lstParentGames);
            }
        }
Пример #8
0
        private static void ProcessDir(RvDir dir, int depth = 1)
        {
            string d = new string(' ', 4 * depth);

            for (int i = 0; i < dir.ChildCount; i++)
            {
                RvDir game = dir.Child(i) as RvDir;
                if (game != null && game.FileType == FileType.Zip)
                {
                    WriteLine(d + "<game name=\"" + clean(game.Name) + "\">");
                    WriteLine(d + "    <description>" + clean(game.Name) + "</description>");


                    for (int j = 0; j < game.ChildCount; j++)
                    {
                        RvFile file = game.Child(j) as RvFile;
                        if (file != null)
                        {
                            WriteLine(d + "    <rom name=\"" + clean(file.Name) + "\" size=\"" + file.Size + "\" crc=\"" + Utils.ArrByte.ToString(file.CRC) + "\" md5=\"" + Utils.ArrByte.ToString(file.MD5) + "\" sha1=\"" + Utils.ArrByte.ToString(file.SHA1) + "\"/>");
                        }
                    }
                    WriteLine(d + "</game>");
                }
                if (game != null && game.FileType == FileType.Dir)
                {
                    WriteLine(d + "<dir name=\"" + clean(game.Name) + "\">");
                    ProcessDir(game, depth + 1);
                    WriteLine(d + "</dir>");
                }
            }
        }
Пример #9
0
        private void SetupInt()
        {
            _yPos = 0;

            int treeCount = _lTree.ChildCount;

            if (treeCount >= 1)
            {
                for (int i = 0; i < treeCount - 1; i++)
                {
                    SetupTree((RvDir)_lTree.Child(i), "├");
                }

                SetupTree((RvDir)_lTree.Child(treeCount - 1), "└");
            }
            AutoScrollMinSize = new Size(500, _yPos);
            Refresh();
        }
Пример #10
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--;
                    }
                }
            }
        }
Пример #11
0
        private bool CheckMouseDown(RvDir pTree, int x, int y, MouseEventArgs mevent)
        {
            if (pTree.Tree.RChecked.Contains(x, y))
            {
                if (pTree.Tree.Checked == RvTreeRow.TreeSelect.Disabled)
                {
                    return(true);
                }

                _mousehit = true;
                SetChecked(pTree, pTree.Tree.Checked == RvTreeRow.TreeSelect.Selected ? RvTreeRow.TreeSelect.UnSelected : RvTreeRow.TreeSelect.Selected);
                return(true);
            }

            if (pTree.Tree.RExpand.Contains(x, y))
            {
                _mousehit = true;
                SetExpanded(pTree, mevent.Button == MouseButtons.Right);
                return(true);
            }

            if (pTree.Tree.RText.Contains(x, y))
            {
                _mousehit = true;

                if (RvSelected != null)
                {
                    RvSelected(pTree, mevent);
                }

                _lSelected = pTree;
                return(true);
            }

            if (pTree.Tree.TreeExpanded)
            {
                for (int i = 0; i < pTree.ChildCount; i++)
                {
                    RvBase rBase = pTree.Child(i);
                    if (rBase is RvDir)
                    {
                        RvDir rDir = (RvDir)rBase;
                        if (rDir.Tree != null)
                        {
                            if (CheckMouseDown(rDir, x, y, mevent))
                            {
                                return(true);
                            }
                        }
                    }
                }
            }

            return(false);
        }
Пример #12
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>");
                }
            }
        }
Пример #13
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--;
                    }
                }
            }
        }
Пример #14
0
 private static bool IsDeepScanned(RvDir tZip)
 {
     for (int i = 0; i < tZip.ChildCount; i++)
     {
         RvFile zFile = tZip.Child(i) as RvFile;
         if (zFile != null && zFile.GotStatus == GotStatus.Got &&
             (!zFile.FileStatusIs(FileStatus.SizeVerified) || !zFile.FileStatusIs(FileStatus.CRCVerified) || !zFile.FileStatusIs(FileStatus.SHA1Verified) || !zFile.FileStatusIs(FileStatus.MD5Verified)))
         {
             return(false);
         }
     }
     return(true);
 }
Пример #15
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);
             }
         }
     }
 }
Пример #16
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);
             }
         }
     }
 }
Пример #17
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);
        }
Пример #18
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);
        }
Пример #19
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));
            }
        }
Пример #20
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"));
            }
        }
Пример #21
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);
                }
            }
        }
Пример #22
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));
            }
        }
Пример #23
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));
                }
            }
        }
Пример #24
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;
                    }
                }
            }
        }
Пример #25
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);
        }
Пример #26
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);
            }
        }
Пример #27
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;
                }
            }
        }
Пример #28
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);
        }
Пример #29
0
        private static void RemoveOldDats(RvBase dbDir, RvDir tmpDir)
        {
            // now compare the old and new dats removing any old dats
            // in the current directory

            RvDir lDir = dbDir as RvDir;

            if (lDir == null)
            {
                return;
            }

            int dbIndex   = 0;
            int scanIndex = 0;

            while (dbIndex < lDir.DirDatCount || scanIndex < tmpDir.DirDatCount)
            {
                RvDat dbDat   = null;
                RvDat fileDat = null;
                int   res     = 0;

                if (dbIndex < lDir.DirDatCount && scanIndex < tmpDir.DirDatCount)
                {
                    dbDat   = lDir.DirDat(dbIndex);
                    fileDat = tmpDir.DirDat(scanIndex);
                    res     = DBHelper.DatCompare(dbDat, fileDat);
                }
                else if (scanIndex < tmpDir.DirDatCount)
                {
                    //this is a new dat that we have now found at the end of the list
                    //fileDat = tmpDir.DirDat(scanIndex);
                    res = 1;
                }
                else if (dbIndex < lDir.DirDatCount)
                {
                    dbDat = lDir.DirDat(dbIndex);
                    res   = -1;
                }

                switch (res)
                {
                case 0:
                    dbDat.Status = DatUpdateStatus.Correct;
                    dbIndex++;
                    scanIndex++;
                    break;

                case 1:
                    // this is a new dat that we will add next time around
                    scanIndex++;
                    break;

                case -1:
                    dbDat.Status = DatUpdateStatus.Delete;
                    lDir.DirDatRemove(dbIndex);
                    break;
                }
            }

            // now scan the child directory structure of this directory
            dbIndex   = 0;
            scanIndex = 0;

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

                if (dbIndex < lDir.ChildCount && scanIndex < tmpDir.ChildCount)
                {
                    dbChild   = lDir.Child(dbIndex);
                    fileChild = tmpDir.Child(scanIndex);
                    res       = DBHelper.CompareName(dbChild, fileChild);
                }
                else if (scanIndex < tmpDir.ChildCount)
                {
                    //found a new directory on the end of the list
                    //fileChild = tmpDir.Child(scanIndex);
                    res = 1;
                }
                else if (dbIndex < lDir.ChildCount)
                {
                    dbChild = lDir.Child(dbIndex);
                    res     = -1;
                }
                switch (res)
                {
                case 0:
                    // found a matching directory in DatRoot So recurse back into it
                    RemoveOldDats(dbChild, (RvDir)fileChild);
                    dbIndex++;
                    scanIndex++;
                    break;

                case 1:
                    // found a new directory will be added later
                    scanIndex++;
                    break;

                case -1:
                    if (dbChild.FileType == FileType.Dir && dbChild.Dat == null)
                    {
                        RemoveOldDats(dbChild, new RvDir(FileType.Dir));
                    }
                    dbIndex++;
                    break;
                }
            }
        }
Пример #30
0
        private void SetupTree(RvDir pTree, string pTreeBranches)
        {
            int nodeDepth = pTreeBranches.Length - 1;

            pTree.Tree.TreeBranches = pTreeBranches;

            pTree.Tree.RTree    = new Rectangle(0, _yPos - 8, nodeDepth * 18, 16);
            pTree.Tree.RExpand  = new Rectangle(5 + nodeDepth * 18, _yPos + 4, 9, 9);
            pTree.Tree.RChecked = new Rectangle(20 + nodeDepth * 18, _yPos + 2, 13, 13);
            pTree.Tree.RIcon    = new Rectangle(35 + nodeDepth * 18, _yPos, 16, 16);
            pTree.Tree.RText    = new Rectangle(51 + nodeDepth * 18, _yPos, 500, 16);

            pTreeBranches = pTreeBranches.Replace("├", "│");
            pTreeBranches = pTreeBranches.Replace("└", " ");

            _yPos = _yPos + 16;

            bool found = false;
            int  last  = 0;

            for (int i = 0; i < pTree.ChildCount; i++)
            {
                RvBase t = pTree.Child(i);
                if (t is RvDir)
                {
                    if (((RvDir)t).Tree != null)
                    {
                        found = true;
                        if (pTree.Tree.TreeExpanded)
                        {
                            last = i;
                        }
                    }
                }
            }
            if (!found)
            {
                pTree.Tree.RExpand = new Rectangle(0, 0, 0, 0);
            }



            for (int i = 0; i < pTree.ChildCount; i++)
            {
                RvBase t = pTree.Child(i);
                if (t is RvDir)
                {
                    if (((RvDir)t).Tree != null)
                    {
                        if (pTree.Tree.TreeExpanded)
                        {
                            if (i != last)
                            {
                                SetupTree((RvDir)pTree.Child(i), pTreeBranches + "├");
                            }
                            else
                            {
                                SetupTree((RvDir)pTree.Child(i), pTreeBranches + "└");
                            }
                        }
                    }
                }
            }
        }