private void BWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            this.OnProgressStateChanged(new ProgressBarStateChangedEventArgs(Forms.MyMainMenu.ProgressBarVisibleState.Infinite));
            PrepatchWorkerParams wp = e.Argument as PrepatchWorkerParams;
            // Let's get to see how many patchlist{0}.txt there are
            var remoteresult = CheckForUpdates();

            if (remoteresult.IsPrepatchExisted)
            {
                if (wp.Force || remoteresult.IsNewVersion)
                {
                    if (GetFilesList(remoteresult.Latest.ListCount) > 0)
                    {
                        string pso2precedePath = Path.Combine(wp.PSO2Path, "_precede");
                        System.Collections.Concurrent.ConcurrentDictionary <string, PSO2File> myPSO2filesList = ParseFilelist(this.myFileList);
                        if (!myPSO2filesList.IsEmpty)
                        {
                            Microsoft.VisualBasic.FileIO.FileSystem.CreateDirectory(pso2precedePath);
                            this.ProgressTotal = myPSO2filesList.Count;
                            this.OnProgressStateChanged(new ProgressBarStateChangedEventArgs(Forms.MyMainMenu.ProgressBarVisibleState.Percent, new Forms.MyMainMenuCode.CircleProgressBarProperties(true)));
                            PrepatchVersion verstring = wp.NewVersion;
                            if (string.IsNullOrWhiteSpace(verstring.Version))
                            {
                                verstring = remoteresult.Latest;
                            }

                            /*if (string.IsNullOrWhiteSpace(verstring))
                             *  verstring = this.myWebClient.DownloadString(DefaultValues.PatchInfo.VersionLink);//*/
                            anothersmallthreadpool                  = new PrepatchSmallThreadPool(pso2precedePath, myPSO2filesList);
                            anothersmallthreadpool.StepChanged     += Anothersmallthreadpool_StepChanged;
                            anothersmallthreadpool.ProgressChanged += Anothersmallthreadpool_ProgressChanged;
                            anothersmallthreadpool.KaboomFinished  += Anothersmallthreadpool_KaboomFinished;
                            anothersmallthreadpool.StartWork(new PrepatchWorkerParams(pso2precedePath, verstring, wp.Force));
                            e.Result = null;
                        }
                        else
                        {
                            e.Result = new PSO2UpdateResult(UpdateResult.Failed);
                        }
                    }
                    else
                    {
                        e.Result = new PSO2UpdateResult(UpdateResult.Unknown);
                        throw new PSO2UpdateException(LanguageManager.GetMessageText("PSO2PrepatchManager_GetPatchListFailed", "Failed to get PSO2's pre-patch file list."));
                    }
                }
            }
            else
            {
                throw remoteresult.Error;
            }
        }
        public void StartWork(PrepatchWorkerParams argument)
        {
            if (!this.IsBusy)
            {
                this.token = argument;
                if (!myPSO2filesList.IsEmpty)
                {
                    this.bWorker.RunWorkerAsync();

                    /*ExtendedBackgroundWorker asdasd;
                     * asdasd = this._bwList.GetRestingWorker();
                     * if (asdasd != null && !asdasd.IsBusy)
                     *  asdasd.RunWorkerAsync();
                     * while (this._bwList.GetNumberOfRunning() < this._bwList.MaxCount)
                     * {
                     *  asdasd = this._bwList.GetRestingWorker();
                     *  if (asdasd != null && !asdasd.IsBusy)
                     *      asdasd.RunWorkerAsync();
                     * }//*/
                }
            }
        }
        private void Anothersmallthreadpool_KaboomFinished(object sender, KaboomFinishedEventArgs e)
        {
            this.OnProgressStateChanged(new ProgressBarStateChangedEventArgs(Forms.MyMainMenu.ProgressBarVisibleState.None));
            if (e.Error != null)
            {
                this.OnHandledException(e.Error);
                if (this.myFileList.Count > 0)
                {
                    this.myFileList.Clear();
                }
                anothersmallthreadpool.Dispose();
            }
            else
            {
                LogManager.GeneralLog.Print(PSO2UpdateResult.GetMsg(e.Result, e.FailedList == null ? 0 : e.FailedList.Count), LogLevel.Info);
                System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(delegate
                {
                    switch (e.Result)
                    {
                    case UpdateResult.Cancelled:
                        if (e.UserToken != null && e.UserToken is PrepatchWorkerParams)
                        {
                            PrepatchWorkerParams wp = e.UserToken as PrepatchWorkerParams;
                            if (this.myFileList.Count > 0)
                            {
                                this.myFileList.Clear();
                            }
                            this.OnPrepatchDownloaded(new PSO2NotifyEventArgs(true, false, e.FailedList));
                        }
                        break;

                    case UpdateResult.Failed:
                        if (e.UserToken != null && e.UserToken is PrepatchWorkerParams)
                        {
                            PrepatchWorkerParams wp = e.UserToken as PrepatchWorkerParams;
                            if (this.myFileList.Count > 0)
                            {
                                this.myFileList.Clear();
                            }
                            this.OnPrepatchDownloaded(new PSO2NotifyEventArgs(wp.NewVersion.ToString(" revision "), false, e.FailedList));
                        }
                        break;

                    default:
                        if (e.UserToken != null && e.UserToken is PrepatchWorkerParams)
                        {
                            PrepatchWorkerParams wp = e.UserToken as PrepatchWorkerParams;
                            if (this.myFileList.Count > 0)
                            {
                                this.WritePatchListOut(wp.PSO2Path);
                                this.myFileList.Clear();
                            }
                            MySettings.PSO2PrecedeVersion = wp.NewVersion;
                            this.OnPrepatchDownloaded(new PSO2NotifyEventArgs(wp.NewVersion.ToString(" revision "), false));
                        }
                        break;
                    }
                    anothersmallthreadpool.Dispose();
                }));
            }
        }
 private void UpdatePrepatch(PrepatchWorkerParams wp)
 {
     this.bWorker.RunWorkerAsync(wp);
 }