Skip to content

Commit

Permalink
Merge pull request #372 from MarkSummerville/25
Browse files Browse the repository at this point in the history
Bug Fixes
  • Loading branch information
SirSparkles authored Apr 3, 2018
2 parents adaaeda + d588b43 commit 907680b
Show file tree
Hide file tree
Showing 46 changed files with 952 additions and 749 deletions.
20 changes: 11 additions & 9 deletions TVRename#/App/ApplicationBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ protected override void OnCreateMainForm()
}

// Try loading TheTVDB cache file
TheTVDB.Instance.setup(tvdbFile, PathManager.TVDBFile, clargs);
TheTVDB.Instance.Setup(tvdbFile, PathManager.TVDBFile, clargs);

// Try loading settings file
doc = new TVDoc(settingsFile, clargs);
Expand All @@ -111,7 +111,7 @@ protected override void OnCreateMainForm()
if (!TheTVDB.Instance.LoadOK && !string.IsNullOrEmpty(TheTVDB.Instance.LoadErr)) recoverText += $"{Environment.NewLine}{TheTVDB.Instance.LoadErr}";
} while (recover);

convertSeriesTimeZones(doc, TheTVDB.Instance);
ConvertSeriesTimeZones(doc, TheTVDB.Instance);

// Show user interface
UI ui = new UI(doc, (TVRenameSplash)this.SplashScreen, !clargs.Unattended && !clargs.Hide);
Expand All @@ -122,7 +122,7 @@ protected override void OnCreateMainForm()
this.MainForm = ui;
}

private void convertSeriesTimeZones(TVDoc doc, TheTVDB tvdb)
private static void ConvertSeriesTimeZones(TVDoc doc, TheTVDB tvdb)
{
//this is just to convert timezones in the TheTVDB into the TVDOC where they should be:
//itshould only do anything the first time it is run and then be entirely begign
Expand All @@ -131,12 +131,14 @@ private void convertSeriesTimeZones(TVDoc doc, TheTVDB tvdb)
foreach (ShowItem si in doc.ShowItems)
{
string newTimeZone = tvdb.GetSeries(si.TVDBCode)?.tempTimeZone;
if ((si.ShowTimeZone == TimeZone.DefaultTimeZone()) && newTimeZone != TimeZone.DefaultTimeZone() && !string.IsNullOrWhiteSpace(newTimeZone))
{
si.ShowTimeZone = newTimeZone;
doc.SetDirty();
logger.Info("Copied timezone:{0} onto series {1}", newTimeZone, si.ShowName);
}

if (string.IsNullOrWhiteSpace(newTimeZone)) continue;
if ( newTimeZone == TimeZone.DefaultTimeZone() ) continue;
if (si.ShowTimeZone != TimeZone.DefaultTimeZone()) continue;

si.ShowTimeZone = newTimeZone;
doc.SetDirty();
logger.Info("Copied timezone:{0} onto series {1}", newTimeZone, si.ShowName);
}

}
Expand Down
13 changes: 10 additions & 3 deletions TVRename#/App/AutoFolderMonitor.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
using System;
using System.Collections.Generic;
using System.IO;
using Directory = Alphaleonis.Win32.Filesystem.Directory;
using File = Alphaleonis.Win32.Filesystem.File;

namespace TVRename
{
public class AutoFolderMonitor
public sealed class AutoFolderMonitor :IDisposable
{
private TVDoc mDoc;
private UI mUI;
private readonly TVDoc mDoc;
private readonly UI mUI;
private List<System.IO.FileSystemWatcher> Watchers = new List<System.IO.FileSystemWatcher>();
private System.Timers.Timer mScanDelayTimer;
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
Expand Down Expand Up @@ -114,5 +115,11 @@ public void StopMonitor()
}
Watchers.Clear();
}

public void Dispose()
{
// ReSharper disable once UseNullPropagation
if (this.mScanDelayTimer != null) this.mScanDelayTimer.Dispose();
}
}
}
26 changes: 16 additions & 10 deletions TVRename#/Custom Controls/MyListView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,22 +94,28 @@ protected override void OnKeyUp(KeyEventArgs e)
private const int SB_HORZ = 0;
private const int SB_VERT = 1;

[DllImport("user32.dll")]
static extern int GetScrollPos(IntPtr hWnd, int nBar);

[DllImport("user32.dll")]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

public int GetScrollVerticalPos()
{
return GetScrollPos(this.Handle, SB_VERT);
return NativeMethods.GetScrollPos(this.Handle, SB_VERT);
}

public void SetScrollVerticalPos(int position)
{
var currentPos = GetScrollPos(this.Handle, SB_VERT);
var currentPos = NativeMethods.GetScrollPos(this.Handle, SB_VERT);
var delta = -(currentPos - position);
SendMessage(this.Handle, LVM_SCROLL, IntPtr.Zero, (IntPtr)delta); // First param is horizontal scroll amount, second is vertical scroll amount
NativeMethods.SendMessage(this.Handle, LVM_SCROLL, IntPtr.Zero, (IntPtr)delta); // First param is horizontal scroll amount, second is vertical scroll amount
}
}
}
internal static partial class NativeMethods
{
[DllImport("user32.dll")]
internal static extern int GetScrollPos(IntPtr hWnd, int nBar);

[DllImport("user32.dll")]
internal static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

// MAH: Added in support of the Filter TextBox Button
[System.Runtime.InteropServices.DllImport("user32.dll")]
internal static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);
}
}
14 changes: 7 additions & 7 deletions TVRename#/Custom Controls/TheTVDBCodeFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,27 @@ public int SelectedCode()
if (this.lvMatches.SelectedItems.Count == 0)
return int.Parse(this.txtFindThis.Text);

return (int) (this.lvMatches.SelectedItems[0].Tag);
return (int.Parse(this.lvMatches.SelectedItems[0].SubItems[0].Text));
}
catch
{
return -1;
}
}
public string SelectedShowName()

public SeriesInfo SelectedShow()
{
try
{
if (this.lvMatches.SelectedItems.Count == 0) return "";
if (this.lvMatches.SelectedItems.Count == 0) return null;

return (string)(this.lvMatches.SelectedItems[0].SubItems[1].Text);
return ((SeriesInfo)(this.lvMatches.SelectedItems[0].Tag));
}
catch
{
return "";
return null;
}
}

private void txtFindThis_TextChanged(object sender, EventArgs e)
{
if (!this.mInternal)
Expand Down Expand Up @@ -135,7 +135,7 @@ private void DoFind(bool chooseOnlyMatch)
lvi.SubItems.Add(show);
lvi.SubItems.Add(kvp.Value.FirstAired != null ? kvp.Value.FirstAired.Value.Year.ToString() : "");

lvi.Tag = num;
lvi.Tag = kvp.Value;
if (numberMatch)
lvi.Selected = true;
this.lvMatches.Items.Add(lvi);
Expand Down
5 changes: 2 additions & 3 deletions TVRename#/DownloadIdentifers/DownloadEpisodeJPG.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class DownloadEpisodeJPG : DownloadIdentifier

public DownloadEpisodeJPG()
{
reset();
this.reset();
}

public override DownloadType GetDownloadType()
Expand Down Expand Up @@ -42,10 +42,9 @@ public override ItemList ProcessEpisode(ProcessedEpisode dbep, FileInfo filo, bo
return base.ProcessEpisode(dbep, filo, forceRefresh);
}

public override void reset()
public sealed override void reset()
{
doneJPG = new List<string>();
base.reset();
}
}

Expand Down
3 changes: 1 addition & 2 deletions TVRename#/DownloadIdentifers/DownloadFanartJPG.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ public override ItemList ProcessShow(ShowItem si, bool forceRefresh)
return base.ProcessShow(si, forceRefresh);
}

public override void reset()
public sealed override void reset()
{
doneFanartJPG = new List<string>();
base.reset();
}

}
Expand Down
5 changes: 2 additions & 3 deletions TVRename#/DownloadIdentifers/DownloadIdentifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ namespace TVRename
{
abstract class DownloadIdentifier
{

public DownloadIdentifier()
protected DownloadIdentifier()
{

}
Expand Down Expand Up @@ -51,6 +50,6 @@ public virtual void notifyComplete(FileInfo file)
{
}

public virtual void reset() { }
public abstract void reset();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public DownloadIdentifiersController() {
Identifiers.Add(new DownloadMede8erMetaData());
Identifiers.Add(new DownloadpyTivoMetaData());
Identifiers.Add(new DownloadSeriesJPG());
Identifiers.Add(new DownloadKODIMetaData());
Identifiers.Add(new DownloadKodiMetaData());
Identifiers.Add(new DownloadKODIImages());
Identifiers.Add(new IncorrectFileDates());
}
Expand Down
3 changes: 1 addition & 2 deletions TVRename#/DownloadIdentifers/DownloadJolderJPG.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,9 @@ public override ItemList ProcessSeason(ShowItem si, string folder, int snum, boo

return base.ProcessSeason(si,folder,snum,forceRefresh);
}
public override void reset()
public sealed override void reset()
{
doneFolderJPG = new List<string>();
base.reset();
}
}

Expand Down
4 changes: 2 additions & 2 deletions TVRename#/DownloadIdentifers/DownloadMede8erMetaData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace TVRename
{
// ReSharper disable once InconsistentNaming
class DownloadMede8erMetaData : DownloadIdentifier
{
private List<string> doneFiles;
Expand Down Expand Up @@ -83,10 +84,9 @@ public override ItemList ProcessEpisode(ProcessedEpisode dbep, FileInfo filo, bo
return base.ProcessEpisode(dbep, filo, forceRefresh);
}

public override void reset()
public sealed override void reset()
{
this.doneFiles = new List<string>();
base.reset();
}

}
Expand Down
3 changes: 1 addition & 2 deletions TVRename#/DownloadIdentifers/DownloadSeriesJPG.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace TVRename
{
class DownloadSeriesJPG : DownloadIdentifier
sealed class DownloadSeriesJPG : DownloadIdentifier
{
private List<string> doneJPG;
private const string defaultFileName = "series.jpg";
Expand Down Expand Up @@ -41,7 +41,6 @@ public override ItemList ProcessSeason(ShowItem si, string folder, int snum, boo
public override void reset()
{
doneJPG = new List<string>();
base.reset();
}
}

Expand Down
3 changes: 1 addition & 2 deletions TVRename#/DownloadIdentifers/DownloadXBMCImages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,12 @@ private ActionDownloadImage DoEpisode(ShowItem si, Episode ep, FileInfo filo,str

}

public override void reset()
public sealed override void reset()
{
doneBannerJPG = new List<String>();
donePosterJPG = new List<String>();
doneFanartJPG = new List<String>();
doneTBN = new List<String>();
base.reset();
}

}
Expand Down
15 changes: 7 additions & 8 deletions TVRename#/DownloadIdentifers/DownloadXBMCMetaData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

namespace TVRename
{
class DownloadKODIMetaData : DownloadIdentifier
class DownloadKodiMetaData : DownloadIdentifier
{
private static List<string> doneNFO;

public DownloadKODIMetaData()
public DownloadKodiMetaData()
{
reset();
}
Expand All @@ -23,7 +23,7 @@ public override void notifyComplete(FileInfo file)
{
if (file.FullName.EndsWith(".nfo", true, new CultureInfo("en")))
{
DownloadKODIMetaData.doneNFO.Add(file.FullName);
DownloadKodiMetaData.doneNFO.Add(file.FullName);
}
base.notifyComplete(file);
}
Expand All @@ -41,12 +41,12 @@ public override ItemList ProcessShow(ShowItem si, bool forceRefresh)
// was it written before we fixed the bug in <episodeguideurl> ?
(tvshownfo.LastWriteTime.ToUniversalTime().CompareTo(new DateTime(2009, 9, 13, 7, 30, 0, 0, DateTimeKind.Utc)) < 0);

bool alreadyOnTheList = DownloadKODIMetaData.doneNFO.Contains(tvshownfo.FullName);
bool alreadyOnTheList = DownloadKodiMetaData.doneNFO.Contains(tvshownfo.FullName);

if ((forceRefresh || needUpdate) && !alreadyOnTheList)
{
TheActionList.Add(new ActionNFO(tvshownfo, si));
DownloadKODIMetaData.doneNFO.Add(tvshownfo.FullName);
DownloadKodiMetaData.doneNFO.Add(tvshownfo.FullName);
}
return TheActionList;

Expand All @@ -66,7 +66,7 @@ public override ItemList ProcessEpisode(ProcessedEpisode dbep, FileInfo filo,boo
if (!nfo.Exists || (dbep.Srv_LastUpdated > TimeZone.Epoch(nfo.LastWriteTime)) || forceRefresh)
{
//If we do not already have plans to put the file into place
if (!(DownloadKODIMetaData.doneNFO.Contains(nfo.FullName)))
if (!(DownloadKodiMetaData.doneNFO.Contains(nfo.FullName)))
{
TheActionList.Add(new ActionNFO(nfo, dbep));
doneNFO.Add(nfo.FullName);
Expand All @@ -77,10 +77,9 @@ public override ItemList ProcessEpisode(ProcessedEpisode dbep, FileInfo filo,boo
return base.ProcessEpisode(dbep, filo, forceRefresh);
}

public override void reset()
public sealed override void reset()
{
doneNFO = new List<String>();
base.reset();
}

}
Expand Down
3 changes: 1 addition & 2 deletions TVRename#/DownloadIdentifers/DownloadpyTivoMetaData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ public override ItemList ProcessEpisode(ProcessedEpisode dbep, FileInfo filo, bo
return base.ProcessEpisode(dbep, filo, forceRefresh);
}

public override void reset()
public sealed override void reset()
{
base.reset();
}

}
Expand Down
1 change: 0 additions & 1 deletion TVRename#/DownloadIdentifers/IncorrectFileDates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ public override ItemList ProcessEpisode(ProcessedEpisode dbep, FileInfo filo, bo
public override void reset()
{
this.doneFilesAndFolders = new List<string>();
base.reset();
}

}
Expand Down
Loading

0 comments on commit 907680b

Please sign in to comment.