Skip to content

Commit

Permalink
Merge pull request #349 from MarkSummerville/master
Browse files Browse the repository at this point in the history
Updates for 2.4
  • Loading branch information
SirSparkles authored Feb 28, 2018
2 parents b587b52 + 94f0975 commit eac9ba0
Show file tree
Hide file tree
Showing 18 changed files with 365 additions and 304 deletions.
36 changes: 31 additions & 5 deletions TVRename#/App/ApplicationBase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Alphaleonis.Win32.Filesystem;
using Microsoft.VisualBasic.ApplicationServices;
Expand All @@ -12,7 +13,7 @@ namespace TVRename.App
/// <seealso cref="WindowsFormsApplicationBase" />
internal class ApplicationBase : WindowsFormsApplicationBase
{
private static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();
private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();

/// <summary>
/// Initializes the splash screen.
Expand All @@ -22,7 +23,7 @@ protected override void OnCreateSplashScreen()
this.SplashScreen = new TVRenameSplash();

CommandLineArgs clargs = new CommandLineArgs(this.CommandLineArgs);
if ((!clargs.Unattended) && (!clargs.Hide)) this.SplashScreen.Enabled = false;
if ((clargs.Unattended) || (clargs.Hide)) this.SplashScreen.Visible = false;

}

Expand All @@ -32,15 +33,18 @@ protected override void OnCreateSplashScreen()
/// </summary>
protected override void OnCreateMainForm()
{
CommandLineArgs clargs = new CommandLineArgs(this.CommandLineArgs);
if ((clargs.Unattended) || (clargs.Hide))
this.SplashScreen.SafeInvoke(
() => ((TVRenameSplash)this.SplashScreen).Visible = false,true);

// Update splash screen
this.SplashScreen.SafeInvoke(
() => ((TVRenameSplash) this.SplashScreen).UpdateStatus("Initializing"), true);

// Update RegVersion to bring the WebBrowser up to speed
RegistryHelper.UpdateBrowserEmulationVersion();

CommandLineArgs clargs = new CommandLineArgs(this.CommandLineArgs);

bool recover = false;
string recoverText = string.Empty;

Expand All @@ -62,7 +66,7 @@ protected override void OnCreateMainForm()
{
if (!clargs.Unattended && !clargs.Hide) MessageBox.Show($"Error while setting the User-Defined File Path:{Environment.NewLine}{ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

Logger.Error(ex, $"Error while setting the User-Defined File Path - EXITING: {clargs.UserFilePath}");
logger.Error(ex, $"Error while setting the User-Defined File Path - EXITING: {clargs.UserFilePath}");

Environment.Exit(1);
}
Expand Down Expand Up @@ -96,6 +100,9 @@ protected override void OnCreateMainForm()
// Try loading settings file
doc = new TVDoc(settingsFile, clargs);

convertSeriesTimeZones(doc, TheTVDB.Instance);


if (recover) doc.SetDirty();
recover = !doc.LoadOK;

Expand All @@ -116,5 +123,24 @@ protected override void OnCreateMainForm()

this.MainForm = ui;
}

private 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
//can be removed after 1/1/19

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);
}
}

}
}
}
31 changes: 31 additions & 0 deletions TVRename#/App/CommandLineArgs.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;

namespace TVRename
{
Expand All @@ -25,6 +26,8 @@ public enum MissingFolderBehavior
public bool Quit { get; }
public bool ForceRecover { get; }
public bool Scan { get; }
public bool QuickScan { get; }
public bool RecentScan { get; }
public bool DoAll { get; }
public bool Unattended { get; }
public string UserFilePath { get; }
Expand All @@ -41,6 +44,8 @@ public CommandLineArgs(ReadOnlyCollection<string> args)
this.ForceRecover = args.Contains("/recover", StringComparer.OrdinalIgnoreCase);
this.DoAll = args.Contains("/doall", StringComparer.OrdinalIgnoreCase);
this.Scan = args.Contains("/scan", StringComparer.OrdinalIgnoreCase);
this.QuickScan = args.Contains("/quickscan", StringComparer.OrdinalIgnoreCase);
this.RecentScan = args.Contains("/recentscan", StringComparer.OrdinalIgnoreCase);
this.Unattended = args.Contains("/unattended", StringComparer.OrdinalIgnoreCase);

this.UserFilePath = args.Where(a => a.StartsWith("/userfilepath:", StringComparison.OrdinalIgnoreCase)).Select(a => a.Substring(a.IndexOf(":", StringComparison.Ordinal) + 1)).FirstOrDefault();
Expand All @@ -58,5 +63,31 @@ public CommandLineArgs(ReadOnlyCollection<string> args)
this.MissingFolder = MissingFolderBehavior.Ask;
}
}

public static string Helptext()
{
StringBuilder output = new StringBuilder();
output.AppendLine("/scan will Tell TV Rename to run a scan");
output.AppendLine("/quickscan will scan shows most likely to need an update: http://www.tvrename.com/userguide#scan");
output.AppendLine("/recentscan will scan recent shows: http://www.tvrename.com/userguide#scan");
output.AppendLine("/doall Tell TV Rename execute all the actions it can.");
output.AppendLine("/quit Tell a running TV Rename session to exit.");
output.AppendLine("");
output.AppendLine("/hide will hide the UI");
output.AppendLine("/unattended same as /hide");
output.AppendLine("");
output.AppendLine("/recover will Recover will load a dialog box that enables the user to recover a prior TVDB.xml or TVRenameSettings.xml file");
output.AppendLine("/userfilepath:BLAH Sets a custom folder path for the settings files.");
output.AppendLine("/createmissing will Create folders if they are missing.");
output.AppendLine("/ignoremissing will Ignore missing folders.");
output.AppendLine("/norenamecheck will Allows a request to an existing TV Rename session to scan without renaming.");
output.AppendLine("");
output.AppendLine("Further information is available at http://www.tvrename.com/cmd-line");

return output.ToString();


}
}
}

15 changes: 12 additions & 3 deletions TVRename#/App/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading;
using System.Windows.Forms;
using TVRename.Ipc;
Expand Down Expand Up @@ -28,14 +29,19 @@ private static void Main(string[] args)

AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(GlobalExceptionHandler);

if (args.Contains("/?", StringComparer.OrdinalIgnoreCase))
{
Logger.Info(CommandLineArgs.Helptext());
Console.WriteLine(CommandLineArgs.Helptext());
}
// Check if an application instance is already running
Mutex mutex = new Mutex(true, "TVRename", out bool newInstance);

if (!newInstance)
{
// Already running

Logger.Warn("An instance is alrady running");
Logger.Warn("An instance is already running");

// Create an IPC channel to the existing instance
RemoteClient.Proxy();
Expand Down Expand Up @@ -72,8 +78,11 @@ private static void Main(string[] args)

// TODO: Unify command line handling between here and in UI.cs (ProcessArgs). Just send in clargs via IPC?

// DoAll implies Scan
if (clargs.DoAll || clargs.Scan) ipc.Scan();

if (clargs.Scan) ipc.Scan();

if (clargs.QuickScan) ipc.QuickScan();
if (clargs.RecentScan) ipc.RecentScan();

if (clargs.DoAll) ipc.ProcessAll();

Expand Down
2 changes: 1 addition & 1 deletion TVRename#/DownloadIdentifers/DownloadXBMCImages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public override ItemList ProcessEpisode(ProcessedEpisode dbep, FileInfo filo, bo
string foldername = filo.DirectoryName;
string filename =
TVSettings.Instance.FilenameFriendly(
TVSettings.Instance.NamingStyle.GetTargetEpisodeName(sourceEp,dbep.SI.ShowName));
TVSettings.Instance.NamingStyle.GetTargetEpisodeName(sourceEp,dbep.SI.ShowName, dbep.SI.GetTimeZone()));
ActionDownload b = DoEpisode(dbep.SI,sourceEp,new FileInfo(foldername+"/"+filename), ".jpg", forceRefresh);
if (b != null) theActionList.Add(b);
}
Expand Down
10 changes: 2 additions & 8 deletions TVRename#/Forms/AddEditShow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ namespace TVRename
/// </summary>
public partial class AddEditShow : Form
{
public string ShowTimeZone;
private ShowItem mSI;
private TheTVDBCodeFinder mTCCF;

Expand All @@ -43,6 +42,7 @@ public AddEditShow(ShowItem si)
this.cbTimeZone.Items.Add(s);

this.cbTimeZone.EndUpdate();
this.cbTimeZone.Text = si.ShowTimeZone;

this.mTCCF = new TheTVDBCodeFinder(si.TVDBCode != -1 ? si.TVDBCode.ToString() : "");
this.mTCCF.Dock = DockStyle.Fill;
Expand Down Expand Up @@ -72,11 +72,6 @@ public AddEditShow(ShowItem si)

this.chkPadTwoDigits.Checked = si.PadSeasonToTwoDigits;

this.ShowTimeZone = ((si == null) || (si.TheSeries() == null))
? TimeZone.DefaultTimeZone()
: si.TheSeries().ShowTimeZone;

this.cbTimeZone.Text = this.ShowTimeZone;
this.chkDVDOrder.Checked = si.DVDOrder;
this.cbIncludeFuture.Checked = si.ForceCheckFuture;
this.cbIncludeNoAirdate.Checked = si.ForceCheckNoAirdate;
Expand Down Expand Up @@ -157,11 +152,10 @@ private void SetmSI()
{
int code = this.mTCCF.SelectedCode();

string tz = (this.cbTimeZone.SelectedItem != null) ? this.cbTimeZone.SelectedItem.ToString() : "";

this.mSI.CustomShowName = this.txtCustomShowName.Text;
this.mSI.UseCustomShowName = this.chkCustomShowName.Checked;
this.ShowTimeZone = tz; //TODO: move to somewhere else. make timezone manager for tvdb?
this.mSI.ShowTimeZone = cbTimeZone.SelectedItem?.ToString() ?? TVRename.TimeZone.DefaultTimeZone();
this.mSI.ShowNextAirdate = this.chkShowNextAirdate.Checked;
this.mSI.PadSeasonToTwoDigits = this.chkPadTwoDigits.Checked;
this.mSI.TVDBCode = code;
Expand Down
27 changes: 10 additions & 17 deletions TVRename#/Forms/CustomNameDesigner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,16 @@ private void FillExamples()
string fn = TVSettings.Instance.FilenameFriendly(this.CN.NameForExt(pe));
lvi.Text = fn;

bool ok = false;
bool ok1 = false;
bool ok2 = false;

//TODO: Do we still need this check, MarkSummerville
if (fn.Length < 255)
{
ok = TVDoc.FindSeasEp(new FileInfo(fn + ".avi"), out int seas, out int ep, pe.SI);
ok1 = ok && (seas == pe.SeasonNumber);
ok2 = ok && (ep == pe.EpNum);
string pre1 = ok1 ? "" : "* ";
string pre2 = ok2 ? "" : "* ";

lvi.SubItems.Add(pre1 + ((seas != -1) ? seas.ToString() : ""));
lvi.SubItems.Add(pre2 + ((ep != -1) ? ep.ToString() : ""));
lvi.Tag = pe;
}
bool ok = TVDoc.FindSeasEp(new FileInfo(fn + ".avi"), out int seas, out int ep, pe.SI);
bool ok1 = ok && (seas == pe.SeasonNumber);
bool ok2 = ok && (ep == pe.EpNum);
string pre1 = ok1 ? "" : "* ";
string pre2 = ok2 ? "" : "* ";

lvi.SubItems.Add(pre1 + ((seas != -1) ? seas.ToString() : ""));
lvi.SubItems.Add(pre2 + ((ep != -1) ? ep.ToString() : ""));
lvi.Tag = pe;

if (!ok || !ok1 || !ok2)
lvi.BackColor = Helpers.WarningColor();
this.lvTest.Items.Add(lvi);
Expand Down
41 changes: 22 additions & 19 deletions TVRename#/Forms/UI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,9 @@ protected void LessBusy()

private void SetupIPC()
{
this.AFMFullScan += this.ProcessAll;
this.AFMQuickScan += this.ScanQuick;
this.AFMRecentScan += this.ScanRecent;
this.AFMFullScan += this.Scan;
this.AFMQuickScan += this.QuickScan;
this.AFMRecentScan += this.RecentScan;
this.AFMDoAll += this.ProcessAll;
}

Expand All @@ -236,8 +236,12 @@ public void ProcessArgs()
{
// TODO: Unify command line handling between here and in Program.cs

if (this.mDoc.Args.Scan || this.mDoc.Args.DoAll) // doall implies scan
if (this.mDoc.Args.Scan)
this.Scan();
if (this.mDoc.Args.QuickScan )
this.QuickScan();
if (this.mDoc.Args.RecentScan )
this.RecentScan();
if (this.mDoc.Args.DoAll)
this.ProcessAll();
if (this.mDoc.Args.Quit || this.mDoc.Args.Hide)
Expand Down Expand Up @@ -2373,7 +2377,7 @@ public TreeNode AddShowItemToTree(ShowItem si)
{
Color nodeColor =
TVSettings.Instance.ShowStatusColors.GetEntry(true, false,
ser.Seasons[snum].Status.ToString());
ser.Seasons[snum].Status(si.GetTimeZone()).ToString());
if (!nodeColor.IsEmpty)
n2.ForeColor = nodeColor;
}
Expand Down Expand Up @@ -2492,12 +2496,11 @@ private void bnMyShowsAdd_Click(object sender, System.EventArgs e)
{
this.mDoc.GetShowItems(true).Add(si);
this.mDoc.UnlockShowItems();
SeriesInfo ser = TheTVDB.Instance.GetSeries(si.TVDBCode);
if (ser != null)
ser.ShowTimeZone = aes.ShowTimeZone;

this.ShowAddedOrEdited(true);
this.SelectShow(si);
logger.Info("Added new show called {0}", ser.Name);

logger.Info("Added new show called {0}", si.ShowName);
}
else logger.Info("Cancelled adding new show");

Expand Down Expand Up @@ -2596,11 +2599,10 @@ private void EditShow(ShowItem si)

if (dr == System.Windows.Forms.DialogResult.OK)
{
if (ser != null)
ser.ShowTimeZone = aes.ShowTimeZone; // TODO: move into AddEditShow

this.ShowAddedOrEdited(si.TVDBCode != oldCode);
this.SelectShow(si);

logger.Info("Modified show called {0}", si.ShowName);
}

this.LessBusy();
Expand Down Expand Up @@ -2911,7 +2913,8 @@ public void Scan()
this.mDoc.ExportMissingXML(); //Save missing shows to XML
}

private void ScanRecent()

public void RecentScan()
{
Scan(this.mDoc.getRecentShows());
}
Expand All @@ -2927,7 +2930,7 @@ private void Scan(List<ShowItem> shows)
this.FillActionList();
}

private void ScanQuick()
public void QuickScan()
{
logger.Info("*******************************");
logger.Info("Starting QuickScan...");
Expand Down Expand Up @@ -3085,7 +3088,7 @@ private void FillActionList()

private void bnActionAction_Click(object sender, System.EventArgs e)
{
this.ActionAction(true);
ProcessAll();
}

public void ProcessAll()
Expand Down Expand Up @@ -3559,9 +3562,9 @@ private void bnHideHTMLPanel_Click(object sender, EventArgs e)
}
}

private void bnActionRecentCheck_Click(object sender, EventArgs e) => this.ScanRecent();
private void bnActionRecentCheck_Click(object sender, EventArgs e) => this.RecentScan();

private void btnActionQuickScan_Click(object sender, EventArgs e) => this.ScanQuick();
private void btnActionQuickScan_Click(object sender, EventArgs e) => this.QuickScan();

private void btnFilter_Click(object sender, EventArgs e)
{
Expand Down Expand Up @@ -3691,10 +3694,10 @@ private void RunAutoScan(string scanType)
Scan();
break;
case TVRename.TVSettings.ScanType.Recent:
ScanRecent();
RecentScan();
break;
case TVRename.TVSettings.ScanType.Quick:
ScanQuick();
QuickScan();
break;
}

Expand Down
Loading

0 comments on commit eac9ba0

Please sign in to comment.