private bool SaveOneFile(AutoSaveSettings settings, DateTime now, int i, List <ScannedImage> images, ISaveNotify notify, ref string firstFileSaved) { if (images.Count == 0) { return(true); } var form = formFactory.Create <FProgress>(); string subPath = fileNamePlaceholders.SubstitutePlaceholders(settings.FilePath, now, true, i); if (settings.PromptForFilePath) { if (dialogHelper.PromptToSavePdfOrImage(subPath, out string newPath)) { subPath = fileNamePlaceholders.SubstitutePlaceholders(newPath, now, true, i); } } var extension = Path.GetExtension(subPath); if (extension != null && extension.Equals(".pdf", StringComparison.InvariantCultureIgnoreCase)) { if (File.Exists(subPath)) { subPath = fileNamePlaceholders.SubstitutePlaceholders(subPath, now, true, 0, 1); } var op = operationFactory.Create <SavePdfOperation>(); form.Operation = op; var ocrLanguageCode = userConfigManager.Config.EnableOcr ? userConfigManager.Config.OcrLanguageCode : null; if (op.Start(subPath, now, images, pdfSettingsContainer.PdfSettings, ocrLanguageCode, false)) { form.ShowDialog(); } if (op.Status.Success && firstFileSaved == null) { firstFileSaved = subPath; } if (op.Status.Success) { notify?.PdfSaved(subPath); } return(op.Status.Success); } else { var op = operationFactory.Create <SaveImagesOperation>(); form.Operation = op; if (op.Start(subPath, now, images)) { form.ShowDialog(); } if (op.Status.Success && firstFileSaved == null) { firstFileSaved = op.FirstFileSaved; } if (op.Status.Success) { notify?.ImagesSaved(images.Count, op.FirstFileSaved); } return(op.Status.Success); } }
public bool Save(AutoSaveSettings settings, List <ScannedImage> images, ISaveNotify notify) { if (appConfigManager.Config.DisableAutoSave) { return(false); } try { bool ok = true; DateTime now = DateTime.Now; int i = 0; string firstFileSaved = null; var scans = SaveSeparatorHelper.SeparateScans(new[] { images }, settings.Separator).ToList(); foreach (var imageList in scans) { if (!SaveOneFile(settings, now, i++, imageList, scans.Count == 1 ? notify : null, ref firstFileSaved)) { ok = false; } } if (notify != null && scans.Count > 1 && ok) { // Can't just do images.Count because that includes patch codes int imageCount = scans.SelectMany(x => x).Count(); notify.ImagesSaved(imageCount, firstFileSaved); } return(ok); } catch (Exception ex) { Log.ErrorException(MiscResources.AutoSaveError, ex); errorOutput.DisplayError(MiscResources.AutoSaveError); return(false); } }
private async Task <(bool, string)> SaveOneFile(AutoSaveSettings settings, DateTime now, int i, List <ScannedImage> images, ISaveNotify notify) { if (images.Count == 0) { return(true, null); } string subPath = fileNamePlaceholders.SubstitutePlaceholders(settings.FilePath, now, true, i); if (settings.PromptForFilePath) { if (dialogHelper.PromptToSavePdfOrImage(subPath, out string newPath)) { subPath = fileNamePlaceholders.SubstitutePlaceholders(newPath, now, true, i); } else { return(false, null); } } var extension = Path.GetExtension(subPath); if (extension != null && extension.Equals(".pdf", StringComparison.InvariantCultureIgnoreCase)) { if (File.Exists(subPath)) { subPath = fileNamePlaceholders.SubstitutePlaceholders(subPath, now, true, 0, 1); } var op = operationFactory.Create <SavePdfOperation>(); if (op.Start(subPath, now, images, pdfSettingsContainer.PdfSettings, ocrManager.DefaultParams, false, null)) { operationProgress.ShowProgress(op); } bool success = await op.Success; if (success) { notify?.PdfSaved(subPath); } return(success, subPath); } else { var op = operationFactory.Create <SaveImagesOperation>(); if (op.Start(subPath, now, images)) { operationProgress.ShowProgress(op); } bool success = await op.Success; if (success) { notify?.ImagesSaved(images.Count, op.FirstFileSaved); } return(success, subPath); } }