示例#1
0
        public virtual void Read(BinaryReader br, List <RvDat> parentDirDats)
        {
            Name      = br.ReadString();
            FileName  = br.ReadString();
            TimeStamp = br.ReadInt64();
            bool foundDat = br.ReadBoolean();

            if (foundDat)
            {
                int index = br.ReadInt32();
                if (index == -1)
                {
                    ReportError.SendAndShow(Resources.RvBase_Read_Dat_found_without_an_index);
                }
                else
                {
                    Dat = parentDirDats[index];
                }
            }
            else
            {
                Dat = null;
            }

            _datStatus = (DatStatus)br.ReadByte();
            _gotStatus = (GotStatus)br.ReadByte();
            RepStatusReset();
        }
        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;
        }
示例#3
0
        public void DirDatAdd(RvDat dat)
        {
            int index;

            DirDatSearch(dat, out index);
            _dirDats.Insert(index, dat);
            for (int i = 0; i < _dirDats.Count; i++)
            {
                _dirDats[i].DatIndex = i;
            }
        }
示例#4
0
        public static int DatCompare(RvDat var1, RvDat var2)
        {
            int retv = Math.Sign(string.Compare(var1.GetData(RvDat.DatData.DatFullName), var2.GetData(RvDat.DatData.DatFullName), StringComparison.CurrentCultureIgnoreCase));
            if (retv != 0) return retv;

            retv = Math.Sign(var1.TimeStamp.CompareTo(var2.TimeStamp));
            if (retv != 0) return retv;

            retv = Math.Sign(var1.AutoAddDirectory.CompareTo(var2.AutoAddDirectory));
            if (retv != 0) return retv;

            return 0;
        }
示例#5
0
        public virtual EFile DatRemove()
        {
            Dat = null;
            if (GotStatus == GotStatus.NotGot)
            {
                return(EFile.Delete);
            }

            if (!String.IsNullOrEmpty(FileName))
            {
                Name     = FileName;
                FileName = null;
            }
            DatStatus = DatStatus.NotInDat;
            return(EFile.Keep);
        }
示例#6
0
 private string SuperDatFileName(RvDat dat)
 {
     if (dat.AutoAddDirectory)
     {
         if (Parent == null || Parent.Parent == null || Parent.Parent.Dat != dat)
         {
             return(Name);
         }
     }
     else
     {
         if (Parent == null || Parent.Dat != dat)
         {
             return(Name);
         }
     }
     return(IO.Path.Combine(Parent.SuperDatFileName(dat), Name));
 }
示例#7
0
        private static bool LoadHeaderFromDat(ref RvDir tDir, ref FileType thisFileType)
        {

            if (DatFileLoader.Next != "(")
            {
                DatUpdate.SendAndShowDat(Resources.DatCmpReader_LoadHeaderFromDat_not_found_after_clrmamepro, DatFileLoader.Filename);
                return false;
            }
            DatFileLoader.Gn();

            RvDat tDat = new RvDat();
            while (DatFileLoader.Next != ")")
            {
                string nextstr = DatFileLoader.Next.ToLower();
                if (nextstr.Length > 5 && nextstr.Substring(0, 5) == "name:")
                {
                    tDat.AddData(RvDat.DatData.DatName,  VarFix.CleanFileName(DatFileLoader.Next.Substring(5) + " " + DatFileLoader.GnRest()).Trim()); DatFileLoader.Gn();
                }
                else
                {
                    switch (nextstr)
                    {
                        case "name:": tDat.AddData(RvDat.DatData.DatName, VarFix.CleanFileName(DatFileLoader.GnRest())); DatFileLoader.Gn(); break;
                        case "description:": tDat.AddData(RvDat.DatData.Description , DatFileLoader.GnRest()); DatFileLoader.Gn(); break;
                        case "version:": tDat.AddData(RvDat.DatData.Version , DatFileLoader.GnRest()); DatFileLoader.Gn(); break;
                        case "date:": tDat.AddData(RvDat.DatData.Date , DatFileLoader.GnRest()); DatFileLoader.Gn(); break;
                        case "author:": tDat.AddData(RvDat.DatData.Author , DatFileLoader.GnRest()); DatFileLoader.Gn(); break;
                        case "homepage:": tDat.AddData(RvDat.DatData.HomePage , DatFileLoader.GnRest()); DatFileLoader.Gn(); break;

                        case "comment:": DatFileLoader.GnRest(); DatFileLoader.Gn(); break;
                        default:
                            DatUpdate.SendAndShowDat(Resources.DatCmpReader_ReadDat_Error_keyword + DatFileLoader.Next + Resources.DatCmpReader_LoadHeaderFromDat_not_known_in_clrmamepro, DatFileLoader.Filename);
                            DatFileLoader.Gn();
                            break;
                    }
                }
            }

            thisFileType = FileType.ZipFile;
            tDir.Dat = tDat;
            return true;

        }
示例#8
0
        private void DirDatSearch(RvDat dat, out int index)
        {
            int intBottom = 0;
            int intTop    = _dirDats.Count;
            int intMid    = 0;
            int intRes    = -1;

            //Binary chop to find the closest match
            while ((intBottom < intTop) && (intRes != 0))
            {
                intMid = (intBottom + intTop) / 2;

                intRes = DBHelper.DatCompare(dat, _dirDats[intMid]);
                if (intRes < 0)
                {
                    intTop = intMid;
                }
                else if (intRes > 0)
                {
                    intBottom = intMid + 1;
                }
            }
            index = intMid;

            // if match was found check up the list for the first match
            if (intRes == 0)
            {
                int intRes1 = 0;
                while ((index > 0) && (intRes1 == 0))
                {
                    intRes1 = DBHelper.DatCompare(dat, _dirDats[index - 1]);
                    if (intRes1 == 0)
                    {
                        index--;
                    }
                }
            }
            // if the search is greater than the closest match move one up the list
            else if (intRes > 0)
            {
                index++;
            }
        }
示例#9
0
        public virtual void Read(BinaryReader br, List<RvDat> parentDirDats)
        {
            Name = br.ReadString();
            FileName = br.ReadString();
            TimeStamp = br.ReadInt64();
            bool foundDat = br.ReadBoolean();
            if (foundDat)
            {
                int index = br.ReadInt32();
                if (index == -1)
                    ReportError.SendAndShow(Resources.RvBase_Read_Dat_found_without_an_index);
                else
                    Dat = parentDirDats[index];
            }
            else
            {
                Dat = null;
            }

            _datStatus = (DatStatus)br.ReadByte();
            _gotStatus = (GotStatus)br.ReadByte();
            RepStatusReset();
        }
示例#10
0
        public virtual void DatAdd(RvBase b)
        {
            // Parent , TimeStamp Should already be correct.

            if (GotStatus == GotStatus.NotGot)
            {
                ReportError.SendAndShow("Error Adding DAT to NotGot File " + b.GotStatus);
            }

            SetStatus(b.DatStatus, GotStatus.Got);

            if (Name == b.Name) // case match so all is good
            {
                FileName = null;
            }
            else
            {
                FileName = Name;
                Name     = b.Name;
            }

            Dat = b.Dat;
        }
示例#11
0
        public static void MakeFixFiles()
        {
            _tDat = null;
            _ts = null;

            FolderBrowserDialog browse = new FolderBrowserDialog
            {
                ShowNewFolderButton = true,
                Description = @"Please select a folder for Dats",
                RootFolder = Environment.SpecialFolder.MyComputer,
                SelectedPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Reports")
            };

            if (browse.ShowDialog() != DialogResult.OK) return;

            _outdir = browse.SelectedPath;
            _tDat = null;
            MakeFixFilesRecurse(DB.DirTree.Child(0), true);

            if (_ts == null) return;

            _ts.WriteLine("</datafile>");
            _ts.Close();
        }
示例#12
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;
        }
示例#13
0
        public override void Read(BinaryReader br, List <RvDat> parentDirDats)
        {
            base.Read(br, parentDirDats);
            bool foundTree = br.ReadBoolean();

            if (foundTree)
            {
                Tree = new RvTreeRow();
                Tree.Read(br);
            }
            else
            {
                Tree = null;
            }

            bool foundGame = br.ReadBoolean();

            if (foundGame)
            {
                Game = new RvGame();
                Game.Read(br);
            }
            else
            {
                Game = null;
            }

            int count = br.ReadInt32();

            _dirDats.Clear();
            for (int i = 0; i < count; i++)
            {
                RvDat dat = new RvDat {
                    DatIndex = i
                };
                dat.Read(br);
                _dirDats.Add(dat);

                string datname = TreeFullName + @"\" + dat.GetData(RvDat.DatData.DatName);
                if ((datname.Length >= 9) && (datname.Substring(0, 9) == @"RomVault\"))
                {
                    datname = datname.Substring(9);
                }

                DB.Bgw.ReportProgress(0, new bgwText("Loading: " + datname));
                DB.Bgw.ReportProgress((int)br.BaseStream.Position);
            }
            if (_dirDats.Count > 0)
            {
                parentDirDats = _dirDats;
            }

            count = br.ReadInt32();
            _children.Clear();
            for (int i = 0; i < count; i++)
            {
                RvBase tChild = DBTypeGet.GetRvType((FileType)br.ReadByte());

                tChild.Parent = this;
                tChild.Read(br, parentDirDats);
                _children.Add(tChild);
            }

            if (DBTypeGet.isCompressedDir(FileType))
            {
                ZipStatus = (ZipStatus)br.ReadByte();
            }
        }
示例#14
0
        private static bool LoadHeaderFromDat(ref RvDir tDir, ref FileType thisFileType)
        {

            if (DatFileLoader.Next != "(")
            {
                DatUpdate.SendAndShowDat(Resources.DatCmpReader_LoadHeaderFromDat_not_found_after_clrmamepro, DatFileLoader.Filename);
                return false;
            }
            DatFileLoader.Gn();

            string forceZipping = "";

            RvDat tDat = new RvDat();
            while (DatFileLoader.Next != ")")
            {
                switch (DatFileLoader.Next.ToLower())
                {
                    case "name": tDat.AddData(RvDat.DatData.DatName, VarFix.CleanFileName(DatFileLoader.GnRest())); DatFileLoader.Gn(); break;
                    case "description": tDat.AddData(RvDat.DatData.Description, DatFileLoader.GnRest()); DatFileLoader.Gn(); break;
                    case "category": tDat.AddData(RvDat.DatData.Category, DatFileLoader.GnRest()); DatFileLoader.Gn(); break;
                    case "version": tDat.AddData(RvDat.DatData.Version, DatFileLoader.GnRest()); DatFileLoader.Gn(); break;
                    case "date": tDat.AddData(RvDat.DatData.Date, DatFileLoader.GnRest()); DatFileLoader.Gn(); break;
                    case "author": tDat.AddData(RvDat.DatData.Author, DatFileLoader.GnRest()); DatFileLoader.Gn(); break;
                    case "email": tDat.AddData(RvDat.DatData.Email, DatFileLoader.GnRest()); DatFileLoader.Gn(); break;
                    case "homepage": tDat.AddData(RvDat.DatData.HomePage, DatFileLoader.GnRest()); DatFileLoader.Gn(); break;
                    case "url": tDat.AddData(RvDat.DatData.URL, DatFileLoader.GnRest()); DatFileLoader.Gn(); break;

                    case "comment": DatFileLoader.GnRest(); DatFileLoader.Gn(); break;
                    case "header": DatFileLoader.GnRest(); DatFileLoader.Gn(); break;
                    case "forcezipping": forceZipping = DatFileLoader.GnRest(); DatFileLoader.Gn(); break;
                    case "forcepacking": DatFileLoader.GnRest(); DatFileLoader.Gn(); break; // incorrect usage
                    case "forcemerging": tDat.AddData(RvDat.DatData.MergeType, DatFileLoader.GnRest()); DatFileLoader.Gn(); break;
                    case "forcenodump": DatFileLoader.GnRest(); DatFileLoader.Gn(); break;
                    case "dir": tDat.AddData(RvDat.DatData.DirSetup, DatFileLoader.GnRest()); DatFileLoader.Gn(); break;
                    default:
                        DatUpdate.SendAndShowDat(Resources.DatCmpReader_ReadDat_Error_keyword + DatFileLoader.Next + Resources.DatCmpReader_LoadHeaderFromDat_not_known_in_clrmamepro, DatFileLoader.Filename);
                        DatFileLoader.Gn();
                        break;
                }
            }

            thisFileType = forceZipping.ToLower() != "no" ? FileType.ZipFile : FileType.File;
            tDir.Dat = tDat;
            return true;

        }
示例#15
0
        public virtual EFile DatRemove()
        {
            Dat = null;
            if (GotStatus == GotStatus.NotGot)
                return EFile.Delete;

            if (!String.IsNullOrEmpty(FileName))
            {
                Name = FileName;
                FileName = null;
            }
            DatStatus = DatStatus.NotInDat;
            return EFile.Keep;
        }
示例#16
0
        private void DirDatSearch(RvDat dat, out int index)
        {
            int intBottom = 0;
            int intTop = _dirDats.Count;
            int intMid = 0;
            int intRes = -1;

            //Binary chop to find the closest match
            while (intBottom < intTop && intRes != 0)
            {
                intMid = (intBottom + intTop) / 2;

                intRes = DBHelper.DatCompare(dat, _dirDats[intMid]);
                if (intRes < 0)
                    intTop = intMid;
                else if (intRes > 0)
                    intBottom = intMid + 1;
            }
            index = intMid;

            // if match was found check up the list for the first match
            if (intRes == 0)
            {
                int intRes1 = 0;
                while (index > 0 && intRes1 == 0)
                {
                    intRes1 = DBHelper.DatCompare(dat, _dirDats[index - 1]);
                    if (intRes1 == 0)
                        index--;
                }
            }
            // if the search is greater than the closest match move one up the list
            else if (intRes > 0)
                index++;
        }
示例#17
0
 public void DirDatAdd(RvDat dat)
 {
     int index;
     DirDatSearch(dat, out index);
     _dirDats.Insert(index, dat);
     for (int i = 0; i < _dirDats.Count; i++)
         _dirDats[i].DatIndex = i;
 }
示例#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;
        }
示例#19
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;
        }
示例#20
0
        private static bool UpdateDatFile(RvDat file, bool autoAddDirectory, RvDir thisDirectory)
        {
            // Read the new Dat File into newDatFile
            RvDir newDatFile = DatReader.ReadInDatFile(file, _bgw);

            // If we got a valid Dat File back
            if (newDatFile == null || newDatFile.Dat == null)
            {
                ReportError.Show("Error reading Dat " + file.GetData(RvDat.DatData.DatFullName));
                return false;
            }

            newDatFile.Dat.AutoAddDirectory = autoAddDirectory;

            if ((autoAddDirectory || !String.IsNullOrEmpty(newDatFile.Dat.GetData(RvDat.DatData.RootDir))) && newDatFile.Dat.GetData(RvDat.DatData.DirSetup)!= "noautodir")
            {   // if we are auto adding extra directorys then create a new directory.

                newDatFile.Name = !String.IsNullOrEmpty(newDatFile.Dat.GetData(RvDat.DatData.RootDir)) ?
                    newDatFile.Dat.GetData(RvDat.DatData.RootDir) : newDatFile.Dat.GetData(RvDat.DatData.DatName);

                newDatFile.DatStatus = DatStatus.InDatCollect;
                newDatFile.Tree = new RvTreeRow();

                RvDir newDirectory = new RvDir(FileType.Dir) { Dat = newDatFile.Dat };

                // add the DAT into this directory
                newDirectory.ChildAdd(newDatFile);
                newDatFile = newDirectory;
            }

            if (thisDirectory.Tree == null)
                thisDirectory.Tree = new RvTreeRow();

            RvDat conflictDat;
            if (MergeInDat(thisDirectory, newDatFile, out conflictDat, true))
            {
                ReportError.Show("Dat Merge conflict occured Cache contains " + conflictDat.GetData(RvDat.DatData.DatFullName) + " new dat " + newDatFile.Dat.GetData(RvDat.DatData.DatFullName) + " is trying to use the same dirctory and so will be ignored.");
                return false;
            }

            //SetInDat(thisDirectory);

            // Add the new Dat
            thisDirectory.DirDatAdd(newDatFile.Dat);

            // Merge the files/directories in the Dat
            MergeInDat(thisDirectory, newDatFile, out conflictDat, false);
            return true;
        }
示例#21
0
        public static void MakeFixFiles()
        {
            _tDat = null;
            _ts = null;

            FolderBrowserDialog browse = new FolderBrowserDialog
            {
                ShowNewFolderButton = true,
                Description = @"Please select a folder for Dats",
                RootFolder = (Settings.IsMono ? Environment.SpecialFolder.MyComputer : Environment.SpecialFolder.DesktopDirectory),
                SelectedPath = @"apps"
            };

            if (browse.ShowDialog() != DialogResult.OK) return;

            _outdir = browse.SelectedPath;
            _tDat = null;
            MakeFixFilesRecurse(DB.DirTree.Child(0), true);

            if (_ts == null) return;

            _ts.WriteLine("</datafile>");
            _ts.Close();
        }
示例#22
0
        private static bool LoadHeaderFromDat(ref RvDir tDir, ref XmlDocument doc, ref FileType thisFileType)
        {
            if (doc.DocumentElement == null)
                return false;
            XmlNode head = doc.DocumentElement.SelectSingleNode("header");

            if (head == null)
                return false;
            RvDat tDat = new RvDat();
            tDat.AddData(RvDat.DatData.DatName, VarFix.CleanFileName(head.SelectSingleNode("name")));
            tDat.AddData(RvDat.DatData.RootDir, VarFix.CleanFileName(head.SelectSingleNode("rootdir")));
            tDat.AddData(RvDat.DatData.Description, VarFix.String(head.SelectSingleNode("description")));
            tDat.AddData(RvDat.DatData.Category, VarFix.String(head.SelectSingleNode("category")));
            tDat.AddData(RvDat.DatData.Version, VarFix.String(head.SelectSingleNode("version")));
            tDat.AddData(RvDat.DatData.Date, VarFix.String(head.SelectSingleNode("date")));
            tDat.AddData(RvDat.DatData.Author, VarFix.String(head.SelectSingleNode("author")));
            tDat.AddData(RvDat.DatData.Email, VarFix.String(head.SelectSingleNode("email")));
            tDat.AddData(RvDat.DatData.HomePage, VarFix.String(head.SelectSingleNode("homepage")));
            tDat.AddData(RvDat.DatData.URL, VarFix.String(head.SelectSingleNode("url")));


            string superDAT = VarFix.String(head.SelectSingleNode("type"));
            _cleanFileNames = superDAT.ToLower() != "superdat" && superDAT.ToLower() != "gigadat";
            if (!_cleanFileNames) tDat.AddData(RvDat.DatData.SuperDat, "superdat");

            thisFileType = FileType.ZipFile;

            // Look for:   <romvault forcepacking="unzip"/>
            XmlNode packingNode = head.SelectSingleNode("romvault");
            if (packingNode == null)
                // Look for:   <clrmamepro forcepacking="unzip"/>
                packingNode = head.SelectSingleNode("clrmamepro");
            if (packingNode != null)
            {
                if (packingNode.Attributes != null)
                {
                    string val = VarFix.String(packingNode.Attributes.GetNamedItem("forcepacking")).ToLower();
                    switch (val.ToLower())
                    {
                        case "zip":
                            tDat.AddData(RvDat.DatData.FileType, "zip");
                            thisFileType = FileType.ZipFile;
                            break;
                        case "unzip":
                        case "file":
                            tDat.AddData(RvDat.DatData.FileType, "file");
                            thisFileType = FileType.File;
                            break;
                        default:
                            thisFileType = FileType.ZipFile;
                            break;
                    }

                    val = VarFix.String(packingNode.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;
                    }
                    val = VarFix.String(packingNode.Attributes.GetNamedItem("dir")).ToLower(); // noautodir , nogame
                    if (!String.IsNullOrEmpty(val))
                        tDat.AddData(RvDat.DatData.DirSetup, val);
                }
            }

            // Look for: <notzipped>true</notzipped>
            string notzipped = VarFix.String(head.SelectSingleNode("notzipped"));
            if (notzipped.ToLower() == "true" || notzipped.ToLower() == "yes") thisFileType = FileType.File;

            tDir.Dat = tDat;
            return true;
        }
示例#23
0
        private static void MakeFixFilesRecurse(RvBase b, bool selected)
        {
            if (selected)
            {
                if (b.Dat != null)
                {
                    RvDir tDir = b as RvDir;
                    if (tDir != null && tDir.Game != null && tDir.DirStatus.HasMissing())
                    {
                        if (_tDat != b.Dat)
                        {
                            if (_tDat != null)
                            {
                                _ts.WriteLine("</datafile>");
                                _ts.WriteLine();
                            }

                            if (_ts != null) _ts.Close();

                            _tDat = b.Dat;
                            int test = 0;
                            string datFilename = Path.Combine(_outdir, "fixDat_" + Path.GetFileNameWithoutExtension(_tDat.GetData(RvDat.DatData.DatFullName)) + ".dat");
                            while (File.Exists(datFilename))
                            {
                                test++;
                                datFilename = Path.Combine(_outdir, "fixDat_" + Path.GetFileNameWithoutExtension(_tDat.GetData(RvDat.DatData.DatFullName)) + "(" + test + ").dat");
                            }
                            _ts = new StreamWriter(datFilename);

                            _ts.WriteLine("<?xml version=\"1.0\"?>");
                            _ts.WriteLine(
                                "<!DOCTYPE datafile PUBLIC \"-//Logiqx//DTD ROM Management Datafile//EN\" \"http://www.logiqx.com/Dats/datafile.dtd\">");
                            _ts.WriteLine("");
                            _ts.WriteLine("<datafile>");
                            _ts.WriteLine("\t<header>");
                            _ts.WriteLine("\t\t<name>fix_" + Etxt(_tDat.GetData(RvDat.DatData.DatName)) + "</name>");
                            if (_tDat.GetData(RvDat.DatData.SuperDat) == "superdat")
                                _ts.WriteLine("\t\t<type>SuperDAT</type>");
                            _ts.WriteLine("\t\t<description>fix_" + Etxt(_tDat.GetData(RvDat.DatData.Description)) + "</description>");
                            _ts.WriteLine("\t\t<category>FIXDATFILE</category>");
                            _ts.WriteLine("\t\t<version>" + DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss") + "</version>");
                            _ts.WriteLine("\t\t<date>" + DateTime.Now.ToString("MM/dd/yyyy") + "</date>");
                            _ts.WriteLine("\t\t<author>RomVault</author>");
                            _ts.WriteLine("\t</header>");
                        }

                        _ts.WriteLine("\t<game name=\"" + Etxt(tDir.SuperDatFileName()) + "\">");
                        if (!string.IsNullOrEmpty(tDir.Game.GetData(RvGame.GameData.Description)))
                            _ts.WriteLine("\t\t<description>" + Etxt(tDir.Game.GetData(RvGame.GameData.Description)) + "</description>");

                    }

                    RvFile tRom = b as RvFile;
                    if (tRom != null)
                    {

                        if (tRom.DatStatus == DatStatus.InDatCollect && tRom.GotStatus != GotStatus.Got)
                        {
                            string strRom;
                            if (tRom.FileStatusIs(FileStatus.SHA1CHDFromDAT | FileStatus.MD5CHDFromDAT))
                                strRom = "\t\t<disk name=\"" + Etxt(tRom.Name) + "\"";
                            else
                                strRom = "\t\t<rom name=\"" + Etxt(tRom.Name) + "\"";

                            if (tRom.FileStatusIs(FileStatus.SizeFromDAT) && tRom.Size != null)
                                strRom += " size=\"" + tRom.Size + "\"";

                            string strCRC = ArrByte.ToString(tRom.CRC);
                            if (tRom.FileStatusIs(FileStatus.CRCFromDAT) && !string.IsNullOrEmpty(strCRC))
                                strRom += " crc=\"" + strCRC + "\"";

                            string strSHA1 = ArrByte.ToString(tRom.SHA1);
                            if (tRom.FileStatusIs(FileStatus.SHA1FromDAT) && !string.IsNullOrEmpty(strSHA1))
                                strRom += " sha1=\"" + strSHA1 + "\"";

                            string strMD5 = ArrByte.ToString(tRom.MD5);
                            if (tRom.FileStatusIs(FileStatus.MD5FromDAT) && !string.IsNullOrEmpty(strMD5))
                                strRom += " md5=\"" + strMD5 + "\"";

                            string strSHA1CHD = ArrByte.ToString(tRom.SHA1CHD);
                            if (tRom.FileStatusIs(FileStatus.SHA1CHDFromDAT) && !string.IsNullOrEmpty(strSHA1CHD))
                                strRom += " sha1=\"" + strSHA1CHD + "\"";

                            string strMD5CHD = ArrByte.ToString(tRom.MD5CHD);
                            if (tRom.FileStatusIs(FileStatus.MD5CHDFromDAT) && !string.IsNullOrEmpty(strMD5CHD))
                                strRom += " md5=\"" + strMD5CHD + "\"";

                            strRom += "/>";

                            _ts.WriteLine(strRom);
                        }
                    }
                }
            }

            RvDir d = b as RvDir;
            if (d != null)
            {
                for (int i = 0; i < d.ChildCount; i++)
                {
                    bool nextSelected = selected;
                    if (d.Tree != null)
                        nextSelected = d.Tree.Checked == RvTreeRow.TreeSelect.Selected;
                    MakeFixFilesRecurse(d.Child(i), nextSelected);
                }
            }

            if (selected)
            {
                if (b.Dat != null)
                {
                    RvDir tDir = b as RvDir;
                    if (tDir != null && tDir.Game != null && tDir.DirStatus.HasMissing())
                    {
                        _ts.WriteLine("\t</game>");
                    }
                }
            }
        }
示例#24
0
        public override void Read(BinaryReader br, List<RvDat> parentDirDats)
        {
            base.Read(br, parentDirDats);
            bool foundTree = br.ReadBoolean();
            if (foundTree)
            {
                Tree = new RvTreeRow();
                Tree.Read(br);
            }
            else
                Tree = null;

            bool foundGame = br.ReadBoolean();
            if (foundGame)
            {
                Game = new RvGame();
                Game.Read(br);
            }
            else
                Game = null;

            int count = br.ReadInt32();
            _dirDats.Clear();
            for (int i = 0; i < count; i++)
            {
                RvDat dat = new RvDat { DatIndex = i };
                dat.Read(br);
                _dirDats.Add(dat);

                string datname = TreeFullName + @"\" + dat.GetData(RvDat.DatData.DatName);
                if (datname.Length >= 9 && datname.Substring(0, 9) == @"ROMVault\")
                    datname = datname.Substring(9);

                DB.Bgw.ReportProgress(0, new bgwText("Loading: " + datname));
                DB.Bgw.ReportProgress((int)br.BaseStream.Position);

            }
            if (_dirDats.Count > 0)
                parentDirDats = _dirDats;

            count = br.ReadInt32();
            _children.Clear();
            for (int i = 0; i < count; i++)
            {
                RvBase tChild = DBTypeGet.GetRvType((FileType)br.ReadByte());

                tChild.Parent = this;
                tChild.Read(br, parentDirDats);
                _children.Add(tChild);
            }

            if (DBTypeGet.isCompressedDir(FileType))
                ZipStatus = (ZipStatus)br.ReadByte();
        }
示例#25
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);
            }
        }
示例#26
0
        public virtual void DatAdd(RvBase b)
        {
            // Parent , TimeStamp Should already be correct.

            if (GotStatus == GotStatus.NotGot)
                ReportError.SendAndShow("Error Adding DAT to NotGot File " + b.GotStatus);

            SetStatus(b.DatStatus, GotStatus.Got);

            if (Name == b.Name) // case match so all is good
            {
                FileName = null;
            }
            else
            {
                FileName = Name;
                Name = b.Name;
            }

            Dat = b.Dat;
        }
示例#27
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);
            }
        }
示例#28
0
 private string SuperDatFileName(RvDat dat)
 {
     if (dat.AutoAddDirectory)
     {
         if (Parent == null || Parent.Parent == null || Parent.Parent.Dat != dat) return Name;
     }
     else
     {
         if (Parent == null || Parent.Dat != dat) return Name;
     }
     return IO.Path.Combine(Parent.SuperDatFileName(dat), Name);
 }
示例#29
0
        public static RvDir ReadInDatFile(RvDat datFile, BackgroundWorker bgw)
        {
            _bgw = bgw;

            RvDir newDir = new RvDir(FileType.Dir);

            string datFullName = datFile.GetData(RvDat.DatData.DatFullName);

            System.IO.Stream fs;
            int errorCode = IO.FileStream.OpenFileRead(datFullName, out fs);
            if (errorCode != 0)
            {
                _bgw.ReportProgress(0, new bgwShowError(datFullName, errorCode + ": " + new Win32Exception(errorCode).Message));
                return null;
            }

            System.IO.StreamReader myfile = new System.IO.StreamReader(fs, Program.Enc);
            string strLine = myfile.ReadLine();
            myfile.Close();
            fs.Close();
            fs.Dispose();

            if (strLine == null)
                return null;

            if (strLine.ToLower().IndexOf("xml", StringComparison.Ordinal) >= 0)
            {
                if (!ReadXMLDat(ref newDir, datFullName))
                    return null;
            }

            else if (strLine.ToLower().IndexOf("clrmamepro", StringComparison.Ordinal) >= 0 || strLine.ToLower().IndexOf("romvault", StringComparison.Ordinal) >= 0 || strLine.ToLower().IndexOf("game", StringComparison.Ordinal) >= 0)
            {
                if (!DatCmpReader.ReadDat(ref newDir, datFullName))
                    return null;
            }
            else if (strLine.ToLower().IndexOf("doscenter", StringComparison.Ordinal) >= 0)
            {
                if (!DatDOSReader.ReadDat(ref newDir, datFullName))
                    return null;
            }
            else
            {
                _bgw.ReportProgress(0, new bgwShowError(datFullName, "Invalid DAT File"));
                return null;
            }

            if (newDir.Dat == null)
            {
                _bgw.ReportProgress(0, new bgwShowError(datFullName, "Invalid Header"));
                return null;
            }

            newDir.Dat.AddData(RvDat.DatData.DatFullName, datFullName);
            newDir.Dat.TimeStamp = datFile.TimeStamp;
            newDir.Dat.Status = DatUpdateStatus.Correct;

            DatSetRemoveUnneededDirs(newDir);
            DatSetCheckParentSets(newDir);
            DatSetRenameAndRemoveDups(newDir);

            if (newDir.Dat.GetData(RvDat.DatData.MergeType).ToLower() == "full")
                DatSetMergeSets(newDir);

            DatSetCheckCollect(newDir);

            DatSetCreateSubDirs(newDir);

            if (newDir.Dat.GetData(RvDat.DatData.DirSetup).ToLower() == "nogame")
            {
                DatSetRemoveGameDir(newDir);
            }

            return newDir;
        }