Skip to content

Commit cc4e93d

Browse files
Fixed error where app would not kill Calibre when importing one file;
Fixed error where it would not launch Calibre after import Improved setup file
1 parent ab6d91c commit cc4e93d

File tree

5 files changed

+96
-4
lines changed

5 files changed

+96
-4
lines changed

CalibreImport/CalibreImport.cs

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ private void ExecuteImport(string selectedLibrary = null, ReportProgressDelegate
336336
reportProgress?.Invoke((i + 1) * 100 / totalFiles);
337337
}
338338

339-
// Method 2: Import all files at once
339+
// Post-import actions
340340
if (allSuccessful)
341341
{
342342
Logger.LogThis("Files imported successfully.", true);
@@ -362,6 +362,7 @@ private void ExecuteImport(string selectedLibrary = null, ReportProgressDelegate
362362
var result = MessageBox.Show(ResourceStrings.ImportSuccessRes, ResourceStrings.NameAppRes, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
363363
if (result == DialogResult.Yes)
364364
{
365+
Logger.LogThis("Auto-opening Calibre due to user choice.", true);
365366
LaunchCalibre(selectedLibrary);
366367
}
367368
}
@@ -434,6 +435,67 @@ private void ExecuteImportWithProgress(string selectedLibrary, ToolStripMenuItem
434435

435436
Task.Run(() =>
436437
{
438+
439+
// Ensure Calibre is not running before import
440+
if (IsCalibreRunning())
441+
{
442+
Logger.LogThis("Calibre is running (ExecuteImportWithProgress).", true);
443+
444+
if (autoKillCalibre)
445+
{
446+
Logger.LogThis("Auto-killing Calibre without asking (ExecuteImportWithProgress).", true);
447+
KillCalibre();
448+
449+
// Re-check if Calibre is still running
450+
if (IsCalibreRunning())
451+
{
452+
Logger.LogThis("Failed to close Calibre. Import cannot proceed (ExecuteImportWithProgress).", true);
453+
progressForm.Invoke(new Action(() =>
454+
{
455+
progressForm.Close();
456+
MessageBox.Show("Calibre could not be closed automatically. Please close Calibre and try again.",
457+
ResourceStrings.NameAppRes, MessageBoxButtons.OK, MessageBoxIcon.Error);
458+
}));
459+
return;
460+
}
461+
}
462+
else
463+
{
464+
Logger.LogThis("Prompting user to close Calibre (ExecuteImportWithProgress).", true);
465+
var result = DialogResult.No;
466+
progressForm.Invoke(new Action(() =>
467+
{
468+
result = MessageBox.Show(ResourceStrings.CalibreRunningRes, ResourceStrings.CalibreRunning2Res, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
469+
}));
470+
if (result == DialogResult.Yes)
471+
{
472+
KillCalibre();
473+
474+
// Re-check if Calibre is still running
475+
if (IsCalibreRunning())
476+
{
477+
Logger.LogThis("Failed to close Calibre. Import cannot proceed (ExecuteImportWithProgress).", true);
478+
progressForm.Invoke(new Action(() =>
479+
{
480+
progressForm.Close();
481+
MessageBox.Show("Calibre could not be closed automatically. Please close Calibre and try again.",
482+
ResourceStrings.NameAppRes, MessageBoxButtons.OK, MessageBoxIcon.Error);
483+
}));
484+
return;
485+
}
486+
}
487+
else
488+
{
489+
Logger.LogThis("calibre.exe must be closed to proceed (ExecuteImportWithProgress).", true);
490+
progressForm.Invoke(new Action(() =>
491+
{
492+
progressForm.Close();
493+
}));
494+
return;
495+
}
496+
}
497+
}
498+
437499
try
438500
{
439501
// For single file imports, we need more granular progress updates
@@ -452,6 +514,36 @@ private void ExecuteImportWithProgress(string selectedLibrary, ToolStripMenuItem
452514

453515
// Ensure the progress bar shows completion
454516
progressForm.UpdateProgress(100);
517+
518+
// Post-import actions for single file
519+
if (success)
520+
{
521+
Logger.LogThis("Files imported successfully.", true);
522+
523+
if (skipSuccessMessage)
524+
{
525+
Logger.LogThis("Skipping success message due to user settings.", true);
526+
527+
if (autoCalibreOpen)
528+
{
529+
Logger.LogThis("Auto-opening Calibre due to user settings.", true);
530+
LaunchCalibre(selectedLibrary);
531+
}
532+
else
533+
{
534+
Logger.LogThis("Not opening Calibre due to user settings.", true);
535+
}
536+
}
537+
else
538+
{
539+
var result = MessageBox.Show(ResourceStrings.ImportSuccessRes, ResourceStrings.NameAppRes, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
540+
if (result == DialogResult.Yes)
541+
{
542+
Logger.LogThis("Auto-opening Calibre due to user choice.", true);
543+
LaunchCalibre(selectedLibrary);
544+
}
545+
}
546+
}
455547
}
456548
else
457549
{

CalibreImport/InnoSetup/CalibreImportSetup.iss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
[Setup]
1010
; Application metadata
1111
AppName={#AppNameNice}
12-
AppVersion=0.1.1.0
12+
AppVersion=0.1.1.2
1313
DefaultDirName={autopf}\{#AppName}
1414
DefaultGroupName={#AppName}
1515
UninstallDisplayIcon={app}\{#MainDll}

CalibreImport/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@
2828
// Build Number
2929
// Revision
3030
//
31-
[assembly: AssemblyVersion("0.1.1.0")]
32-
[assembly: AssemblyFileVersion("0.1.1.0")]
31+
[assembly: AssemblyVersion("0.1.1.2")]
32+
[assembly: AssemblyFileVersion("0.1.1.2")]
2 KB
Binary file not shown.
166 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)