private static void ReadDats(uint ParentId, string datRoot, string subPath) { DirectoryInfo di = new DirectoryInfo(Path.Combine(datRoot, subPath)); DirectoryInfo[] dis = di.GetDirectories(); foreach (DirectoryInfo d in dis) { uint DirId = FindOrInsert.FindOrInsertIntoDir(ParentId, d.Name, Path.Combine(subPath, d.Name) + "\\"); ReadDats(DirId, datRoot, Path.Combine(subPath, d.Name)); if (_bgw.CancellationPending) { return; } } FileInfo[] fis = di.GetFiles("*.DAT"); ReadDat(fis, subPath, ParentId); fis = di.GetFiles("*.XML"); ReadDat(fis, subPath, ParentId); }
public static void UpdateDat(object sender, DoWorkEventArgs e) { try { _bgw = sender as BackgroundWorker; if (_bgw == null) { return; } Program.SyncCont = e.Argument as SynchronizationContext; if (Program.SyncCont == null) { _bgw = null; return; } _bgw.ReportProgress(0, new bgwText("Clearing Found DAT List")); DataAccessLayer.ClearFoundDATs(); const string datRoot = @""; uint DirId = FindOrInsert.FindOrInsertIntoDir(0, "DatRoot", "DatRoot\\"); _bgw.ReportProgress(0, new bgwText("Pull File DB into memory")); NoFilesInDB = FindAFile.copyDBtoMem(); _bgw.ReportProgress(0, new bgwText("Finding Dats")); _datCount = 0; DatCount(datRoot, "DatRoot"); int dbDatCount = DataAccessLayer.DatDBCount(); bool dropIndex = false; dropIndex = (_datCount - dbDatCount > 10); if (dropIndex) { _bgw.ReportProgress(0, new bgwText("Removing Indexes")); DataAccessLayer.DropIndex(); } _bgw.ReportProgress(0, new bgwText("Scanning Dats")); _datsProcessed = 0; _bgw.ReportProgress(0, new bgwSetRange(_datCount - 1)); ReadDats(DirId, datRoot, "DatRoot"); _bgw.ReportProgress(0, new bgwText("Removing old DATs")); DataAccessLayer.RemoveNotFoundDATs(); if (dropIndex) { _bgw.ReportProgress(0, new bgwText("Re-Creating Indexes")); DataAccessLayer.MakeIndex(); } _bgw.ReportProgress(0, new bgwText("Re-calculating DIR Got Totals")); DataAccessLayer.UpdateGotTotal(); _bgw.ReportProgress(0, new bgwText("Dat Update Complete")); _bgw = null; Program.SyncCont = null; } catch (Exception exc) { ReportError.UnhandledExceptionHandler(exc); _bgw = null; Program.SyncCont = null; } }