/// <summary> /// Add the new DAT's into the DAT list /// And merge in the new DAT data into the database /// </summary> /// <param name="dbDir">The Current database dir</param> /// <param name="tmpDir">A temp directory containing the DAT found in this directory in DatRoot</param> private static void AddNewDats(RvDir dbDir, RvDir tmpDir) { bool autoAddDirectory = (tmpDir.DirDatCount) > 1; int dbIndex = 0; int scanIndex = 0; Debug.WriteLine(""); Debug.WriteLine("Scanning for Adding new DATS"); while (dbIndex < dbDir.DirDatCount || scanIndex < tmpDir.DirDatCount) { RvDat dbDat = null; RvDat fileDat = null; int res = 0; if (dbIndex < dbDir.DirDatCount && scanIndex < tmpDir.DirDatCount) { dbDat = dbDir.DirDat(dbIndex); fileDat = tmpDir.DirDat(scanIndex); res = DBHelper.DatCompare(dbDat, fileDat); Debug.WriteLine("Checking " + dbDat.GetData(RvDat.DatData.DatFullName) + " : and " + fileDat.GetData(RvDat.DatData.DatFullName) + " : " + res); } else if (scanIndex < tmpDir.DirDatCount) { fileDat = tmpDir.DirDat(scanIndex); res = 1; Debug.WriteLine("Checking : and " + fileDat.GetData(RvDat.DatData.DatFullName) + " : " + res); } else if (dbIndex < dbDir.DirDatCount) { dbDat = dbDir.DirDat(dbIndex); res = -1; Debug.WriteLine("Checking " + dbDat.GetData(RvDat.DatData.DatFullName) + " : and : " + res); } switch (res) { case 0: _datsProcessed++; _bgw.ReportProgress(_datsProcessed); _bgw.ReportProgress(0, new bgwText("Dat : " + Path.GetFileNameWithoutExtension(fileDat.GetData(RvDat.DatData.DatFullName)))); Debug.WriteLine("Correct"); // Should already be set as correct above dbDat.Status = DatUpdateStatus.Correct; dbIndex++; scanIndex++; break; case 1: _datsProcessed++; _bgw.ReportProgress(_datsProcessed); _bgw.ReportProgress(0, new bgwText("Scanning New Dat : " + Path.GetFileNameWithoutExtension(fileDat.GetData(RvDat.DatData.DatFullName)))); Debug.WriteLine("Adding new DAT"); if (UpdateDatFile(fileDat, autoAddDirectory, dbDir)) { dbIndex++; } scanIndex++; break; case -1: // This should not happen as deleted dat have been removed above //dbIndex++; ReportError.SendAndShow(Resources.DatUpdate_UpdateDatList_ERROR_Deleting_a_DAT_that_should_already_be_deleted); break; } } }
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; } } }
private void PaintTree(RvDir pTree, Graphics g, Rectangle t) { int y = pTree.Tree.RTree.Top - _vScroll; if (pTree.Tree.RTree.IntersectsWith(t)) { Pen p = new Pen(Brushes.Gray, 1) { DashStyle = DashStyle.Dot }; string lTree = pTree.Tree.TreeBranches; for (int j = 0; j < lTree.Length; j++) { int x = j * 18 - _hScroll; string cTree = lTree.Substring(j, 1); switch (cTree) { case "│": g.DrawLine(p, x + 9, y, x + 9, y + 16); break; case "├": case "└": g.DrawLine(p, x + 9, y, x + 9, y + 16); g.DrawLine(p, x + 9, y + 16, x + 27, y + 16); break; } } } if (!pTree.Tree.RExpand.IsEmpty) { if (pTree.Tree.RExpand.IntersectsWith(t)) { g.DrawImage(pTree.Tree.TreeExpanded ? rvImages.ExpandBoxMinus : rvImages.ExpandBoxPlus, RSub(pTree.Tree.RExpand, _hScroll, _vScroll)); } } if (pTree.Tree.RChecked.IntersectsWith(t)) { switch (pTree.Tree.Checked) { case RvTreeRow.TreeSelect.Disabled: g.DrawImage(rvImages.TickBoxDisabled, RSub(pTree.Tree.RChecked, _hScroll, _vScroll)); break; case RvTreeRow.TreeSelect.UnSelected: g.DrawImage(rvImages.TickBoxUnTicked, RSub(pTree.Tree.RChecked, _hScroll, _vScroll)); break; case RvTreeRow.TreeSelect.Selected: g.DrawImage(rvImages.TickBoxTicked, RSub(pTree.Tree.RChecked, _hScroll, _vScroll)); break; } } if (pTree.Tree.RIcon.IntersectsWith(t)) { int icon = 2; if (pTree.DirStatus.HasInToSort()) { icon = 4; } else if (!pTree.DirStatus.HasCorrect()) { icon = 1; } else if (!pTree.DirStatus.HasMissing()) { icon = 3; } Bitmap bm; if (pTree.Dat == null && pTree.DirDatCount != 1) // Directory above DAT's in Tree { bm = rvImages.GetBitmap("DirectoryTree" + icon); } else if (pTree.Dat == null && pTree.DirDatCount == 1) // Directory that contains DAT's { bm = rvImages.GetBitmap("Tree" + icon); } else if (pTree.Dat != null && pTree.DirDatCount == 0) // Directories made by a DAT { bm = rvImages.GetBitmap("Tree" + icon); } else { ReportError.SendAndShow("Unknown Tree settings in DisplayTree."); bm = null; } if (bm != null) { g.DrawImage(bm, RSub(pTree.Tree.RIcon, _hScroll, _vScroll)); } } Rectangle recBackGround = new Rectangle(pTree.Tree.RText.X, pTree.Tree.RText.Y, Width - pTree.Tree.RText.X + _hScroll, pTree.Tree.RText.Height); if (recBackGround.IntersectsWith(t)) { string thistxt; if (pTree.Dat == null && pTree.DirDatCount != 1) // Directory above DAT's in Tree { thistxt = pTree.Name; } else if (pTree.Dat == null && pTree.DirDatCount == 1) // Directory that contains DAT's { thistxt = pTree.Name + ": " + pTree.DirDat(0).GetData(RvDat.DatData.Description) + " ( Have:" + pTree.DirStatus.CountCorrect() + " \\ Missing: " + pTree.DirStatus.CountMissing() + " )"; } // pTree.Parent.DirDatCount>1: This should probably be a test like parent contains Dat else if (pTree.Dat != null && pTree.Dat.AutoAddDirectory && pTree.Parent.DirDatCount > 1) { thistxt = pTree.Name + ": " + pTree.Dat.GetData(RvDat.DatData.Description) + " ( Have:" + pTree.DirStatus.CountCorrect() + " \\ Missing: " + pTree.DirStatus.CountMissing() + " )"; } else if (pTree.Dat != null && pTree.DirDatCount == 0) // Directories made by a DAT { thistxt = pTree.Name + " ( Have:" + pTree.DirStatus.CountCorrect() + " \\ Missing: " + pTree.DirStatus.CountMissing() + " )"; } else { ReportError.SendAndShow("Unknown Tree settings in DisplayTree."); thistxt = ""; } if (_lSelected != null && pTree.TreeFullName == _lSelected.TreeFullName) { g.FillRectangle(new SolidBrush(Color.FromArgb(51, 153, 255)), RSub(recBackGround, _hScroll, _vScroll)); g.DrawString(thistxt, new Font("Microsoft Sans Serif", 8), Brushes.White, pTree.Tree.RText.Left - _hScroll, pTree.Tree.RText.Top + 1 - _vScroll); } else { g.DrawString(thistxt, new Font("Microsoft Sans Serif", 8), Brushes.Black, pTree.Tree.RText.Left - _hScroll, pTree.Tree.RText.Top + 1 - _vScroll); } } if (pTree.Tree.TreeExpanded) { for (int i = 0; i < pTree.ChildCount; i++) { RvBase tBase = pTree.Child(i); if (tBase is RvDir) { RvDir tDir = (RvDir)tBase; if (tDir.Tree != null) { PaintTree(tDir, g, t); } } } } }
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); }
private static void FindAllDats(RvBase b, ReportType rt) { RvDir d = b as RvDir; if (d == null) { return; } if (d.DirDatCount > 0) { for (int i = 0; i < d.DirDatCount; i++) { RvDat dat = d.DirDat(i); int correct = 0; int missing = 0; int fixesNeeded = 0; if (d.Dat == dat) { correct += d.DirStatus.CountCorrect(); missing += d.DirStatus.CountMissing(); fixesNeeded += d.DirStatus.CountFixesNeeded(); } else { for (int j = 0; j < d.ChildCount; j++) { RvDir c = d.Child(j) as RvDir; if (c == null || c.Dat != dat) { continue; } correct += c.DirStatus.CountCorrect(); missing += c.DirStatus.CountMissing(); fixesNeeded += c.DirStatus.CountFixesNeeded(); } } switch (rt) { case ReportType.Complete: if (correct > 0 && missing == 0 && fixesNeeded == 0) { _ts.WriteLine(RemoveBase(dat.GetData(RvDat.DatData.DatFullName))); } break; case ReportType.CompletelyMissing: if (correct == 0 && missing > 0 && fixesNeeded == 0) { _ts.WriteLine(RemoveBase(dat.GetData(RvDat.DatData.DatFullName))); } break; case ReportType.PartialMissing: if ((correct > 0 && missing > 0) || fixesNeeded > 0) { _ts.WriteLine(RemoveBase(dat.GetData(RvDat.DatData.DatFullName))); _fileNameLength = 0; _fileSizeLength = 0; _repStatusLength = 0; ReportMissingFindSizes(d, dat, rt); ReportDrawBars(); ReportMissing(d, dat, rt); ReportDrawBars(); _ts.WriteLine(); } break; case ReportType.Fixing: if (fixesNeeded > 0) { _ts.WriteLine(RemoveBase(dat.GetData(RvDat.DatData.DatFullName))); _fileNameLength = 0; _fileSizeLength = 0; _repStatusLength = 0; ReportMissingFindSizes(d, dat, rt); ReportDrawBars(); ReportMissing(d, dat, rt); ReportDrawBars(); _ts.WriteLine(); } break; } } } if (b.Dat != null) { return; } for (int i = 0; i < d.ChildCount; i++) { FindAllDats(d.Child(i), rt); } }