mirror of
https://github.com/cyanfish/naps2.git
synced 2024-11-13 06:27:11 +03:00
Parallelize test running
This commit is contained in:
parent
50184f9bd5
commit
93de083cf0
@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using NAPS2.Config;
|
||||
using NAPS2.Config.Experimental;
|
||||
using NAPS2.Images;
|
||||
using NAPS2.Images.Storage;
|
||||
@ -84,6 +85,15 @@ namespace NAPS2.Modules
|
||||
Bind<BitmapRenderer>().ToSelf();
|
||||
Bind<ImageContext>().To<GdiImageContext>().InSingletonScope();
|
||||
|
||||
var configProvider = Kernel.Get<ConfigScopes>().Provider;
|
||||
var profileManager = new ProfileManager(
|
||||
Path.Combine(Paths.AppData, "profiles.xml"),
|
||||
Path.Combine(Paths.Executable, "profiles.xml"),
|
||||
configProvider.Get(c => c.LockSystemProfiles),
|
||||
configProvider.Get(c => c.LockUnspecifiedDevices),
|
||||
configProvider.Get(c => c.NoUserProfiles));
|
||||
Bind<IProfileManager>().ToConstant(profileManager);
|
||||
|
||||
StaticConfiguration.Initialize(Kernel);
|
||||
}
|
||||
}
|
||||
|
@ -19,12 +19,6 @@ namespace NAPS2
|
||||
public static void Initialize(IKernel kernel)
|
||||
{
|
||||
var configProvider = kernel.Get<ConfigScopes>().Provider;
|
||||
ProfileManager.Current = new ProfileManager(
|
||||
Path.Combine(Paths.AppData, "profiles.xml"),
|
||||
Path.Combine(Paths.Executable, "profiles.xml"),
|
||||
configProvider.Get(c => c.LockSystemProfiles),
|
||||
configProvider.Get(c => c.LockUnspecifiedDevices),
|
||||
configProvider.Get(c => c.NoUserProfiles));
|
||||
|
||||
Log.Logger = new NLogLogger();
|
||||
if (PlatformCompat.System.CanUseWin32)
|
||||
|
@ -40,6 +40,7 @@ namespace NAPS2.Automation
|
||||
private readonly ConfigProvider<CommonConfig> configProvider;
|
||||
private readonly ConfigProvider<PdfSettings> pdfSettingsProvider;
|
||||
private readonly ConfigProvider<ImageSettings> imageSettingsProvider;
|
||||
private readonly IProfileManager profileManager;
|
||||
|
||||
private readonly AutomatedScanningOptions options;
|
||||
private List<List<ScannedImage>> scanList;
|
||||
@ -49,7 +50,7 @@ namespace NAPS2.Automation
|
||||
private List<string> actualOutputPaths;
|
||||
private OcrParams ocrParams;
|
||||
|
||||
public AutomatedScanning(AutomatedScanningOptions options, ImageContext imageContext, IScanPerformer scanPerformer, ErrorOutput errorOutput, IEmailProviderFactory emailProviderFactory, IScannedImageImporter scannedImageImporter, IOperationFactory operationFactory, OcrEngineManager ocrEngineManager, IFormFactory formFactory, ConfigScopes configScopes)
|
||||
public AutomatedScanning(AutomatedScanningOptions options, ImageContext imageContext, IScanPerformer scanPerformer, ErrorOutput errorOutput, IEmailProviderFactory emailProviderFactory, IScannedImageImporter scannedImageImporter, IOperationFactory operationFactory, OcrEngineManager ocrEngineManager, IFormFactory formFactory, ConfigScopes configScopes, IProfileManager profileManager)
|
||||
{
|
||||
this.options = options;
|
||||
this.imageContext = imageContext;
|
||||
@ -61,6 +62,7 @@ namespace NAPS2.Automation
|
||||
this.ocrEngineManager = ocrEngineManager;
|
||||
this.formFactory = formFactory;
|
||||
this.configScopes = configScopes;
|
||||
this.profileManager = profileManager;
|
||||
|
||||
userTransact = configScopes.User.BeginTransaction();
|
||||
configProvider = configScopes.Provider.Replace(configScopes.User, userTransact);
|
||||
@ -613,13 +615,13 @@ namespace NAPS2.Automation
|
||||
if (options.ProfileName == null)
|
||||
{
|
||||
// If no profile is specified, use the default (if there is one)
|
||||
profile = ProfileManager.Current.Profiles.Single(x => x.IsDefault);
|
||||
profile = profileManager.Profiles.Single(x => x.IsDefault);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Use the profile with the specified name (try case-sensitive first, then case-insensitive)
|
||||
profile = ProfileManager.Current.Profiles.FirstOrDefault(x => x.DisplayName == options.ProfileName) ??
|
||||
ProfileManager.Current.Profiles.First(x => x.DisplayName.ToLower() == options.ProfileName.ToLower());
|
||||
profile = profileManager.Profiles.FirstOrDefault(x => x.DisplayName == options.ProfileName) ??
|
||||
profileManager.Profiles.First(x => x.DisplayName.ToLower() == options.ProfileName.ToLower());
|
||||
}
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
|
@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using NAPS2.Config;
|
||||
using NAPS2.Images.Storage;
|
||||
|
||||
@ -18,14 +19,15 @@ namespace NAPS2.Sdk.Tests
|
||||
var tempPath = Path.Combine(FolderPath, "temp");
|
||||
Directory.CreateDirectory(tempPath);
|
||||
|
||||
ProfileManager.Current = new StubProfileManager();
|
||||
|
||||
ProfileManager = new StubProfileManager();
|
||||
ImageContext = new GdiImageContext
|
||||
{
|
||||
FileStorageManager = new FileStorageManager(tempPath)
|
||||
};
|
||||
}
|
||||
|
||||
public IProfileManager ProfileManager { get; }
|
||||
|
||||
public ImageContext ImageContext { get; }
|
||||
|
||||
public string FolderPath { get; }
|
||||
@ -49,7 +51,15 @@ namespace NAPS2.Sdk.Tests
|
||||
public virtual void Dispose()
|
||||
{
|
||||
rsm?.ForceReleaseLock();
|
||||
Directory.Delete(FolderPath, true);
|
||||
try
|
||||
{
|
||||
Directory.Delete(FolderPath, true);
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
Thread.Sleep(100);
|
||||
Directory.Delete(FolderPath, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,8 +23,6 @@ using Xunit;
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("8f59dabd-ee59-471d-b3ae-9c2083fdb13e")]
|
||||
|
||||
[assembly: CollectionBehavior(DisableTestParallelization = true)]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
|
@ -32,12 +32,12 @@ namespace NAPS2.Sdk.Tests.WinForms
|
||||
ProfileDisplayName = "test_name"
|
||||
}
|
||||
});
|
||||
ProfileManager.Current.Profiles.Add(new ScanProfile
|
||||
ProfileManager.Profiles.Add(new ScanProfile
|
||||
{
|
||||
DisplayName = "bad_name",
|
||||
IsDefault = true
|
||||
});
|
||||
ProfileManager.Current.Profiles.Add(new ScanProfile {
|
||||
ProfileManager.Profiles.Add(new ScanProfile {
|
||||
DisplayName = "test_name"
|
||||
});
|
||||
ctx.Form.Show();
|
||||
@ -66,7 +66,7 @@ namespace NAPS2.Sdk.Tests.WinForms
|
||||
DialogHelper = new Mock<DialogHelper>(),
|
||||
ConfigScopes = ConfigScopes.Stub()
|
||||
};
|
||||
ctx.Form = new FBatchScan(ctx.Performer.Object, ctx.ErrorOutput.Object, ctx.DialogHelper.Object)
|
||||
ctx.Form = new FBatchScan(ctx.Performer.Object, ctx.ErrorOutput.Object, ctx.DialogHelper.Object, ProfileManager)
|
||||
{
|
||||
ConfigScopes = ctx.ConfigScopes,
|
||||
ConfigProvider = ctx.ConfigScopes.Provider
|
||||
|
@ -9,14 +9,6 @@ namespace NAPS2.Config
|
||||
{
|
||||
public class ProfileManager : IProfileManager
|
||||
{
|
||||
private static IProfileManager _current = new StubProfileManager();
|
||||
|
||||
public static IProfileManager Current
|
||||
{
|
||||
get => _current;
|
||||
set => _current = value ?? throw new ArgumentNullException(nameof(value));
|
||||
}
|
||||
|
||||
private readonly ISerializer<List<ScanProfile>> serializer = new XmlSerializer<List<ScanProfile>>();
|
||||
private readonly string userPath;
|
||||
private readonly string systemPath;
|
||||
|
@ -29,8 +29,9 @@ namespace NAPS2.Scan.Batch
|
||||
private readonly OcrEngineManager ocrEngineManager;
|
||||
private readonly IFormFactory formFactory;
|
||||
private readonly ConfigProvider<CommonConfig> configProvider;
|
||||
private readonly ProfileManager profileManager;
|
||||
|
||||
public BatchScanPerformer(IScanPerformer scanPerformer, PdfExporter pdfExporter, IOperationFactory operationFactory, ConfigProvider<PdfSettings> pdfSettingsProvider, OcrEngineManager ocrEngineManager, IFormFactory formFactory, ConfigProvider<CommonConfig> configProvider)
|
||||
public BatchScanPerformer(IScanPerformer scanPerformer, PdfExporter pdfExporter, IOperationFactory operationFactory, ConfigProvider<PdfSettings> pdfSettingsProvider, OcrEngineManager ocrEngineManager, IFormFactory formFactory, ConfigProvider<CommonConfig> configProvider, ProfileManager profileManager)
|
||||
{
|
||||
this.scanPerformer = scanPerformer;
|
||||
this.pdfExporter = pdfExporter;
|
||||
@ -39,11 +40,12 @@ namespace NAPS2.Scan.Batch
|
||||
this.ocrEngineManager = ocrEngineManager;
|
||||
this.formFactory = formFactory;
|
||||
this.configProvider = configProvider;
|
||||
this.profileManager = profileManager;
|
||||
}
|
||||
|
||||
public async Task PerformBatchScan(ConfigProvider<BatchSettings> settings, FormBase batchForm, Action<ScannedImage> imageCallback, Action<string> progressCallback, CancellationToken cancelToken)
|
||||
{
|
||||
var state = new BatchState(scanPerformer, pdfExporter, operationFactory, pdfSettingsProvider, ocrEngineManager, formFactory, configProvider)
|
||||
var state = new BatchState(scanPerformer, pdfExporter, operationFactory, pdfSettingsProvider, ocrEngineManager, formFactory, configProvider, profileManager)
|
||||
{
|
||||
Settings = settings,
|
||||
ProgressCallback = progressCallback,
|
||||
@ -63,13 +65,14 @@ namespace NAPS2.Scan.Batch
|
||||
private readonly OcrEngineManager ocrEngineManager;
|
||||
private readonly IFormFactory formFactory;
|
||||
private readonly ConfigProvider<CommonConfig> configProvider;
|
||||
private readonly ProfileManager profileManager;
|
||||
|
||||
private ScanProfile profile;
|
||||
private ScanParams scanParams;
|
||||
private List<List<ScannedImage>> scans;
|
||||
|
||||
public BatchState(IScanPerformer scanPerformer, PdfExporter pdfExporter, IOperationFactory operationFactory,
|
||||
ConfigProvider<PdfSettings> pdfSettingsProvider, OcrEngineManager ocrEngineManager, IFormFactory formFactory, ConfigProvider<CommonConfig> configProvider)
|
||||
ConfigProvider<PdfSettings> pdfSettingsProvider, OcrEngineManager ocrEngineManager, IFormFactory formFactory, ConfigProvider<CommonConfig> configProvider, ProfileManager profileManager)
|
||||
{
|
||||
this.scanPerformer = scanPerformer;
|
||||
this.pdfExporter = pdfExporter;
|
||||
@ -78,6 +81,7 @@ namespace NAPS2.Scan.Batch
|
||||
this.ocrEngineManager = ocrEngineManager;
|
||||
this.formFactory = formFactory;
|
||||
this.configProvider = configProvider;
|
||||
this.profileManager = profileManager;
|
||||
}
|
||||
|
||||
public ConfigProvider<BatchSettings> Settings { get; set; }
|
||||
@ -92,7 +96,7 @@ namespace NAPS2.Scan.Batch
|
||||
|
||||
public async Task Do()
|
||||
{
|
||||
profile = ProfileManager.Current.Profiles.First(x => x.DisplayName == Settings.Get(c => c.ProfileDisplayName));
|
||||
profile = profileManager.Profiles.First(x => x.DisplayName == Settings.Get(c => c.ProfileDisplayName));
|
||||
scanParams = new ScanParams
|
||||
{
|
||||
DetectPatchCodes = Settings.Get(c => c.OutputType) == BatchOutputType.MultipleFiles && Settings.Get(c => c.SaveSeparator) == SaveSeparator.PatchT,
|
||||
|
@ -20,13 +20,15 @@ namespace NAPS2.Scan.Experimental
|
||||
private readonly ConfigProvider<CommonConfig> configProvider;
|
||||
private readonly OperationProgress operationProgress;
|
||||
private readonly AutoSaver autoSaver;
|
||||
private readonly ProfileManager profileManager;
|
||||
|
||||
public ScanPerformer(IFormFactory formFactory, ConfigProvider<CommonConfig> configProvider, OperationProgress operationProgress, AutoSaver autoSaver)
|
||||
public ScanPerformer(IFormFactory formFactory, ConfigProvider<CommonConfig> configProvider, OperationProgress operationProgress, AutoSaver autoSaver, ProfileManager profileManager)
|
||||
{
|
||||
this.formFactory = formFactory;
|
||||
this.configProvider = configProvider;
|
||||
this.operationProgress = operationProgress;
|
||||
this.autoSaver = autoSaver;
|
||||
this.profileManager = profileManager;
|
||||
}
|
||||
|
||||
public ScannedImageSource PerformScan(ScanProfile scanProfile, ScanParams scanParams, IntPtr dialogParent = default,
|
||||
@ -131,7 +133,7 @@ namespace NAPS2.Scan.Experimental
|
||||
if (configProvider.Get(c => c.AlwaysRememberDevice))
|
||||
{
|
||||
scanProfile.Device = options.Device;
|
||||
ProfileManager.Current.Save();
|
||||
profileManager.Save();
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -26,17 +26,19 @@ namespace NAPS2.WinForms
|
||||
private readonly IBatchScanPerformer batchScanPerformer;
|
||||
private readonly ErrorOutput errorOutput;
|
||||
private readonly DialogHelper dialogHelper;
|
||||
private readonly IProfileManager profileManager;
|
||||
private TransactionConfigScope<CommonConfig> userTransact;
|
||||
private ConfigProvider<CommonConfig> transactProvider;
|
||||
|
||||
private bool batchRunning;
|
||||
private CancellationTokenSource cts = new CancellationTokenSource();
|
||||
|
||||
public FBatchScan(IBatchScanPerformer batchScanPerformer, ErrorOutput errorOutput, DialogHelper dialogHelper)
|
||||
public FBatchScan(IBatchScanPerformer batchScanPerformer, ErrorOutput errorOutput, DialogHelper dialogHelper, IProfileManager profileManager)
|
||||
{
|
||||
this.batchScanPerformer = batchScanPerformer;
|
||||
this.errorOutput = errorOutput;
|
||||
this.dialogHelper = dialogHelper;
|
||||
this.profileManager = profileManager;
|
||||
InitializeComponent();
|
||||
|
||||
RestoreFormState = false;
|
||||
@ -55,7 +57,7 @@ namespace NAPS2.WinForms
|
||||
.RightToForm()
|
||||
.Activate();
|
||||
|
||||
btnAddProfile.Enabled = !(ConfigProvider.Get(c => c.NoUserProfiles) && ProfileManager.Current.Profiles.Any(x => x.IsLocked));
|
||||
btnAddProfile.Enabled = !(ConfigProvider.Get(c => c.NoUserProfiles) && profileManager.Profiles.Any(x => x.IsLocked));
|
||||
|
||||
ConditionalControls.LockHeight(this);
|
||||
|
||||
@ -143,15 +145,15 @@ namespace NAPS2.WinForms
|
||||
private void UpdateProfiles()
|
||||
{
|
||||
comboProfile.Items.Clear();
|
||||
comboProfile.Items.AddRange(ProfileManager.Current.Profiles.Cast<object>().ToArray());
|
||||
comboProfile.Items.AddRange(profileManager.Profiles.Cast<object>().ToArray());
|
||||
if (!string.IsNullOrEmpty(transactProvider.Get(c => c.BatchSettings.ProfileDisplayName)) &&
|
||||
ProfileManager.Current.Profiles.Any(x => x.DisplayName == transactProvider.Get(c => c.BatchSettings.ProfileDisplayName)))
|
||||
profileManager.Profiles.Any(x => x.DisplayName == transactProvider.Get(c => c.BatchSettings.ProfileDisplayName)))
|
||||
{
|
||||
comboProfile.Text = transactProvider.Get(c => c.BatchSettings.ProfileDisplayName);
|
||||
}
|
||||
else if (ProfileManager.Current.DefaultProfile != null)
|
||||
else if (profileManager.DefaultProfile != null)
|
||||
{
|
||||
comboProfile.Text = ProfileManager.Current.DefaultProfile.DisplayName;
|
||||
comboProfile.Text = profileManager.DefaultProfile.DisplayName;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -215,8 +217,8 @@ namespace NAPS2.WinForms
|
||||
fedit.ShowDialog();
|
||||
if (fedit.Result)
|
||||
{
|
||||
ProfileManager.Current.Profiles[comboProfile.SelectedIndex] = fedit.ScanProfile;
|
||||
ProfileManager.Current.Save();
|
||||
profileManager.Profiles[comboProfile.SelectedIndex] = fedit.ScanProfile;
|
||||
profileManager.Save();
|
||||
userTransact.Set(c => c.BatchSettings.ProfileDisplayName = fedit.ScanProfile.DisplayName);
|
||||
UpdateProfiles();
|
||||
}
|
||||
@ -225,15 +227,15 @@ namespace NAPS2.WinForms
|
||||
|
||||
private void btnAddProfile_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!(ConfigProvider.Get(c => c.NoUserProfiles) && ProfileManager.Current.Profiles.Any(x => x.IsLocked)))
|
||||
if (!(ConfigProvider.Get(c => c.NoUserProfiles) && profileManager.Profiles.Any(x => x.IsLocked)))
|
||||
{
|
||||
var fedit = FormFactory.Create<FEditProfile>();
|
||||
fedit.ScanProfile = ConfigProvider.Get(c => c.DefaultProfileSettings);
|
||||
fedit.ShowDialog();
|
||||
if (fedit.Result)
|
||||
{
|
||||
ProfileManager.Current.Profiles.Add(fedit.ScanProfile);
|
||||
ProfileManager.Current.Save();
|
||||
profileManager.Profiles.Add(fedit.ScanProfile);
|
||||
profileManager.Save();
|
||||
userTransact.Set(c => c.BatchSettings.ProfileDisplayName = fedit.ScanProfile.DisplayName);
|
||||
UpdateProfiles();
|
||||
}
|
||||
|
@ -61,6 +61,7 @@ namespace NAPS2.WinForms
|
||||
private readonly IWorkerServiceFactory workerServiceFactory;
|
||||
private readonly OperationProgress operationProgress;
|
||||
private readonly UpdateChecker updateChecker;
|
||||
private readonly IProfileManager profileManager;
|
||||
|
||||
#endregion
|
||||
|
||||
@ -76,7 +77,7 @@ namespace NAPS2.WinForms
|
||||
|
||||
#region Initialization and Culture
|
||||
|
||||
public FDesktop(ImageContext imageContext, StringWrapper stringWrapper, RecoveryManager recoveryManager, OcrEngineManager ocrEngineManager, IScanPerformer scanPerformer, IScannedImagePrinter scannedImagePrinter, ChangeTracker changeTracker, StillImage stillImage, IOperationFactory operationFactory, KeyboardShortcutManager ksm, ThumbnailRenderer thumbnailRenderer, WinFormsExportHelper exportHelper, ImageClipboard imageClipboard, ImageRenderer imageRenderer, NotificationManager notify, CultureInitializer cultureInitializer, IWorkerServiceFactory workerServiceFactory, OperationProgress operationProgress, UpdateChecker updateChecker)
|
||||
public FDesktop(ImageContext imageContext, StringWrapper stringWrapper, RecoveryManager recoveryManager, OcrEngineManager ocrEngineManager, IScanPerformer scanPerformer, IScannedImagePrinter scannedImagePrinter, ChangeTracker changeTracker, StillImage stillImage, IOperationFactory operationFactory, KeyboardShortcutManager ksm, ThumbnailRenderer thumbnailRenderer, WinFormsExportHelper exportHelper, ImageClipboard imageClipboard, ImageRenderer imageRenderer, NotificationManager notify, CultureInitializer cultureInitializer, IWorkerServiceFactory workerServiceFactory, OperationProgress operationProgress, UpdateChecker updateChecker, IProfileManager profileManager)
|
||||
{
|
||||
this.imageContext = imageContext;
|
||||
this.stringWrapper = stringWrapper;
|
||||
@ -97,6 +98,7 @@ namespace NAPS2.WinForms
|
||||
this.workerServiceFactory = workerServiceFactory;
|
||||
this.operationProgress = operationProgress;
|
||||
this.updateChecker = updateChecker;
|
||||
this.profileManager = profileManager;
|
||||
imageList = new ScannedImageList(imageContext);
|
||||
InitializeComponent();
|
||||
|
||||
@ -486,20 +488,20 @@ namespace NAPS2.WinForms
|
||||
{
|
||||
Activate();
|
||||
ScanProfile profile;
|
||||
if (ProfileManager.Current.DefaultProfile?.Device?.ID == deviceID)
|
||||
if (profileManager.DefaultProfile?.Device?.ID == deviceID)
|
||||
{
|
||||
// Try to use the default profile if it has the right device
|
||||
profile = ProfileManager.Current.DefaultProfile;
|
||||
profile = profileManager.DefaultProfile;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Otherwise just pick any old profile with the right device
|
||||
// Not sure if this is the best way to do it, but it's hard to prioritize profiles
|
||||
profile = ProfileManager.Current.Profiles.FirstOrDefault(x => x.Device != null && x.Device.ID == deviceID);
|
||||
profile = profileManager.Profiles.FirstOrDefault(x => x.Device != null && x.Device.ID == deviceID);
|
||||
}
|
||||
if (profile == null)
|
||||
{
|
||||
if (ConfigProvider.Get(c => c.NoUserProfiles) && ProfileManager.Current.Profiles.Any(x => x.IsLocked))
|
||||
if (ConfigProvider.Get(c => c.NoUserProfiles) && profileManager.Profiles.Any(x => x.IsLocked))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -525,9 +527,9 @@ namespace NAPS2.WinForms
|
||||
return;
|
||||
}
|
||||
profile = editSettingsForm.ScanProfile;
|
||||
ProfileManager.Current.Profiles.Add(profile);
|
||||
ProfileManager.Current.DefaultProfile = profile;
|
||||
ProfileManager.Current.Save();
|
||||
profileManager.Profiles.Add(profile);
|
||||
profileManager.DefaultProfile = profile;
|
||||
profileManager.Save();
|
||||
|
||||
UpdateScanButton();
|
||||
}
|
||||
@ -542,13 +544,13 @@ namespace NAPS2.WinForms
|
||||
|
||||
private async Task ScanDefault()
|
||||
{
|
||||
if (ProfileManager.Current.DefaultProfile != null)
|
||||
if (profileManager.DefaultProfile != null)
|
||||
{
|
||||
var source = scanPerformer.PerformScan(ProfileManager.Current.DefaultProfile, DefaultScanParams(), Handle);
|
||||
var source = scanPerformer.PerformScan(profileManager.DefaultProfile, DefaultScanParams(), Handle);
|
||||
await source.ForEach(ReceiveScannedImage());
|
||||
Activate();
|
||||
}
|
||||
else if (ProfileManager.Current.Profiles.Count == 0)
|
||||
else if (profileManager.Profiles.Count == 0)
|
||||
{
|
||||
await ScanWithNewProfile();
|
||||
}
|
||||
@ -567,9 +569,9 @@ namespace NAPS2.WinForms
|
||||
{
|
||||
return;
|
||||
}
|
||||
ProfileManager.Current.Profiles.Add(editSettingsForm.ScanProfile);
|
||||
ProfileManager.Current.DefaultProfile = editSettingsForm.ScanProfile;
|
||||
ProfileManager.Current.Save();
|
||||
profileManager.Profiles.Add(editSettingsForm.ScanProfile);
|
||||
profileManager.DefaultProfile = editSettingsForm.ScanProfile;
|
||||
profileManager.Save();
|
||||
|
||||
UpdateScanButton();
|
||||
|
||||
@ -734,7 +736,7 @@ namespace NAPS2.WinForms
|
||||
// Other
|
||||
btnZoomIn.Enabled = imageList.Images.Any() && ConfigProvider.Get(c => c.ThumbnailSize) < ThumbnailRenderer.MAX_SIZE;
|
||||
btnZoomOut.Enabled = imageList.Images.Any() && ConfigProvider.Get(c => c.ThumbnailSize) > ThumbnailRenderer.MIN_SIZE;
|
||||
tsNewProfile.Enabled = !(ConfigProvider.Get(c => c.NoUserProfiles) && ProfileManager.Current.Profiles.Any(x => x.IsLocked));
|
||||
tsNewProfile.Enabled = !(ConfigProvider.Get(c => c.NoUserProfiles) && profileManager.Profiles.Any(x => x.IsLocked));
|
||||
|
||||
if (PlatformCompat.Runtime.RefreshListViewAfterChange)
|
||||
{
|
||||
@ -754,9 +756,9 @@ namespace NAPS2.WinForms
|
||||
}
|
||||
|
||||
// Populate the dropdown
|
||||
var defaultProfile = ProfileManager.Current.DefaultProfile;
|
||||
var defaultProfile = profileManager.DefaultProfile;
|
||||
int i = 1;
|
||||
foreach (var profile in ProfileManager.Current.Profiles)
|
||||
foreach (var profile in profileManager.Profiles)
|
||||
{
|
||||
var item = new ToolStripMenuItem
|
||||
{
|
||||
@ -767,8 +769,8 @@ namespace NAPS2.WinForms
|
||||
AssignProfileShortcut(i, item);
|
||||
item.Click += async (sender, args) =>
|
||||
{
|
||||
ProfileManager.Current.DefaultProfile = profile;
|
||||
ProfileManager.Current.Save();
|
||||
profileManager.DefaultProfile = profile;
|
||||
profileManager.Save();
|
||||
|
||||
UpdateScanButton();
|
||||
|
||||
@ -781,7 +783,7 @@ namespace NAPS2.WinForms
|
||||
i++;
|
||||
}
|
||||
|
||||
if (ProfileManager.Current.Profiles.Any())
|
||||
if (profileManager.Profiles.Any())
|
||||
{
|
||||
tsScan.DropDownItems.Insert(tsScan.DropDownItems.Count - staticButtonCount, new ToolStripSeparator());
|
||||
}
|
||||
|
@ -24,12 +24,14 @@ namespace NAPS2.WinForms
|
||||
private readonly IconButtonSizer iconButtonSizer;
|
||||
private readonly IScanPerformer scanPerformer;
|
||||
private readonly ProfileNameTracker profileNameTracker;
|
||||
private readonly ProfileManager profileManager;
|
||||
|
||||
public FProfiles(IconButtonSizer iconButtonSizer, IScanPerformer scanPerformer, ProfileNameTracker profileNameTracker)
|
||||
public FProfiles(IconButtonSizer iconButtonSizer, IScanPerformer scanPerformer, ProfileNameTracker profileNameTracker, ProfileManager profileManager)
|
||||
{
|
||||
this.iconButtonSizer = iconButtonSizer;
|
||||
this.scanPerformer = scanPerformer;
|
||||
this.profileNameTracker = profileNameTracker;
|
||||
this.profileManager = profileManager;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
@ -41,7 +43,7 @@ namespace NAPS2.WinForms
|
||||
{
|
||||
if (lvProfiles.SelectedIndices.Count == 1)
|
||||
{
|
||||
return ProfileManager.Current.Profiles[lvProfiles.SelectedIndices[0]];
|
||||
return profileManager.Profiles[lvProfiles.SelectedIndices[0]];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -51,11 +53,11 @@ namespace NAPS2.WinForms
|
||||
{
|
||||
get
|
||||
{
|
||||
return ProfileManager.Current.Profiles.ElementsAt(lvProfiles.SelectedIndices.OfType<int>()).Any(x => x.IsLocked);
|
||||
return profileManager.Profiles.ElementsAt(lvProfiles.SelectedIndices.OfType<int>()).Any(x => x.IsLocked);
|
||||
}
|
||||
}
|
||||
|
||||
private bool NoUserProfiles => ConfigProvider.Get(c => c.NoUserProfiles) && ProfileManager.Current.Profiles.Any(x => x.IsLocked);
|
||||
private bool NoUserProfiles => ConfigProvider.Get(c => c.NoUserProfiles) && profileManager.Profiles.Any(x => x.IsLocked);
|
||||
|
||||
protected override void OnLoad(object sender, EventArgs e)
|
||||
{
|
||||
@ -103,7 +105,7 @@ namespace NAPS2.WinForms
|
||||
private void UpdateProfiles()
|
||||
{
|
||||
lvProfiles.Items.Clear();
|
||||
foreach (var profile in ProfileManager.Current.Profiles)
|
||||
foreach (var profile in profileManager.Profiles)
|
||||
{
|
||||
lvProfiles.Items.Add(profile.DisplayName,
|
||||
profile.IsDefault
|
||||
@ -115,7 +117,7 @@ namespace NAPS2.WinForms
|
||||
private void SelectProfile(Func<ScanProfile, bool> pred)
|
||||
{
|
||||
int i = 0;
|
||||
foreach (var profile in ProfileManager.Current.Profiles)
|
||||
foreach (var profile in profileManager.Profiles)
|
||||
{
|
||||
if (pred(profile))
|
||||
{
|
||||
@ -123,7 +125,7 @@ namespace NAPS2.WinForms
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (ProfileManager.Current.Profiles.Count == 1)
|
||||
if (profileManager.Profiles.Count == 1)
|
||||
{
|
||||
lvProfiles.Items[0].Selected = true;
|
||||
}
|
||||
@ -146,12 +148,12 @@ namespace NAPS2.WinForms
|
||||
{
|
||||
int profileIndex = lvProfiles.SelectedItems[0].Index;
|
||||
var fedit = FormFactory.Create<FEditProfile>();
|
||||
fedit.ScanProfile = ProfileManager.Current.Profiles[profileIndex];
|
||||
fedit.ScanProfile = profileManager.Profiles[profileIndex];
|
||||
fedit.ShowDialog();
|
||||
if (fedit.Result)
|
||||
{
|
||||
ProfileManager.Current.Profiles[profileIndex] = fedit.ScanProfile;
|
||||
ProfileManager.Current.Save();
|
||||
profileManager.Profiles[profileIndex] = fedit.ScanProfile;
|
||||
profileManager.Save();
|
||||
UpdateProfiles();
|
||||
SelectProfile(x => x == fedit.ScanProfile);
|
||||
lvProfiles.SelectedIndices.Add(profileIndex);
|
||||
@ -159,7 +161,7 @@ namespace NAPS2.WinForms
|
||||
else
|
||||
{
|
||||
// Rollback
|
||||
ProfileManager.Current.Load();
|
||||
profileManager.Load();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -175,20 +177,20 @@ namespace NAPS2.WinForms
|
||||
if (lvProfiles.SelectedItems.Count > 0 && !SelectionLocked)
|
||||
{
|
||||
string message = lvProfiles.SelectedIndices.Count == 1
|
||||
? string.Format(MiscResources.ConfirmDeleteSingleProfile, ProfileManager.Current.Profiles[lvProfiles.SelectedIndices[0]].DisplayName)
|
||||
? string.Format(MiscResources.ConfirmDeleteSingleProfile, profileManager.Profiles[lvProfiles.SelectedIndices[0]].DisplayName)
|
||||
: string.Format(MiscResources.ConfirmDeleteMultipleProfiles, lvProfiles.SelectedIndices.Count);
|
||||
if (MessageBox.Show(message, MiscResources.Delete, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
|
||||
{
|
||||
foreach (var profile in ProfileManager.Current.Profiles.ElementsAt(lvProfiles.SelectedIndices.OfType<int>()))
|
||||
foreach (var profile in profileManager.Profiles.ElementsAt(lvProfiles.SelectedIndices.OfType<int>()))
|
||||
{
|
||||
profileNameTracker.DeletingProfile(profile.DisplayName);
|
||||
}
|
||||
ProfileManager.Current.Profiles.RemoveAll(lvProfiles.SelectedIndices.OfType<int>());
|
||||
if (ProfileManager.Current.Profiles.Count == 1)
|
||||
profileManager.Profiles.RemoveAll(lvProfiles.SelectedIndices.OfType<int>());
|
||||
if (profileManager.Profiles.Count == 1)
|
||||
{
|
||||
ProfileManager.Current.DefaultProfile = ProfileManager.Current.Profiles.First();
|
||||
profileManager.DefaultProfile = profileManager.Profiles.First();
|
||||
}
|
||||
ProfileManager.Current.Save();
|
||||
profileManager.Save();
|
||||
UpdateProfiles();
|
||||
lvProfiles_SelectedIndexChanged(null, null);
|
||||
}
|
||||
@ -231,7 +233,7 @@ namespace NAPS2.WinForms
|
||||
|
||||
private async void PerformScan()
|
||||
{
|
||||
if (ProfileManager.Current.Profiles.Count == 0)
|
||||
if (profileManager.Profiles.Count == 0)
|
||||
{
|
||||
var editSettingsForm = FormFactory.Create<FEditProfile>();
|
||||
editSettingsForm.ScanProfile = new ScanProfile
|
||||
@ -243,9 +245,9 @@ namespace NAPS2.WinForms
|
||||
{
|
||||
return;
|
||||
}
|
||||
ProfileManager.Current.Profiles.Add(editSettingsForm.ScanProfile);
|
||||
ProfileManager.Current.DefaultProfile = editSettingsForm.ScanProfile;
|
||||
ProfileManager.Current.Save();
|
||||
profileManager.Profiles.Add(editSettingsForm.ScanProfile);
|
||||
profileManager.DefaultProfile = editSettingsForm.ScanProfile;
|
||||
profileManager.Save();
|
||||
UpdateProfiles();
|
||||
lvProfiles.SelectedIndices.Add(0);
|
||||
}
|
||||
@ -255,14 +257,14 @@ namespace NAPS2.WinForms
|
||||
MessageBoxIcon.Warning);
|
||||
return;
|
||||
}
|
||||
if (ProfileManager.Current.DefaultProfile == null)
|
||||
if (profileManager.DefaultProfile == null)
|
||||
{
|
||||
var profile = SelectedProfile;
|
||||
ProfileManager.Current.DefaultProfile = profile;
|
||||
profileManager.DefaultProfile = profile;
|
||||
UpdateProfiles();
|
||||
SelectProfile(x => x == profile);
|
||||
}
|
||||
ProfileManager.Current.Save();
|
||||
profileManager.Save();
|
||||
var source = scanPerformer.PerformScan(SelectedProfile, DefaultScanParams(), Handle);
|
||||
await source.ForEach(ImageCallback);
|
||||
Activate();
|
||||
@ -323,8 +325,8 @@ namespace NAPS2.WinForms
|
||||
{
|
||||
if (SelectedProfile != null)
|
||||
{
|
||||
ProfileManager.Current.DefaultProfile = SelectedProfile;
|
||||
ProfileManager.Current.Save();
|
||||
profileManager.DefaultProfile = SelectedProfile;
|
||||
profileManager.Save();
|
||||
|
||||
UpdateProfiles();
|
||||
SelectProfile(x => x.IsDefault);
|
||||
@ -333,21 +335,21 @@ namespace NAPS2.WinForms
|
||||
|
||||
private void AddProfile(ScanProfile profile)
|
||||
{
|
||||
ProfileManager.Current.Profiles.Add(profile);
|
||||
if (ProfileManager.Current.Profiles.Count == 1)
|
||||
profileManager.Profiles.Add(profile);
|
||||
if (profileManager.Profiles.Count == 1)
|
||||
{
|
||||
ProfileManager.Current.DefaultProfile = profile;
|
||||
profileManager.DefaultProfile = profile;
|
||||
}
|
||||
UpdateProfiles();
|
||||
SelectProfile(x => x == profile);
|
||||
ProfileManager.Current.Save();
|
||||
profileManager.Save();
|
||||
}
|
||||
|
||||
private IDataObject GetSelectedProfileDataObject()
|
||||
{
|
||||
IDataObject ido = new DataObject();
|
||||
int profileIndex = lvProfiles.SelectedItems[0].Index;
|
||||
var profile = ProfileManager.Current.Profiles[profileIndex];
|
||||
var profile = profileManager.Profiles[profileIndex];
|
||||
ido.SetData(typeof(DirectProfileTransfer), new DirectProfileTransfer(profile));
|
||||
return ido;
|
||||
}
|
||||
@ -448,24 +450,24 @@ namespace NAPS2.WinForms
|
||||
if (index != -1)
|
||||
{
|
||||
var selectedIndex = lvProfiles.SelectedItems[0].Index;
|
||||
var selectedProfile = ProfileManager.Current.Profiles[selectedIndex];
|
||||
var selectedProfile = profileManager.Profiles[selectedIndex];
|
||||
if (selectedProfile.IsLocked)
|
||||
{
|
||||
return;
|
||||
}
|
||||
while (index < ProfileManager.Current.Profiles.Count && ProfileManager.Current.Profiles[index].IsLocked)
|
||||
while (index < profileManager.Profiles.Count && profileManager.Profiles[index].IsLocked)
|
||||
{
|
||||
index++;
|
||||
}
|
||||
ProfileManager.Current.Profiles.RemoveAt(selectedIndex);
|
||||
profileManager.Profiles.RemoveAt(selectedIndex);
|
||||
if (index > selectedIndex)
|
||||
{
|
||||
index--;
|
||||
}
|
||||
ProfileManager.Current.Profiles.Insert(index, selectedProfile);
|
||||
profileManager.Profiles.Insert(index, selectedProfile);
|
||||
UpdateProfiles();
|
||||
SelectProfile(x => x == selectedProfile);
|
||||
ProfileManager.Current.Save();
|
||||
profileManager.Save();
|
||||
}
|
||||
}
|
||||
|
||||
@ -474,7 +476,7 @@ namespace NAPS2.WinForms
|
||||
if (e.Effect == DragDropEffects.Move)
|
||||
{
|
||||
var index = GetDragIndex(e);
|
||||
if (index == ProfileManager.Current.Profiles.Count)
|
||||
if (index == profileManager.Profiles.Count)
|
||||
{
|
||||
lvProfiles.InsertionMark.Index = index - 1;
|
||||
lvProfiles.InsertionMark.AppearsAfterItem = true;
|
||||
|
Loading…
Reference in New Issue
Block a user