Esempio n. 1
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);
        }
Esempio n. 2
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);
        }