()
| 32 | } |
| 33 | |
| 34 | public static async void CheckUpdate() |
| 35 | { |
| 36 | var update = await FetchUpdate(); |
| 37 | if (update == null) return; |
| 38 | |
| 39 | var dialog = new ProgressDialog() |
| 40 | { |
| 41 | WindowTitle = Program.Name + " v" + update.Version, |
| 42 | ShowTimeRemaining = false, |
| 43 | ProgressBarStyle = ProgressBarStyle.MarqueeProgressBar |
| 44 | }; |
| 45 | |
| 46 | var cancel = false; |
| 47 | var percent = 0; |
| 48 | var message = "Downloading..."; |
| 49 | |
| 50 | dialog.DoWork += (s, e) => |
| 51 | { |
| 52 | while (percent < 100) |
| 53 | { |
| 54 | if (cancel || dialog.CancellationPending) |
| 55 | { |
| 56 | e.Cancel = true; |
| 57 | return; |
| 58 | } |
| 59 | |
| 60 | dialog.ReportProgress(percent, "Downloading update...", message); |
| 61 | Thread.Sleep(100); |
| 62 | } |
| 63 | |
| 64 | Thread.Sleep(100); |
| 65 | dialog.ReportProgress(100, "Updating...", "Done."); |
| 66 | }; |
| 67 | |
| 68 | MainWindow.Instance.Hide(); |
| 69 | dialog.Show(); |
| 70 | |
| 71 | try |
| 72 | { |
| 73 | var rnd = new Random().Next().ToString("x"); |
| 74 | var updateDir = Path.Combine(Path.GetTempPath(), "pengu_update_" + rnd); |
| 75 | Directory.CreateDirectory(updateDir); |
| 76 | |
| 77 | var tempFile = Path.GetTempFileName(); |
| 78 | await DownloadFile(update.DownloadUrl, tempFile, (downloaded, total, percent_) => |
| 79 | { |
| 80 | percent = percent_; |
| 81 | message = string.Format("{0:0.##} / {1:0.##} MB received.", |
| 82 | (double)downloaded / 1024 / 1024, |
| 83 | (double)total / 1024 / 1024); |
| 84 | }); |
| 85 | |
| 86 | ZipFile.ExtractToDirectory(tempFile, updateDir); |
| 87 | Utils.DeletePath(tempFile); |
| 88 | |
| 89 | while (Module.IsLoaded) |
| 90 | { |
| 91 | MessageBox.Show("Please close your League of Legends Client to apply update.", |
no test coverage detected