mirror of
https://github.com/cyanfish/naps2.git
synced 2024-09-21 20:59:01 +03:00
Improve NAPS2.Console output for recent changes.
This commit is contained in:
parent
48c2dee8bb
commit
b926565994
@ -149,7 +149,7 @@ namespace NAPS2.Console
|
||||
&& File.Exists(subPath)
|
||||
&& !options.ForceOverwrite)
|
||||
{
|
||||
errorOutput.DisplayError(string.Format(ConsoleResources.FileAlreadyExists, Path.GetFileName(subPath)));
|
||||
errorOutput.DisplayError(string.Format(ConsoleResources.FileAlreadyExists, Path.GetFullPath(subPath)));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -311,24 +311,29 @@ namespace NAPS2.Console
|
||||
|
||||
private void ExportToImageFiles()
|
||||
{
|
||||
// TODO: Maybe add return code
|
||||
var path = fileNameSubstitution.SubstituteFileName(options.OutputPath, startTime);
|
||||
DoExportToImageFiles(options.OutputPath);
|
||||
|
||||
OutputVerbose(ConsoleResources.FinishedSavingImages, options.OutputPath);
|
||||
OutputVerbose(ConsoleResources.FinishedSavingImages, Path.GetFullPath(path));
|
||||
}
|
||||
|
||||
private void DoExportToImageFiles(string outputPath)
|
||||
{
|
||||
// TODO: If I add new image settings this may break things
|
||||
imageSettingsContainer.ImageSettings = new ImageSettings { JpegQuality = options.JpegQuality };
|
||||
imageSaver.SaveImages(outputPath, startTime, scannedImages);
|
||||
imageSaver.SaveImages(outputPath, startTime, scannedImages, i =>
|
||||
{
|
||||
OutputVerbose(ConsoleResources.ExportingImage, i, scannedImages.Count);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
private void ExportToPdf()
|
||||
{
|
||||
// Get a local copy of the path just for output
|
||||
var path = fileNameSubstitution.SubstituteFileName(options.OutputPath, startTime);
|
||||
if (DoExportToPdf(options.OutputPath))
|
||||
{
|
||||
OutputVerbose(ConsoleResources.SuccessfullySavedPdf, options.OutputPath);
|
||||
OutputVerbose(ConsoleResources.SuccessfullySavedPdf, path);
|
||||
}
|
||||
}
|
||||
|
||||
@ -378,7 +383,7 @@ namespace NAPS2.Console
|
||||
|
||||
return pdfSaver.SavePdf(path, startTime, scannedImages, pdfSettings, ocrLanguageCode, i =>
|
||||
{
|
||||
OutputVerbose(ConsoleResources.ExportedPage, i, scannedImages.Count);
|
||||
OutputVerbose(ConsoleResources.ExportingPage, i, scannedImages.Count);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
@ -159,15 +159,6 @@ namespace NAPS2.Console.Lang.Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Exported page {0} of {1}..
|
||||
/// </summary>
|
||||
internal static string ExportedPage {
|
||||
get {
|
||||
return ResourceManager.GetString("ExportedPage", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Exporting....
|
||||
/// </summary>
|
||||
@ -177,6 +168,15 @@ namespace NAPS2.Console.Lang.Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Exporting image {0} of {1}....
|
||||
/// </summary>
|
||||
internal static string ExportingImage {
|
||||
get {
|
||||
return ResourceManager.GetString("ExportingImage", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Exporting images for use as an attachment....
|
||||
/// </summary>
|
||||
@ -186,6 +186,15 @@ namespace NAPS2.Console.Lang.Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Exporting page {0} of {1}..
|
||||
/// </summary>
|
||||
internal static string ExportingPage {
|
||||
get {
|
||||
return ResourceManager.GetString("ExportingPage", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Exporting PDF for use as an attachment....
|
||||
/// </summary>
|
||||
|
@ -132,8 +132,8 @@
|
||||
<data name="ScannedImage" xml:space="preserve">
|
||||
<value>Scanned Image</value>
|
||||
</data>
|
||||
<data name="ExportedPage" xml:space="preserve">
|
||||
<value>Exported page {0} of {1}.</value>
|
||||
<data name="ExportingPage" xml:space="preserve">
|
||||
<value>Exporting page {0} of {1}.</value>
|
||||
</data>
|
||||
<data name="SuccessfullySavedPdf" xml:space="preserve">
|
||||
<value>Successfully saved PDF file to {0}</value>
|
||||
@ -223,4 +223,7 @@ Use the "--importpassword" option.</value>
|
||||
<data name="ErrorSaving" xml:space="preserve">
|
||||
<value>An error occurred when trying to save the file.</value>
|
||||
</data>
|
||||
<data name="ExportingImage" xml:space="preserve">
|
||||
<value>Exporting image {0} of {1}...</value>
|
||||
</data>
|
||||
</root>
|
@ -52,8 +52,9 @@ namespace NAPS2.ImportExport.Images
|
||||
/// If multiple images are provided, they will be saved to files with numeric identifiers, e.g. img1.jpg, img2.jpg, etc..
|
||||
/// </summary>
|
||||
/// <param name="fileName">The name of the file to save. For multiple images, this is modified by appending a number before the extension.</param>
|
||||
/// <param name="dateTime"></param>
|
||||
/// <param name="images">The collection of images to save.</param>
|
||||
public void SaveImages(string fileName, DateTime dateTime, ICollection<IScannedImage> images)
|
||||
public void SaveImages(string fileName, DateTime dateTime, ICollection<IScannedImage> images, Func<int, bool> progressCallback)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -78,10 +79,14 @@ namespace NAPS2.ImportExport.Images
|
||||
return;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
int i = 1;
|
||||
int digits = (int)Math.Floor(Math.Log10(images.Count)) + 1;
|
||||
foreach (IScannedImage img in images)
|
||||
{
|
||||
if (!progressCallback(i))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (images.Count == 1 && File.Exists(subFileName))
|
||||
{
|
||||
var dialogResult = overwritePrompt.ConfirmOverwrite(subFileName);
|
||||
@ -102,10 +107,11 @@ namespace NAPS2.ImportExport.Images
|
||||
}
|
||||
else
|
||||
{
|
||||
var fileNameN = fileNameSubstitution.SubstituteFileName(fileName, dateTime, true, i++, digits);
|
||||
var fileNameN = fileNameSubstitution.SubstituteFileName(fileName, dateTime, true, i - 1, digits);
|
||||
DoSaveImage(baseImage, fileNameN, format);
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
catch (UnauthorizedAccessException)
|
||||
|
@ -610,7 +610,7 @@ namespace NAPS2.WinForms
|
||||
{
|
||||
UserConfigManager.Config.LastImageExt = (Path.GetExtension(sd.FileName) ?? "").Replace(".", "");
|
||||
UserConfigManager.Save();
|
||||
imageSaver.SaveImages(sd.FileName, DateTime.Now, images);
|
||||
imageSaver.SaveImages(sd.FileName, DateTime.Now, images, i => true);
|
||||
changeTracker.HasUnsavedChanges = false;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user