示例#1
0
        public static void Read(object sender, DoWorkEventArgs e)
        {
            Bgw = sender as BackgroundWorker;
            Program.SyncCont = e.Argument as SynchronizationContext;

            if (!File.Exists(Settings.CacheFile))
            {
                OpenDefaultDB();
                Bgw = null;
                Program.SyncCont = null;
                return;
            }
            DirTree = new RvDir(FileType.Dir);
            FileStream fs = new FileStream(Settings.CacheFile, FileMode.Open, FileAccess.Read);

            if (fs.Length < 4)
            {
                ReportError.UnhandledExceptionHandler("Cache is Corrupt, revert to Backup.");
            }


            BinaryReader br = new BinaryReader(fs);

            if (Bgw != null)
            {
                Bgw.ReportProgress(0, new bgwSetRange((int)fs.Length));
            }

            DBVersion.VersionNow = br.ReadInt32();

            if (DBVersion.VersionNow != DBVersion.Version)
            {
                ReportError.Show(Resources.DB_Read_Data_Cache_version_is_out_of_date_you_should_now_rescan_your_dat_directory_and_roms_directory_);
                OpenDefaultDB();
            }
            else
            {
                DirTree.Read(br, null);
            }

            if (fs.Position > fs.Length - 8)
            {
                ReportError.UnhandledExceptionHandler("Cache is Corrupt, revert to Backup.");
            }

            ulong testEOF = br.ReadUInt64();

            if (testEOF != EndCacheMarker)
            {
                ReportError.UnhandledExceptionHandler("Cache is Corrupt, revert to Backup.");
            }

            br.Close();
            fs.Close();
            fs.Dispose();

            Bgw = null;
            Program.SyncCont = null;
        }
示例#2
0
        public static void Read(object sender, DoWorkEventArgs e)
        {
            Bgw = sender as BackgroundWorker;
            Program.SyncCont = e.Argument as SynchronizationContext;

            if (!File.Exists(Settings.CacheFile))
            {
                OpenDefaultDB();
                Bgw = null;
                Program.SyncCont = null;
                return;
            }
            DirTree = new RvDir(FileType.Dir);
            FileStream fs = new FileStream(Settings.CacheFile, FileMode.Open, FileAccess.Read);
            if (fs.Length < 4)
                ReportError.UnhandledExceptionHandler("Cache is Corrupt, revert to Backup.");

            BinaryReader br = new BinaryReader(fs);

            if (Bgw != null)
                Bgw.ReportProgress(0, new bgwSetRange((int)fs.Length));

            DBVersion.VersionNow = br.ReadInt32();

            if (DBVersion.VersionNow != DBVersion.Version)
            {
                ReportError.Show(Resources.DB_Read_Data_Cache_version_is_out_of_date_you_should_now_rescan_your_dat_directory_and_roms_directory_);
                OpenDefaultDB();
            }
            else
            {
                DirTree.Read(br, null);
            }

            if (fs.Position > fs.Length - 8)
                ReportError.UnhandledExceptionHandler("Cache is Corrupt, revert to Backup.");

            ulong testEOF = br.ReadUInt64();
            if (testEOF != EndCacheMarker)
                ReportError.UnhandledExceptionHandler("Cache is Corrupt, revert to Backup.");

            br.Close();
            fs.Close();
            fs.Dispose();

            Bgw = null;
            Program.SyncCont = null;
        }