Beispiel #1
0
        /// <summary>
        /// Receives notification that set download was completed
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Arguments</param>
        private void OnDownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
        {
            if (e != null && e.Error != null && e.Error.HResult != 0)
            {
                string localFile = Constants.GetSetZipPath(MissingSets[CurrentDownloadIndex].Item1);
                if (File.Exists(localFile))
                {
                    File.Delete(localFile);
                }

                // Error occured, finish up
                Callback.OnDownloadCanceled(true);
            }
            else
            {
                // Success, finish up and queue up the next one

                ProcessDownloadedSet(MissingSets[CurrentDownloadIndex].Item1, MissingSets[CurrentDownloadIndex].Item2);
                CurrentDownloadIndex++;
                if (CurrentDownloadIndex < MissingSets.Count)
                {
                    CardLibrary.DownloadSet(MissingSets[CurrentDownloadIndex].Item1,
                                            new DownloadProgressChangedEventHandler(OnDownloadProgressChanged),
                                            new AsyncCompletedEventHandler(OnDownloadFileCompleted));
                }
                else
                {
                    // Finished
                    Callback.OnAllSetsDownloaded();
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Find all missing sets and download them
        /// </summary>
        /// <param name="progressDisplay"></param>
        /// <returns></returns>
        public bool DownloadAllSets(IProgressDisplay progressDisplay)
        {
            MyProgressDisplay = progressDisplay;

            MissingSets = FindMissingSets();
            if (MissingSets.Count > 0)
            {
                long totalDownloadSize = MissingSets.Sum(x => x.Item2);
                var  result            = MessageBox.Show(
                    string.Format("Card sets have been updated. Download size is {0} MB. Download new sets?", totalDownloadSize / 1024 / 1024),
                    "Sets Out of Date",
                    MessageBoxButtons.YesNo);
                if (result != DialogResult.Yes)
                {
                    return(false);
                }

                // Delete existing outdated sets
                foreach (var set in MissingSets)
                {
                    if (Directory.Exists(Constants.GetSetPath(set.Item1)))
                    {
                        Directory.Delete(Constants.GetSetPath(set.Item1), true);
                    }
                }

                CurrentDownloadIndex = 0;
                CardLibrary.DownloadSet(MissingSets[CurrentDownloadIndex].Item1,
                                        new DownloadProgressChangedEventHandler(OnDownloadProgressChanged),
                                        new AsyncCompletedEventHandler(OnDownloadFileCompleted));
            }
            else
            {
                Callback.OnAllSetsDownloaded();
            }
            return(true);
        }