Skip to content

Commit

Permalink
Merge pull request #297 from MarkSummerville/master
Browse files Browse the repository at this point in the history
Bug Fixes
  • Loading branch information
SirSparkles authored Jan 18, 2018
2 parents bacfbe3 + 0db3b90 commit 4436b78
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 35 deletions.
5 changes: 4 additions & 1 deletion TVRename#/Finders/FileFinder.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
Expand Down Expand Up @@ -146,6 +146,9 @@ public void KeepTogether(ItemList Actionlist)
FileInfo[] flist = sfdi.GetFiles(basename + ".*");
foreach (FileInfo fi in flist)
{
//check to see whether the file is one of the types we do/don't want to include
if (!TVSettings.Instance.KeepTogetherFilesWithType(fi.Extension)) continue;

// do case insensitive replace
string n = fi.Name;
int p = n.ToUpper().IndexOf(basename.ToUpper());
Expand Down
3 changes: 2 additions & 1 deletion TVRename#/Forms/AddEditShow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public AddEditShow(ShowItem si)
}
this.txtTagList.Text = tl.ToString();

cbUseCustomSearch.Checked = !String.IsNullOrEmpty(si.CustomSearchURL);
cbUseCustomSearch.Checked = si.UseCustomSearchURL && !String.IsNullOrWhiteSpace(si.CustomSearchURL);
txtSearchURL.Text = si.CustomSearchURL ?? "";
EnableDisableCustomSearch();
}
Expand Down Expand Up @@ -179,6 +179,7 @@ private void SetmSI()
this.mSI.DVDOrder = this.chkDVDOrder.Checked;
this.mSI.ForceCheckFuture = this.cbIncludeFuture.Checked;
this.mSI.ForceCheckNoAirdate = this.cbIncludeNoAirdate.Checked;
this.mSI.UseCustomSearchURL = this.cbUseCustomSearch.Checked;
this.mSI.CustomSearchURL = this.txtSearchURL.Text;

this.mSI.UseSequentialMatch = this.cbSequentialMatching.Checked;
Expand Down
3 changes: 2 additions & 1 deletion TVRename#/Forms/Preferences.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions TVRename#/Forms/Preferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,10 @@ private void OKButton_Click(object sender, System.EventArgs e)
S.mode = TVSettings.BetaMode.ProductionOnly;
}

if (this.cbKeepTogetherMode.Text == "all but")
if (this.cbKeepTogetherMode.Text == "All but these")
{
S.keepTogetherMode = TVSettings.KeepTogetherModes.AllBut;
} else if (this.cbKeepTogetherMode.Text == "just")
} else if (this.cbKeepTogetherMode.Text == "Just")

{
S.keepTogetherMode = TVSettings.KeepTogetherModes.Just;
Expand Down Expand Up @@ -432,10 +432,10 @@ private void Preferences_Load(object sender, System.EventArgs e)
this.cbKeepTogetherMode.Text = "All";
break;
case TVSettings.KeepTogetherModes.AllBut:
this.cbKeepTogetherMode.Text = "all but";
this.cbKeepTogetherMode.Text = "All but these";
break;
case TVSettings.KeepTogetherModes.Just:
this.cbKeepTogetherMode.Text = "just";
this.cbKeepTogetherMode.Text = "Just";
break;
}

Expand Down Expand Up @@ -601,7 +601,7 @@ private void chkShowInTaskbar_CheckedChanged(object sender, System.EventArgs e)
private void cbKeepTogether_CheckedChanged(object sender, System.EventArgs e)
{
this.cbTxtToSub.Enabled = this.cbKeepTogether.Checked;
this.txtKeepTogether.Enabled = this.cbKeepTogether.Checked;
this.txtKeepTogether.Enabled = (this.cbKeepTogether.Checked && this.cbKeepTogetherMode.Text != "All");
this.cbKeepTogetherMode.Enabled = this.cbKeepTogether.Checked;
this.label39.Enabled = this.cbKeepTogether.Checked;
}
Expand Down Expand Up @@ -1214,5 +1214,9 @@ private void bnMCPresets_Click(object sender, EventArgs e)
cmDefaults.Show(pt);
}

private void cbKeepTogetherMode_SelectedIndexChanged(object sender, EventArgs e)
{
this.txtKeepTogether.Enabled = (this.cbKeepTogether.Checked && this.cbKeepTogetherMode.Text != "All");
}
}
}
4 changes: 2 additions & 2 deletions TVRename#/Forms/UI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public void UpdateSearchButton()
foreach (ListViewItem lvi in lvWhenToWatch.SelectedItems)
{
ProcessedEpisode pe = lvi.Tag as ProcessedEpisode;
if (pe != null && !String.IsNullOrEmpty(pe.SI.CustomSearchURL))
if (pe != null && pe.SI.UseCustomSearchURL && !String.IsNullOrWhiteSpace(pe.SI.CustomSearchURL))
{
customWTW = true;
break;
Expand All @@ -258,7 +258,7 @@ public void UpdateSearchButton()
foreach (ListViewItem lvi in lvAction.SelectedItems)
{
ProcessedEpisode pe = lvi.Tag as ProcessedEpisode;
if (pe != null && !String.IsNullOrEmpty(pe.SI.CustomSearchURL))
if (pe != null && pe.SI.UseCustomSearchURL && !String.IsNullOrWhiteSpace(pe.SI.CustomSearchURL))
{
customAction = true;
break;
Expand Down
34 changes: 17 additions & 17 deletions TVRename#/Settings/CustomName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,40 +117,40 @@ public static string NameForNoExt(ProcessedEpisode pe, String styleString, bool
epname = System.Web.HttpUtility.UrlEncode(epname);
}

name = name.Replace("{ShowName}", showname);
name = name.Replace("{Season}", pe.SeasonNumber.ToString());
name = name.Replace("{Season:2}", pe.SeasonNumber.ToString("00"));
name = name.Replace("{Episode}", pe.EpNum.ToString("00"));
name = name.Replace("{Episode2}", pe.EpNum2.ToString("00"));
name = name.Replace("{EpisodeName}", epname);
name = name.Replace("{Number}", pe.OverallNumber.ToString());
name = name.Replace("{Number:2}", pe.OverallNumber.ToString("00"));
name = name.Replace("{Number:3}", pe.OverallNumber.ToString("000"));
name = name.ReplaceInsensitive("{ShowName}", showname);
name = name.ReplaceInsensitive("{Season}", pe.SeasonNumber.ToString());
name = name.ReplaceInsensitive("{Season:2}", pe.SeasonNumber.ToString("00"));
name = name.ReplaceInsensitive("{Episode}", pe.EpNum.ToString("00"));
name = name.ReplaceInsensitive("{Episode2}", pe.EpNum2.ToString("00"));
name = name.ReplaceInsensitive("{EpisodeName}", epname);
name = name.ReplaceInsensitive("{Number}", pe.OverallNumber.ToString());
name = name.ReplaceInsensitive("{Number:2}", pe.OverallNumber.ToString("00"));
name = name.ReplaceInsensitive("{Number:3}", pe.OverallNumber.ToString("000"));
DateTime? airdt = pe.GetAirDateDT(false);
if (airdt != null)
{
DateTime dt = (DateTime) airdt;
name = name.Replace("{ShortDate}", dt.ToString("d"));
name = name.Replace("{LongDate}", dt.ToString("D"));
name = name.ReplaceInsensitive("{ShortDate}", dt.ToString("d"));
name = name.ReplaceInsensitive("{LongDate}", dt.ToString("D"));
string ymd = dt.ToString("yyyy/MM/dd");
if (urlEncode)
ymd = System.Web.HttpUtility.UrlEncode(ymd);
name = name.Replace("{YMDDate}", ymd);
name = name.ReplaceInsensitive("{YMDDate}", ymd);
}
else
{
name = name.Replace("{ShortDate}", "---");
name = name.Replace("{LongDate}", "------");
name = name.ReplaceInsensitive("{ShortDate}", "---");
name = name.ReplaceInsensitive("{LongDate}", "------");
string ymd = "----/--/--";
if (urlEncode)
ymd = System.Web.HttpUtility.UrlEncode(ymd);
name = name.Replace("{YMDDate}", ymd);
name = name.ReplaceInsensitive("{YMDDate}", ymd);
}

String allEps = "";
for (int i = pe.EpNum; i <= pe.EpNum2; i++)
allEps += "E" + i.ToString("00");
name = Regex.Replace(name, "{AllEpisodes}", allEps);
name = Regex.Replace(name, "{AllEpisodes}", allEps,RegexOptions.IgnoreCase);

if (pe.EpNum2 == pe.EpNum)
name = Regex.Replace(name, "([^\\\\])\\[.*?[^\\\\]\\]", "$1"); // remove optional parts
Expand All @@ -163,4 +163,4 @@ public static string NameForNoExt(ProcessedEpisode pe, String styleString, bool
return name.Trim();
}
}
}
}
28 changes: 21 additions & 7 deletions TVRename#/Settings/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -814,14 +814,16 @@ public void WriteXML(XmlWriter writer)
XMLHelper.WriteElementToXML(writer,"ExportRSSMaxShows",this.ExportRSSMaxShows);
XMLHelper.WriteElementToXML(writer,"ExportRSSDaysPast",this.ExportRSSDaysPast);
XMLHelper.WriteElementToXML(writer,"KeepTogether",this.KeepTogether);
XMLHelper.WriteElementToXML(writer,"KeepTogetherType", (int)this.keepTogetherMode);
XMLHelper.WriteElementToXML(writer,"KeepTogetherExtensions", this.keepTogetherExtensionsString);
XMLHelper.WriteElementToXML(writer,"LeadingZeroOnSeason",this.LeadingZeroOnSeason);
XMLHelper.WriteElementToXML(writer,"ShowInTaskbar",this.ShowInTaskbar);
XMLHelper.WriteElementToXML(writer,"IgnoreSamples",this.IgnoreSamples);
XMLHelper.WriteElementToXML(writer,"ForceLowercaseFilenames",this.ForceLowercaseFilenames);
XMLHelper.WriteElementToXML(writer,"RenameTxtToSub",this.RenameTxtToSub);
XMLHelper.WriteElementToXML(writer,"ParallelDownloads",this.ParallelDownloads);
XMLHelper.WriteElementToXML(writer,"AutoSelectShowInMyShows",this.AutoSelectShowInMyShows);
XMLHelper.WriteElementToXML(writer, "AutoCreateFolders", this.AutoCreateFolders );
XMLHelper.WriteElementToXML(writer,"AutoCreateFolders", this.AutoCreateFolders );
XMLHelper.WriteElementToXML(writer,"ShowEpisodePictures",this.ShowEpisodePictures);
XMLHelper.WriteElementToXML(writer,"SpecialsFolderName",this.SpecialsFolderName);
XMLHelper.WriteElementToXML(writer,"uTorrentPath",this.uTorrentPath);
Expand All @@ -844,7 +846,7 @@ public void WriteXML(XmlWriter writer)
XMLHelper.WriteElementToXML(writer,"LeaveOriginals",this.LeaveOriginals);
XMLHelper.WriteElementToXML(writer,"LookForDateInFilename",this.LookForDateInFilename);
XMLHelper.WriteElementToXML(writer,"MonitorFolders",this.MonitorFolders);
XMLHelper.WriteElementToXML(writer, "RemoveDownloadDirectoriesFiles", this.RemoveDownloadDirectoriesFiles);
XMLHelper.WriteElementToXML(writer,"RemoveDownloadDirectoriesFiles", this.RemoveDownloadDirectoriesFiles);
XMLHelper.WriteElementToXML(writer,"SABAPIKey",this.SABAPIKey);
XMLHelper.WriteElementToXML(writer,"CheckSABnzbd",this.CheckSABnzbd);
XMLHelper.WriteElementToXML(writer,"SABHostPort",this.SABHostPort);
Expand All @@ -867,8 +869,6 @@ public void WriteXML(XmlWriter writer)
XMLHelper.WriteElementToXML(writer, "PercentDirtyUpgrade", this.upgradeDirtyPercent);
XMLHelper.WriteElementToXML(writer, "BaseSeasonName", this.defaultSeasonWord);
XMLHelper.WriteElementToXML(writer, "SearchSeasonNames", this.searchSeasonWordsString);
XMLHelper.WriteElementToXML(writer, "KeepTogetherType", (int)this.keepTogetherMode);
XMLHelper.WriteElementToXML(writer, "KeepTogetherExtensions", this.keepTogetherExtensionsString);

writer.WriteStartElement("FNPRegexs");
foreach (FilenameProcessorRE re in this.FNPRegexs)
Expand Down Expand Up @@ -1090,9 +1090,9 @@ public string BTSearchURL(ProcessedEpisode epi)
if (s == null)
return "";

String url = String.IsNullOrEmpty(epi.SI.CustomSearchURL)
? this.TheSearchers.CurrentSearchURL()
: epi.SI.CustomSearchURL;
String url = (epi.SI.UseCustomSearchURL && !String.IsNullOrWhiteSpace(epi.SI.CustomSearchURL))
? epi.SI.CustomSearchURL
: this.TheSearchers.CurrentSearchURL();
return CustomName.NameForNoExt(epi, url, true);
}

Expand Down Expand Up @@ -1130,5 +1130,19 @@ public bool DownloadEdenImages()
return (KODIImages && (SelectedKODIType == KODIType.Both || SelectedKODIType == KODIType.Eden));
}

public bool KeepTogetherFilesWithType(string fileExtension)
{
if (this.KeepTogether == false) return false;

switch (this.keepTogetherMode)
{
case KeepTogetherModes.All: return true;
case KeepTogetherModes.Just: return keepTogetherExtensionsArray.Contains(fileExtension);
case KeepTogetherModes.AllBut: return !keepTogetherExtensionsArray.Contains(fileExtension);

}

return true;
}
}
}
5 changes: 5 additions & 0 deletions TVRename#/Settings/ShowsAndEpisodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ public class ShowItem
public bool UseCustomShowName;
public bool UseSequentialMatch;
public List<string> AliasNames = new List<string>();
public bool UseCustomSearchURL;
public String CustomSearchURL;

private DateTime? bannersLastUpdatedOnDisk;
Expand Down Expand Up @@ -234,6 +235,8 @@ public ShowItem(XmlReader reader)
this.DoMissingCheck = reader.ReadElementContentAsBoolean();
else if (reader.Name == "DVDOrder")
this.DVDOrder = reader.ReadElementContentAsBoolean();
else if (reader.Name == "UseCustomSearchURL")
this.UseCustomSearchURL = reader.ReadElementContentAsBoolean();
else if (reader.Name == "CustomSearchURL")
this.CustomSearchURL = reader.ReadElementContentAsString();
else if (reader.Name == "ForceCheckAll") // removed 2.2.0b2
Expand Down Expand Up @@ -509,6 +512,7 @@ public void SetDefaults()
this.CountSpecials = false;
this.DVDOrder = false;
CustomSearchURL = "";
UseCustomSearchURL = false;
ForceCheckNoAirdate = false;
ForceCheckFuture = false;
this.BannersLastUpdatedOnDisk = null; //assume that the baners are old and have expired
Expand Down Expand Up @@ -601,6 +605,7 @@ public void WriteXMLSettings(XmlWriter writer)
}
writer.WriteEndElement();

XMLHelper.WriteElementToXML(writer, "UseCustomSearchURL", this.UseCustomSearchURL);
XMLHelper.WriteElementToXML(writer, "CustomSearchURL",this.CustomSearchURL);

foreach (KeyValuePair<int, List<ShowRule>> kvp in this.SeasonRules)
Expand Down
2 changes: 1 addition & 1 deletion TVRename#/TVRename/TVDoc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1472,7 +1472,7 @@ public void ProcessSingleAction(Object infoIn)
Action action = info.TheAction;
if (action != null)
{
logger.Trace("Triggering Action: {0} - {1} - {32", action.Name, action.produces, action.ToString());
logger.Trace("Triggering Action: {0} - {1} - {2}", action.Name, action.produces, action.ToString());
action.Go(ref this.ActionPause, mStats);
}

Expand Down
11 changes: 11 additions & 0 deletions TVRename#/Utility/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,17 @@ public static bool Contains(this string source, string toCheck, StringComparison
{
return source.IndexOf(toCheck, comp) >= 0;
}


public static string ReplaceInsensitive(this string source, string search, string replacement)
{
return Regex.Replace(
source,
Regex.Escape(search),
replacement.Replace("$", "$$"),
RegexOptions.IgnoreCase
);
}
}

public static class RegistryHelper {
Expand Down

0 comments on commit 4436b78

Please sign in to comment.