public bool DoDownloadsFg(bool showProgress, bool showMsgBox, ICollection <SeriesSpecifier> shows, UI owner) { if (TVSettings.Instance.OfflineMode) { Logger.Info("Cancelling downloads... We're in offline mode"); return(true); // don't do internet in offline mode! } Logger.Info("Doing downloads in the foreground..."); CancellationTokenSource cts = new CancellationTokenSource(); StartBgDownloadThread(true, shows, showMsgBox, cts.Token); const int DELAY_STEP = 100; int count = 1000 / DELAY_STEP; // one second while (count-- > 0 && !DownloadDone) { Thread.Sleep(DELAY_STEP); } if (!DownloadDone && showProgress) // downloading still going on, so time to show the dialog if we're not in /hide mode { owner.ShowFgDownloadProgress(this, cts); } WaitForBgDownloadDone(); if (downloadOk) { return(true); } Logger.Warn(TheTVDB.LocalCache.Instance.LastErrorMessage + " " + TVmaze.LocalCache.Instance.LastErrorMessage); if (showErrorMsgBox) { CannotConnectForm ccform = new CannotConnectForm("Error while downloading", TheTVDB.LocalCache.Instance.LastErrorMessage + " " + TVmaze.LocalCache.Instance.LastErrorMessage); owner.ShowChildDialog(ccform); DialogResult ccresult = ccform.DialogResult; ccform.Dispose(); if (ccresult == DialogResult.Abort) { TVSettings.Instance.OfflineMode = true; } } TheTVDB.LocalCache.Instance.LastErrorMessage = string.Empty; TVmaze.LocalCache.Instance.LastErrorMessage = string.Empty; TMDB.LocalCache.Instance.LastErrorMessage = string.Empty; return(downloadOk); }
public bool DoDownloadsFg(bool showProgress, bool showMsgBox, ICollection <SeriesSpecifier> shows) { if (TVSettings.Instance.OfflineMode) { return(true); // don't do internet in offline mode! } Logger.Info("Doing downloads in the foreground..."); StartBgDownloadThread(true, shows, showMsgBox); const int DELAY_STEP = 100; int count = 1000 / DELAY_STEP; // one second while ((count-- > 0) && (!DownloadDone)) { Thread.Sleep(DELAY_STEP); } if (!DownloadDone && showProgress) // downloading still going on, so time to show the dialog if we're not in /hide mode { DownloadProgress dp = new DownloadProgress(this); dp.ShowDialog(); dp.Update(); } WaitForBgDownloadDone(); //TheTVDB.Instance.SaveCache(); if (!downloadOk) { Logger.Warn(TheTVDB.Instance.LastError); if (showErrorMsgBox) { CannotConnectForm ccform = new CannotConnectForm("Error while downloading", TheTVDB.Instance.LastError); DialogResult ccresult = ccform.ShowDialog(); if (ccresult == DialogResult.Abort) { TVSettings.Instance.OfflineMode = true; } } TheTVDB.Instance.LastError = ""; } return(downloadOk); }