private static bool UpdateDatFile(RvDat file, bool autoAddDirectory, RvFile thisDirectory) { // Read the new Dat File into newDatFile RvFile newDatFile = DatReader.ReadInDatFile(file, _thWrk); // If we got a valid Dat File back if (newDatFile?.Dat == null) { ReportError.Show("Error reading Dat " + file.GetData(RvDat.DatData.DatRootFullName)); 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 directories 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(); RvFile newDirectory = new RvFile(FileType.Dir) { Dat = newDatFile.Dat }; // add the DAT into this directory newDirectory.ChildAdd(newDatFile); newDatFile = newDirectory; } 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); }
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); }