Skip to content

Commit

Permalink
Merge pull request #319 from MarkSummerville/master
Browse files Browse the repository at this point in the history
Merging up recent bug fixes
  • Loading branch information
SirSparkles authored Feb 7, 2018
2 parents ec13087 + 3c59161 commit 6bec0de
Show file tree
Hide file tree
Showing 29 changed files with 862 additions and 178 deletions.
3 changes: 2 additions & 1 deletion TVRename#/App/ApplicationBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ protected override void OnCreateSplashScreen()
protected override void OnCreateMainForm()
{
// Update splash screen
this.SplashScreen.Invoke(new MethodInvoker(() => ((TVRenameSplash)this.SplashScreen).UpdateStatus("Initializing")));
this.SplashScreen.SafeInvoke(
() => ((TVRenameSplash) this.SplashScreen).UpdateStatus("Initializing"), true);

// Update RegVersion to bring the WebBrowser up to speed
RegistryHelper.UpdateBrowserEmulationVersion();
Expand Down
2 changes: 1 addition & 1 deletion TVRename#/App/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private static void Main(string[] args)
static void GlobalExceptionHandler(object sender, UnhandledExceptionEventArgs args)
{
Exception e = (Exception) args.ExceptionObject;
Logger.Fatal("UNHANDLED ERROR",e);
Logger.Fatal(e,"UNHANDLED ERROR");
}
}

Expand Down
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 FileInfo = Alphaleonis.Win32.Filesystem.FileInfo;
Expand All @@ -19,6 +19,7 @@ public DownloadIdentifiersController() {
Identifiers.Add(new DownloadSeriesJPG());
Identifiers.Add(new DownloadKODIMetaData());
Identifiers.Add(new DownloadKODIImages());
Identifiers.Add(new IncorrectFileDates());
}

public void notifyComplete(FileInfo file)
Expand Down
67 changes: 67 additions & 0 deletions TVRename#/DownloadIdentifers/IncorrectFileDates.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using FileInfo = Alphaleonis.Win32.Filesystem.FileInfo;
using DirectoryInfo = Alphaleonis.Win32.Filesystem.DirectoryInfo;

namespace TVRename
{
sealed class IncorrectFileDates : DownloadIdentifier
{
private List<string> doneFilesAndFolders;
public IncorrectFileDates() => reset();

public override DownloadType GetDownloadType() => DownloadType.downloadMetaData;

public override ItemList ProcessShow(ShowItem si, bool forceRefresh)
{
DateTime? newUpdateTime = si.TheSeries().LastAiredDate();
if (TVSettings.Instance.CorrectFileDates && newUpdateTime.HasValue)
{
DirectoryInfo di = new DirectoryInfo(si.AutoAdd_FolderBase);
if ((di.LastWriteTimeUtc != newUpdateTime.Value)&&(!this.doneFilesAndFolders.Contains(di.FullName)))
{
this.doneFilesAndFolders.Add(di.FullName);
return new ItemList() { new ItemDateTouch(di, si, newUpdateTime.Value) };
}
}
return null;
}

public override ItemList ProcessSeason(ShowItem si, string folder, int snum, bool forceRefresh)
{
DateTime? newUpdateTime = si.TheSeries().Seasons[snum].LastAiredDate();

if (TVSettings.Instance.CorrectFileDates && newUpdateTime.HasValue)
{
DirectoryInfo di = new DirectoryInfo(folder);
if ((di.LastWriteTimeUtc != newUpdateTime.Value) &&(!this.doneFilesAndFolders.Contains(di.FullName)))
{
this.doneFilesAndFolders.Add(di.FullName);
return new ItemList() { new ItemDateTouch(di, si, newUpdateTime.Value) };
}

}
return null;
}

public override ItemList ProcessEpisode(ProcessedEpisode dbep, FileInfo filo, bool forceRefresh)
{
if (TVSettings.Instance.CorrectFileDates && dbep.FirstAired.HasValue)
{
DateTime newUpdateTime = dbep.FirstAired.Value;
if ((filo.LastWriteTimeUtc != newUpdateTime) && (!this.doneFilesAndFolders.Contains(filo.FullName)))
{
this.doneFilesAndFolders.Add(filo.FullName);
return new ItemList() { new ItemDateTouch(filo,dbep, newUpdateTime) };
}
}
return null;
}
public override void reset()
{
this.doneFilesAndFolders = new List<string>();
base.reset();
}

}
}
3 changes: 2 additions & 1 deletion TVRename#/Finders/SABnzbdFinder.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.Net;
Expand Down Expand Up @@ -52,6 +52,7 @@ public override void Check(SetProgressDelegate prog, int startpct, int totPct)
}
catch (WebException)
{
logger.Info("Failed to obtain SABnzbd, please recheck settings: " + theURL);
}

if (r == null)
Expand Down
27 changes: 17 additions & 10 deletions TVRename#/Forms/CopyMoveProgress.Designer.cs

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

134 changes: 93 additions & 41 deletions TVRename#/Forms/CopyMoveProgress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
//
// This code is released under GPLv3 http://www.gnu.org/licenses/gpl.html
//

using System.Web.UI.WebControls;

namespace TVRename
{
using System;
Expand Down Expand Up @@ -41,6 +44,7 @@ public CopyMoveProgress(TVDoc doc, ActionQueue[] todo)
this.mToDo = todo;
this.InitializeComponent();
this.copyTimer.Start();
this.diskSpaceTimer.Start();
}

/// <summary>
Expand All @@ -49,6 +53,7 @@ public CopyMoveProgress(TVDoc doc, ActionQueue[] todo)
~CopyMoveProgress()
{
this.copyTimer.Stop();
this.diskSpaceTimer.Stop();
}

private void SetPercentages(double file, double group)
Expand Down Expand Up @@ -76,13 +81,13 @@ private void SetPercentages(double file, double group)
BringToFront();
}

private bool UpdateNewStyle() // return true if all tasks are done
private bool UpdateCopyProgress() // return true if all tasks are done
{
// update each listview item, for non-empty queues
bool allDone = true;

this.lvProgress.BeginUpdate();
int top = this.lvProgress.TopItem != null ? this.lvProgress.TopItem.Index : 0;
int top = lvProgress.TopItem?.Index ?? 0;
ActionCopyMoveRename activeCMAction = null;
long workDone = 0;
long totalWork = 0;
Expand Down Expand Up @@ -120,42 +125,9 @@ private void SetPercentages(double file, double group)
this.lvProgress.TopItem = this.lvProgress.Items[top];
this.lvProgress.EndUpdate();

int diskValue = 0;
string diskText = "--- GB free";
string fileText = "";

if (activeCMAction != null)
{
string folder = activeCMAction.TargetFolder;
DirectoryInfo toRoot = (!string.IsNullOrEmpty(folder) && !folder.StartsWith("\\\\")) ? new DirectoryInfo(folder).Root : null;

if (toRoot != null)
{
System.IO.DriveInfo di;
try
{
// try to get root of drive
di = new System.IO.DriveInfo(toRoot.ToString());
}
catch (System.ArgumentException)
{
di = null;
}

if (di != null)
{
int pct = (int) ((1000 * di.TotalFreeSpace) / di.TotalSize);
diskValue = 1000 - pct;
diskText = ((int) (di.TotalFreeSpace / 1024.0 / 1024.0 / 1024.0 + 0.5)) + " GB free";
}

fileText = activeCMAction.ProgressText;
}

this.txtFilename.Text = fileText;
this.pbDiskSpace.Value = diskValue;
this.txtDiskSpace.Text = diskText;

this.txtFilename.Text = activeCMAction.ProgressText;
this.SetPercentages(activeCMAction.PercentDone, totalWork == 0 ? 0.0 : (workDone * 100.0 / totalWork));
}

Expand All @@ -167,7 +139,7 @@ private void copyTimer_Tick(object sender, System.EventArgs e)
this.copyTimer.Stop();

//this.UpdateOldStyle();
bool allDone = this.UpdateNewStyle();
bool allDone = this.UpdateCopyProgress();

if (allDone)
{
Expand All @@ -178,13 +150,92 @@ private void copyTimer_Tick(object sender, System.EventArgs e)
this.copyTimer.Start();
}

private void bnCancel_Click(object sender, System.EventArgs e)
private void diskSpaceTimer_Tick(object sender, System.EventArgs e)
{
this.diskSpaceTimer.Stop();
UpdateDiskSpace();
this.diskSpaceTimer.Start();
}

private void UpdateDiskSpace()
{
int diskValue = 0;
string diskText = "--- GB free";

ActionCopyMoveRename activeCMAction = null;

activeCMAction = GetActiveCmAction();

if (activeCMAction is null) return;


string folder = activeCMAction.TargetFolder;
DirectoryInfo toRoot = (!string.IsNullOrEmpty(folder) && !folder.StartsWith("\\\\")) ? new DirectoryInfo(folder).Root : null;

if (toRoot != null)
{
System.IO.DriveInfo di;
try
{
// try to get root of drive
di = new System.IO.DriveInfo(toRoot.ToString());
}
catch (System.ArgumentException)
{
di = null;
}

if (di != null)
{
int pct = (int)((1000 * di.TotalFreeSpace) / di.TotalSize);
diskValue = 1000 - pct;
diskText = ((int)(di.TotalFreeSpace / 1024.0 / 1024.0 / 1024.0 + 0.5)) + " GB free";
}
}

DirectoryInfo toUNCRoot = (!string.IsNullOrEmpty(folder) && folder.StartsWith("\\\\")) ? new DirectoryInfo(folder).Root : null;
if (toUNCRoot != null)
{
FileSystemProperties driveStats = FileHelper.GetProperties(toUNCRoot.ToString());
if (driveStats != null)
{
int pct = (int)((1000 * driveStats.AvailableBytes) / driveStats.TotalBytes);
diskValue = 1000 - pct;
diskText = ((int)(driveStats.AvailableBytes / 1024.0 / 1024.0 / 1024.0 + 0.5)) + " GB free";
}
}

this.pbDiskSpace.Value = diskValue;
this.txtDiskSpace.Text = diskText;
}

private ActionCopyMoveRename GetActiveCmAction()
{
foreach (ActionQueue aq in this.mToDo)
{
if (aq.Actions.Count == 0)
continue;

foreach (Action action in aq.Actions)
{
if ((!action.Done) && (action.PercentDone > 0))
{
if (action is ActionCopyMoveRename cmAction )
return cmAction;
}
}
}

return null;
}

private void bnCancel_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
this.Close();
Close();
}

private void cbPause_CheckedChanged(object sender, System.EventArgs e)
private void cbPause_CheckedChanged(object sender, EventArgs e)
{
this.mDoc.ActionPause = this.cbPause.Checked;

Expand All @@ -201,5 +252,6 @@ private void cbPause_CheckedChanged(object sender, System.EventArgs e)
this.label3.Enabled = en;
this.txtFilename.Enabled = en;
}

}
}
}
Loading

0 comments on commit 6bec0de

Please sign in to comment.