Exemplo n.º 1
0
 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, ex);
         return false;
     }
 }
Exemplo n.º 2
0
        public ScanProfile Clone()
        {
            var profile = (ScanProfile)MemberwiseClone();

            if (profile.AutoSaveSettings != null)
            {
                profile.AutoSaveSettings = AutoSaveSettings.Clone();
            }
            return(profile);
        }
Exemplo n.º 3
0
 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>();
     var subPath = fileNamePlaceholders.SubstitutePlaceholders(settings.FilePath, 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 != null)
         {
             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 != null)
         {
             notify.ImagesSaved(images.Count, op.FirstFileSaved);
         }
         return op.Status.Success;
     }
 }
Exemplo n.º 4
0
        public ScanProfile Clone()
        {
            var profile = (ScanProfile)MemberwiseClone();

            if (profile.AutoSaveSettings != null)
            {
                profile.AutoSaveSettings = AutoSaveSettings.Clone();
            }
            if (profile.HistogramStretchConfig != null)
            {
                profile.HistogramStretchConfig = HistogramStretchConfig.Clone();
            }
            return(profile);
        }
Exemplo n.º 5
0
 public bool AutoSave(AutoSaveSettings settings, List<ScannedImage> images)
 {
     if (appConfigManager.Config.DisableAutoSave)
     {
         return false;
     }
     try
     {
         bool ok = true;
         DateTime now = DateTime.Now;
         if (settings.Separator == AutoSaveSeparator.FilePerScan)
         {
             if (!SaveOneFile(settings, now, 0, images))
             {
                 ok = false;
             }
         }
         else if (settings.Separator == AutoSaveSeparator.FilePerPage)
         {
             for (int i = 0; i < images.Count; i++)
             {
                 if (!SaveOneFile(settings, now, i, new List<ScannedImage> { images[i] }))
                 {
                     ok = false;
                 }
             }
         }
         else if (settings.Separator == AutoSaveSeparator.PatchT)
         {
             var imageSet = new List<ScannedImage>();
             int fileIndex = 0;
             foreach (ScannedImage img in images)
             {
                 if (img.PatchCode == PatchCode.PatchT)
                 {
                     if (imageSet.Count > 0)
                     {
                         if (!SaveOneFile(settings, now, fileIndex++, imageSet))
                         {
                             ok = false;
                         }
                         imageSet.Clear();
                     }
                 }
                 else
                 {
                     imageSet.Add(img);
                 }
             }
             if (!SaveOneFile(settings, now, fileIndex, imageSet))
             {
                 ok = false;
             }
         }
         return ok;
     }
     catch (Exception ex)
     {
         Log.ErrorException(MiscResources.AutoSaveError, ex);
         errorOutput.DisplayError(MiscResources.AutoSaveError);
         return false;
     }
 }
Exemplo n.º 6
0
 public bool AutoSave(AutoSaveSettings settings, List<ScannedImage> images)
 {
     // Not supported in NAPS2.Console
     return false;
 }