Exemplo n.º 1
0
        private static void LoadGameFromDat(ref RvDir tDat, XmlNode gameNode, FileType thisFileType)
        {
            if (gameNode.Attributes == null)
            {
                return;
            }

            RvDir parent = tDat;

            RvDir tDir = new RvDir(DBTypeGet.DirFromFile(thisFileType))
            {
                Name      = VarFix.CleanFileName(gameNode.Attributes.GetNamedItem("name")),
                Game      = new RvGame(),
                Dat       = tDat.Dat,
                DatStatus = DatStatus.InDatCollect
            };


            tDir.Game.AddData(RvGame.GameData.Description, VarFix.String(gameNode.SelectSingleNode("description")));

            tDir.Game.AddData(RvGame.GameData.RomOf, VarFix.CleanFileName(gameNode.Attributes.GetNamedItem("cloneof")));
            tDir.Game.AddData(RvGame.GameData.CloneOf, VarFix.CleanFileName(gameNode.Attributes.GetNamedItem("cloneof")));
            tDir.Game.AddData(RvGame.GameData.Year, VarFix.CleanFileName(gameNode.SelectSingleNode("year")));
            tDir.Game.AddData(RvGame.GameData.Manufacturer, VarFix.CleanFileName(gameNode.SelectSingleNode("publisher")));


            RvDir tDirCHD = new RvDir(FileType.Dir)
            {
                Name      = VarFix.CleanFileName(gameNode.Attributes.GetNamedItem("name")),
                Game      = new RvGame(),
                Dat       = tDat.Dat,
                DatStatus = DatStatus.InDatCollect
            };

            tDirCHD.Game.AddData(RvGame.GameData.Description, VarFix.String(gameNode.SelectSingleNode("description")));

            tDirCHD.Game.AddData(RvGame.GameData.RomOf, VarFix.CleanFileName(gameNode.Attributes.GetNamedItem("cloneof")));
            tDirCHD.Game.AddData(RvGame.GameData.CloneOf, VarFix.CleanFileName(gameNode.Attributes.GetNamedItem("cloneof")));
            tDirCHD.Game.AddData(RvGame.GameData.Year, VarFix.CleanFileName(gameNode.SelectSingleNode("year")));
            tDirCHD.Game.AddData(RvGame.GameData.Manufacturer, VarFix.CleanFileName(gameNode.SelectSingleNode("publisher")));


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

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


            XmlNodeList partNodeList = gameNode.SelectNodes("part");

            if (partNodeList == null)
            {
                return;
            }

            for (int iP = 0; iP < partNodeList.Count; iP++)
            {
                _indexContinue = -1;
                XmlNodeList dataAreaNodeList = partNodeList[iP].SelectNodes("dataarea");
                if (dataAreaNodeList != null)
                {
                    for (int iD = 0; iD < dataAreaNodeList.Count; iD++)
                    {
                        XmlNodeList romNodeList = dataAreaNodeList[iD].SelectNodes("rom");
                        if (romNodeList != null)
                        {
                            for (int iR = 0; iR < romNodeList.Count; iR++)
                            {
                                LoadRomFromDat(ref tDir, romNodeList[iR], thisFileType);
                            }
                        }
                    }
                }
            }
            for (int iP = 0; iP < partNodeList.Count; iP++)
            {
                XmlNodeList diskAreaNodeList = partNodeList[iP].SelectNodes("diskarea");
                if (diskAreaNodeList != null)
                {
                    for (int iD = 0; iD < diskAreaNodeList.Count; iD++)
                    {
                        XmlNodeList romNodeList = diskAreaNodeList[iD].SelectNodes("disk");
                        if (romNodeList != null)
                        {
                            for (int iR = 0; iR < romNodeList.Count; iR++)
                            {
                                LoadDiskFromDat(ref tDirCHD, romNodeList[iR]);
                            }
                        }
                    }
                }
            }

            if (tDir.ChildCount > 0)
            {
                parent.ChildAdd(tDir, index1);
            }
            if (tDirCHD.ChildCount > 0)
            {
                parent.ChildAdd(tDirCHD, index1);
            }
        }
Exemplo n.º 2
0
        private static void LoadGameFromDat(ref RvDir tDat, XmlNode gameNode, FileType thisFileType)
        {
            if (gameNode.Attributes == null)
            {
                return;
            }

            RvDir parent = tDat;
            RvDir tDir;
            int   index1 = 0;

            string fullname = VarFix.CleanFullFileName(gameNode.Attributes.GetNamedItem("name"));

            if (_cleanFileNames)
            {
                fullname = fullname.Replace("/", "-");
            }
            else
            {
                while (fullname.Contains("/"))
                {
                    int    firstSlash = fullname.IndexOf("/", StringComparison.Ordinal);
                    string dir        = fullname.Substring(0, firstSlash);
                    dir = VarFix.CleanFileName(dir);

                    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;
                    }
                }
            }

            tDir = new RvDir(DBTypeGet.DirFromFile(thisFileType))
            {
                Name      = fullname,
                DatStatus = DatStatus.InDatCollect,
                Dat       = tDat.Dat
            };

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

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

            tDir.Game = new RvGame();
            tDir.Game.AddData(RvGame.GameData.RomOf, VarFix.CleanFileName(gameNode.Attributes.GetNamedItem("romof")));
            tDir.Game.AddData(RvGame.GameData.Description, VarFix.String(gameNode.SelectSingleNode("description")));

            tDir.Game.AddData(RvGame.GameData.Sourcefile, VarFix.String(gameNode.Attributes.GetNamedItem("sourcefile")));
            tDir.Game.AddData(RvGame.GameData.IsBios, VarFix.String(gameNode.Attributes.GetNamedItem("isbios")));
            tDir.Game.AddData(RvGame.GameData.CloneOf, VarFix.CleanFileName(gameNode.Attributes.GetNamedItem("cloneof")));
            tDir.Game.AddData(RvGame.GameData.SampleOf, VarFix.CleanFileName(gameNode.Attributes.GetNamedItem("sampleof")));
            tDir.Game.AddData(RvGame.GameData.Board, VarFix.String(gameNode.Attributes.GetNamedItem("board")));
            tDir.Game.AddData(RvGame.GameData.Year, VarFix.String(gameNode.SelectSingleNode("year")));
            tDir.Game.AddData(RvGame.GameData.Manufacturer, VarFix.String(gameNode.SelectSingleNode("manufacturer")));

            XmlNode trurip = gameNode.SelectSingleNode("trurip");

            if (trurip != null)
            {
                tDir.Game.AddData(RvGame.GameData.Trurip, "yes");
                tDir.Game.AddData(RvGame.GameData.Year, VarFix.String(trurip.SelectSingleNode("year")));
                tDir.Game.AddData(RvGame.GameData.Publisher, VarFix.String(trurip.SelectSingleNode("publisher")));
                tDir.Game.AddData(RvGame.GameData.Developer, VarFix.String(trurip.SelectSingleNode("developer")));
                tDir.Game.AddData(RvGame.GameData.Edition, VarFix.String(trurip.SelectSingleNode("edition")));
                tDir.Game.AddData(RvGame.GameData.Version, VarFix.String(trurip.SelectSingleNode("version")));
                tDir.Game.AddData(RvGame.GameData.Type, VarFix.String(trurip.SelectSingleNode("type")));
                tDir.Game.AddData(RvGame.GameData.Media, VarFix.String(trurip.SelectSingleNode("media")));
                tDir.Game.AddData(RvGame.GameData.Language, VarFix.String(trurip.SelectSingleNode("language")));
                tDir.Game.AddData(RvGame.GameData.Players, VarFix.String(trurip.SelectSingleNode("players")));
                tDir.Game.AddData(RvGame.GameData.Ratings, VarFix.String(trurip.SelectSingleNode("ratings")));
                tDir.Game.AddData(RvGame.GameData.Peripheral, VarFix.String(trurip.SelectSingleNode("peripheral")));
                tDir.Game.AddData(RvGame.GameData.Genre, VarFix.String(trurip.SelectSingleNode("genre")));
                tDir.Game.AddData(RvGame.GameData.MediaCatalogNumber, VarFix.String(trurip.SelectSingleNode("mediacatalognumber")));
                tDir.Game.AddData(RvGame.GameData.BarCode, VarFix.String(trurip.SelectSingleNode("barcode")));
            }

            RvDir tDirCHD = new RvDir(FileType.Dir)
            {
                Name      = tDir.Name,
                DatStatus = tDir.DatStatus,
                Dat       = tDir.Dat,
                Game      = tDir.Game
            };

            XmlNodeList romNodeList = gameNode.SelectNodes("rom");

            if (romNodeList != null)
            {
                for (int i = 0; i < romNodeList.Count; i++)
                {
                    LoadRomFromDat(ref tDir, romNodeList[i], thisFileType);
                }
            }

            XmlNodeList diskNodeList = gameNode.SelectNodes("disk");

            if (diskNodeList != null)
            {
                for (int i = 0; i < diskNodeList.Count; i++)
                {
                    LoadDiskFromDat(ref tDirCHD, diskNodeList[i]);
                }
            }

            if (tDir.ChildCount > 0)
            {
                parent.ChildAdd(tDir, index1);
            }

            if (tDirCHD.ChildCount > 0)
            {
                parent.ChildAdd(tDirCHD);
            }
        }
Exemplo n.º 3
0
        private static ReturnCode OpenInputStream(RvFile fileIn, bool rawCopy, out ICompress zipFileIn, out bool sourceTrrntzip, out Stream readStream, out ulong streamSize, out ushort compressionMethod, out string error)
        {
            zipFileIn         = null;
            sourceTrrntzip    = false;
            readStream        = null;
            streamSize        = 0;
            compressionMethod = 0;

            if (fileIn.FileType == FileType.ZipFile || fileIn.FileType == FileType.SevenZipFile) // Input is a ZipFile
            {
                RvFile zZipFileIn = fileIn.Parent;
                if (zZipFileIn.FileType != DBTypeGet.DirFromFile(fileIn.FileType))
                {
                    error = "File Open but Source File is not correct type, Logic Error.";
                    return(ReturnCode.LogicError);
                }

                string    fileNameIn = zZipFileIn.FullName;
                ZipReturn zr1;


                if (zZipFileIn.FileType == FileType.SevenZip)
                {
                    sourceTrrntzip = false;
                    zipFileIn      = new SevenZ();
                    zr1            = zipFileIn.ZipFileOpen(fileNameIn, zZipFileIn.TimeStamp);
                }
                else
                {
                    sourceTrrntzip = (zZipFileIn.ZipStatus & ZipStatus.TrrntZip) == ZipStatus.TrrntZip;
                    zipFileIn      = new ZipFile();
                    zr1            = zipFileIn.ZipFileOpen(fileNameIn, zZipFileIn.TimeStamp, fileIn.ZipFileHeaderPosition == null);
                }

                switch (zr1)
                {
                case ZipReturn.ZipGood:
                    break;

                case ZipReturn.ZipErrorFileNotFound:
                    error = "File not found, Rescan required before fixing " + fileIn.Name;
                    return(ReturnCode.RescanNeeded);

                case ZipReturn.ZipErrorTimeStamp:
                    error = "File has changed, Rescan required before fixing " + fileIn.Name;
                    return(ReturnCode.RescanNeeded);

                default:
                    error = "Error Open Zip" + zr1 + ", with File " + fileIn.DatTreeFullName;
                    return(ReturnCode.FileSystemError);
                }

                if (fileIn.FileType == FileType.SevenZipFile)
                {
                    ((SevenZ)zipFileIn).ZipFileOpenReadStream(fileIn.ZipFileIndex, out readStream, out streamSize);
                }
                else
                {
                    if (fileIn.ZipFileHeaderPosition != null)
                    {
                        ((ZipFile)zipFileIn).ZipFileOpenReadStreamQuick((ulong)fileIn.ZipFileHeaderPosition, rawCopy, out readStream, out streamSize, out compressionMethod);
                    }
                    else
                    {
                        ((ZipFile)zipFileIn).ZipFileOpenReadStream(fileIn.ZipFileIndex, rawCopy, out readStream, out streamSize, out compressionMethod);
                    }
                }
            }
            else // Input is a regular file
            {
                string fileNameIn = fileIn.FullName;
                if (!File.Exists(fileNameIn))
                {
                    error = "Rescan needed, File Not Found :" + fileNameIn;
                    return(ReturnCode.RescanNeeded);
                }
                FileInfo fileInInfo = new FileInfo(fileNameIn);
                if (fileInInfo.LastWriteTime != fileIn.TimeStamp)
                {
                    error = "Rescan needed, File Changed :" + fileNameIn;
                    return(ReturnCode.RescanNeeded);
                }
                int errorCode = FileStream.OpenFileRead(fileNameIn, out readStream);
                if (errorCode != 0)
                {
                    error = new Win32Exception(errorCode).Message + ". " + fileNameIn;
                    return(ReturnCode.FileSystemError);
                }
                if (fileIn.Size == null)
                {
                    error = "Null File Size found in Fixing File :" + fileNameIn;
                    return(ReturnCode.LogicError);
                }
                streamSize = (ulong)fileIn.Size;
                if ((ulong)readStream.Length != streamSize)
                {
                    error = "Rescan needed, File Length Changed :" + fileNameIn;
                    return(ReturnCode.RescanNeeded);
                }
            }

            error = "";
            return(ReturnCode.Good);
        }