Esempio n. 1
0
        private static void DBFileNotFound(RvBase dbChild, RvDir dbDir, ref int dbIndex)
        {
            if (dbChild == null)
            {
                ReportError.SendAndShow(Resources.FileScanning_CheckADir_Error_in_File_Scanning_Code);
                return;
            }

            if (dbChild.FileRemove() == EFile.Delete)
            {
                dbDir.ChildRemove(dbIndex);
            }
            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;
                }
                dbIndex++;
            }
        }
Esempio n. 2
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;
                    }
                }
            }
        }
Esempio n. 3
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);
            }
        }
Esempio n. 4
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--;
                    }
                }
            }
        }
Esempio n. 5
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);
        }
Esempio n. 6
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--;
                    }
                }
            }
        }
Esempio n. 7
0
        private static bool RecursiveDatTree(RvDir tDir, out int datCount)
        {
            datCount = 0;
            string strPath = tDir.DatFullName;

            if (!Directory.Exists(strPath))
            {
                ReportError.Show(Resources.DatUpdate_UpdateDatList_Path + strPath + Resources.DatUpdate_UpdateDatList_Not_Found);
                return(false);
            }

            DirectoryInfo oDir = new DirectoryInfo(strPath);

            FileInfo[] oFilesIn = oDir.GetFiles("*.dat", false);
            datCount += oFilesIn.Length;
            foreach (FileInfo file in oFilesIn)
            {
                RvDat tDat = new RvDat();
                tDat.AddData(RvDat.DatData.DatFullName, file.FullName);
                tDat.TimeStamp = file.LastWriteTime;
                tDir.DirDatAdd(tDat);
            }


            oFilesIn  = oDir.GetFiles("*.xml", false);
            datCount += oFilesIn.Length;
            foreach (FileInfo file in oFilesIn)
            {
                RvDat tDat = new RvDat();
                tDat.AddData(RvDat.DatData.DatFullName, file.FullName);
                tDat.TimeStamp = file.LastWriteTime;
                tDir.DirDatAdd(tDat);
            }

            if (tDir.DirDatCount > 1)
            {
                for (int i = 0; i < tDir.DirDatCount; i++)
                {
                    tDir.DirDat(i).AutoAddDirectory = true;
                }
            }

            DirectoryInfo[] oSubDir = oDir.GetDirectories(false);

            foreach (DirectoryInfo t in oSubDir)
            {
                RvDir cDir = new RvDir(FileType.Dir)
                {
                    Name = t.Name, DatStatus = DatStatus.InDatCollect
                };
                int index = tDir.ChildAdd(cDir);

                int retDatCount;

                RecursiveDatTree(cDir, out retDatCount);
                datCount += retDatCount;

                if (retDatCount == 0)
                {
                    tDir.ChildRemove(index);
                }
            }

            return(true);
        }
Esempio n. 8
0
        private static void DatSetCreateSubDirs(RvDir tDat)
        {
            for (int g = 0; g < tDat.ChildCount; g++)
            {
                if (tDat.Child(g).FileType == FileType.Zip)
                {
                    continue;
                }

                RvDir datGame = (RvDir)tDat.Child(g);

                // first do a quick check to see if anything needs done.
                bool fixNeeded = false;
                for (int r = 0; r < datGame.ChildCount; r++)
                {
                    fixNeeded = datGame.Child(r).Name.Contains("/");

                    if (fixNeeded)
                    {
                        break;
                    }
                }
                // if nothing needs done skip to next game
                if (!fixNeeded)
                {
                    continue;
                }


                RvDir fixedGame = new RvDir(FileType.Dir);
                while (datGame.ChildCount > 0)
                {
                    RvBase nextChild = datGame.Child(0);
                    datGame.ChildRemove(0);
                    if (nextChild.GetType() == typeof(RvFile))
                    {
                        RvFile tFile = (RvFile)nextChild;
                        if (tFile.Name.Contains("/"))
                        {
                            RvDir tBase = fixedGame;
                            Debug.WriteLine("tFile " + tFile.TreeFullName);
                            while (tFile.Name.Contains("/"))
                            {
                                int    dirIndex = tFile.Name.IndexOf("/", StringComparison.Ordinal);
                                string dirName  = tFile.Name.Substring(0, dirIndex);
                                RvDir  tDir     = new RvDir(FileType.Dir)
                                {
                                    Name      = dirName,
                                    DatStatus = DatStatus.InDatCollect,
                                    Dat       = datGame.Dat
                                };
                                int index;
                                if (tBase.ChildNameSearch(tDir, out index) != 0)
                                {
                                    tBase.ChildAdd(tDir, index);
                                }
                                tBase      = (RvDir)tBase.Child(index);
                                tFile.Name = tFile.Name.Substring(tFile.Name.IndexOf("/", StringComparison.Ordinal) + 1);
                            }
                            tBase.ChildAdd(tFile);
                        }
                        else
                        {
                            fixedGame.ChildAdd(nextChild);
                        }
                    }
                    else
                    {
                        fixedGame.ChildAdd(nextChild);
                    }
                }

                for (int r = 0; r < fixedGame.ChildCount; r++)
                {
                    datGame.ChildAdd(fixedGame.Child(r), r);
                }
            }
        }
Esempio n. 9
0
        private static void DatSetMergeSets(RvDir tDat)
        {
            for (int g = tDat.ChildCount - 1; g >= 0; g--)
            {
                RvDir mGame = (RvDir)tDat.Child(g);

                if (mGame.Game == null)
                {
                    DatSetMergeSets(mGame);
                    continue;
                }

                List <RvDir> lstParentGames = new List <RvDir>();
                FindParentSet(mGame, tDat, ref lstParentGames);
                while (lstParentGames.Count > 0 && lstParentGames[lstParentGames.Count - 1].Game.GetData(RvGame.GameData.IsBios).ToLower() == "yes")
                {
                    lstParentGames.RemoveAt(lstParentGames.Count - 1);
                }

                if (lstParentGames.Count <= 0)
                {
                    continue;
                }

                RvDir romofGame = lstParentGames[lstParentGames.Count - 1];

                bool founderror = false;
                for (int r = 0; r < mGame.ChildCount; r++)
                {
                    string name      = mGame.Child(r).Name;
                    string mergename = ((RvFile)mGame.Child(r)).Merge;

                    for (int r1 = 0; r1 < romofGame.ChildCount; r1++)
                    {
                        if ((name == romofGame.Child(r1).Name || mergename == romofGame.Child(r1).Name) &&
                            (ArrByte.iCompare(((RvFile)mGame.Child(r)).CRC, ((RvFile)romofGame.Child(r1)).CRC) != 0 ||
                             ((RvFile)mGame.Child(r)).Size != ((RvFile)romofGame.Child(r1)).Size))
                        {
                            founderror = true;
                        }
                    }
                }
                if (founderror)
                {
                    mGame.Game.DeleteData(RvGame.GameData.RomOf);
                    continue;
                }

                for (int r = 0; r < mGame.ChildCount; r++)
                {
                    string name      = mGame.Child(r).Name;
                    string mergename = ((RvFile)mGame.Child(r)).Merge;

                    bool found = false;
                    for (int r1 = 0; r1 < romofGame.ChildCount; r1++)
                    {
                        if ((name == romofGame.Child(r1).Name || mergename == romofGame.Child(r1).Name) &&
                            (ArrByte.iCompare(((RvFile)mGame.Child(r)).CRC, ((RvFile)romofGame.Child(r1)).CRC) == 0 &&
                             ((RvFile)mGame.Child(r)).Size == ((RvFile)romofGame.Child(r1)).Size))
                        {
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        romofGame.ChildAdd(mGame.Child(r));
                    }
                }
                tDat.ChildRemove(g);
            }
        }