Beispiel #1
0
        /// <summary>
        /// Handles all returned PatchFile instances in the queues.
        /// </summary>
        private static void ProcessQueues()
        {
            PatchFile file;

            // handle error files
            while (updateStage != UpdateStage.Abort && queueErrors.TryDequeue(out file))
            {
                // raise errorcounter for this file
                file.ErrorCount++;

                // try again by enqueueing again
                if (file.ErrorCount < MAXRETRIES)
                {
                    file.LengthDone = 0;
                    queue.Enqueue(file);
                }
                else
                {
                    if (!isHeadless)
                    {
                        MessageBox.Show(String.Format(languageHandler.FileFailed + file.Filename),
                                        languageHandler.ErrorText, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    // make sure to quit loop
                    UpdateStage = UpdateStage.Abort;
                }
            }

            // handle finished files
            while (queueDone.TryDequeue(out file))
            {
                // raise counter for finished files
                filesDone++;

                if (!clientFilesUpdated && file.HashedStatus == PatchFileHashedStatus.Download)
                {
                    clientFilesUpdated = true;
                }
                // check for finish
                if (filesDone >= files.Count)
                {
                    // if dotnet format and admin, try to 'ngen' the exe files
                    if (updateStage != UpdateStage.Abort)
                    {
                        if (updateFormat == UpdateFormat.DotNet &&
                            principal.IsInRole(WindowsBuiltInRole.Administrator))
                        {
                            form.DisplayStatus(languageHandler.NgenInit);
                            UpdateStage = UpdateStage.Ngen;
                        }
                        else
                        {
                            UpdateStage = UpdateStage.FinishedTransition;
                        }
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Internal thread loop
        /// </summary>
        protected void ThreadProc()
        {
            PatchFile file;

            while (IsRunning)
            {
                // just sleep until async download is done
                if (isDownloading)
                {
                    Thread.Sleep(16);
                }

                // try get next file to check/calculate hash for
                else if (queue.TryDequeue(out file))
                {
                    // CASE 1: File on disk has equal hash, skip it
                    if (IsDiskFileEqual(file))
                    {
                        file.LengthDone   = file.Length;
                        file.HashedStatus = PatchFileHashedStatus.DoNotDownload;
                        queueFinished.Enqueue(file);
                    }

                    // CASE 2: File must be downloaded
                    else
                    {
                        file.HashedStatus = PatchFileHashedStatus.Download;
                        queueHashed.Enqueue(file);
                    }
                }

                // otherwise try to get next file to download
                else if (queueHashed.TryDequeue(out file))
                {
                    // build full url and filepath
                    string fullUrl  = baseUrl + file.Basepath + file.Filename;
                    string fullDir  = baseFilePath + file.Basepath;
                    string fullFile = fullDir + file.Filename;

                    // possibly create directory structure
                    Directory.CreateDirectory(fullDir);

                    // start download it
                    isDownloading = true;
                    webClient.DownloadFileAsync(new Uri(fullUrl), fullFile, file);
                }

                // not downloading and no tasks
                else
                {
                    Thread.Sleep(100);
                }
            }

            // make sure to cancel async tasks
            webClient.CancelAsync();
        }
Beispiel #3
0
        /// <summary>
        /// Handles all returned PatchFile instances in the queues.
        /// </summary>
        private static void ProcessQueues()
        {
            PatchFile file;

            // handle error files
            while (!abort && queueErrors.TryDequeue(out file))
            {
                // raise errorcounter for this file
                file.ErrorCount++;

                // try again by enqueueing again
                if (file.ErrorCount < MAXRETRIES)
                {
                    file.LengthDone = 0;
                    queue.Enqueue(file);
                }
                else
                {
                    if (!isHeadless)
                    {
                        MessageBox.Show("Download of file " + file.Filename + " failed.",
                                        "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    // make sure to quit loop
                    abort     = true;
                    isRunning = false;
                }
            }

            // handle finished files
            while (queueDone.TryDequeue(out file))
            {
                // raise counter for finished files
                filesDone++;

                // check for finish
                if (filesDone >= files.Count)
                {
                    isRunning = false;
                }
            }
        }