diff --git a/PlexDL/Common/UiUtils.cs b/PlexDL/Common/UiUtils.cs new file mode 100644 index 0000000..bc39b6c --- /dev/null +++ b/PlexDL/Common/UiUtils.cs @@ -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(); + } + } +} \ No newline at end of file diff --git a/PlexDL/Internal/Program.cs b/PlexDL/Internal/Program.cs index 3c3ea3c..7ff9dd8 100644 --- a/PlexDL/Internal/Program.cs +++ b/PlexDL/Internal/Program.cs @@ -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; @@ -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) { @@ -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 @@ -101,39 +100,6 @@ private static void CheckOverrideLogProtection(ICollection 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 args) { if (args.Contains("-v1")) diff --git a/PlexDL/PlexDL.csproj b/PlexDL/PlexDL.csproj index 44f170b..403399b 100644 --- a/PlexDL/PlexDL.csproj +++ b/PlexDL/PlexDL.csproj @@ -192,6 +192,7 @@ + diff --git a/PlexDL/UI/Home.Designer.cs b/PlexDL/UI/Home.Designer.cs index 4c78a24..fd798bb 100644 --- a/PlexDL/UI/Home.Designer.cs +++ b/PlexDL/UI/Home.Designer.cs @@ -217,7 +217,7 @@ private void InitializeComponent() // // ofdLoadProfile // - this.ofdLoadProfile.Filter = "XML Profile|*.prof"; + this.ofdLoadProfile.Filter = "XML Profile|*.prof|PXZ File|*.pxz"; this.ofdLoadProfile.Title = "Load XML Profile"; // // wkrGetMetadata @@ -272,14 +272,14 @@ private void InitializeComponent() // itmEpisodeMetadataView // this.itmEpisodeMetadataView.Name = "itmEpisodeMetadataView"; - this.itmEpisodeMetadataView.Size = new System.Drawing.Size(180, 22); + this.itmEpisodeMetadataView.Size = new System.Drawing.Size(108, 22); this.itmEpisodeMetadataView.Text = "View"; this.itmEpisodeMetadataView.Click += new System.EventHandler(this.ItmEpisodeMetadataView_Click); // // itmEpisodeMetadataExport // this.itmEpisodeMetadataExport.Name = "itmEpisodeMetadataExport"; - this.itmEpisodeMetadataExport.Size = new System.Drawing.Size(180, 22); + this.itmEpisodeMetadataExport.Size = new System.Drawing.Size(108, 22); this.itmEpisodeMetadataExport.Text = "Export"; this.itmEpisodeMetadataExport.Click += new System.EventHandler(this.ItmEpisodeMetadataExport_Click); // @@ -370,7 +370,7 @@ private void InitializeComponent() this.itmContentSearch, this.itmContentCast}); this.cxtMovieOptions.Name = "cxtEpisodeOptions"; - this.cxtMovieOptions.Size = new System.Drawing.Size(181, 136); + this.cxtMovieOptions.Size = new System.Drawing.Size(129, 114); this.cxtMovieOptions.Opening += new System.ComponentModel.CancelEventHandler(this.CxtContentOptions_Opening); // // itmContentMetadata @@ -379,20 +379,20 @@ private void InitializeComponent() this.itmContentMetadataView, this.itmContentMetadataExport}); this.itmContentMetadata.Name = "itmContentMetadata"; - this.itmContentMetadata.Size = new System.Drawing.Size(180, 22); + this.itmContentMetadata.Size = new System.Drawing.Size(128, 22); this.itmContentMetadata.Text = "Metadata"; // // itmContentMetadataView // this.itmContentMetadataView.Name = "itmContentMetadataView"; - this.itmContentMetadataView.Size = new System.Drawing.Size(180, 22); + this.itmContentMetadataView.Size = new System.Drawing.Size(108, 22); this.itmContentMetadataView.Text = "View"; this.itmContentMetadataView.Click += new System.EventHandler(this.ItmContentMetadataView_Click); // // itmContentMetadataExport // this.itmContentMetadataExport.Name = "itmContentMetadataExport"; - this.itmContentMetadataExport.Size = new System.Drawing.Size(180, 22); + this.itmContentMetadataExport.Size = new System.Drawing.Size(108, 22); this.itmContentMetadataExport.Text = "Export"; this.itmContentMetadataExport.Click += new System.EventHandler(this.ItmContentMetadataExport_Click); // @@ -402,7 +402,7 @@ private void InitializeComponent() this.itmDGVDownloadThisMovie, this.itmDGVViewMovieDownloadLink}); this.itmContentDownload.Name = "itmContentDownload"; - this.itmContentDownload.Size = new System.Drawing.Size(180, 22); + this.itmContentDownload.Size = new System.Drawing.Size(128, 22); this.itmContentDownload.Text = "Download"; // // itmDGVDownloadThisMovie @@ -422,21 +422,21 @@ private void InitializeComponent() // itmContentStream // this.itmContentStream.Name = "itmContentStream"; - this.itmContentStream.Size = new System.Drawing.Size(180, 22); + this.itmContentStream.Size = new System.Drawing.Size(128, 22); this.itmContentStream.Text = "Stream"; this.itmContentStream.Click += new System.EventHandler(this.ItmContentStream_Click); // // itmContentSearch // this.itmContentSearch.Name = "itmContentSearch"; - this.itmContentSearch.Size = new System.Drawing.Size(180, 22); + this.itmContentSearch.Size = new System.Drawing.Size(128, 22); this.itmContentSearch.Text = "Search"; this.itmContentSearch.Click += new System.EventHandler(this.ItmContentSearch_Click); // // itmContentCast // this.itmContentCast.Name = "itmContentCast"; - this.itmContentCast.Size = new System.Drawing.Size(180, 22); + this.itmContentCast.Size = new System.Drawing.Size(128, 22); this.itmContentCast.Text = "Cast"; this.itmContentCast.Click += new System.EventHandler(this.ItmContentCast_Click); // @@ -1153,7 +1153,7 @@ private void InitializeComponent() // this.itmLoadProfile.Name = "itmLoadProfile"; this.itmLoadProfile.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.O))); - this.itmLoadProfile.Size = new System.Drawing.Size(148, 22); + this.itmLoadProfile.Size = new System.Drawing.Size(180, 22); this.itmLoadProfile.Text = "Load"; this.itmLoadProfile.Click += new System.EventHandler(this.ItmLoadProfile_Click); // @@ -1161,7 +1161,7 @@ private void InitializeComponent() // this.itmSaveProfile.Name = "itmSaveProfile"; this.itmSaveProfile.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.S))); - this.itmSaveProfile.Size = new System.Drawing.Size(148, 22); + this.itmSaveProfile.Size = new System.Drawing.Size(180, 22); this.itmSaveProfile.Text = "Save"; this.itmSaveProfile.Click += new System.EventHandler(this.ItmSaveProfile_Click); // @@ -1169,14 +1169,14 @@ private void InitializeComponent() // this.itmExportObj.Name = "itmExportObj"; this.itmExportObj.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.E))); - this.itmExportObj.Size = new System.Drawing.Size(148, 22); + this.itmExportObj.Size = new System.Drawing.Size(180, 22); this.itmExportObj.Text = "Export"; this.itmExportObj.Click += new System.EventHandler(this.ItmExportObj_Click); // // itmSettings // this.itmSettings.Name = "itmSettings"; - this.itmSettings.Size = new System.Drawing.Size(148, 22); + this.itmSettings.Size = new System.Drawing.Size(180, 22); this.itmSettings.Text = "Settings"; this.itmSettings.Click += new System.EventHandler(this.ItmSettings_Click); // diff --git a/PlexDL/UI/Home.cs b/PlexDL/UI/Home.cs index 32f3743..7b0ebca 100644 --- a/PlexDL/UI/Home.cs +++ b/PlexDL/UI/Home.cs @@ -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 {