From 6f49adb06de038b01036490aed632334454b2196 Mon Sep 17 00:00:00 2001 From: soukoku Date: Wed, 18 Feb 2015 21:52:17 -0500 Subject: [PATCH] Some CA changes. --- NTwain/CapWrapper.cs | 12 +- NTwain/CapabilityReader.cs | 194 ++++++++++---------- NTwain/Data/ValueExtensions.cs | 2 +- NTwain/DataSource.Caps.cs | 6 +- NTwain/DataSource.cs | 2 +- NTwain/GlobalSuppressions.cs | Bin 0 -> 5556 bytes NTwain/ICapWrapper.cs | 10 +- NTwain/ImageTools.cs | 1 - NTwain/NTwain.csproj | 1 + NTwain/State.cs | 4 + Tests/Tester.WPF/ViewModels/DataSourceVM.cs | 2 +- Tests/Tester.WPF/ViewModels/TwainVM.cs | 2 +- Tests/Tester.Winform/TestForm.cs | 16 +- 13 files changed, 127 insertions(+), 125 deletions(-) create mode 100644 NTwain/GlobalSuppressions.cs diff --git a/NTwain/CapWrapper.cs b/NTwain/CapWrapper.cs index 98f5907..11496a1 100644 --- a/NTwain/CapWrapper.cs +++ b/NTwain/CapWrapper.cs @@ -192,7 +192,7 @@ namespace NTwain public bool IsSupported { get { return SupportedActions > QuerySupports.None; } } /// - /// Gets a value indicating whether is supported. + /// Gets a value indicating whether is supported. /// /// /// true if this capability can get values; otherwise, false. @@ -248,7 +248,7 @@ namespace NTwain public bool CanReset { get { return Supports(QuerySupports.Reset); } } /// - /// Gets a value indicating whether is supported. + /// Gets a value indicating whether is supported. /// /// /// true if this capability can set; otherwise, false. @@ -297,7 +297,7 @@ namespace NTwain /// Gets all the possible values of this capability. /// /// - public IList Get() + public IList GetValues() { return _source.CapGet(Capability).Select(o => _getConvertRoutine(o)).ToList(); } @@ -393,7 +393,7 @@ namespace NTwain /// The value. /// /// Simple Set() is not defined for this capability. - public ReturnCode Set(TValue value) + public ReturnCode SetValue(TValue value) { ReturnCode rc = ReturnCode.Failure; @@ -420,7 +420,7 @@ namespace NTwain /// /// The value. /// - public ReturnCode Set(TWArray value) + public ReturnCode SetValue(TWArray value) { ReturnCode rc = ReturnCode.Failure; using (var cap = new TWCapability(Capability, value)) @@ -435,7 +435,7 @@ namespace NTwain /// /// The value. /// - public ReturnCode Set(TWEnumeration value) + public ReturnCode SetValue(TWEnumeration value) { ReturnCode rc = ReturnCode.Failure; using (var cap = new TWCapability(Capability, value)) diff --git a/NTwain/CapabilityReader.cs b/NTwain/CapabilityReader.cs index 7fa6275..2a63f93 100644 --- a/NTwain/CapabilityReader.cs +++ b/NTwain/CapabilityReader.cs @@ -207,109 +207,107 @@ namespace NTwain } break; case ContainerType.Range: - // horrible cast but should work. - // in the for loop we also compare against min in case the step - // is parsed as negative number and causes infinite loop. - switch (ItemType) - { - case Data.ItemType.Fix32: - { - var min = (TWFix32)RangeMinValue; - var counter = min; - var max = (TWFix32)RangeMaxValue; - var step = (TWFix32)RangeStepSize; - - for (var i = min; i >= min && i <= max; i += step) - { - toPopulate.Add(i); - } - } - break; - case Data.ItemType.UInt32: - { - var min = (uint)RangeMinValue; - var counter = min; - var max = (uint)RangeMaxValue; - var step = (uint)RangeStepSize; - - for (var i = min; i >= min && i <= max; i += step) - { - toPopulate.Add(i); - } - } - break; - case Data.ItemType.Int32: - { - var min = (int)RangeMinValue; - var counter = min; - var max = (int)RangeMaxValue; - var step = (int)RangeStepSize; - - for (var i = min; i >= min && i <= max; i += step) - { - toPopulate.Add(i); - } - } - break; - // these should never happen since TW_ENUM fields are 4 bytes but you never know - case Data.ItemType.UInt16: - { - var min = (ushort)RangeMinValue; - var counter = min; - var max = (ushort)RangeMaxValue; - var step = (ushort)RangeStepSize; - - for (var i = min; i >= min && i <= max; i += step) - { - toPopulate.Add(i); - } - } - break; - case Data.ItemType.Int16: - { - var min = (short)RangeMinValue; - var counter = min; - var max = (short)RangeMaxValue; - var step = (short)RangeStepSize; - - for (var i = min; i >= min && i <= max; i += step) - { - toPopulate.Add(i); - } - } - break; - case Data.ItemType.UInt8: - { - var min = (byte)RangeMinValue; - var counter = min; - var max = (byte)RangeMaxValue; - var step = (byte)RangeStepSize; - - for (var i = min; i >= min && i <= max; i += step) - { - toPopulate.Add(i); - } - } - break; - case Data.ItemType.Int8: - { - var min = (sbyte)RangeMinValue; - var counter = min; - var max = (sbyte)RangeMaxValue; - var step = (sbyte)RangeStepSize; - - for (var i = min; i >= min && i <= max; i += step) - { - toPopulate.Add(i); - } - } - break; - } + PopulateRange(toPopulate); break; } return toPopulate; } + private void PopulateRange(IList toPopulate) + { + // horrible cast but should work. + // in the for loop we also compare against min in case the step + // is parsed as negative number and causes infinite loop. + switch (ItemType) + { + case Data.ItemType.Fix32: + { + var min = (TWFix32)RangeMinValue; + var max = (TWFix32)RangeMaxValue; + var step = (TWFix32)RangeStepSize; + + for (var i = min; i >= min && i <= max; i += step) + { + toPopulate.Add(i); + } + } + break; + case Data.ItemType.UInt32: + { + var min = (uint)RangeMinValue; + var max = (uint)RangeMaxValue; + var step = (uint)RangeStepSize; + + for (var i = min; i >= min && i <= max; i += step) + { + toPopulate.Add(i); + } + } + break; + case Data.ItemType.Int32: + { + var min = (int)RangeMinValue; + var max = (int)RangeMaxValue; + var step = (int)RangeStepSize; + + for (var i = min; i >= min && i <= max; i += step) + { + toPopulate.Add(i); + } + } + break; + // these should never happen since TW_ENUM fields are 4 bytes but you never know + case Data.ItemType.UInt16: + { + var min = (ushort)RangeMinValue; + var max = (ushort)RangeMaxValue; + var step = (ushort)RangeStepSize; + + for (var i = min; i >= min && i <= max; i += step) + { + toPopulate.Add(i); + } + } + break; + case Data.ItemType.Int16: + { + var min = (short)RangeMinValue; + var max = (short)RangeMaxValue; + var step = (short)RangeStepSize; + + for (var i = min; i >= min && i <= max; i += step) + { + toPopulate.Add(i); + } + } + break; + case Data.ItemType.UInt8: + { + var min = (byte)RangeMinValue; + var max = (byte)RangeMaxValue; + var step = (byte)RangeStepSize; + + for (var i = min; i >= min && i <= max; i += step) + { + toPopulate.Add(i); + } + } + break; + case Data.ItemType.Int8: + { + var min = (sbyte)RangeMinValue; + var max = (sbyte)RangeMaxValue; + var step = (sbyte)RangeStepSize; + + for (var i = min; i >= min && i <= max; i += step) + { + toPopulate.Add(i); + } + } + break; + } + } + CapabilityReader ReadOneValue(IntPtr baseAddr) { diff --git a/NTwain/Data/ValueExtensions.cs b/NTwain/Data/ValueExtensions.cs index 18cfdcc..8814efd 100644 --- a/NTwain/Data/ValueExtensions.cs +++ b/NTwain/Data/ValueExtensions.cs @@ -79,7 +79,7 @@ namespace NTwain.Data // new method: // try to convert to enum's underlying type first then cast to the enum - return (TEnum)Convert.ChangeType(value, rawType); + return (TEnum)Convert.ChangeType(value, rawType, CultureInfo.InvariantCulture); } else if (typeof(IConvertible).IsAssignableFrom(returnType)) { diff --git a/NTwain/DataSource.Caps.cs b/NTwain/DataSource.Caps.cs index fe6d8c3..dc44858 100644 --- a/NTwain/DataSource.Caps.cs +++ b/NTwain/DataSource.Caps.cs @@ -1576,7 +1576,7 @@ namespace NTwain }; // this needs to also set undefined size optino - rc = ICapUndefinedImageSize.Set(value); + rc = ICapUndefinedImageSize.SetValue(value); using (TWCapability capValue = new TWCapability(CapabilityId.ICapAutomaticBorderDetection, one)) { rc = _session.DGControl.Capability.Set(capValue); @@ -2002,11 +2002,11 @@ namespace NTwain // for one of them since setting autoscan also sets autofeed if (CapAutoScan.CanSet) { - rc = CapAutoScan.Set(value); + rc = CapAutoScan.SetValue(value); } else if (CapAutoFeed.CanSet) { - rc = CapAutoFeed.Set(value); + rc = CapAutoFeed.SetValue(value); } return rc; diff --git a/NTwain/DataSource.cs b/NTwain/DataSource.cs index 716393a..f1dd2cb 100644 --- a/NTwain/DataSource.cs +++ b/NTwain/DataSource.cs @@ -174,7 +174,7 @@ namespace NTwain { if (_supportedCapsList == null && _session.State > 3) { - _supportedCapsList = CapSupportedCaps.Get(); + _supportedCapsList = CapSupportedCaps.GetValues(); } return _supportedCapsList ?? _emptyCapList; } diff --git a/NTwain/GlobalSuppressions.cs b/NTwain/GlobalSuppressions.cs new file mode 100644 index 0000000000000000000000000000000000000000..f57f13817f4bf0968dbb94cc7dea6da7d5fb8543 GIT binary patch literal 5556 zcmeI0-D?v;6vgke;Qz41mlkZQ;)4i2l(cHWR&i5BL~u^lGnS7vB zjOJwt?e6TobLY&t=g!W~kMGBJY>Bn)+6Go|*W)_0oI7vNd74|7_9t8Lzhx6zvY*)4 zGJF?!xNnIqu@O%P*vjQKvDD@^?_SsK$>>S9(!=<*g4pr5!Pj zveU6IJa^_CkMdvTT`Gyzh~{@1a}CXjUJ^;8PQmVatI##J6qjsht`T}x46kC1C>nMi z@NKHMV&W;Is!|#&j3)LDG;>gO1EbQ1G%?0+RjC!zzgFC)qAQ-gzQ&B9+Eewpx`q2a z&&021UAD)JorVfkEsgL!1-1AWvI1<%QNi0ykA^3-6A6T5Hs?14Q5*%kKOydG5vvw%ju-YzRG$KTft>0j#7`XI&?F9o^RMPg4v z{8hcXPn#aGGTrNv)$SY5rI{u<0Wlz)}l29!z^4K*++0U?T$Uex3o7{hGalk z59|;;hxQ>tG)_cuo$6WWQ#A zAMC$C{n}j(YyS7L0!9AMcn{3k-_&*R_jPcJs`W*avb)k-R$mrz?~?{wiKX8A>|*zM zbGENwzGshWjqhNsiC+LI>ee@tf7Pw(JgUD|`Yx1y6VA2n)N9MGzHI-D@p^sP)tN%I vrnkcxf=&>7tTO(++O@Ogd0@%uhR!B*`cj=NTn7F7iQzf>89ymo-_`sC@TbNn literal 0 HcmV?d00001 diff --git a/NTwain/ICapWrapper.cs b/NTwain/ICapWrapper.cs index 26c041d..f624f5e 100644 --- a/NTwain/ICapWrapper.cs +++ b/NTwain/ICapWrapper.cs @@ -11,7 +11,7 @@ namespace NTwain public interface IReadOnlyCapWrapper { /// - /// Gets a value indicating whether is supported. + /// Gets a value indicating whether is supported. /// /// /// true if this capability can get values; otherwise, false. @@ -95,7 +95,7 @@ namespace NTwain /// Gets all the possible values of this capability. /// /// - IList Get(); + IList GetValues(); /// /// Gets the current value of this capability. @@ -153,20 +153,20 @@ namespace NTwain /// /// The value. /// - ReturnCode Set(TValue value);/// + ReturnCode SetValue(TValue value);/// /// /// A version of Set that uses an array. /// /// The value. /// - ReturnCode Set(TWArray value); + ReturnCode SetValue(TWArray value); /// /// A version of Set that uses an enumeration. /// /// The value. /// - ReturnCode Set(TWEnumeration value); + ReturnCode SetValue(TWEnumeration value); /// /// Sets the constraint value of this capability. diff --git a/NTwain/ImageTools.cs b/NTwain/ImageTools.cs index d6d1f6a..d4575ed 100644 --- a/NTwain/ImageTools.cs +++ b/NTwain/ImageTools.cs @@ -88,7 +88,6 @@ namespace NTwain var headerSize = Marshal.SizeOf(typeof(TIFFHEADER)); var tagSize = Marshal.SizeOf(typeof(TIFFTAG)); var tiffSize = 0; - var header = (TIFFHEADER)Marshal.PtrToStructure(data, typeof(TIFFHEADER)); var tagPtr = data.ToInt64() + headerSize; for (int i = 0; i < 999; i++) { diff --git a/NTwain/NTwain.csproj b/NTwain/NTwain.csproj index 653961a..3cd2e49 100644 --- a/NTwain/NTwain.csproj +++ b/NTwain/NTwain.csproj @@ -61,6 +61,7 @@ + diff --git a/NTwain/State.cs b/NTwain/State.cs index a37483c..fdc65a0 100644 --- a/NTwain/State.cs +++ b/NTwain/State.cs @@ -10,6 +10,10 @@ namespace NTwain /// public enum State { + /// + /// Just a default value. + /// + Invalid = 0, /// /// The starting state, corresponds to state 1. /// diff --git a/Tests/Tester.WPF/ViewModels/DataSourceVM.cs b/Tests/Tester.WPF/ViewModels/DataSourceVM.cs index 90a2579..c20e6f0 100644 --- a/Tests/Tester.WPF/ViewModels/DataSourceVM.cs +++ b/Tests/Tester.WPF/ViewModels/DataSourceVM.cs @@ -49,7 +49,7 @@ namespace Tester.WPF //rc = DGControl.Status.Get(dsId, ref stat); if (rc == ReturnCode.Success) { - foreach (var c in DS.CapSupportedCaps.Get().Select(o => new CapVM(DS, o))) + foreach (var c in DS.CapSupportedCaps.GetValues().Select(o => new CapVM(DS, o))) { Caps.Add(c); } diff --git a/Tests/Tester.WPF/ViewModels/TwainVM.cs b/Tests/Tester.WPF/ViewModels/TwainVM.cs index 5e613f7..6464de9 100644 --- a/Tests/Tester.WPF/ViewModels/TwainVM.cs +++ b/Tests/Tester.WPF/ViewModels/TwainVM.cs @@ -248,7 +248,7 @@ namespace Tester.WPF { if (_session.CurrentSource.ICapXferMech.GetCurrent() == XferMech.File) { - var formats = _session.CurrentSource.ICapImageFileFormat.Get(); + var formats = _session.CurrentSource.ICapImageFileFormat.GetValues(); var wantFormat = formats.Contains(FileFormat.Tiff) ? FileFormat.Tiff : FileFormat.Bmp; var fileSetup = new TWSetupFileXfer diff --git a/Tests/Tester.Winform/TestForm.cs b/Tests/Tester.Winform/TestForm.cs index bbc89e6..07ccced 100644 --- a/Tests/Tester.Winform/TestForm.cs +++ b/Tests/Tester.Winform/TestForm.cs @@ -322,7 +322,7 @@ namespace Tester.Winform private void LoadPaperSize(ICapWrapper cap) { - var list = cap.Get(); + var list = cap.GetValues(); comboSize.DataSource = list; var cur = cap.GetCurrent(); if (list.Contains(cur)) @@ -346,7 +346,7 @@ namespace Tester.Winform private void LoadDPI(ICapWrapper cap) { // only allow dpi of certain values for those source that lists everything - var list = cap.Get().Where(dpi => (dpi % 50) == 0).ToList(); + var list = cap.GetValues().Where(dpi => (dpi % 50) == 0).ToList(); comboDPI.DataSource = list; var cur = cap.GetCurrent(); if (list.Contains(cur)) @@ -357,7 +357,7 @@ namespace Tester.Winform private void LoadDepth(ICapWrapper cap) { - var list = cap.Get(); + var list = cap.GetValues(); comboDepth.DataSource = list; var cur = cap.GetCurrent(); if (list.Contains(cur)) @@ -376,7 +376,7 @@ namespace Tester.Winform if (!_loadingCaps && _twain.State == 4) { var sel = (SupportedSize)comboSize.SelectedItem; - _twain.CurrentSource.ICapSupportedSizes.Set(sel); + _twain.CurrentSource.ICapSupportedSizes.SetValue(sel); } } @@ -385,7 +385,7 @@ namespace Tester.Winform if (!_loadingCaps && _twain.State == 4) { var sel = (PixelType)comboDepth.SelectedItem; - _twain.CurrentSource.ICapPixelType.Set(sel); + _twain.CurrentSource.ICapPixelType.SetValue(sel); } } @@ -394,8 +394,8 @@ namespace Tester.Winform if (!_loadingCaps && _twain.State == 4) { var sel = (TWFix32)comboDPI.SelectedItem; - _twain.CurrentSource.ICapXResolution.Set(sel); - _twain.CurrentSource.ICapYResolution.Set(sel); + _twain.CurrentSource.ICapXResolution.SetValue(sel); + _twain.CurrentSource.ICapYResolution.SetValue(sel); } } @@ -403,7 +403,7 @@ namespace Tester.Winform { if (!_loadingCaps && _twain.State == 4) { - _twain.CurrentSource.CapDuplexEnabled.Set(ckDuplex.Checked ? BoolType.True : BoolType.False); + _twain.CurrentSource.CapDuplexEnabled.SetValue(ckDuplex.Checked ? BoolType.True : BoolType.False); } }