示例#1
0
        private static bool LoadNewDat(RvDat fileDat, RvFile thisDirectory)
        {
            // Read the new Dat File into newDatFile
            RvFile newDatFile = DatReader.ReadInDatFile(fileDat, _thWrk, out string extraDirName);

            // If we got a valid Dat File back
            if (newDatFile?.Dat == null)
            {
                ReportError.Show("Error reading Dat " + fileDat.GetData(RvDat.DatData.DatRootFullName));
                return(false);
            }
            if (newDatFile.ChildCount == 0)
            {
                return(false);
            }

            if (!string.IsNullOrWhiteSpace(extraDirName))
            {
                newDatFile.Name = VarFix.CleanFileName(extraDirName);

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

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

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

                newDatFile.Dat.AutoAddedDirectory = true;
            }
            else
            {
                newDatFile.Dat.AutoAddedDirectory = false;
            }

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

            if (MergeInDat(thisDirectory, newDatFile, out RvDat conflictDat, true))
            {
                ReportError.Show("Dat Merge conflict occured Cache contains " + conflictDat.GetData(RvDat.DatData.DatRootFullName) + " new dat " + newDatFile.Dat.GetData(RvDat.DatData.DatRootFullName) + " is trying to use the same directory 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);
        }
示例#2
0
        private static bool RecursiveDatTree(RvFile tDir, out int datCount)
        {
            datCount = 0;
            string strPath = RvFile.GetDatPhysicalPath(tDir.DatTreeFullName);

            if (!Directory.Exists(strPath))
            {
                ReportError.Show($"Path: {strPath} Not Found.");
                return(false);
            }

            DirectoryInfo oDir = new DirectoryInfo(strPath);

            List <FileInfo> lFilesIn = new List <FileInfo>();

            FileInfo[] oFilesIn = oDir.GetFiles("*.dat");
            lFilesIn.AddRange(oFilesIn);
            oFilesIn = oDir.GetFiles("*.xml");
            lFilesIn.AddRange(oFilesIn);

            datCount += lFilesIn.Count;
            foreach (FileInfo file in lFilesIn)
            {
                RvDat tDat = new RvDat();
                tDat.SetData(RvDat.DatData.DatRootFullName, Path.Combine(tDir.DatTreeFullName, file.Name));
                tDat.TimeStamp = file.LastWriteTime;

                // this works passing in the full DirectoryName of the Dat, because the rules
                // has a directory separator character added to the end of them,
                // so they match up to the directory name in this full Directory Name.
                string  datRootFullName = tDat.GetData(RvDat.DatData.DatRootFullName);
                DatRule datRule         = DatReader.FindDatRule(datRootFullName);
                tDat.MultiDatOverride        = datRule.MultiDATDirOverride;
                tDat.UseDescriptionAsDirName = datRule.UseDescriptionAsDirName;
                tDat.SingleArchive           = datRule.SingleArchive;
                tDat.SubDirType = datRule.SubDirType;

                tDir.DirDatAdd(tDat);
            }

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

            DirectoryInfo[] oSubDir = oDir.GetDirectories();

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

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

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

            return(true);
        }
示例#3
0
        private static bool LoadNewDat(RvDat fileDat, RvFile thisDirectory)
        {
            // Read the new Dat File into newDatFile
            RvFile newDatFile = DatReader.ReadInDatFile(fileDat, _thWrk);

            // If we got a valid Dat File back
            if (newDatFile?.Dat == null)
            {
                ReportError.Show("Error reading Dat " + fileDat.GetData(RvDat.DatData.DatRootFullName));
                return(false);
            }
            if (newDatFile.ChildCount == 0)
            {
                return(false);
            }

            if (
                !fileDat.MultiDatOverride &&
                newDatFile.Dat.GetData(RvDat.DatData.DirSetup) != "noautodir" &&
                (
                    fileDat.MultiDatsInDirectory ||
                    !string.IsNullOrEmpty(newDatFile.Dat.GetData(RvDat.DatData.RootDir))
                )
                )
            {
                // if we are auto adding extra directories then create a new directory.
                string dirName = "";
                if (string.IsNullOrEmpty(dirName) && fileDat.UseDescriptionAsDirName && !string.IsNullOrWhiteSpace(newDatFile.Dat.GetData(RvDat.DatData.Description)))
                {
                    dirName = newDatFile.Dat.GetData(RvDat.DatData.Description);
                }
                if (string.IsNullOrEmpty(dirName) && !string.IsNullOrEmpty(newDatFile.Dat.GetData(RvDat.DatData.RootDir)))
                {
                    dirName = newDatFile.Dat.GetData(RvDat.DatData.RootDir);
                }
                if (string.IsNullOrEmpty(dirName))
                {
                    dirName = newDatFile.Dat.GetData(RvDat.DatData.DatName);
                }
                if (string.IsNullOrEmpty(dirName))
                {
                    dirName = Path.GetFileNameWithoutExtension(newDatFile.Dat.GetData(RvDat.DatData.DatRootFullName));
                }

                newDatFile.Name = VarFix.CleanFileName(dirName);

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

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

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

                newDatFile.Dat.AutoAddedDirectory = true;
            }
            else
            {
                newDatFile.Dat.AutoAddedDirectory = false;
            }

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

            if (MergeInDat(thisDirectory, newDatFile, out RvDat conflictDat, true))
            {
                ReportError.Show("Dat Merge conflict occured Cache contains " + conflictDat.GetData(RvDat.DatData.DatRootFullName) + " new dat " + newDatFile.Dat.GetData(RvDat.DatData.DatRootFullName) + " is trying to use the same directory 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);
        }