private static void RemoveOldDats(RvBase dbDir, RvDir tmpDir) { // now compare the old and new dats removing any old dats // in the current directory RvDir lDir = dbDir as RvDir; if (lDir == null) { return; } int dbIndex = 0; int scanIndex = 0; while (dbIndex < lDir.DirDatCount || scanIndex < tmpDir.DirDatCount) { RvDat dbDat = null; RvDat fileDat = null; int res = 0; if (dbIndex < lDir.DirDatCount && scanIndex < tmpDir.DirDatCount) { dbDat = lDir.DirDat(dbIndex); fileDat = tmpDir.DirDat(scanIndex); res = DBHelper.DatCompare(dbDat, fileDat); } else if (scanIndex < tmpDir.DirDatCount) { //this is a new dat that we have now found at the end of the list //fileDat = tmpDir.DirDat(scanIndex); res = 1; } else if (dbIndex < lDir.DirDatCount) { dbDat = lDir.DirDat(dbIndex); res = -1; } switch (res) { case 0: dbDat.Status = DatUpdateStatus.Correct; dbIndex++; scanIndex++; break; case 1: // this is a new dat that we will add next time around scanIndex++; break; case -1: dbDat.Status = DatUpdateStatus.Delete; lDir.DirDatRemove(dbIndex); break; } } // now scan the child directory structure of this directory dbIndex = 0; scanIndex = 0; while (dbIndex < lDir.ChildCount || scanIndex < tmpDir.ChildCount) { RvBase dbChild = null; RvBase fileChild = null; int res = 0; if (dbIndex < lDir.ChildCount && scanIndex < tmpDir.ChildCount) { dbChild = lDir.Child(dbIndex); fileChild = tmpDir.Child(scanIndex); res = DBHelper.CompareName(dbChild, fileChild); } else if (scanIndex < tmpDir.ChildCount) { //found a new directory on the end of the list //fileChild = tmpDir.Child(scanIndex); res = 1; } else if (dbIndex < lDir.ChildCount) { dbChild = lDir.Child(dbIndex); res = -1; } switch (res) { case 0: // found a matching directory in DatRoot So recurse back into it RemoveOldDats(dbChild, (RvDir)fileChild); dbIndex++; scanIndex++; break; case 1: // found a new directory will be added later scanIndex++; break; case -1: if (dbChild.FileType == FileType.Dir && dbChild.Dat == null) { RemoveOldDats(dbChild, new RvDir(FileType.Dir)); } dbIndex++; break; } } }