Skip to content

Commit

Permalink
Fixed some issues with PXZ handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Brhsoftco committed Aug 22, 2020
1 parent 007fe52 commit 6e89558
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 54 deletions.
59 changes: 59 additions & 0 deletions PlexDL/Common/UiUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using PlexDL.Common.Structures.Plex;
using PlexDL.UI;
using System.Windows.Forms;
using UIHelpers;

namespace PlexDL.Common
{
public static class UiUtils
{
public static void RunMetadataWindow(PlexObject metadata, bool appRun = false)
{
var form = new Metadata();
if (metadata != null)
{
form.StreamingContent = metadata;

if (appRun)
Application.Run(form);
else
form.ShowDialog();
}
else
{
UIMessages.Error(@"Invalid PlexMovie Metadata File; the decoded data was null.",
@"Validation Error");
}
}

public static void RunPlexDlHome(bool appRun = false)
{
var form = new Home();

if (appRun)
Application.Run(form);
else
form.ShowDialog();
}

public static void RunTestingWindow(bool appRun = false)
{
var form = new TestForm();

if (appRun)
Application.Run(form);
else
form.ShowDialog();
}

public static void RunTranslator(bool appRun = false)
{
var form = new Translator();

if (appRun)
Application.Run(form);
else
form.ShowDialog();
}
}
}
42 changes: 4 additions & 38 deletions PlexDL/Internal/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using PlexDL.Common.Enums;
using PlexDL.Common.Globals;
using PlexDL.Common.Logging;
using PlexDL.Common.Structures.Plex;
using PlexDL.UI;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -62,7 +61,7 @@ private static void Main(string[] args)
try
{
var metadata = ImportExport.MetadataFromFile(firstArg);
RunMetadataWindow(metadata);
UiUtils.RunMetadataWindow(metadata, true);
}
catch (Exception ex)
{
Expand All @@ -79,11 +78,11 @@ private static void Main(string[] args)
else
{
if (arr.Contains("-tw"))
RunTestingWindow();
UiUtils.RunTestingWindow(true);
else if (arr.Contains("-t"))
RunTranslator();
UiUtils.RunTranslator(true);
else
RunPlexDlHome();
UiUtils.RunPlexDlHome(true);
}
}
else
Expand All @@ -101,39 +100,6 @@ private static void CheckOverrideLogProtection(ICollection<string> args)
Vars.Protected = LogSecurity.Unprotected;
}

private static void RunMetadataWindow(PlexObject metadata)
{
var form = new Metadata();
if (metadata != null)
{
form.StreamingContent = metadata;
Application.Run(form);
}
else
{
UIMessages.Error(@"Invalid PlexMovie Metadata File; the decoded data was null.",
@"Validation Error");
}
}

private static void RunPlexDlHome()
{
var form = new Home();
Application.Run(form);
}

private static void RunTestingWindow()
{
var form = new TestForm();
Application.Run(form);
}

private static void RunTranslator()
{
var form = new Translator();
Application.Run(form);
}

private static void VisualStyles(ICollection<string> args)
{
if (args.Contains("-v1"))
Expand Down
1 change: 1 addition & 0 deletions PlexDL/PlexDL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@
<Compile Include="Common\SearchFramework\SearchQuery.cs" />
<Compile Include="Common\Structures\TvShowDirectoryLayout.cs" />
<Compile Include="Common\TypeConverters\StringListTypeConverter.cs" />
<Compile Include="Common\UiUtils.cs" />
<Compile Include="Common\Update\UpdateManager.cs" />
<Compile Include="Common\WebCheck.cs" />
<Compile Include="Internal\UnhandledExceptionHandler.cs" />
Expand Down
30 changes: 15 additions & 15 deletions PlexDL/UI/Home.Designer.cs

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

39 changes: 38 additions & 1 deletion PlexDL/UI/Home.cs
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,44 @@ public void LoadProfile()
{
if (!Flags.IsConnected)
{
if (ofdLoadProfile.ShowDialog() == DialogResult.OK) DoLoadProfile(ofdLoadProfile.FileName);
if (ofdLoadProfile.ShowDialog() == DialogResult.OK)
{
//store the file-type of the currently selected file
var actExt = Path.GetExtension(ofdLoadProfile.FileName);

//what we're checking for
const string expExt = @".prof";
const string metExp = @".pxz";

//execute file-type checks
switch (actExt)
{
//XML settings profile
case expExt:
DoLoadProfile(ofdLoadProfile.FileName);
break;

//PXZ metadata archive
case metExp:
try
{
var metadata = ImportExport.MetadataFromFile(ofdLoadProfile.FileName);
UiUtils.RunMetadataWindow(metadata);
}
catch (Exception ex)
{
LoggingHelpers.RecordException(ex.Message, @"StartupLoadPxz");
UIMessages.Error($"Error occurred whilst loading PXZ file:\n\n{ex}");
}

break;

//anything else can't be handled
default:
UIMessages.Error(@"Unrecognised file-type");
break;
}
}
}
else
{
Expand Down

0 comments on commit 6e89558

Please sign in to comment.