public PrepatchSmallThreadPool(string _pso2Path, ConcurrentDictionary <string, PSO2File> PSO2filesList)
 {
     this._throttlecachespeed = MySettings.GameClientUpdateThrottleCache;
     MySettings.GameClientUpdateThrottleCacheChanged += this.MySettings_GameClientUpdateThrottleCacheChanged;
     this.bWorker                      = new ExtendedBackgroundWorker();
     this.bWorker.DoWork              += this.Bworker_DoWork;
     this.bWorker.RunWorkerCompleted  += this.Bworker_RunWorkerCompleted;
     this.SynchronizationContextObject = WebClientPool.SynchronizationContext;
     this.IsBusy   = false;
     this.PSO2Path = _pso2Path;
     this.ResetWork(PSO2filesList);
 }
        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;
            }
        }
Esempio n. 3
0
 public ExtendedBackgroundWorkerEventArgs(ExtendedBackgroundWorker _worker) : base()
 {
     this.Worker = _worker;
 }