2016-01-08 05:21:47 +03:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using NAPS2.Lang.Resources;
|
2018-09-29 03:33:53 +03:00
|
|
|
|
using NAPS2.Logging;
|
2016-01-08 05:21:47 +03:00
|
|
|
|
using NAPS2.Operation;
|
|
|
|
|
using NAPS2.Scan.Images;
|
|
|
|
|
using NAPS2.Util;
|
|
|
|
|
|
|
|
|
|
namespace NAPS2.ImportExport
|
|
|
|
|
{
|
2016-01-08 06:00:22 +03:00
|
|
|
|
public class DirectImportOperation : OperationBase
|
2016-01-08 05:21:47 +03:00
|
|
|
|
{
|
2016-02-09 09:54:36 +03:00
|
|
|
|
private readonly ThumbnailRenderer thumbnailRenderer;
|
2016-01-08 05:21:47 +03:00
|
|
|
|
|
2018-08-26 19:05:22 +03:00
|
|
|
|
public DirectImportOperation(ThumbnailRenderer thumbnailRenderer)
|
2016-01-08 05:21:47 +03:00
|
|
|
|
{
|
2016-02-09 09:54:36 +03:00
|
|
|
|
this.thumbnailRenderer = thumbnailRenderer;
|
2016-01-08 05:21:47 +03:00
|
|
|
|
|
|
|
|
|
AllowCancel = true;
|
2018-09-08 23:06:05 +03:00
|
|
|
|
AllowBackground = true;
|
2016-01-08 05:21:47 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-11 05:37:59 +03:00
|
|
|
|
public bool Start(DirectImageTransfer data, bool copy, Action<ScannedImage> imageCallback)
|
2016-01-08 05:21:47 +03:00
|
|
|
|
{
|
2016-01-08 07:09:02 +03:00
|
|
|
|
ProgressTitle = copy ? MiscResources.CopyProgress : MiscResources.ImportProgress;
|
2016-01-08 05:21:47 +03:00
|
|
|
|
Status = new OperationStatus
|
|
|
|
|
{
|
2016-01-08 07:09:02 +03:00
|
|
|
|
StatusText = copy ? MiscResources.Copying : MiscResources.Importing,
|
2016-01-08 06:00:22 +03:00
|
|
|
|
MaxProgress = data.ImageRecovery.Length
|
2016-01-08 05:21:47 +03:00
|
|
|
|
};
|
|
|
|
|
|
2018-09-05 23:26:04 +03:00
|
|
|
|
RunAsync(async () =>
|
2016-01-08 05:21:47 +03:00
|
|
|
|
{
|
2016-01-08 07:09:02 +03:00
|
|
|
|
Exception error = null;
|
|
|
|
|
foreach (var ir in data.ImageRecovery)
|
2016-01-08 05:21:47 +03:00
|
|
|
|
{
|
2016-01-08 07:09:02 +03:00
|
|
|
|
try
|
2016-01-08 05:21:47 +03:00
|
|
|
|
{
|
2016-02-09 09:54:36 +03:00
|
|
|
|
ScannedImage img;
|
2016-01-08 06:00:22 +03:00
|
|
|
|
using (var bitmap = new Bitmap(Path.Combine(data.RecoveryFolder, ir.FileName)))
|
2016-01-08 05:21:47 +03:00
|
|
|
|
{
|
2016-02-09 09:54:36 +03:00
|
|
|
|
img = new ScannedImage(bitmap, ir.BitDepth, ir.HighQuality, -1);
|
|
|
|
|
}
|
|
|
|
|
foreach (var transform in ir.TransformList)
|
|
|
|
|
{
|
|
|
|
|
img.AddTransform(transform);
|
|
|
|
|
}
|
2018-09-06 21:58:12 +03:00
|
|
|
|
// TODO: Don't bother, here, in recovery, etc.
|
2018-09-05 23:26:04 +03:00
|
|
|
|
img.SetThumbnail(await thumbnailRenderer.RenderThumbnail(img));
|
2016-02-09 09:54:36 +03:00
|
|
|
|
imageCallback(img);
|
2016-01-08 05:21:47 +03:00
|
|
|
|
|
2016-02-09 09:54:36 +03:00
|
|
|
|
Status.CurrentProgress++;
|
|
|
|
|
InvokeStatusChanged();
|
2018-08-26 19:05:22 +03:00
|
|
|
|
if (CancelToken.IsCancellationRequested)
|
2016-02-09 09:54:36 +03:00
|
|
|
|
{
|
|
|
|
|
break;
|
2016-01-08 05:21:47 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-01-08 07:09:02 +03:00
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
error = ex;
|
|
|
|
|
}
|
2016-01-08 05:21:47 +03:00
|
|
|
|
}
|
2016-01-08 07:09:02 +03:00
|
|
|
|
if (error != null)
|
2016-01-08 05:21:47 +03:00
|
|
|
|
{
|
2016-01-08 07:09:02 +03:00
|
|
|
|
Log.ErrorException(string.Format(MiscResources.ImportErrorCouldNot, data.RecoveryFolder), error);
|
2016-01-08 05:21:47 +03:00
|
|
|
|
}
|
2018-08-26 19:05:22 +03:00
|
|
|
|
return true;
|
2016-01-08 05:21:47 +03:00
|
|
|
|
});
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|