Remove UnownedFileStorage type and move the logic to the call site

This commit is contained in:
Ben Olden-Cooligan 2019-07-14 23:08:43 -04:00
parent 5a8176bb46
commit 53f5ed9a04
5 changed files with 4 additions and 49 deletions

View File

@ -215,7 +215,6 @@ namespace NAPS2.Images.Storage
RegisterTransformers<GdiImage>(new GdiTransformers());
ImageType = typeof(GdiImage);
// TODO: Not sure where to do these
RegisterConverters(new OwnershipConverters(this));
RegisterConverters(new PdfConverters(this));
}
}

View File

@ -1,22 +0,0 @@
using System.IO;
namespace NAPS2.Images.Storage
{
public class OwnershipConverters
{
private readonly ImageContext imageContext;
public OwnershipConverters(ImageContext imageContext)
{
this.imageContext = imageContext;
}
[StorageConverter]
public FileStorage ConvertToFile(UnownedFileStorage input, StorageConvertParams convertParams)
{
string newPath = imageContext.FileStorageManager.NextFilePath();
File.Copy(input.FilePath, newPath);
return new FileStorage(newPath);
}
}
}

View File

@ -1,22 +0,0 @@
using System;
namespace NAPS2.Images.Storage
{
/// <summary>
/// Represents an image received across the wire where we must copy the backing
/// file before it can be used.
/// </summary>
public class UnownedFileStorage : IStorage
{
public UnownedFileStorage(string filePath)
{
FilePath = filePath ?? throw new ArgumentNullException(nameof(filePath));
}
public string FilePath { get; }
public void Dispose()
{
}
}
}

View File

@ -188,9 +188,7 @@
<Compile Include="Images\MemoryStreamRenderer.cs" />
<Compile Include="Images\ScannedImageSink.cs" />
<Compile Include="Images\Storage\LockMode.cs" />
<Compile Include="Images\Storage\OwnershipConverters.cs" />
<Compile Include="Images\Storage\PdfConverters.cs" />
<Compile Include="Images\Storage\UnownedFileStorage.cs" />
<Compile Include="Images\Storage\PdfStorage.cs" />
<Compile Include="ImportExport\DirectImportParams.cs" />
<Compile Include="ImportExport\Email\Mapi\IMapiWrapper.cs" />

View File

@ -68,8 +68,10 @@ namespace NAPS2.Serialization
}
else
{
// TODO: With this logic centralized, maybe we can remove UnownedFileStorage and just move the file copy logic here?
storage = new UnownedFileStorage(serializedImage.FilePath);
// Not transfering or sharing the file, so we need to make a copy
string newPath = imageContext.FileStorageManager.NextFilePath();
File.Copy(serializedImage.FilePath, newPath);
storage = new FileStorage(newPath);
}
}
else