Reworked FChooseProfile. Decoupled some stuf.

This commit is contained in:
ben-cyanfish 2013-03-03 16:28:26 -05:00
parent db64481042
commit d4a672d406
26 changed files with 351 additions and 97 deletions

View File

@ -6,9 +6,6 @@ EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NAPS2.Tests", "NAPS2.Tests\NAPS2.Tests.csproj", "{11FC4BE1-882D-4ABA-8781-2F3F77DF9453}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{F6CC4F6D-EE76-43D9-977B-8802C9665CC4}"
ProjectSection(SolutionItems) = preProject
.nuget\packages.config = .nuget\packages.config
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution

Binary file not shown.

View File

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NAPS2
{
public static class CollectionExtensions
{
public static void RemoveAll<T>(this IList<T> list, IEnumerable<int> indices)
{
int offset = 0;
foreach (int i in indices.OrderBy(x => x))
{
list.RemoveAt(i - offset++);
}
}
public static IEnumerable<T> ElementsAt<T>(this IList<T> list, IEnumerable<int> indices)
{
foreach (int i in indices)
{
yield return list[i];
}
}
}
}

View File

@ -50,40 +50,78 @@ namespace NAPS2
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FChooseProfile));
this.lvProfiles = new System.Windows.Forms.ListView();
this.ilProfileIcons = new NAPS2.ILProfileIcons(this.components);
this.btnScan = new System.Windows.Forms.Button();
this.btnProfiles = new System.Windows.Forms.Button();
this.btnDone = new System.Windows.Forms.Button();
this.ilProfileIcons = new NAPS2.ILProfileIcons(this.components);
this.SuspendLayout();
//
// lvProfiles
//
this.lvProfiles.HideSelection = false;
this.lvProfiles.Location = new System.Drawing.Point(12, 12);
this.lvProfiles.MultiSelect = false;
this.lvProfiles.Name = "lvProfiles";
this.lvProfiles.Size = new System.Drawing.Size(653, 94);
this.lvProfiles.Size = new System.Drawing.Size(563, 80);
this.lvProfiles.TabIndex = 0;
this.lvProfiles.UseCompatibleStateImageBehavior = false;
this.lvProfiles.ItemActivate += new System.EventHandler(this.lvProfiles_ItemActivate);
//
// btnScan
//
this.btnScan.BackColor = System.Drawing.SystemColors.Control;
this.btnScan.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
this.btnScan.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btnScan.Image = global::NAPS2.Icons.scanner_72;
this.btnScan.ImageAlign = System.Drawing.ContentAlignment.TopCenter;
this.btnScan.Location = new System.Drawing.Point(581, 12);
this.btnScan.Name = "btnScan";
this.btnScan.Padding = new System.Windows.Forms.Padding(0, 2, 0, 6);
this.btnScan.Size = new System.Drawing.Size(117, 118);
this.btnScan.TabIndex = 4;
this.btnScan.Text = "&Scan";
this.btnScan.TextAlign = System.Drawing.ContentAlignment.BottomCenter;
this.btnScan.UseVisualStyleBackColor = false;
this.btnScan.Click += new System.EventHandler(this.btnScan_Click);
//
// btnProfiles
//
this.btnProfiles.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
this.btnProfiles.Image = global::NAPS2.Icons.blueprints_small;
this.btnProfiles.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.btnProfiles.Location = new System.Drawing.Point(12, 112);
this.btnProfiles.Location = new System.Drawing.Point(12, 98);
this.btnProfiles.Name = "btnProfiles";
this.btnProfiles.Padding = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.btnProfiles.Size = new System.Drawing.Size(121, 32);
this.btnProfiles.TabIndex = 2;
this.btnProfiles.Size = new System.Drawing.Size(128, 32);
this.btnProfiles.TabIndex = 5;
this.btnProfiles.Text = "Manage &Profiles";
this.btnProfiles.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
this.btnProfiles.UseVisualStyleBackColor = true;
this.btnProfiles.Click += new System.EventHandler(this.btnProfiles_Click);
//
// btnDone
//
this.btnDone.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
this.btnDone.Image = global::NAPS2.Icons.tick_small;
this.btnDone.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.btnDone.Location = new System.Drawing.Point(481, 98);
this.btnDone.Name = "btnDone";
this.btnDone.Padding = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.btnDone.Size = new System.Drawing.Size(94, 32);
this.btnDone.TabIndex = 6;
this.btnDone.Text = "&Done";
this.btnDone.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
this.btnDone.UseVisualStyleBackColor = true;
this.btnDone.Click += new System.EventHandler(this.btnDone_Click);
//
// FChooseProfile
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(677, 156);
this.ClientSize = new System.Drawing.Size(714, 142);
this.Controls.Add(this.btnDone);
this.Controls.Add(this.btnProfiles);
this.Controls.Add(this.btnScan);
this.Controls.Add(this.lvProfiles);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
@ -101,6 +139,8 @@ namespace NAPS2
private System.Windows.Forms.ListView lvProfiles;
private ILProfileIcons ilProfileIcons;
private System.Windows.Forms.Button btnScan;
private System.Windows.Forms.Button btnProfiles;
private System.Windows.Forms.Button btnDone;
}
}

View File

@ -25,30 +25,49 @@ using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Ninject;
namespace NAPS2
{
public partial class FChooseProfile : Form
{
private List<ScanSettings> settings;
private readonly IProfileManager profileManager;
private readonly IScanPerformer scanPerformer;
private readonly IScanReceiver scanReceiver;
private ScanSettings profile;
public ScanSettings Profile
private ScanSettings SelectedProfile
{
get { return profile; }
get
{
if (lvProfiles.SelectedIndices.Count == 1)
{
return profileManager.Profiles[lvProfiles.SelectedIndices[0]];
}
else
{
return null;
}
}
}
public FChooseProfile()
public FChooseProfile(IProfileManager profileManager, IScanPerformer scanPerformer, IScanReceiver scanReceiver)
{
this.profileManager = profileManager;
this.scanPerformer = scanPerformer;
this.scanReceiver = scanReceiver;
InitializeComponent();
}
private void FChooseProfile_Load(object sender, EventArgs e)
{
lvProfiles.LargeImageList = ilProfileIcons.IconsList;
settings = ProfileManager.LoadProfiles();
foreach (ScanSettings profile in settings)
UpdateProfiles();
}
private void UpdateProfiles()
{
lvProfiles.Items.Clear();
foreach (var profile in profileManager.Profiles)
{
lvProfiles.Items.Add(profile.DisplayName, profile.IconID);
}
@ -56,11 +75,49 @@ namespace NAPS2
private void lvProfiles_ItemActivate(object sender, EventArgs e)
{
if (lvProfiles.SelectedIndices.Count > 0)
if (SelectedProfile != null)
{
profile = settings[lvProfiles.SelectedIndices[0]];
this.Close();
PerformScan();
}
}
private void btnDone_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnScan_Click(object sender, EventArgs e)
{
PerformScan();
}
private void PerformScan()
{
if (profileManager.Profiles.Count == 0)
{
var editSettingsForm = KernelManager.Kernel.Get<FEditScanSettings>();
editSettingsForm.ScanSettings = new ExtendedScanSettings();
editSettingsForm.ShowDialog();
if (editSettingsForm.Result)
{
profileManager.Profiles.Add(editSettingsForm.ScanSettings);
profileManager.Save();
UpdateProfiles();
lvProfiles.SelectedIndices.Add(0);
}
}
if (SelectedProfile == null)
{
MessageBox.Show("Select a profile before clicking Scan.", "Choose Profile", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
scanPerformer.PerformScan(SelectedProfile, this, scanReceiver);
}
private void btnProfiles_Click(object sender, EventArgs e)
{
KernelManager.Kernel.Get<FManageProfiles>().ShowDialog();
UpdateProfiles();
}
}
}

View File

@ -38,10 +38,11 @@ using Ninject;
using WIA;
using System.Drawing.Imaging;
using Ninject.Parameters;
namespace NAPS2
{
public partial class FDesktop : Form
public partial class FDesktop : Form, IScanReceiver
{
private ScannedImageList imageList;
private readonly IEmailer emailer;
@ -80,22 +81,10 @@ namespace NAPS2
SelectedIndices = selection;
}
private void Scan(ScanSettings Profile)
public void ReceiveScan(IEnumerable<IScannedImage> scannedImages)
{
IScanDriver driver = Dependencies.Kernel.Get<IScanDriver>(Profile.Device.DriverName);
driver.DialogParent = this;
driver.ScanSettings = Profile;
try
{
var newImages = driver.Scan();
imageList.Images.AddRange(newImages);
UpdateThumbnails();
}
catch (ScanDriverException e)
{
MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
imageList.Images.AddRange(scannedImages);
UpdateThumbnails();
}
private void Delete()
@ -137,7 +126,7 @@ namespace NAPS2
private void exportPDF(string filename)
{
FPDFSave pdfdialog = Dependencies.Kernel.Get<FPDFSave>();
FPDFSave pdfdialog = KernelManager.Kernel.Get<FPDFSave>();
pdfdialog.Filename = filename;
pdfdialog.Images = imageList.Images;
pdfdialog.ShowDialog(this);
@ -176,16 +165,8 @@ namespace NAPS2
private void tsScan_Click(object sender, EventArgs e)
{
//demoScan();
//return;
FChooseProfile prof = new FChooseProfile();
FChooseProfile prof = KernelManager.Kernel.Get<FChooseProfile>(new ConstructorArgument("scanReceiver", this));
prof.ShowDialog();
if (prof.Profile == null)
return;
Scan(prof.Profile);
}
private void tsSavePDF_Click(object sender, EventArgs e)
@ -331,7 +312,7 @@ namespace NAPS2
private void tsProfiles_Click(object sender, EventArgs e)
{
new FManageProfiles().ShowDialog();
KernelManager.Kernel.Get<FManageProfiles>().ShowDialog();
}
private void tsAbout_Click(object sender, EventArgs e)

View File

@ -104,7 +104,7 @@ namespace NAPS2
private void choose(string driverName)
{
IScanDriver driver = Dependencies.Kernel.Get<IScanDriver>(driverName);
IScanDriver driver = KernelManager.Kernel.Get<IScanDriver>(driverName);
try
{
driver.DialogParent = this;

View File

@ -74,7 +74,6 @@ namespace NAPS2
listViewItem5,
listViewItem6});
this.lvProfiles.Location = new System.Drawing.Point(12, 12);
this.lvProfiles.MultiSelect = false;
this.lvProfiles.Name = "lvProfiles";
this.lvProfiles.Size = new System.Drawing.Size(563, 80);
this.lvProfiles.TabIndex = 0;

View File

@ -23,6 +23,7 @@ using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Ninject;
@ -31,10 +32,11 @@ namespace NAPS2
{
public partial class FManageProfiles : Form
{
private List<ScanSettings> profiles;
private readonly IProfileManager profileManager;
public FManageProfiles()
public FManageProfiles(IProfileManager profileManager)
{
this.profileManager = profileManager;
InitializeComponent();
}
@ -46,7 +48,7 @@ namespace NAPS2
private void loadList()
{
lvProfiles.Items.Clear();
foreach (ScanSettings profile in profiles)
foreach (var profile in profileManager.Profiles)
{
lvProfiles.Items.Add(profile.DisplayName, profile.IconID);
}
@ -55,14 +57,14 @@ namespace NAPS2
private void btnAdd_Click(object sender, EventArgs e)
{
FEditScanSettings fedit = Dependencies.Kernel.Get<FEditScanSettings>();
FEditScanSettings fedit = KernelManager.Kernel.Get<FEditScanSettings>();
fedit.ScanSettings = new ExtendedScanSettings();
fedit.ShowDialog();
if (fedit.Result)
{
this.profiles.Add(fedit.ScanSettings);
profileManager.Profiles.Add(fedit.ScanSettings);
loadList();
ProfileManager.SaveProfiles(profiles);
profileManager.Save();
}
}
@ -71,21 +73,27 @@ namespace NAPS2
if (lvProfiles.SelectedItems.Count > 0)
{
int profileIndex = lvProfiles.SelectedItems[0].Index;
FEditScanSettings fedit = Dependencies.Kernel.Get<FEditScanSettings>();
fedit.ScanSettings = profiles[profileIndex];
FEditScanSettings fedit = KernelManager.Kernel.Get<FEditScanSettings>();
fedit.ScanSettings = profileManager.Profiles[profileIndex];
fedit.ShowDialog();
if (fedit.Result)
{
profileManager.Profiles[profileIndex] = fedit.ScanSettings;
profileManager.Save();
loadList();
lvProfiles.SelectedIndices.Add(profileIndex);
ProfileManager.SaveProfiles(profiles);
}
else
{
// Rollback
profileManager.Load();
}
}
}
private void lvProfiles_SelectedIndexChanged(object sender, EventArgs e)
{
btnEdit.Enabled = lvProfiles.SelectedItems.Count > 0;
btnEdit.Enabled = lvProfiles.SelectedItems.Count == 1;
btnDelete.Enabled = lvProfiles.SelectedItems.Count > 0;
}
@ -94,7 +102,6 @@ namespace NAPS2
lvProfiles.LargeImageList = ilProfileIcons.IconsList;
btnEdit.Enabled = false;
btnDelete.Enabled = false;
this.profiles = ProfileManager.LoadProfiles();
loadList();
}
@ -102,11 +109,20 @@ namespace NAPS2
{
if (lvProfiles.SelectedItems.Count > 0)
{
if (MessageBox.Show("Do you really want to delete " + profiles[lvProfiles.SelectedItems[0].Index].DisplayName + "?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
string label;
if (lvProfiles.SelectedIndices.Count == 1)
{
profiles.RemoveAt(lvProfiles.SelectedItems[0].Index);
label = "the profile \"" + profileManager.Profiles[lvProfiles.SelectedIndices[0]].DisplayName + "\"";
}
else
{
label = lvProfiles.SelectedIndices.Count + " profiles";
}
if (MessageBox.Show("Are you sure want to delete " + label + "?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
{
profileManager.Profiles.RemoveAll(lvProfiles.SelectedIndices.OfType<int>());
profileManager.Save();
loadList();
ProfileManager.SaveProfiles(profiles);
lvProfiles_SelectedIndexChanged(null, null);
}
}

15
NAPS2/IProfileManager.cs Normal file
View File

@ -0,0 +1,15 @@
using NAPS2.Scan;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NAPS2
{
public interface IProfileManager
{
void Load();
List<ScanSettings> Profiles { get; }
void Save();
}
}

14
NAPS2/IScanPerformer.cs Normal file
View File

@ -0,0 +1,14 @@
using NAPS2.Scan;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace NAPS2
{
public interface IScanPerformer
{
void PerformScan(ScanSettings scanSettings, IWin32Window dialogParent, IScanReceiver scanReceiver);
}
}

13
NAPS2/IScanReceiver.cs Normal file
View File

@ -0,0 +1,13 @@
using NAPS2.Scan;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NAPS2
{
public interface IScanReceiver
{
void ReceiveScan(IEnumerable<IScannedImage> scannedImages);
}
}

View File

@ -310,6 +310,36 @@ namespace NAPS2 {
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap scanner_48 {
get {
object obj = ResourceManager.GetObject("scanner_48", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap scanner_64 {
get {
object obj = ResourceManager.GetObject("scanner_64", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap scanner_72 {
get {
object obj = ResourceManager.GetObject("scanner_72", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
/// </summary>

View File

@ -217,4 +217,13 @@
<data name="blueprints_small" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\blueprints-small.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="scanner_48" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\scanner-48.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="scanner_64" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\scanner-64.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="scanner_72" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\scanner-72.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

View File

@ -34,11 +34,11 @@ using NAPS2.Scan.Stub;
namespace NAPS2
{
class Dependencies
static class KernelManager
{
public static IKernel Kernel { get; private set; }
static Dependencies()
static KernelManager()
{
Kernel = new StandardKernel(new DependenciesModule());
}
@ -47,6 +47,8 @@ namespace NAPS2
{
public override void Load()
{
Bind<IScanPerformer>().To<ScanPerformer>();
Bind<IProfileManager>().To<ProfileManager>().InSingletonScope();
Bind<IPdfExporter>().To<PdfSharpExporter>();
Bind<IEmailer>().To<MAPIEmailer>();
#if DEBUG

View File

@ -86,13 +86,18 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="CollectionExtensions.cs" />
<Compile Include="ImageHelper.cs" />
<Compile Include="Icons.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Icons.resx</DependentUpon>
</Compile>
<Compile Include="IProfileManager.cs" />
<Compile Include="IScanPerformer.cs" />
<Compile Include="IScanReceiver.cs" />
<Compile Include="ScannedImageList.cs" />
<Compile Include="ScanPerformer.cs" />
<Compile Include="Scan\Stub\StubScanDriver.cs" />
<Compile Include="Scan\Twain\DibUtils.cs" />
<Compile Include="Scan\Twain\TwainApi.cs" />
@ -110,7 +115,7 @@
<Compile Include="Scan\Exceptions\DeviceOfflineException.cs" />
<Compile Include="Scan\Exceptions\DeviceNotFoundException.cs" />
<Compile Include="Scan\Wia\WiaApi.cs" />
<Compile Include="Dependencies.cs" />
<Compile Include="KernelManager.cs" />
<Compile Include="Pdf\IPdfExporter.cs" />
<Compile Include="Pdf\PdfInfo.cs" />
<Compile Include="Pdf\PdfSharpExporter.cs" />
@ -290,14 +295,17 @@
<None Include="Resources\accept.png" />
<None Include="Resources\pencil.png" />
<None Include="Resources\blueprints-small.png" />
<None Include="Resources\scanner-48.png" />
<None Include="Resources\scanner-72.png" />
<None Include="Resources\scanner-64.png" />
<Content Include="Resources\scanner-app.ico" />
<Content Include="Resources\scanner-large.png" />
<Content Include="Resources\scanner.ico" />
<Content Include="Resources\scanner.png" />
<None Include="Resources\tick.png" />
<None Include="Resources\tick-small.png" />
<Content Include="Setup\lib\Interop.WIA.dll" />
<Content Include="Setup\lib\PdfSharp.dll" />
<None Include="Setup\lib\Interop.WIA.dll" />
<None Include="Setup\lib\PdfSharp.dll" />
<None Include="Resources\information.png" />
<None Include="Resources\arrow_rotate_anticlockwise.png" />
<None Include="Resources\arrow_rotate_clockwise.png" />
@ -318,7 +326,7 @@
<None Include="Resources\zoom_actual.png" />
<Content Include="Setup\license.txt" />
<Content Include="Setup\setup.iss" />
<Content Include="Setup\lib\wiaaut.dll" />
<None Include="Setup\lib\wiaaut.dll" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">

View File

@ -27,7 +27,7 @@ using NAPS2.Scan;
namespace NAPS2
{
public class ProfileManager
public class ProfileManager : IProfileManager
{
private static readonly string ProfilesFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "NAPS2");
private static readonly string ProfilesFileName = "profiles.xml";
@ -35,9 +35,27 @@ namespace NAPS2
private static readonly string OldProfilesPath = Path.Combine(Application.StartupPath, "profiles.xml");
public static List<ScanSettings> LoadProfiles()
private List<ScanSettings> profiles;
public ProfileManager()
{
List<ScanSettings> profiles;
}
public List<ScanSettings> Profiles
{
get
{
if (profiles == null)
{
Load();
}
return profiles;
}
}
public void Load()
{
profiles = null;
TryLoadProfiles(ProfilesPath, out profiles);
if (profiles == null)
{
@ -45,22 +63,35 @@ namespace NAPS2
TryLoadProfiles(OldProfilesPath, out profiles);
if (profiles != null)
{
SaveProfiles(profiles);
Save();
try
{
File.Delete(OldProfilesPath);
}
catch (Exception) { }
catch (IOException) { }
}
}
if (profiles == null)
{
profiles = new List<ScanSettings>();
Save();
}
return profiles;
}
private static bool TryLoadProfiles(string profilesPath, out List<ScanSettings> profiles)
public void Save()
{
if (!Directory.Exists(ProfilesFolder))
{
Directory.CreateDirectory(ProfilesFolder);
}
using (Stream strFile = File.Open(ProfilesPath, FileMode.Create))
{
XmlSerializer serializer = new XmlSerializer(typeof(List<ScanSettings>));
serializer.Serialize(strFile, profiles);
}
}
private bool TryLoadProfiles(string profilesPath, out List<ScanSettings> profiles)
{
profiles = null;
if (File.Exists(profilesPath))
@ -78,18 +109,5 @@ namespace NAPS2
}
return false;
}
public static void SaveProfiles(List<ScanSettings> profiles)
{
if (!Directory.Exists(ProfilesFolder))
{
Directory.CreateDirectory(ProfilesFolder);
}
using (Stream strFile = File.Open(ProfilesPath, FileMode.Create))
{
XmlSerializer serializer = new XmlSerializer(typeof(List<ScanSettings>));
serializer.Serialize(strFile, profiles);
}
}
}
}

View File

@ -37,7 +37,7 @@ namespace NAPS2
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(Dependencies.Kernel.Get<FDesktop>());
Application.Run(KernelManager.Kernel.Get<FDesktop>());
}
}
}

View File

@ -50,4 +50,4 @@ using System.Runtime.InteropServices;
// Revision
//
[assembly: AssemblyVersion("0.10.*")]
[assembly: AssemblyFileVersion("0.10.*")]
[assembly: AssemblyFileVersion("1.0.0.0")]

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

View File

@ -52,7 +52,7 @@ namespace NAPS2.Scan.Stub
g.DrawString(new Random().Next().ToString(), new Font("Times New Roman", 80), Brushes.Black, 0, 350);
return new List<IScannedImage>
{
new ScannedImage(bitmap, ScanBitDepth.C24BIT, ImageFormat.Jpeg)
new ScannedImage(bitmap, ScanBitDepth.C24BIT, ScanSettings.MaxQuality ? ImageFormat.Png : ImageFormat.Jpeg)
};
}

View File

@ -45,7 +45,7 @@ namespace NAPS2.Scan.Twain
tw.Select();
return tw.GetCurrentName();
}
catch (ScanDriverException e)
catch (ScanDriverException)
{
throw;
}

29
NAPS2/ScanPerformer.cs Normal file
View File

@ -0,0 +1,29 @@
using NAPS2.Scan;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Ninject;
namespace NAPS2
{
public class ScanPerformer : IScanPerformer
{
public void PerformScan(ScanSettings scanSettings, IWin32Window dialogParent, IScanReceiver scanReceiver)
{
IScanDriver driver = KernelManager.Kernel.Get<IScanDriver>(scanSettings.Device.DriverName);
driver.DialogParent = dialogParent;
driver.ScanSettings = scanSettings;
try
{
scanReceiver.ReceiveScan(driver.Scan());
}
catch (ScanDriverException e)
{
MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

View File

@ -91,12 +91,11 @@ namespace NAPS2
public void Delete(IEnumerable<int> selection)
{
int offset = 0;
foreach (int i in selection.OrderBy(x => x))
foreach (var img in Images.ElementsAt(selection))
{
Images[i - offset].Dispose();
Images.RemoveAt(i - offset++);
img.Dispose();
}
Images.RemoveAll(selection);
}
}