private void ReadChecksumCache() { int corruptEntryCount = 0; this.myCheckSumList.Clear(); if (MySettings.GameClientUpdateCache) { string checksumpath = Infos.DefaultValues.MyInfo.Filename.PSO2ChecksumListPath; if (File.Exists(checksumpath)) { using (FileStream fs = File.OpenRead(checksumpath)) if (fs.Length > 0) { try { using (DeflateStream gs = new DeflateStream(fs, CompressionMode.Decompress)) using (StreamReader sr = new StreamReader(gs, Encoding.UTF8)) { PSO2FileChecksum hohoho; if (!sr.EndOfStream) { string tmpline = null; string[] tmpsplit; string checksumver = sr.ReadLine(); if (checksumver == MySettings.PSO2Version) { while (!sr.EndOfStream) { tmpline = sr.ReadLine(); if (!string.IsNullOrWhiteSpace(tmpline)) { tmpsplit = tmpline.Split(Microsoft.VisualBasic.ControlChars.Tab); if (tmpsplit.Length == 3) { hohoho = new PSO2FileChecksum(tmpsplit[0], long.Parse(tmpsplit[1]), tmpsplit[2]); this.myCheckSumList.TryAdd(hohoho.RelativePath.ToLower(), hohoho); } else { corruptEntryCount++; } } } } } } } catch (InvalidDataException dataEx) { this.myCheckSumList.Clear(); LogManager.GeneralLog.Print(dataEx); } } if (corruptEntryCount > 0) { this.OnStepChanged(new StepEventArgs(string.Format(LanguageManager.GetMessageText("PSO2Updater_CacheHasCorruptedEntries", "The updater cache has {0} corrupted entries. Those entry will be excluded from cache. This affects ONLY the speed for the file checking, accuracy will stay the same."), corruptEntryCount))); } } } }
private void Bworker_DoWork(object sender, DoWorkEventArgs e) { ExtendedBackgroundWorker bworker = sender as ExtendedBackgroundWorker; string currentfilepath, filemd5, _key; PSO2File _value; PSO2FileChecksum checksumobj; if (_keys.TryDequeue(out _key)) { if (myPSO2filesList.TryGetValue(_key, out _value)) { currentfilepath = null; filemd5 = null; //This hard-coded looks ugly, doesn't it??? if (Leayal.StringHelper.IsEqual(_value.SafeFilename, CommonMethods.CensorFilename, true)) { if (File.Exists(Infos.CommonMethods.PathConcat(this.PSO2Path, _key))) { if (this.myCheckSumList.TryGetValue(_key, out checksumobj)) { currentfilepath = Infos.CommonMethods.PathConcat(this.PSO2Path, checksumobj.RelativePath); FileInfo asd = new FileInfo(currentfilepath); if (asd.Exists && asd.Length == checksumobj.FileSize) { filemd5 = checksumobj.MD5; //Let's slow down a little if (this.ThrottleCacheSpeed > 0) { Thread.Sleep(this.ThrottleCacheSpeed); } } else { currentfilepath = null; } } if (string.IsNullOrEmpty(currentfilepath)) { currentfilepath = Infos.CommonMethods.PathConcat(this.PSO2Path, _key); checksumobj = PSO2FileChecksum.FromFile(this.PSO2Path, currentfilepath); filemd5 = checksumobj.MD5; if (!this.myCheckSumList.TryAdd(checksumobj.RelativePath, checksumobj)) { this.myCheckSumList[checksumobj.RelativePath] = checksumobj; } } if (!string.IsNullOrEmpty(filemd5)) { if (_value.MD5Hash == filemd5) { Interlocked.Increment(ref this._DownloadedFileCount); } else { this.OnStepChanged(new StepEventArgs(string.Format(LanguageManager.GetMessageText("PSO2UpdateManager_DownloadingFile", "Downloading file {0}"), _value.SafeFilename))); try { if (bworker.WebClient.DownloadFile(_value.Url, currentfilepath)) { this.myCheckSumList.TryUpdate(checksumobj.RelativePath, PSO2FileChecksum.FromFile(this.PSO2Path, currentfilepath), checksumobj); Interlocked.Increment(ref this._DownloadedFileCount); } else { _failedList.Add(_key); } } catch (System.Net.WebException) { _failedList.Add(_key); } } } else { this.OnStepChanged(new StepEventArgs(string.Format(LanguageManager.GetMessageText("PSO2UpdateManager_DownloadingFile", "Downloading file {0}"), _value.SafeFilename))); try { if (bworker.WebClient.DownloadFile(_value.Url, currentfilepath)) { this.myCheckSumList.TryUpdate(checksumobj.RelativePath, PSO2FileChecksum.FromFile(this.PSO2Path, currentfilepath), checksumobj); Interlocked.Increment(ref this._DownloadedFileCount); } else { _failedList.Add(_key); } } catch (System.Net.WebException) { _failedList.Add(_key); } } } else if (File.Exists(Infos.CommonMethods.PathConcat(this.PSO2Path, _key + ".backup"))) { if (this.myCheckSumList.TryGetValue(_key, out checksumobj)) { currentfilepath = Infos.CommonMethods.PathConcat(this.PSO2Path, checksumobj.RelativePath + ".backup"); FileInfo asd = new FileInfo(currentfilepath); if (asd.Exists && asd.Length == checksumobj.FileSize) { filemd5 = checksumobj.MD5; //Let's slow down a little if (this.ThrottleCacheSpeed > 0) { Thread.Sleep(this.ThrottleCacheSpeed); } } else { currentfilepath = null; } } if (string.IsNullOrEmpty(currentfilepath)) { currentfilepath = Infos.CommonMethods.PathConcat(this.PSO2Path, _key + ".backup"); checksumobj = PSO2FileChecksum.FromFile(this.PSO2Path, currentfilepath); filemd5 = checksumobj.MD5; if (!this.myCheckSumList.TryAdd(checksumobj.RelativePath, checksumobj)) { this.myCheckSumList[checksumobj.RelativePath] = checksumobj; } } if (!string.IsNullOrEmpty(filemd5)) { if (_value.MD5Hash == filemd5) { Interlocked.Increment(ref this._DownloadedFileCount); } else { this.OnStepChanged(new StepEventArgs(string.Format(LanguageManager.GetMessageText("PSO2UpdateManager_DownloadingFile", "Downloading file {0}"), _value.SafeFilename))); try { if (bworker.WebClient.DownloadFile(_value.Url, currentfilepath)) { currentfilepath = Infos.CommonMethods.PathConcat(this.PSO2Path, _key); using (var myfs = new FileStream(currentfilepath + ".backup", FileMode.Open, FileAccess.Read)) this.myCheckSumList.TryUpdate(checksumobj.RelativePath, new PSO2FileChecksum(currentfilepath, myfs.Length, Leayal.Security.Cryptography.MD5Wrapper.FromStream(myfs)), checksumobj); Interlocked.Increment(ref this._DownloadedFileCount); } else { _failedList.Add(_key); } } catch (System.Net.WebException) { _failedList.Add(_key); } } } else { this.OnStepChanged(new StepEventArgs(string.Format(LanguageManager.GetMessageText("PSO2UpdateManager_DownloadingFile", "Downloading file {0}"), _value.SafeFilename))); try { if (bworker.WebClient.DownloadFile(_value.Url, currentfilepath)) { this.myCheckSumList.TryUpdate(checksumobj.RelativePath, PSO2FileChecksum.FromFile(this.PSO2Path, currentfilepath), checksumobj); Interlocked.Increment(ref this._DownloadedFileCount); } else { _failedList.Add(_key); } } catch (System.Net.WebException) { _failedList.Add(_key); } } } } else { if (this.myCheckSumList.TryGetValue(_key, out checksumobj)) { currentfilepath = Infos.CommonMethods.PathConcat(this.PSO2Path, checksumobj.RelativePath); FileInfo asd = new FileInfo(currentfilepath); if (asd.Exists && asd.Length == checksumobj.FileSize) { filemd5 = checksumobj.MD5; //Let's slow down a little if (this.ThrottleCacheSpeed > 0) { Thread.Sleep(this.ThrottleCacheSpeed); } } else { currentfilepath = null; } } if (string.IsNullOrEmpty(currentfilepath)) { currentfilepath = Infos.CommonMethods.PathConcat(this.PSO2Path, _key); checksumobj = PSO2FileChecksum.FromFile(this.PSO2Path, currentfilepath); filemd5 = checksumobj.MD5; if (!this.myCheckSumList.TryAdd(checksumobj.RelativePath, checksumobj)) { this.myCheckSumList[checksumobj.RelativePath] = checksumobj; } } if (!string.IsNullOrEmpty(filemd5)) { if (_value.MD5Hash == filemd5) { Interlocked.Increment(ref this._DownloadedFileCount); } else { this.OnStepChanged(new StepEventArgs(string.Format(LanguageManager.GetMessageText("PSO2UpdateManager_DownloadingFile", "Downloading file {0}"), _value.SafeFilename))); if (bworker.WebClient.DownloadFile(_value.Url, currentfilepath)) { this.myCheckSumList.TryUpdate(checksumobj.RelativePath, PSO2FileChecksum.FromFile(this.PSO2Path, currentfilepath), checksumobj); Interlocked.Increment(ref this._DownloadedFileCount); } else { _failedList.Add(_key); } } } else { this.OnStepChanged(new StepEventArgs(string.Format(LanguageManager.GetMessageText("PSO2UpdateManager_DownloadingFile", "Downloading file {0}"), _value.SafeFilename))); if (bworker.WebClient.DownloadFile(_value.Url, currentfilepath)) { this.myCheckSumList.TryUpdate(checksumobj.RelativePath, PSO2FileChecksum.FromFile(this.PSO2Path, currentfilepath), checksumobj); Interlocked.Increment(ref this._DownloadedFileCount); } else { _failedList.Add(_key); } } } } } Interlocked.Increment(ref this._FileCount); this.OnProgressChanged(new DetailedProgressChangedEventArgs(this.FileCount, this.FileTotal)); if (bworker.CancellationPending) { e.Cancel = true; } }
private void Bworker_DoWork(object sender, DoWorkEventArgs e) { ExtendedBackgroundWorker bworker = sender as ExtendedBackgroundWorker; string currentfilepath, filemd5, _key; PSO2File _value; PSO2FileChecksum checksumobj; if (_keys.TryDequeue(out _key)) { if (myPSO2filesList.TryGetValue(_key, out _value)) { currentfilepath = null; filemd5 = null; if (string.IsNullOrEmpty(currentfilepath)) { currentfilepath = Infos.CommonMethods.PathConcat(this.PSO2Path, _key); checksumobj = PSO2FileChecksum.FromFile(this.PSO2Path, currentfilepath); filemd5 = checksumobj.MD5; } if (!string.IsNullOrEmpty(filemd5)) { if (_value.MD5Hash == filemd5) { Interlocked.Increment(ref this._DownloadedFileCount); } else { this.OnStepChanged(new StepEventArgs(string.Format(LanguageManager.GetMessageText("PSO2UpdateManager_DownloadingFile", "Downloading file {0}"), _value.SafeFilename))); try { if (bworker.WebClient.DownloadFile(_value.Url, currentfilepath)) { Interlocked.Increment(ref this._DownloadedFileCount); } else { _failedList.Add(_key); } } catch (System.Net.WebException) { _failedList.Add(_key); } } } else { this.OnStepChanged(new StepEventArgs(string.Format(LanguageManager.GetMessageText("PSO2UpdateManager_DownloadingFile", "Downloading file {0}"), _value.SafeFilename))); try { if (bworker.WebClient.DownloadFile(_value.Url, currentfilepath)) { Interlocked.Increment(ref this._DownloadedFileCount); } else { _failedList.Add(_key); } } catch (System.Net.WebException) { _failedList.Add(_key); } } } } Interlocked.Increment(ref this._FileCount); this.OnProgressChanged(new DetailedProgressChangedEventArgs(this.FileCount, this.FileTotal)); if (bworker.CancellationPending) { e.Cancel = true; } }