Skip to content

Commit

Permalink
Fix for #476
Browse files Browse the repository at this point in the history
  • Loading branch information
SirSparkles committed Aug 20, 2018
1 parent 4d2bdb8 commit ecdca02
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
30 changes: 24 additions & 6 deletions TVRename/Forms/UI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,12 @@ private ListView ListViewByName(string name)

private void flushCacheToolStripMenuItem_Click(object sender, EventArgs e)
{
if (busy != 0)
{
MessageBox.Show("Can't refresh until background download is complete");
return;
}

DialogResult res = MessageBox.Show(
"Are you sure you want to remove all " +
"locally stored TheTVDB information? This information will have to be downloaded again. You " +
Expand All @@ -355,11 +361,12 @@ private void flushCacheToolStripMenuItem_Click(object sender, EventArgs e)

if (res == DialogResult.Yes)
{

TheTVDB.Instance.ForgetEverything();
FillMyShows();
FillEpGuideHtml();
FillWhenToWatchList();
backgroundDownloadToolStripMenuItem_Click(sender, e);
BGDownloadTimer_QuickFire();
}
}

Expand Down Expand Up @@ -1871,21 +1878,27 @@ private void BGDownloadTimer_Tick(object sender, EventArgs e)
{
BGDownloadTimer.Interval = 10000; // come back in 10 seconds
BGDownloadTimer.Start();
Logger.Info("BG Download is busy - try again in 10 seconds");
return;
}

BGDownloadTimer.Interval = BgdlLongInterval(); // after first time (10 seconds), put up to 60 minutes
BGDownloadTimer.Start();

if (TVSettings.Instance.BGDownload && mDoc.DownloadsRemaining() == 0
) // only do auto-download if don't have stuff to do already
if (TVSettings.Instance.BGDownload && mDoc.DownloadsRemaining() == 0)
// only do auto-download if don't have stuff to do already
{
mDoc.DoDownloadsBG();

statusTimer_Tick(null, null);
BackgroundDownloadNow();
}
}

private void BGDownloadTimer_QuickFire()
{
BGDownloadTimer.Stop();
BGDownloadTimer.Interval = 1000;
BGDownloadTimer.Start();
}

private void backgroundDownloadNowToolStripMenuItem_Click(object sender, EventArgs e)
{
if (TVSettings.Instance.OfflineMode)
Expand All @@ -1897,6 +1910,11 @@ private void backgroundDownloadNowToolStripMenuItem_Click(object sender, EventAr
return;
}

BackgroundDownloadNow();
}

private void BackgroundDownloadNow()
{
BGDownloadTimer.Stop();
BGDownloadTimer.Start();

Expand Down
10 changes: 5 additions & 5 deletions TVRename/TheTVDB/TheTVDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ public bool GetUpdates()
int numberOfUpdatedEpisodes = 0;

ICollection<int> oldEpisodeIds = new List<int>();
foreach (KeyValuePair<int, Season> kvp2 in this.series[id].AiredSeasons)
foreach (KeyValuePair<int, Season> kvp2 in GetSeries(id)?.AiredSeasons??new Dictionary<int, Season>())
{
foreach (Episode ep in kvp2.Value.Episodes.Values)
{
Expand Down Expand Up @@ -863,7 +863,7 @@ private List<JObject> GetEpisodes(int id,string lang)
JToken x = jsonEpisodeResponse["links"]["next"];
bool moreResponses = !string.IsNullOrWhiteSpace(x.ToString());
Logger.Info(
$"Page {pageNumber} of {this.series[id].Name} had {numberOfResponses} episodes listed in {lang} with {(moreResponses?"":"no ")}more to come");
$"Page {pageNumber} of {GetSeries(id)?.Name} had {numberOfResponses} episodes listed in {lang} with {(moreResponses?"":"no ")}more to come");

if (numberOfResponses < 100 || !moreResponses)
{
Expand Down Expand Up @@ -1411,7 +1411,7 @@ private SeriesInfo DownloadSeriesNow(int code, bool episodesToo, bool bannersToo
JObject jsonActorsResponse = HttpHelper.JsonHttpGetRequest(TvDbTokenProvider.TVDB_API_URL + "/series/" + code + "/actors",
null, tvDbTokenProvider.GetToken());

series[si.TvdbCode].ClearActors();
GetSeries(si.TvdbCode)?.ClearActors();
foreach (JToken jsonActor in jsonActorsResponse["data"])
{
int actorId = (int)jsonActor["id"];
Expand All @@ -1421,7 +1421,7 @@ private SeriesInfo DownloadSeriesNow(int code, bool episodesToo, bool bannersToo
int actorSeriesId = (int)jsonActor["seriesId"];
int actorSortOrder = (int)jsonActor["sortOrder"];

series[si.TvdbCode].AddActor(new Actor(actorId, actorImage, actorName, actorRole, actorSeriesId,
GetSeries(si.TvdbCode)?.AddActor(new Actor(actorId, actorImage, actorName, actorRole, actorSeriesId,
actorSortOrder));
}
}
Expand Down Expand Up @@ -1711,7 +1711,7 @@ public bool EnsureUpdated(int code, bool bannersToo)
if ((series[code].Dirty) || (bannersToo && !series[code].BannersLoaded))
ok = (DownloadSeriesNow(code, false, bannersToo) != null);

foreach (KeyValuePair<int, Season> kvp in series[code].AiredSeasons)
foreach (KeyValuePair<int, Season> kvp in GetSeries(code)?.AiredSeasons??new Dictionary<int, Season>())
{
Season seas = kvp.Value;
foreach (Episode e in seas.Episodes.Values)
Expand Down

0 comments on commit ecdca02

Please sign in to comment.