Skip to content

Commit

Permalink
Merge pull request #324 from MarkSummerville/master
Browse files Browse the repository at this point in the history
Latest fixes
  • Loading branch information
SirSparkles authored Feb 8, 2018
2 parents 6bec0de + 397dd0c commit 8ff785c
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 53 deletions.
5 changes: 3 additions & 2 deletions TVRename#/Forms/CopyMoveProgress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ private void UpdateDiskSpace()
{
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";
diskText = di.TotalFreeSpace.GBMB(1) + " free";

}
}

Expand All @@ -201,7 +202,7 @@ private void UpdateDiskSpace()
{
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";
diskText = (driveStats.AvailableBytes??0).GBMB(1) + " free";
}
}

Expand Down
2 changes: 1 addition & 1 deletion TVRename#/Forms/Preferences.Designer.cs

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

44 changes: 17 additions & 27 deletions TVRename#/Forms/UI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,10 @@ public UI(TVDoc doc, TVRenameSplash splash)
{
this.LoadLayoutXML();
}
catch
catch (Exception e)
{
// silently fail, doesn't matter too much
logger.Info(e, "Error loading layout XML");
}

this.SetProgress += this.SetProgressActual;
Expand All @@ -142,12 +143,12 @@ public UI(TVDoc doc, TVRenameSplash splash)
this.FillMyShows();
this.UpdateSearchButton();
this.ClearInfoWindows();
updateSplashPercent(splash, 12);
updateSplashPercent(splash, 10);
updateSplashStatus(splash, "Updating WTW");
this.mDoc.DoWhenToWatch(true);
updateSplashPercent(splash, 50);
updateSplashPercent(splash, 40);
this.FillWhenToWatchList();
updateSplashPercent(splash, 90);
updateSplashPercent(splash, 60);
updateSplashStatus(splash, "Write Upcoming");
this.mDoc.WriteUpcoming();
updateSplashStatus(splash, "Setting Notifications");
Expand All @@ -158,20 +159,23 @@ public UI(TVDoc doc, TVRenameSplash splash)
this.tabControl1.SelectedIndex = TVSettings.Instance.StartupTab;
this.tabControl1_SelectedIndexChanged(null, null);

updateSplashStatus(splash, "Starting Monitor");

this.mAutoFolderMonitor = new TVRename.AutoFolderMonitor(mDoc, this);
if (TVSettings.Instance.MonitorFolders)
this.mAutoFolderMonitor.StartMonitor();
updateSplashStatus(splash, "Creating Monitors");

this.mAutoFolderMonitor = new TVRename.AutoFolderMonitor(mDoc, this);

this.tmrPeriodicScan.Interval = TVSettings.Instance.PeriodicCheckPeriod();
this.tmrPeriodicScan.Enabled = TVSettings.Instance.RunPeriodicCheck();



updateSplashStatus(splash, "Update Available?");

SearchForUpdates(false);

updateSplashStatus(splash, "Starting Monitor");
if (TVSettings.Instance.MonitorFolders)
this.mAutoFolderMonitor.StartMonitor();

this.tmrPeriodicScan.Enabled = TVSettings.Instance.RunPeriodicCheck();

updateSplashStatus(splash, "Running autoscan");
//splash.Close();

Expand Down Expand Up @@ -2968,20 +2972,6 @@ private void ScanQuick()
this.FillActionList();
}

private static string GBMB(long size)
{
long gb1 = (1024 * 1024 * 1024);
long gb = ((gb1 / 2) + size) / gb1;
if (gb > 1)
return gb + " GB";
else
{
long mb1 = 1024 * 1024;
long mb = ((mb1 / 2) + size) / mb1;
return mb + " MB";
}
}

private static string itemitems(int n)
{
return n == 1 ? "Item" : "Items";
Expand Down Expand Up @@ -3112,9 +3102,9 @@ private void FillActionList()
this.lvAction.Groups[0].Header = "Missing (" + missingCount + " " + itemitems(missingCount) + ")";
this.lvAction.Groups[1].Header = "Rename (" + renameCount + " " + itemitems(renameCount) + ")";
this.lvAction.Groups[2].Header =
"Copy (" + copyCount + " " + itemitems(copyCount) + ", " + GBMB(copySize) + ")";
"Copy (" + copyCount + " " + itemitems(copyCount) + ", " + copySize.GBMB(1) + ")";
this.lvAction.Groups[3].Header =
"Move (" + moveCount + " " + itemitems(moveCount) + ", " + GBMB(moveSize) + ")";
"Move (" + moveCount + " " + itemitems(moveCount) + ", " + moveSize.GBMB(1) + ")";
this.lvAction.Groups[4].Header = "Remove (" + removeCount + " " + itemitems(removeCount) + ")";
this.lvAction.Groups[5].Header = "Download RSS (" + rssCount + " " + itemitems(rssCount) + ")";
this.lvAction.Groups[6].Header = "Download (" + downloadCount + " " + itemitems(downloadCount) + ")";
Expand Down
17 changes: 10 additions & 7 deletions TVRename#/ItemsAndActions/ItemMissing.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//
//
// Main website for TVRename is http://tvrename.com
//
// Source code available at http://code.google.com/p/tvrename/
Expand All @@ -14,11 +14,15 @@ namespace TVRename
public class ItemMissing : Item, ScanListItem
{
public string TheFileNoExt;
private string folder;
private string filename;

public ItemMissing(ProcessedEpisode pe, string whereItShouldBeNoExt)
public ItemMissing(ProcessedEpisode pe, string whereItShouldBeFolder, string expectedFilenameNoExt)
{
this.Episode = pe;
this.TheFileNoExt = whereItShouldBeNoExt;
this.TheFileNoExt = whereItShouldBeFolder + System.IO.Path.DirectorySeparatorChar + expectedFilenameNoExt;
this.folder = whereItShouldBeFolder;
this.filename = expectedFilenameNoExt;
}

#region Item Members
Expand Down Expand Up @@ -84,9 +88,8 @@ public ListViewItem ScanListViewItem
else
lvi.SubItems.Add("");

FileInfo fi = new FileInfo(this.TheFileNoExt);
lvi.SubItems.Add(fi.DirectoryName);
lvi.SubItems.Add(fi.Name);
lvi.SubItems.Add(this.folder);
lvi.SubItems.Add(this.filename);

lvi.Tag = this;

Expand Down Expand Up @@ -116,4 +119,4 @@ public int IconNumber

#endregion
}
}
}
2 changes: 1 addition & 1 deletion TVRename#/TVRename/TVDoc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2506,7 +2506,7 @@ public void RenameAndMissingCheck(SetProgressDelegate prog, List<ShowItem> showL
(si.ForceCheckNoAirdate && !dtOK))
{
// then add it as officially missing
this.TheActionList.Add(new ItemMissing(dbep, folder + System.IO.Path.DirectorySeparatorChar + TVSettings.Instance.FilenameFriendly(TVSettings.Instance.NamingStyle.NameForExt(dbep, null, folder.Length))));
this.TheActionList.Add(new ItemMissing(dbep, folder, TVSettings.Instance.FilenameFriendly(TVSettings.Instance.NamingStyle.NameForExt(dbep, null, folder.Length))));
}
}
else
Expand Down
20 changes: 8 additions & 12 deletions TVRename#/TheTVDB/TheTVDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,12 @@ public void setup(FileInfo loadFrom, FileInfo cacheFile, CommandLineArgs args)
this.APIRoot = "https://api.thetvdb.com";

this.Series = new System.Collections.Generic.Dictionary<int, SeriesInfo>();
this.New_Srv_Time = this.Srv_Time = 0;

//assume that the data is up to date (this will be overridden by the value in the XML if we have a prior install)
//If we have no prior install then the app has no shows and is by definition up-to-date
this.New_Srv_Time = DateTime.UtcNow.ToUnixTime();

this.Srv_Time = 0;

this.LoadOK = (loadFrom == null) || this.LoadCache(loadFrom);

Expand Down Expand Up @@ -723,7 +728,7 @@ public bool GetUpdates()
//As a safety measure we check that no more than 10 calls are made
if (numberofCallsMade > 10) {
moreUpdates = false;
String errorMessage = "We have run 10 weeks of updates but it appears the system may need to check again once this set have been processed." + Environment.NewLine + "Last Updated time was " + Helpers.FromUnixTime(this.Srv_Time).ToLocalTime() + Environment.NewLine + "New Last Updated time is " + Helpers.FromUnixTime(this.New_Srv_Time).ToLocalTime() + Environment.NewLine + Environment.NewLine + "If the dates keep getting closer then keep getting 10 weeks of updates, otherwise consider a full refresh";
String errorMessage = "We have run 10 weeks of updates and we are not up to date. The system will need to check again once this set of updates have been processed." + Environment.NewLine + "Last Updated time was " + Helpers.FromUnixTime(this.Srv_Time).ToLocalTime() + Environment.NewLine + "New Last Updated time is " + Helpers.FromUnixTime(this.New_Srv_Time).ToLocalTime() + Environment.NewLine + Environment.NewLine + "If the dates keep getting more recent then let the system keep getting 10 week blocks of updates, otherwise consider a 'Force Refresh All'";
logger.Warn(errorMessage);
if ((!this.Args.Unattended) && (!this.Args.Hide)) MessageBox.Show(errorMessage , "Long Running Update", MessageBoxButtons.OK, MessageBoxIcon.Warning);

Expand All @@ -737,14 +742,6 @@ public bool GetUpdates()

foreach (JObject jsonResponse in updatesResponses)
{








// if updatetime > localtime for item, then remove it, so it will be downloaded later
try
{
Expand Down Expand Up @@ -1178,8 +1175,7 @@ private bool ProcessXML(Stream str, int? codeHint)
else if (r.Name == "Data")
{
string time = r.GetAttribute("time");
if (time != null)
this.New_Srv_Time = long.Parse(time);
this.New_Srv_Time = (time == null)?0:long.Parse(time);
r.Read();
}
else
Expand Down
23 changes: 20 additions & 3 deletions TVRename#/Utility/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,25 @@ public static bool FolderIsSubfolderOf(string thisOne, string ofThat)
return ((thisOne.Length >= l) && (thisOne.Substring(0, l).ToLower() == ofThat.ToLower()));
}

public static string GBMB(this long value, int decimalPlaces = 0)
{
const long OneKb = 1024;
const long OneMb = OneKb * 1024;
const long OneGb = OneMb * 1024;
const long OneTb = OneGb * 1024;

var asTb = Math.Round((double)value / OneTb, decimalPlaces);
var asGb = Math.Round((double)value / OneGb, decimalPlaces);
var asMb = Math.Round((double)value / OneMb, decimalPlaces);
var asKb = Math.Round((double)value / OneKb, decimalPlaces);
string chosenValue = asTb >= 1 ? string.Format("{0} TB", asTb)
: asGb >= 1 ? string.Format("{0} GB", asGb)
: asMb >= 1 ? string.Format("{0} MB", asMb)
: asKb >= 1 ? string.Format("{0} KB", asKb)
: string.Format("{0} B", Math.Round((double)value, decimalPlaces));
return chosenValue;
}

[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
private static extern bool GetDiskFreeSpaceEx(string lpDirectoryName, out ulong lpFreeBytesAvailable, out ulong lpTotalNumberOfBytes, out ulong lpTotalNumberOfFreeBytes);
Expand Down Expand Up @@ -291,9 +310,7 @@ public static bool SimplifyAndCheckFilename(string filename, string showname)
}

internal static string TempPath(string v) => Path.GetTempPath() + v;


}
}

public static class HTTPHelper
{
Expand Down

0 comments on commit 8ff785c

Please sign in to comment.