Skip to content

Commit

Permalink
Fix identified optimisations
Browse files Browse the repository at this point in the history
  • Loading branch information
SirSparkles committed Jul 5, 2022
1 parent 659d8aa commit 25d0828
Show file tree
Hide file tree
Showing 90 changed files with 1,273 additions and 1,410 deletions.
3 changes: 2 additions & 1 deletion TVRename/App/ApplicationBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,9 @@ private void SetupLogging()
Logger.Info($"Copyright (C) {DateTime.Now.Year} TV Rename");
Logger.Info("This program comes with ABSOLUTELY NO WARRANTY; This is free software, and you are welcome to redistribute it under certain conditions");
}

// ReSharper disable once UnusedMember.Local
[System.Diagnostics.CodeAnalysis.SuppressMessage("CodeQuality", "IDE0051:Remove unused private members", Justification = "<Pending>")]
private static void SetupSemaTextLogging()
{
try
Expand Down
2 changes: 1 addition & 1 deletion TVRename/Custom Controls/CodeFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ private bool DoFind(bool chooseOnlyMatch)

protected abstract int FindMedia(MediaCache cache, bool numeric, int matchnum, string what);

protected bool Matches(int num, CachedMediaInfo kvp, bool numeric, string what, int matchnum)
protected static bool Matches(int num, CachedMediaInfo kvp, bool numeric, string what, int matchnum)
{
string show = kvp.Name.CompareName();

Expand Down
40 changes: 19 additions & 21 deletions TVRename/Exporter/RecentExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,32 @@ protected override void Do()
DirFilesCache dfc = new();

//Write Contents to file
using (System.IO.StreamWriter file = new(Location()))
using System.IO.StreamWriter file = new(Location());
file.WriteLine(GenerateHeader());
foreach (ProcessedEpisode episode in lpe)
{
file.WriteLine(GenerateHeader());
foreach (ProcessedEpisode episode in lpe)
try
{
try
{
List<FileInfo> files = dfc.FindEpOnDisk(episode, false);

if (!files.Any())
{
continue;
}

string name = TVSettings.Instance.NamingStyle.NameFor(episode);
int length = files.First().GetFilmLength();
List<FileInfo> files = dfc.FindEpOnDisk(episode, false);

file.WriteLine(GenerateRecord(episode, files.First(), name, length));
}
catch (Exception ex)
if (!files.Any())
{
LOGGER.Error(ex,
$"Had to skip saving {episode.Show.ShowName} S{episode.AppropriateSeasonNumber}E{episode.AppropriateEpNum} saving to {Location()}");
continue;
}
}

file.WriteLine(GenerateFooter());
string name = TVSettings.Instance.NamingStyle.NameFor(episode);
int length = files.First().GetFilmLength();

file.WriteLine(GenerateRecord(episode, files.First(), name, length));
}
catch (Exception ex)
{
LOGGER.Error(ex,
$"Had to skip saving {episode.Show.ShowName} S{episode.AppropriateSeasonNumber}E{episode.AppropriateEpNum} saving to {Location()}");
}
}

file.WriteLine(GenerateFooter());
}

protected abstract string GenerateHeader();
Expand Down
15 changes: 2 additions & 13 deletions TVRename/Forms/BrowserRequestHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public bool OnBeforeBrowse(IWebBrowser browserControl, IBrowser browser, IFrame

if (url.StartsWith(UI.EXPLORE_PROXY, StringComparison.InvariantCultureIgnoreCase))
{
string openlocation = System.Web.HttpUtility.UrlDecode(url.Substring(UI.EXPLORE_PROXY.Length));
string openlocation = System.Web.HttpUtility.UrlDecode(url.RemoveFirst(UI.EXPLORE_PROXY.Length));
if (Helpers.OpenFolder(openlocation))
{
return true;
Expand All @@ -43,7 +43,7 @@ public bool OnBeforeBrowse(IWebBrowser browserControl, IBrowser browser, IFrame

if (url.StartsWith(UI.WATCH_PROXY, StringComparison.InvariantCultureIgnoreCase))
{
string fileName = System.Web.HttpUtility.UrlDecode(url.Substring(UI.WATCH_PROXY.Length)).Replace('/', '\\');
string fileName = System.Web.HttpUtility.UrlDecode(url.RemoveFirst(UI.WATCH_PROXY.Length)).Replace('/', '\\');
Helpers.OpenFile(fileName);
return true;
}
Expand Down Expand Up @@ -87,17 +87,6 @@ public bool OnSelectClientCertificate(IWebBrowser chromiumWebBrowser, IBrowser b
X509Certificate2Collection certificates, ISelectClientCertificateCallback callback) =>
false;

public void OnPluginCrashed(IWebBrowser browserControl, IBrowser browser, string pluginPath)
{
throw new Exception("Plugin crashed!");
}

public CefReturnValue OnBeforeResourceLoad(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request,
IRequestCallback callback)
{
return CefReturnValue.Continue;
}

public void OnRenderProcessTerminated(IWebBrowser browserControl, IBrowser browser, CefTerminationStatus status)
{
}
Expand Down
55 changes: 27 additions & 28 deletions TVRename/Forms/BulkAddMovies/BulkAddEditMovie.resx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
Expand All @@ -26,36 +26,36 @@
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
Expand Down Expand Up @@ -117,7 +117,6 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
AAABAAIAICAQAAAABADoAgAAJgAAABAQEAAAAAQAKAEAAA4DAAAoAAAAIAAAAEAAAAABAAQAAAAAAAAC
Expand Down
5 changes: 1 addition & 4 deletions TVRename/Forms/BulkAddMovies/BulkAddMovie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,7 @@ private void lstFMMonitorFolders_DragOver(object _, DragEventArgs e)
e.Effect = GetDragEffect(e);
}

private DragDropEffects GetDragEffect(DragEventArgs e)
{
return e.Data?.GetDataPresent(DataFormats.FileDrop) ?? false ? DragDropEffects.Copy : DragDropEffects.None;
}
private static DragDropEffects GetDragEffect(DragEventArgs e) => e.Data?.GetDataPresent(DataFormats.FileDrop) ?? false ? DragDropEffects.Copy : DragDropEffects.None;

private void lstFMIgnoreFolders_DragOver(object _, DragEventArgs e)
{
Expand Down
55 changes: 27 additions & 28 deletions TVRename/Forms/BulkAddMovies/BulkAddMovie.resx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
Expand All @@ -26,36 +26,36 @@
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
Expand Down Expand Up @@ -170,7 +170,6 @@
<metadata name="bwIdentify.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>559, 17</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
AAABAAIAICAQAAAABADoAgAAJgAAABAQEAAAAAQAKAEAAA4DAAAoAAAAIAAAAEAAAAABAAQAAAAAAAAC
Expand Down
2 changes: 1 addition & 1 deletion TVRename/Forms/BulkAddShows/BulkAddEditShow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public BulkAddEditShow(PossibleNewTvShow hint)
string s = hint.Folder.FullName;
int p = s.LastIndexOf(System.IO.Path.DirectorySeparatorChar);
codeFinderControl.SetHint(string.IsNullOrWhiteSpace(hint.RefinedHint)
? s[(p + 1)..]
? s.RemoveFirst(p + 1)
: hint.RefinedHint, TVDoc.ProviderType.libraryDefault);
}
Code = -1;
Expand Down
Loading

0 comments on commit 25d0828

Please sign in to comment.