Ejemplo n.º 1
0
        private static void ReadDat(FileInfo[] fis, string subPath, uint dirId, bool extraDir)
        {
            foreach (FileInfo f in fis)
            {
                _datsProcessed++;
                _bgw.ReportProgress(_datsProcessed);

                uint?datId = FindDat(subPath, f.Name, f.LastWriteTime, extraDir);
                if (datId != null)
                {
                    SetDatFound((uint)datId);
                    continue;
                }

                _bgw.ReportProgress(0, new bgwText("Dat : " + subPath + @"\" + f.Name));

                if (DatRead.ReadDat(f.FullName, ReadError, out DatHeader dh))
                //if (DatReader.DatReader.ReadDat(f.FullName, _bgw, out RvDat rvDat))
                {
                    RvDat rvDat     = ExternalDatConverter.ConvertFromExternalDat(f.FullName, dh);
                    uint  nextDirId = dirId;
                    if (extraDir)
                    {
                        string extraDirName = VarFix.CleanFileName(rvDat.GetExtraDirName()); // read this from dat.
                        nextDirId = RvDir.FindOrInsertIntoDir(dirId, extraDirName, Path.Combine(subPath, extraDirName) + "\\");
                    }

                    rvDat.DirId        = nextDirId;
                    rvDat.ExtraDir     = extraDir;
                    rvDat.Path         = subPath;
                    rvDat.DatTimeStamp = f.LastWriteTime;


                    DatSetRemoveUnneededDirs(rvDat);
                    DatSetCheckParentSets(rvDat);
                    DatSetRenameAndRemoveDups(rvDat);


                    if ((rvDat.MergeType ?? "").ToLower() == "full")
                    {
                        DatSetMergeSets(rvDat);
                    }

                    DatSetCheckCollect(rvDat);

                    DBSqlite.db.Commit();
                    DBSqlite.db.Begin();
                    rvDat.DbWrite();
                    DBSqlite.db.Commit();
                    DBSqlite.db.Begin();
                }

                if (_bgw.CancellationPending)
                {
                    return;
                }
            }
        }
Ejemplo n.º 2
0
        private static void ScanDirs(uint dirId, string datRoot, string subPath)
        {
            DirectoryInfo di = new DirectoryInfo(Path.Combine(datRoot, subPath));

            DirectoryInfo[] dis = di.GetDirectories();
            foreach (DirectoryInfo d in dis)
            {
                uint nextDirId = RvDir.FindOrInsertIntoDir(dirId, d.Name, Path.Combine(subPath, d.Name) + "\\");
                ScanDirs(nextDirId, datRoot, Path.Combine(subPath, d.Name));
                if (_bgw.CancellationPending)
                {
                    return;
                }
            }

            FileInfo[] fisDat   = di.GetFiles("*.DAT");
            FileInfo[] fisXml   = di.GetFiles("*.XML");
            int        datCount = fisDat.Length + fisXml.Length;

            ReadDat(fisDat, subPath, dirId, datCount > 1);

            ReadDat(fisXml, subPath, dirId, datCount > 1);
        }
Ejemplo n.º 3
0
        public static void UpdateDat(object sender, DoWorkEventArgs e)
        {
            try
            {
                _bgw = sender as BackgroundWorker;
                if (_bgw == null)
                {
                    return;
                }

                _bgw.ReportProgress(0, new bgwText("Clearing Found DAT List"));
                ClearFoundDATs();

                const string datRoot = @"";
                uint         dirId   = RvDir.FindOrInsertIntoDir(0, "DatRoot", "DatRoot\\");

                _bgw.ReportProgress(0, new bgwText("Pull File DB into memory"));
                NoFilesInDb = RvFile.FilesinDBCheck();

                _bgw.ReportProgress(0, new bgwText("Finding Dats"));
                _datCount = 0;
                DatCount(datRoot, "DatRoot");

                int dbDatCount = DatDBCount();

                bool dropIndex = false;
                //bool dropIndex = _datCount - dbDatCount > 10;

                if (dropIndex)
                {
                    _bgw.ReportProgress(0, new bgwText("Removing Indexes"));
                    DBSqlite.db.DropIndex();
                }

                _bgw.ReportProgress(0, new bgwText("Scanning Dats"));
                _datsProcessed = 0;

                _bgw.ReportProgress(0, new bgwSetRange(_datCount - 1));
                DBSqlite.db.Begin();
                ScanDirs(dirId, datRoot, "DatRoot");
                DBSqlite.db.Commit();

                _bgw.ReportProgress(0, new bgwText("Removing old DATs"));
                RemoveNotFoundDATs();

                _bgw.ReportProgress(0, new bgwText("Re-Creating Indexes"));
                DBSqlite.db.MakeIndex(_bgw);

                _bgw.ReportProgress(0, new bgwText("Re-calculating DIR Got Totals"));
                UpdateGotTotal();

                _bgw.ReportProgress(0, new bgwText("Dat Update Complete"));
                _bgw = null;
            }
            catch (Exception exc)
            {
                ReportError.UnhandledExceptionHandler(exc);

                _bgw = null;
            }
        }