From a7c8a77b53c29598253fc58f429bb232c8be213c Mon Sep 17 00:00:00 2001 From: t0815 <10379828+t0815@users.noreply.github.com> Date: Thu, 22 Aug 2024 11:26:10 +0200 Subject: [PATCH] make whole pagesettings dialog threadded upon opening --- MyCBZ/App.config | 2 +- MyCBZ/Forms/PageSettingsForm.Designer.cs | 15 +- MyCBZ/Forms/PageSettingsForm.cs | 543 ++++++++++++++--------- MyCBZ/Win_CBZSettings.Designer.cs | 2 +- MyCBZ/Win_CBZSettings.settings | 2 +- Readme.md | 2 +- Win_CBZ-Setup/Win_CBZ-Setup.vdproj | 6 +- 7 files changed, 343 insertions(+), 229 deletions(-) diff --git a/MyCBZ/App.config b/MyCBZ/App.config index f3430169..b8df2680 100644 --- a/MyCBZ/App.config +++ b/MyCBZ/App.config @@ -135,7 +135,7 @@ - 0.19.146b + 0.19.147b diff --git a/MyCBZ/Forms/PageSettingsForm.Designer.cs b/MyCBZ/Forms/PageSettingsForm.Designer.cs index 90366d79..f0007a18 100644 --- a/MyCBZ/Forms/PageSettingsForm.Designer.cs +++ b/MyCBZ/Forms/PageSettingsForm.Designer.cs @@ -228,6 +228,7 @@ private void InitializeComponent() // ButtonOk.Anchor = System.Windows.Forms.AnchorStyles.Right; ButtonOk.DialogResult = System.Windows.Forms.DialogResult.OK; + ButtonOk.Enabled = false; ButtonOk.Location = new System.Drawing.Point(477, 636); ButtonOk.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); ButtonOk.Name = "ButtonOk"; @@ -357,7 +358,7 @@ private void InitializeComponent() tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 48F)); tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 48F)); tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 48F)); - tableLayoutPanel1.Size = new System.Drawing.Size(427, 640); + tableLayoutPanel1.Size = new System.Drawing.Size(406, 640); tableLayoutPanel1.TabIndex = 2; // // label3 @@ -501,7 +502,7 @@ private void InitializeComponent() label8.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right; label8.AutoSize = true; label8.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0); - label8.Location = new System.Drawing.Point(351, 48); + label8.Location = new System.Drawing.Point(330, 48); label8.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); label8.Name = "label8"; label8.Padding = new System.Windows.Forms.Padding(0, 9, 0, 0); @@ -513,7 +514,7 @@ private void InitializeComponent() // LabelBits // LabelBits.AutoSize = true; - LabelBits.Location = new System.Drawing.Point(386, 48); + LabelBits.Location = new System.Drawing.Point(365, 48); LabelBits.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); LabelBits.Name = "LabelBits"; LabelBits.Padding = new System.Windows.Forms.Padding(0, 9, 0, 0); @@ -527,7 +528,7 @@ private void InitializeComponent() label7.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right; label7.AutoSize = true; label7.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0); - label7.Location = new System.Drawing.Point(347, 96); + label7.Location = new System.Drawing.Point(326, 96); label7.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); label7.Name = "label7"; label7.Padding = new System.Windows.Forms.Padding(0, 9, 0, 0); @@ -539,7 +540,7 @@ private void InitializeComponent() // LabelImageColors // LabelImageColors.AutoSize = true; - LabelImageColors.Location = new System.Drawing.Point(386, 96); + LabelImageColors.Location = new System.Drawing.Point(365, 96); LabelImageColors.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); LabelImageColors.Name = "LabelImageColors"; LabelImageColors.Padding = new System.Windows.Forms.Padding(0, 9, 0, 0); @@ -725,7 +726,7 @@ private void InitializeComponent() // pictureBox2.Image = Properties.Resources.information; pictureBox2.InitialImage = Properties.Resources.information; - pictureBox2.Location = new System.Drawing.Point(345, 288); + pictureBox2.Location = new System.Drawing.Point(324, 288); pictureBox2.Margin = new System.Windows.Forms.Padding(4, 0, 0, 0); pictureBox2.Name = "pictureBox2"; pictureBox2.Size = new System.Drawing.Size(23, 29); @@ -737,7 +738,7 @@ private void InitializeComponent() // ButtonReloadImage // ButtonReloadImage.Image = Properties.Resources.arrow_circle2; - ButtonReloadImage.Location = new System.Drawing.Point(385, 4); + ButtonReloadImage.Location = new System.Drawing.Point(364, 4); ButtonReloadImage.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); ButtonReloadImage.Name = "ButtonReloadImage"; ButtonReloadImage.Size = new System.Drawing.Size(32, 29); diff --git a/MyCBZ/Forms/PageSettingsForm.cs b/MyCBZ/Forms/PageSettingsForm.cs index 2f063165..52f15233 100644 --- a/MyCBZ/Forms/PageSettingsForm.cs +++ b/MyCBZ/Forms/PageSettingsForm.cs @@ -56,13 +56,7 @@ private void PageSettingsForm_FormClosing(object sender, FormClosingEventArgs e) { FirstPage?.FreeImage(); - foreach (Page page in Pages) - { - page.FreeImage(); - page.IsMemoryCopy = false; - - } - + FreeResult(); } private bool ThumbAbort() @@ -77,19 +71,28 @@ public List GetResult() public void FreeResult() { - foreach (Page page in Pages) + Task freeResultTask = new Task(() => { - try + bool result = true; + + foreach (Page page in Pages) { - page.FreeImage(); + try + { + page.FreeImage(); + page.IsMemoryCopy = false; + } + catch (ApplicationException ex) + { + result = false; + } } - catch (ApplicationException ex) - { - } - //page.DeleteTemporaryFile(); + return result; - } + }); + + freeResultTask.Start(); } private void PageNameTextBox_TextChanged(object sender, EventArgs e) @@ -252,12 +255,12 @@ private void TabControlPageProperties_SelectedIndexChanged(object sender, EventA // Transform the XML data MemoryStream ms = new MemoryStream(); - + xTrans.Transform(xReader, null, ms); ms.Position = 0; // Set to the document stream - + TextReader tr = new StreamReader(ms); string xml = tr.ReadToEnd(); @@ -587,31 +590,327 @@ private void PageSettingsForm_Shown(object sender, EventArgs e) Pages = new List(); Page pageList = null; - try + Task> loadingTask = new Task>(() => { + List resultPages = new List(); + foreach (Page p in SelectedPages) { bool realMemoryCopyState = p.IsMemoryCopy; pageList = new Page(p, true, false); + pageList.UpdatePageAttributes(p); - Pages.Add(pageList); pageList.IsMemoryCopy = realMemoryCopyState; + resultPages.Add(pageList); + //p.FreeImage(); } - } - catch (Exception ex) + + return resultPages; + }); + + Task>> loadFirstPageTask = loadingTask.ContinueWith>>(t => { - ApplicationMessage.ShowException(ex); - ButtonOk.Enabled = false; + if (t.IsCompletedSuccessfully) + { + if (t.Result != null && t.Result.Count > 0) + { + + FirstPage = new Page(SelectedPages[0], true); // todo: maybe use memory copy here too and just set real memorycopy state + + if (SelectedPages.Count == 1) + { + return Tuple.Create>(FirstPage, FirstPage.GetThumbnailBitmap(), t.Result); + } + else + { + return Tuple.Create>(FirstPage, null, t.Result); + } + } + } + else + { + + } + + return Tuple.Create>(null, null, t.Result); + }); + + Task uddateImageMetadata = loadFirstPageTask.ContinueWith(t => + { + try + { + if (t.IsCompletedSuccessfully) + { + FirstPage = t.Result.Item1; + Pages = t.Result.Item3; + + if (t.Result.Item2 != null) + { + Invoke(new Action(() => + { + ImagePreviewButton.BackgroundImage = Image.FromHbitmap(t.Result.Item2.GetHbitmap()); + + LabelDimensions.Text = FirstPage.Format.W.ToString() + " x " + FirstPage.Format.H.ToString() + " px"; + LabelDpi.Text = FirstPage.Format.DPI.ToString(); + LabelImageFormat.Text = FirstPage.Format.Name; + if (FirstPage.Format?.ColorPalette != null) + { + LabelImageColors.Text = FirstPage.Format.ColorPalette.Entries.Length.ToString(); + } + })); + } + + bool deletedState = false; + bool doublePageState = false; + bool compressedState = false; + + if (t.Result.Item3.Count == 1) + { + if (t.Result.Item1 == null) + { + FirstPage = new Page(); + ButtonOk.Enabled = false; + } + + if (FirstPage.LocalFile != null && FirstPage.LocalFile.Exists()) + { + if (!FirstPage.Compressed) + { + imageLocation = FirstPage.LocalFile.FilePath; + } + else + { + try + { + ZipArchiveEntry entry = FirstPage.GetCompressedEntry(); + imageLocation = "\\\\" + entry.Name; + } + catch + { + imageLocation = "?\\" + FirstPage.Name; + } + } + } + else + { + if (!FirstPage.IsMemoryCopy && FirstPage.TemporaryFile != null && FirstPage.TemporaryFile.Exists()) + { + imageLocation = FirstPage.TemporaryFile.FilePath; + } + else + { + try + { + ZipArchiveEntry entry = FirstPage.GetCompressedEntry(); + imageLocation = "\\\\" + entry.Name; + } + catch (Exception eentry) + { + imageLocation = "?\\" + FirstPage.Name; + } + } + } + + Invoke(new Action(() => + { + + ComboBoxPageType.Text = FirstPage.ImageType; + TextBoxFileLocation.Text = imageLocation; + PageNameTextBox.Text = FirstPage.Name; + LabelSize.Text = FirstPage.SizeFormat(); + PageIndexTextbox.Text = (FirstPage.Index + 1).ToString(); + CheckBoxPageDeleted.Checked = FirstPage.Deleted; + + + if (MetaDataVersionFlavorHandler.GetInstance().TargetVersion() == MetaData.PageIndexVersion.VERSION_2) + { + textBoxKey.Text = FirstPage.Key; + textBoxKey.Enabled = true; + ButtonNewKey.Enabled = true; + label10.Enabled = true; + } + else + { + textBoxKey.Text = ""; + textBoxKey.Enabled = false; + ButtonNewKey.Enabled = false; + label10.Enabled = false; + } + + CheckBoxDoublePage.Checked = FirstPage.DoublePage; + IsCompressedLabel.Text = FirstPage.Compressed ? "Yes" : "No"; + })); + } + else + { + Invoke(new Action(() => + { + PageIndexTextbox.Enabled = false; + PageNameTextBox.Enabled = false; + textBoxKey.Enabled = false; + + if (SelectedPages.Count > 1) + { + ImagePreviewButton.Text = "[" + SelectedPages.Count.ToString() + " Pages]"; + ImagePreviewButton.BackgroundImage = null; + } + + textBoxKey.Text = ""; + LabelDimensions.Text = "Multiple dimensions"; + LabelDpi.Text = "Multiple"; + LabelImageFormat.Text = "Multiple formats"; + TextBoxFileLocation.Text = ""; + + foreach (Page page in SelectedPages) + { + + if (deletedState != page.Deleted) + { + countDeletedStates++; + deletedState = page.Deleted; + } + + if (compressedState != page.Compressed) + { + countCompressedStates++; + compressedState = page.Compressed; + } + + if (doublePageState != page.DoublePage) + { + countDoublePageStates++; + doublePageState = page.DoublePage; + } + + if (typesList.IndexOf(page.Format.Name) == -1) + { + typesList.Add(page.Format.Name); + } + + if (dpiList.IndexOf(page.Format.DPI.ToString()) == -1) + { + dpiList.Add(page.Format.DPI.ToString()); + } + + if (dimensionsList.IndexOf(page.Format.W.ToString() + " x " + page.Format.H.ToString()) == -1) + { + dimensionsList.Add(page.Format.W.ToString() + " x " + page.Format.H.ToString()); + } + + if (imageTypeList.IndexOf(page.ImageType) == -1) + { + imageTypeList.Add(page.ImageType); + } + + totalSize += page.Size; + } + + LabelSize.Text = Program.ProjectModel.SizeFormat(totalSize); + + + if (typesList.Count == 1) + { + LabelImageFormat.Text = typesList[0].ToString(); + } + + if (imageTypeList.Count == 1) + { + ComboBoxPageType.Text = imageTypeList[0].ToString(); + } + + if (dimensionsList.Count == 1) + { + LabelDimensions.Text = dimensionsList[0].ToString(); + } + + if (dpiList.Count == 1) + { + LabelDpi.Text = dpiList[0].ToString(); + } + + if (countCompressedStates < 2) + { + + } + else + { + + } + + if (countDeletedStates < 2) + { + CheckBoxPageDeleted.Checked = deletedState; + } + else + { + CheckBoxPageDeleted.CheckState = CheckState.Indeterminate; + } + + if (countDoublePageStates < 2) + { + CheckBoxDoublePage.Checked = doublePageState; + } + else + { + CheckBoxDoublePage.CheckState = CheckState.Indeterminate; + } + })); + } + } + else + { + Invoke(new Action(() => + { + //ButtonOk.Enabled = false; + if ((t.Exception.InnerException as ApplicationException).ShowErrorDialog) + { + ApplicationMessage.ShowException(t.Exception); + } + })); + + return false; + } + } + catch (Exception ee) + { + Invoke(new Action(() => + { + ApplicationMessage.ShowException(ee); + })); + + return false; + } + finally + { + FirstPage.FreeImage(); + } + + return true; + }); + + Task finalTask = uddateImageMetadata.ContinueWith(t => + { + if (t.IsCompletedSuccessfully && t.Result) + { + Invoke(new Action(() => + { + ButtonOk.Enabled = true; + })); + } + }); + + + loadingTask.Start(); + + ////// + /// + + return; - return; - } - bool deletedState = false; - bool doublePageState = false; - bool compressedState = false; if (SelectedPages != null && SelectedPages.Count > 0) { @@ -671,198 +970,12 @@ private void PageSettingsForm_Shown(object sender, EventArgs e) imageTask.Start(); } - + // //PreviewThumbPictureBox.Image = PreviewThumb; - if (SelectedPages.Count == 1) - { - if (FirstPage == null) - { - FirstPage = new Page(); - ButtonOk.Enabled = false; - } - if (FirstPage.LocalFile != null && FirstPage.LocalFile.Exists()) - { - if (!FirstPage.Compressed) - { - imageLocation = FirstPage.LocalFile.FilePath; - } - else - { - try - { - ZipArchiveEntry entry = FirstPage.GetCompressedEntry(); - imageLocation = "\\\\" + entry.Name; - } - catch - { - imageLocation = "?\\" + FirstPage.Name; - } - } - } - else - { - if (!FirstPage.IsMemoryCopy && FirstPage.TemporaryFile != null && FirstPage.TemporaryFile.Exists()) - { - imageLocation = FirstPage.TemporaryFile.FilePath; - } - else - { - try - { - ZipArchiveEntry entry = FirstPage.GetCompressedEntry(); - imageLocation = "\\\\" + entry.Name; - } - catch (Exception eentry) - { - imageLocation = "?\\" + FirstPage.Name; - } - } - } - - ComboBoxPageType.Text = FirstPage.ImageType; - TextBoxFileLocation.Text = imageLocation; - PageNameTextBox.Text = FirstPage.Name; - LabelSize.Text = FirstPage.SizeFormat(); - PageIndexTextbox.Text = (FirstPage.Index + 1).ToString(); - CheckBoxPageDeleted.Checked = FirstPage.Deleted; - - - if (MetaDataVersionFlavorHandler.GetInstance().TargetVersion() == MetaData.PageIndexVersion.VERSION_2) - { - textBoxKey.Text = FirstPage.Key; - textBoxKey.Enabled = true; - ButtonNewKey.Enabled = true; - label10.Enabled = true; - } - else - { - textBoxKey.Text = ""; - textBoxKey.Enabled = false; - ButtonNewKey.Enabled = false; - label10.Enabled = false; - } - - CheckBoxDoublePage.Checked = FirstPage.DoublePage; - IsCompressedLabel.Text = FirstPage.Compressed ? "Yes" : "No"; - } - else - { - PageIndexTextbox.Enabled = false; - PageNameTextBox.Enabled = false; - textBoxKey.Enabled = false; - - if (SelectedPages.Count > 1) - { - ImagePreviewButton.Text = "[" + SelectedPages.Count.ToString() + " Pages]"; - ImagePreviewButton.BackgroundImage = null; - } - - textBoxKey.Text = ""; - LabelDimensions.Text = "Multiple dimensions"; - LabelDpi.Text = "Multiple"; - LabelImageFormat.Text = "Multiple formats"; - TextBoxFileLocation.Text = ""; - - foreach (Page page in SelectedPages) - { - - if (deletedState != page.Deleted) - { - countDeletedStates++; - deletedState = page.Deleted; - } - - if (compressedState != page.Compressed) - { - countCompressedStates++; - compressedState = page.Compressed; - } - - if (doublePageState != page.DoublePage) - { - countDoublePageStates++; - doublePageState = page.DoublePage; - } - - if (typesList.IndexOf(page.Format.Name) == -1) - { - typesList.Add(page.Format.Name); - } - - if (dpiList.IndexOf(page.Format.DPI.ToString()) == -1) - { - dpiList.Add(page.Format.DPI.ToString()); - } - - if (dimensionsList.IndexOf(page.Format.W.ToString() + " x " + page.Format.H.ToString()) == -1) - { - dimensionsList.Add(page.Format.W.ToString() + " x " + page.Format.H.ToString()); - } - - if (imageTypeList.IndexOf(page.ImageType) == -1) - { - imageTypeList.Add(page.ImageType); - } - - totalSize += page.Size; - } - - LabelSize.Text = Program.ProjectModel.SizeFormat(totalSize); - - - if (typesList.Count == 1) - { - LabelImageFormat.Text = typesList[0].ToString(); - } - - if (imageTypeList.Count == 1) - { - ComboBoxPageType.Text = imageTypeList[0].ToString(); - } - - if (dimensionsList.Count == 1) - { - LabelDimensions.Text = dimensionsList[0].ToString(); - } - - if (dpiList.Count == 1) - { - LabelDpi.Text = dpiList[0].ToString(); - } - - if (countCompressedStates < 2) - { - - } - else - { - - } - - if (countDeletedStates < 2) - { - CheckBoxPageDeleted.Checked = deletedState; - } - else - { - CheckBoxPageDeleted.CheckState = CheckState.Indeterminate; - } - - if (countDoublePageStates < 2) - { - CheckBoxDoublePage.Checked = doublePageState; - } - else - { - CheckBoxDoublePage.CheckState = CheckState.Indeterminate; - } - - - } } } diff --git a/MyCBZ/Win_CBZSettings.Designer.cs b/MyCBZ/Win_CBZSettings.Designer.cs index b1b79ec8..ec3e0e30 100644 --- a/MyCBZ/Win_CBZSettings.Designer.cs +++ b/MyCBZ/Win_CBZSettings.Designer.cs @@ -37,7 +37,7 @@ public string TempFolderPath { [global::System.Configuration.ApplicationScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("0.19.146b")] + [global::System.Configuration.DefaultSettingValueAttribute("0.19.147b")] public string Version { get { return ((string)(this["Version"])); diff --git a/MyCBZ/Win_CBZSettings.settings b/MyCBZ/Win_CBZSettings.settings index 3f6c6d8e..63b87556 100644 --- a/MyCBZ/Win_CBZSettings.settings +++ b/MyCBZ/Win_CBZSettings.settings @@ -6,7 +6,7 @@ %APPDATA%\WIN_CBZ\Temp\ - 0.19.146b + 0.19.147b <?xml version="1.0" encoding="utf-16"?> diff --git a/Readme.md b/Readme.md index 5b20b52d..a90cbf58 100644 --- a/Readme.md +++ b/Readme.md @@ -48,7 +48,7 @@ Microsoft Visual Studio [Community] 2022 (64-Bit) ## Latest Release -v0.19.146b released! +v0.19.147b released! ## Third party components diff --git a/Win_CBZ-Setup/Win_CBZ-Setup.vdproj b/Win_CBZ-Setup/Win_CBZ-Setup.vdproj index 3b789393..e72c0971 100644 --- a/Win_CBZ-Setup/Win_CBZ-Setup.vdproj +++ b/Win_CBZ-Setup/Win_CBZ-Setup.vdproj @@ -248,15 +248,15 @@ { "Name" = "8:Microsoft Visual Studio" "ProductName" = "8:Win_CBZ" - "ProductCode" = "8:{1ECC262C-C229-4BBA-9970-4EAC5C53C40A}" - "PackageCode" = "8:{43737E4F-CA59-4C4D-BBA8-646DF9191011}" + "ProductCode" = "8:{43941DEC-9F85-48D9-8EEE-EFA40411CF90}" + "PackageCode" = "8:{51021596-378B-4402-A26B-BD68BFDB31B9}" "UpgradeCode" = "8:{66FAEF81-1CAE-4971-9E0F-796310EFEA5E}" "AspNetVersion" = "8:4.0.30319.0" "RestartWWWService" = "11:FALSE" "RemovePreviousVersions" = "11:FALSE" "DetectNewerInstalledVersion" = "11:TRUE" "InstallAllUsers" = "11:FALSE" - "ProductVersion" = "8:0.19.146" + "ProductVersion" = "8:0.19.147" "Manufacturer" = "8:Trash_s0Ft" "ARPHELPTELEPHONE" = "8:" "ARPHELPLINK" = "8:"