Ejemplo n.º 1
0
        private void StartNext()
        {
            Download item = this._downloadQueue[0];

            if (!Directory.Exists(item.DestinationFolder))
            {
                Directory.CreateDirectory(item.DestinationFolder);
            }
            PathEx.Delete(item.Destination);
            PacksDownloader packsDownloader = this;

            packsDownloader._current = packsDownloader._current + 1;
            this._webClient.DownloadFileAsync(item.FileUrl, item.Destination, item);
            this._stopwatch.Reset();
            this._stopwatch.Start();
        }
Ejemplo n.º 2
0
        private void Download_ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
        {
            int num = (this._totalBytes == (long)0 ? 0 : (int)((long)100 * (this._currentBytes + e.BytesReceived) / this._totalBytes));
            DownloadProgressChangedArgs downloadProgressChangedArg = new DownloadProgressChangedArgs()
            {
                CurrentDownload = this._current
            };
            double   bytesReceived = (double)e.BytesReceived;
            TimeSpan elapsed       = this._stopwatch.Elapsed;

            downloadProgressChangedArg.DownloadSpeed     = PacksDownloader.FormatDownloadSpeed(bytesReceived / elapsed.TotalSeconds);
            downloadProgressChangedArg.CurrentPercentage = e.ProgressPercentage;
            downloadProgressChangedArg.TotalPercentage   = num;
            downloadProgressChangedArg.TotalDownloads    = this._downloadCount;
            downloadProgressChangedArg.FileName          = this._downloadQueue[0].FileName;
            downloadProgressChangedArg.PackName          = this._downloadQueue[0].VoicePack.PackName;
            this.OnProgressChanged(sender, downloadProgressChangedArg);
        }
Ejemplo n.º 3
0
        private void Download_Completed(object sender, AsyncCompletedEventArgs e)
        {
            Download userState = (Download)e.UserState;
            bool     error     = e.Error != null;

            if (e.Cancelled || error)
            {
                try
                {
                    FileEx.Delete(userState.Destination);
                }
                catch
                {
                }
                if (e.Cancelled)
                {
                    this.OnDownloadCompleted(sender, new DownloadCompletedArgs(true));
                    return;
                }
                if (error)
                {
                    this.OnDownloadCompleted(sender, new DownloadCompletedArgs(false, e.Error));
                }
                return;
            }
            this._downloadQueue.RemoveAt(0);
            if (this._downloadQueue.All <Download>((Download d) => d.VoicePack != userState.VoicePack))
            {
                this.PacksQueue.RemoveAll <VoicePack>((VoicePack d) => d == userState.VoicePack);
            }
            string filePathWithoutExtension = PathEx.GetFilePathWithoutExtension(userState.Destination);

            FileEx.Move(userState.Destination, filePathWithoutExtension, true);
            if (!this._downloadQueue.Any <Download>())
            {
                this.OnDownloadCompleted(sender, new DownloadCompletedArgs(false));
                return;
            }
            PacksDownloader fileSize = this;

            fileSize._currentBytes = fileSize._currentBytes + userState.FileSize;
            this.StartNext();
        }
Ejemplo n.º 4
0
        private static IEnumerable <Download> GetDownloadList(VoicePack pack)
        {
            string          patchPathFromUrl = PacksDownloader.GetPatchPathFromUrl(pack.BaseUrl);
            PatchInfoReader patchInfoReader  = PatchInfoReader.Download(Path.Combine(patchPathFromUrl, "patchinfo.xml"));

            foreach (string kom in pack.Koms)
            {
                IEnumerable <PatchInfoEntry> entries = patchInfoReader.Entries;
                PatchInfoEntry patchInfoEntry        = entries.FirstOrDefault <PatchInfoEntry>((PatchInfoEntry e) => e.FileName.Equals(kom, StringComparison.OrdinalIgnoreCase));
                if (patchInfoEntry == null)
                {
                    continue;
                }
                string str = Path.Combine(Paths.Main.Packs, pack.PackName, kom);
                if (File.Exists(str) && patchInfoEntry.Equals(str))
                {
                    continue;
                }
                str = string.Concat(str, ".tmp");
                Uri uri = new Uri(Path.Combine(patchPathFromUrl, "data", kom));
                yield return(new Download(uri, patchInfoEntry.Size, str, pack));
            }
        }
Ejemplo n.º 5
0
 private void _worker_DoWork(object sender, DoWorkEventArgs e)
 {
     this._currentBytes = (long)0;
     this._current      = 0;
     this._totalBytes   = (long)0;
     this._downloadQueue.Clear();
     for (int i = this.PacksQueue.Count - 1; i >= 0; i--)
     {
         IEnumerable <Download> downloadList = PacksDownloader.GetDownloadList(this.PacksQueue[i]);
         Download[]             array        = downloadList as Download[] ?? downloadList.ToArray <Download>();
         if (array.Any <Download>())
         {
             Download[] downloadArray = array;
             for (int j = 0; j < (int)downloadArray.Length; j++)
             {
                 Download download = downloadArray[j];
                 this._downloadQueue.Add(download);
             }
         }
         else
         {
             this.PacksQueue.RemoveAt(i);
         }
         if (this._worker.CancellationPending)
         {
             e.Cancel = true;
             return;
         }
     }
     this._downloadQueue.Reverse();
     foreach (Download download1 in this._downloadQueue)
     {
         PacksDownloader fileSize = this;
         fileSize._totalBytes = fileSize._totalBytes + download1.FileSize;
     }
     this._downloadCount = this._downloadQueue.Count;
 }
Ejemplo n.º 6
0
 public static bool HasUpdates(VoicePack pack)
 {
     return(PacksDownloader.GetDownloadList(pack).Any <Download>());
 }