mirror of
https://github.com/cyanfish/naps2.git
synced 2024-09-11 15:26:55 +03:00
Add UiImageList to the RecoveryStorageManager constructor and other minor fixes
This commit is contained in:
parent
4298c0d3aa
commit
dafc26c6b3
@ -9,8 +9,7 @@ public class RecoveryModule : NinjectModule
|
||||
public override void Load()
|
||||
{
|
||||
string recoveryFolderPath = Path.Combine(Paths.Recovery, Path.GetRandomFileName());
|
||||
var recoveryStorageManager = RecoveryStorageManager.CreateFolder(recoveryFolderPath);
|
||||
recoveryStorageManager.RegisterForChanges(Kernel.Get<UiImageList>());
|
||||
var recoveryStorageManager = RecoveryStorageManager.CreateFolder(recoveryFolderPath, Kernel.Get<UiImageList>());
|
||||
var fileStorageManager = new FileStorageManager(recoveryFolderPath);
|
||||
Kernel.Bind<RecoveryStorageManager>().ToConstant(recoveryStorageManager);
|
||||
Kernel.Bind<FileStorageManager>().ToConstant(fileStorageManager);
|
||||
|
@ -36,8 +36,8 @@ public class DesktopControllerTests : ContextualTexts
|
||||
{
|
||||
ScanningContext.RecoveryPath = Path.Combine(FolderPath, "recovery");
|
||||
ScanningContext.FileStorageManager = new FileStorageManager(ScanningContext.RecoveryPath);
|
||||
_recoveryStorageManager = RecoveryStorageManager.CreateFolder(ScanningContext.RecoveryPath);
|
||||
_imageList = new UiImageList();
|
||||
_recoveryStorageManager = RecoveryStorageManager.CreateFolder(ScanningContext.RecoveryPath, _imageList);
|
||||
_thumbnailRenderQueue = new ThumbnailRenderQueue(ScanningContext, new ThumbnailRenderer(ImageContext));
|
||||
_operationProgress = new Mock<OperationProgress>();
|
||||
_config = Naps2Config.Stub();
|
||||
|
@ -7,13 +7,15 @@ namespace NAPS2.Sdk.Tests.Images;
|
||||
public class RecoveryStorageManagerTests : ContextualTexts
|
||||
{
|
||||
private readonly string _recoveryFolder;
|
||||
private readonly UiImageList _imageList; // TODO: Add tests for this
|
||||
private readonly RecoveryStorageManager _recoveryStorageManager;
|
||||
|
||||
public RecoveryStorageManagerTests()
|
||||
{
|
||||
_recoveryFolder = Path.Combine(FolderPath, "recovery");
|
||||
ScanningContext.FileStorageManager = new FileStorageManager(_recoveryFolder);
|
||||
_recoveryStorageManager = RecoveryStorageManager.CreateFolder(_recoveryFolder);
|
||||
_imageList = new UiImageList();
|
||||
_recoveryStorageManager = RecoveryStorageManager.CreateFolder(_recoveryFolder, _imageList);
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
|
@ -168,7 +168,8 @@ public class RecoveryManagerTests : ContextualTexts
|
||||
|
||||
private List<UiImage> CreateFolderToRecoverFrom(string folderPath, int imageCount)
|
||||
{
|
||||
var rsm1 = RecoveryStorageManager.CreateFolder(folderPath);
|
||||
var imageList = new UiImageList();
|
||||
var rsm1 = RecoveryStorageManager.CreateFolder(folderPath, imageList);
|
||||
var recoveryContext = new ScanningContext(new GdiImageContext(), new FileStorageManager(folderPath));
|
||||
var images = Enumerable.Range(0, imageCount).Select(x => new UiImage(CreateRecoveryImage(recoveryContext)))
|
||||
.ToList();
|
||||
|
@ -33,12 +33,12 @@ public class RecoveryStorageManager : IDisposable
|
||||
|
||||
private bool _disposed;
|
||||
|
||||
public static RecoveryStorageManager CreateFolder(string recoveryFolderPath)
|
||||
public static RecoveryStorageManager CreateFolder(string recoveryFolderPath, UiImageList imageList)
|
||||
{
|
||||
return new RecoveryStorageManager(recoveryFolderPath);
|
||||
return new RecoveryStorageManager(recoveryFolderPath, imageList);
|
||||
}
|
||||
|
||||
private RecoveryStorageManager(string recoveryFolderPath)
|
||||
private RecoveryStorageManager(string recoveryFolderPath, UiImageList imageList)
|
||||
{
|
||||
RecoveryFolderPath = recoveryFolderPath;
|
||||
_folder = new DirectoryInfo(RecoveryFolderPath);
|
||||
@ -46,23 +46,13 @@ public class RecoveryStorageManager : IDisposable
|
||||
_folderLockFile = new FileInfo(Path.Combine(RecoveryFolderPath, LOCK_FILE_NAME));
|
||||
_folderLock = _folderLockFile.Open(FileMode.CreateNew, FileAccess.Write, FileShare.None);
|
||||
_writeThrottle = new TimedThrottle(WriteIndexFromImageList, WriteThrottleInterval);
|
||||
_imageList = imageList;
|
||||
imageList.ImagesUpdated += ImageListUpdated;
|
||||
imageList.ImagesThumbnailInvalidated += ImageListUpdated;
|
||||
}
|
||||
|
||||
public string RecoveryFolderPath { get; }
|
||||
|
||||
// TODO: Maybe just make UiImageList part of the constructor?
|
||||
public void RegisterForChanges(UiImageList imageList)
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
if (_disposed) throw new ObjectDisposedException(nameof(RecoveryStorageManager));
|
||||
if (_imageList != null) throw new InvalidOperationException();
|
||||
_imageList = imageList;
|
||||
imageList.ImagesUpdated += ImageListUpdated;
|
||||
imageList.ImagesThumbnailInvalidated += ImageListUpdated;
|
||||
}
|
||||
}
|
||||
|
||||
private void ImageListUpdated(object? sender, EventArgs args)
|
||||
{
|
||||
_writeThrottle.RunAction(null);
|
||||
@ -114,11 +104,8 @@ public class RecoveryStorageManager : IDisposable
|
||||
_folderLock.Close();
|
||||
_folderLockFile.Delete();
|
||||
_folder.Delete(true);
|
||||
if (_imageList != null)
|
||||
{
|
||||
_imageList.ImagesUpdated -= ImageListUpdated;
|
||||
_imageList.ImagesThumbnailInvalidated -= ImageListUpdated;
|
||||
}
|
||||
_imageList.ImagesUpdated -= ImageListUpdated;
|
||||
_imageList.ImagesThumbnailInvalidated -= ImageListUpdated;
|
||||
_disposed = true;
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ public class UndoStack : IDisposable
|
||||
_maxLength = maxLength;
|
||||
_stack = new LinkedList<Memento>();
|
||||
_stack.AddFirst(Memento.Empty);
|
||||
_current = _stack.First;
|
||||
_current = _stack.First!;
|
||||
}
|
||||
|
||||
public Memento Current => _current.Value;
|
||||
@ -26,7 +26,7 @@ public class UndoStack : IDisposable
|
||||
|
||||
public bool Push(Memento memento)
|
||||
{
|
||||
if (_stack.First.Value == memento)
|
||||
if (_stack.First!.Value == memento)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -41,7 +41,7 @@ public class UndoStack : IDisposable
|
||||
{
|
||||
while (_stack.Count > _maxLength && _stack.Last != _current)
|
||||
{
|
||||
_stack.Last.Value.Dispose();
|
||||
_stack.Last!.Value.Dispose();
|
||||
_stack.RemoveLast();
|
||||
}
|
||||
}
|
||||
@ -50,7 +50,7 @@ public class UndoStack : IDisposable
|
||||
{
|
||||
while (_stack.First != _current)
|
||||
{
|
||||
_stack.First.Value.Dispose();
|
||||
_stack.First!.Value.Dispose();
|
||||
_stack.RemoveFirst();
|
||||
}
|
||||
}
|
||||
@ -59,7 +59,7 @@ public class UndoStack : IDisposable
|
||||
{
|
||||
while (_stack.Last != _current)
|
||||
{
|
||||
_stack.Last.Value.Dispose();
|
||||
_stack.Last!.Value.Dispose();
|
||||
_stack.RemoveLast();
|
||||
}
|
||||
}
|
||||
|
@ -115,6 +115,7 @@ public static class CollectionExtensions
|
||||
/// <param name="key"></param>
|
||||
/// <param name="value"></param>
|
||||
public static void AddMulti<TKey, TValue>(this Dictionary<TKey, HashSet<TValue>> dict, TKey key, TValue value)
|
||||
where TKey : notnull
|
||||
{
|
||||
if (!dict.ContainsKey(key))
|
||||
{
|
||||
@ -171,6 +172,7 @@ public static class CollectionExtensions
|
||||
/// <param name="defaultValue"></param>
|
||||
/// <returns></returns>
|
||||
public static TValue Get<TKey, TValue>(this Dictionary<TKey, TValue> dict, TKey key, TValue defaultValue)
|
||||
where TKey : notnull
|
||||
{
|
||||
if (dict.ContainsKey(key))
|
||||
{
|
||||
@ -189,6 +191,7 @@ public static class CollectionExtensions
|
||||
/// <param name="defaultValue"></param>
|
||||
/// <returns></returns>
|
||||
public static TValue Get<TKey, TValue>(this Dictionary<TKey, TValue> dict, TKey key, Func<TValue> defaultValue)
|
||||
where TKey : notnull
|
||||
{
|
||||
if (dict.ContainsKey(key))
|
||||
{
|
||||
@ -207,6 +210,7 @@ public static class CollectionExtensions
|
||||
/// <param name="defaultValue"></param>
|
||||
/// <returns></returns>
|
||||
public static TValue GetOrSet<TKey, TValue>(this Dictionary<TKey, TValue> dict, TKey key, TValue defaultValue)
|
||||
where TKey : notnull
|
||||
{
|
||||
if (!dict.ContainsKey(key))
|
||||
{
|
||||
@ -225,6 +229,7 @@ public static class CollectionExtensions
|
||||
/// <param name="defaultValue"></param>
|
||||
/// <returns></returns>
|
||||
public static TValue GetOrSet<TKey, TValue>(this Dictionary<TKey, TValue> dict, TKey key, Func<TValue> defaultValue)
|
||||
where TKey : notnull
|
||||
{
|
||||
if (!dict.ContainsKey(key))
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user