Skip to content

Commit

Permalink
Merge pull request #334 from MarkSummerville/master
Browse files Browse the repository at this point in the history
Latest Bug Fixes
  • Loading branch information
SirSparkles authored Feb 15, 2018
2 parents ce87cc9 + 8f87d98 commit 8fe9d8a
Show file tree
Hide file tree
Showing 8 changed files with 335 additions and 253 deletions.
3 changes: 0 additions & 3 deletions TVRename#/Forms/FolderMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
//
using System.Windows.Forms;
using System.Threading;
using FileSystemInfo = Alphaleonis.Win32.Filesystem.FileSystemInfo;
using Directory = Alphaleonis.Win32.Filesystem.Directory;
using DirectoryInfo = Alphaleonis.Win32.Filesystem.DirectoryInfo;
using FileInfo = Alphaleonis.Win32.Filesystem.FileInfo;

namespace TVRename
{
Expand Down
466 changes: 233 additions & 233 deletions TVRename#/Forms/UI.Designer.cs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions TVRename#/Forms/UI.resx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAADk
HQAAAk1TRnQBSQFMAgEBEwEAARABAwEQAQMBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
HQAAAk1TRnQBSQFMAgEBEwEAARgBAwEYAQMBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
AwABQAMAAVADAAEBAQABCAYAARQYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA
AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5
AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA
Expand Down Expand Up @@ -274,7 +274,7 @@
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAACa
GAAAAk1TRnQBSQFMAgEBCgEAASwBAwEsAQMBEgEAAQ0BAAT/ARkBAAj/AUIBTQE2BwABNgMAASgDAAFI
GAAAAk1TRnQBSQFMAgEBCgEAATQBAwE0AQMBEgEAAQ0BAAT/ARkBAAj/AUIBTQE2BwABNgMAASgDAAFI
AwABJwMAAQEBAAEYBQAB6AEgGAAD7wMSBjADCQYwAw8DKgMwAxsD0Q8AASEB1gEIASEB1gEIASEB1gEI
ASEB1gEImQAD7wM8A58D5gMwA+ADzgNPA9gDtwOPA9EMAAEhAdYBCAEhAdYBCAEhAdYBCAEhAdYBCAEh
AdYBCAEhAdYBCJYAA+8DNgOPA+IDMAPbA8YDTwPOA0ADjwPRDAABIQHWAQgBIQHWAQgBIQHWAQgBIQHW
Expand Down
1 change: 1 addition & 0 deletions TVRename#/ItemsAndActions/ActionCopyMoveRename.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public override bool Go(ref bool pause, TVRenameStats stats)

if (Operation == Op.Move && _tidyup != null && _tidyup.DeleteEmpty)
{
logger.Info($"Testing {From.Directory.FullName } to see whether it should be tidied up");
DoTidyup(From.Directory );
}

Expand Down
2 changes: 2 additions & 0 deletions TVRename#/ItemsAndActions/ActionDelete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public override bool Go(ref bool pause, TVRenameStats stats)
DeleteOrRecycleFile(this.toRemove);
if (this._tidyup != null && this._tidyup.DeleteEmpty)
{
logger.Info($"Testing {this.toRemove.Directory.FullName } to see whether it should be tidied up");
DoTidyup(this.toRemove.Directory);
}
}
Expand Down Expand Up @@ -158,6 +159,7 @@ public override bool Go(ref bool pause, TVRenameStats stats)
DeleteOrRecycleFolder(this.toRemove);
if (this._tidyup != null && this._tidyup.DeleteEmpty)
{
logger.Info($"Testing {this.toRemove.Parent.FullName } to see whether it should be tidied up");
DoTidyup(this.toRemove.Parent);
}
}
Expand Down
15 changes: 6 additions & 9 deletions TVRename#/ItemsAndActions/ActionItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,10 @@
namespace TVRename
{
using System;
using System.CodeDom;
using System.Diagnostics;
using Alphaleonis.Win32.Filesystem;
using System.Linq;
using System.Security.AccessControl;
using System.Threading;
using System.Web.UI.WebControls;
using System.Windows.Forms;

using File = Alphaleonis.Win32.Filesystem.File;
using FileInfo = Alphaleonis.Win32.Filesystem.FileInfo;
using FileSystemInfo = Alphaleonis.Win32.Filesystem.FileSystemInfo;
using DirectoryInfo = Alphaleonis.Win32.Filesystem.DirectoryInfo;


Expand Down Expand Up @@ -102,6 +94,7 @@ public abstract class ActionFileOperation : Item, Action, ScanListItem
{
protected double _percent;
protected TidySettings _tidyup;
protected static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();

public bool Done { get; set; }
public bool Error { get; set; }
Expand All @@ -118,10 +111,12 @@ protected void DeleteOrRecycleFile(FileInfo file )
if (file == null) return;
if (_tidyup.DeleteEmptyIsRecycle)
{
logger.Info($"Recycling {file.FullName}");
Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile(file.FullName, Microsoft.VisualBasic.FileIO.UIOption.OnlyErrorDialogs, Microsoft.VisualBasic.FileIO.RecycleOption.SendToRecycleBin);
}
else
{
logger.Info($"Deleting {file.FullName}");
file.Delete(true);
}
}
Expand All @@ -131,10 +126,12 @@ protected void DeleteOrRecycleFolder(DirectoryInfo di)
if (di == null) return;
if (_tidyup.DeleteEmptyIsRecycle)
{
logger.Info($"Recycling {di.FullName}");
Microsoft.VisualBasic.FileIO.FileSystem.DeleteDirectory(di.FullName, Microsoft.VisualBasic.FileIO.UIOption.OnlyErrorDialogs, Microsoft.VisualBasic.FileIO.RecycleOption.SendToRecycleBin);
}
else
{
logger.Info($"Deleting {di.FullName}");
di.Delete();
}
}
Expand Down Expand Up @@ -217,4 +214,4 @@ protected void DoTidyup(DirectoryInfo di)
public abstract bool SameAs(Item o);
public abstract bool Go(ref bool pause, TVRenameStats stats);
}
}
}
51 changes: 47 additions & 4 deletions TVRename#/TVRename/TVDoc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1093,13 +1093,15 @@ public static void ApplyRules(List<ProcessedEpisode> eis, List<ShowRule> rules,
if ((n1 != -1) && (n2 != -1) && (n1 < ec) && (n2 < ec) && (n1 < n2))
{
ProcessedEpisode oldFirstEI = eis[n1];
List<string> episodeNames = new List<string> {eis[n1].Name};
string combinedName = eis[n1].Name + " + ";
string combinedSummary = eis[n1].Overview + "<br/><br/>";
List<Episode> alleps = new List<Episode>();
alleps.Add(eis[n1]);
//int firstNum = eis[n1]->TVcomEpCount();
for (int i = n1 + 1; i <= n2; i++)
{
episodeNames.Add(eis[i].Name);
combinedName += eis[i].Name;
combinedSummary += eis[i].Overview;
alleps.Add(eis[i]);
Expand All @@ -1114,6 +1116,19 @@ public static void ApplyRules(List<ProcessedEpisode> eis, List<ShowRule> rules,

eis.RemoveAt(n1);

string root = Helpers.GetCommonStartString(episodeNames);
int shortestEpisodeName = episodeNames.Min(x => x.Length);
int longestEpisodeName = episodeNames.Max(x => x.Length);
bool namesSameLength = (shortestEpisodeName == longestEpisodeName);
bool rootIsIgnored = root.Trim().Equals("Episode", StringComparison.OrdinalIgnoreCase);


if (namesSameLength && !rootIsIgnored && root.Length > 3 &&
root.Length > shortestEpisodeName / 2)
{
combinedName = root.Trim().TrimEnd('(').Trim();
}

ProcessedEpisode pe2 = new ProcessedEpisode(oldFirstEI, si, alleps)
{
Name = ((string.IsNullOrEmpty(txt)) ? combinedName : txt),
Expand Down Expand Up @@ -1795,6 +1810,11 @@ protected internal void findDoubleEps()
{
StringBuilder output = new StringBuilder();

output.AppendLine("##################################################");
output.AppendLine("DUPLICATE FINDER - Part one");
output.AppendLine("##################################################");


foreach (ShowItem si in this.ShowItems)
{
foreach (KeyValuePair<int, List<ProcessedEpisode>> kvp in si.SeasonEpisodes)
Expand All @@ -1812,19 +1832,40 @@ protected internal void findDoubleEps()
//Search through each pair of episodes for the same season
foreach (ProcessedEpisode pep in kvp.Value)
{
foreach (ProcessedEpisode comparePep in kvp.Value)
if (pep.type == ProcessedEpisode.ProcessedEpisodeType.merged)
{
output.AppendLine(si.ShowName + " - Season: " + kvp.Key + " - " + pep.NumsAsString() +" - "+pep.Name+" is:");
foreach (Episode sourceEpisode in pep.sourceEpisodes)
{
output.AppendLine(" - " + sourceEpisode.EpNum + " - " + sourceEpisode.Name);
}
}

foreach (ProcessedEpisode comparePep in kvp.Value)
{
if (pep.FirstAired.HasValue && comparePep.FirstAired.HasValue && pep.FirstAired == comparePep.FirstAired && pep.EpisodeID < comparePep.EpisodeID)
{
output.AppendLine(si.ShowName + " - Season: " + kvp.Key + " - " + pep.FirstAired.ToString() + " - " + pep.EpNum + " - " + comparePep.EpNum);
output.AppendLine($"{si.ShowName} - Season: {kvp.Key} - {pep.FirstAired.ToString()} - {pep.EpNum}({pep.Name}) - {comparePep.EpNum}({comparePep.Name})");
string root = Helpers.GetCommonStartString(pep.Name, comparePep.Name);
bool sameLength = (pep.Name.Length == comparePep.Name.Length);
if (!root.Trim().Equals("Episode") && sameLength && root.Length>3 && root.Length > pep.Name.Length/2)
output.AppendLine("####### POSSIBLE DUPLICATE ##########");
}
}
}
}
}

logger.Info(output.ToString());
output.AppendLine("##################################################");
output.AppendLine("DUPLICATE FINDER - End");
output.AppendLine("##################################################");




logger.Info(output.ToString());
}


public void QuickScan() => QuickScan(true, true);

public void QuickScan(bool doMissingRecents, bool doFilesInDownloadDir)
Expand Down Expand Up @@ -2145,6 +2186,7 @@ public void FindUnusedFilesInDLDirectory(List<ShowItem> showList)
SeriesInfo s = si.TheSeries();
Episode ep = s.getEpisode(seasF, epF);
ProcessedEpisode pep = new ProcessedEpisode(ep, si);
logger.Info($"Removing {fi.FullName } as it matches {matchingShows[0].ShowName} and no episodes are needed");
this.TheActionList.Add(new ActionDeleteFile(fi, pep, TVSettings.Instance.Tidyup));
}

Expand Down Expand Up @@ -2186,6 +2228,7 @@ public void FindUnusedFilesInDLDirectory(List<ShowItem> showList)
SeriesInfo s = si.TheSeries();
Episode ep = s.getEpisode(seasF, epF);
ProcessedEpisode pep = new ProcessedEpisode(ep, si);
logger.Info($"Removing {di.FullName } as it matches {matchingShows[0].ShowName} and no episodes are needed");
this.TheActionList.Add(new ActionDeleteDirectory(di, pep, TVSettings.Instance.Tidyup));
}

Expand Down
46 changes: 44 additions & 2 deletions TVRename#/Utility/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.Text.RegularExpressions;
using System.Xml;
using System.Collections.Generic;
using System.Diagnostics;
using System.Net;
using Newtonsoft.Json.Linq;
using DirectoryInfo = Alphaleonis.Win32.Filesystem.DirectoryInfo;
Expand All @@ -26,6 +27,7 @@
using Microsoft.Win32;
using System.Security;
using System.Windows.Forms;
using NLog;

// Helpful functions and classes

Expand Down Expand Up @@ -638,7 +640,7 @@ public static void UpdateBrowserEmulationVersion()
public static class Helpers
{

private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
private static Logger logger = LogManager.GetCurrentClassLogger();

/// <summary>
/// Gets a value indicating whether application is running under Mono.
Expand Down Expand Up @@ -725,7 +727,7 @@ public static bool SysOpen(string what, string arguments = null)
{
try
{
System.Diagnostics.Process.Start(what, arguments);
Process.Start(what, arguments);
return true;
}
catch (Exception e)
Expand Down Expand Up @@ -762,6 +764,46 @@ public static string CompareName(string n)

}

public static string GetCommonStartString(List<string> testValues)
{
string root = string.Empty;
bool first = true;
foreach (string test in testValues)
{
if (first)
{
root = test;
first = false;
}
else
{
root = GetCommonStartString(root, test);
}

}
return root;
}


public static string GetCommonStartString(string fist, string second)
{
StringBuilder builder = new StringBuilder();
char[] ar1 = fist.ToArray();
int minLength = Math.Min(fist.Length, second.Length);
for (int i = 0; i < minLength; i++)
{
if (fist.Length > i + 1 && ar1[i].Equals(second[i]))
{
builder.Append(ar1[i]);
}
else
{
break;
}
}
return builder.ToString();
}

public static string RemoveDiacritics(string stIn)
{
// From http://blogs.msdn.com/b/michkap/archive/2007/05/14/2629747.aspx
Expand Down

0 comments on commit 8fe9d8a

Please sign in to comment.