From 1b7b80b6f5ea13d5e8e03dba6f2001c663f68d8b Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Thu, 6 Jun 2019 11:08:15 +1000 Subject: [PATCH 01/13] arrayNode cannot be null --- XmpCore/Impl/XmpUtils.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/XmpCore/Impl/XmpUtils.cs b/XmpCore/Impl/XmpUtils.cs index bc633ae..c9a40cf 100644 --- a/XmpCore/Impl/XmpUtils.cs +++ b/XmpCore/Impl/XmpUtils.cs @@ -136,7 +136,7 @@ public static void SeparateArrayItems(IXmpMeta xmp, string schemaNs, string arra var arrayNode = SeparateFindCreateArray(schemaNs, arrayName, arrayOptions, xmpImpl); var arrayElementLimit = int.MaxValue; - if (arrayNode != null && arrayOptions != null) + if (arrayOptions != null) { arrayElementLimit = arrayOptions.ArrayElementsLimit; if (arrayElementLimit == -1) From 0a0f7abb7dade13b1d000cb382de9d8292b8c156 Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Thu, 6 Jun 2019 11:09:05 +1000 Subject: [PATCH 02/13] Add explicit accessibility modifiers --- XmpCore/Impl/XmpUtils.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/XmpCore/Impl/XmpUtils.cs b/XmpCore/Impl/XmpUtils.cs index c9a40cf..6a264fc 100644 --- a/XmpCore/Impl/XmpUtils.cs +++ b/XmpCore/Impl/XmpUtils.cs @@ -1139,7 +1139,7 @@ private static bool IsClosingQuote(char ch, char openQuote, char closeQuote) /// Schema of the specified property /// Name of the property /// true in case of success otherwise false. - static bool MoveOneProperty(XmpMeta stdXMP, XmpMeta extXMP, string schemaURI, string propName) + private static bool MoveOneProperty(XmpMeta stdXMP, XmpMeta extXMP, string schemaURI, string propName) { XmpNode propNode = null; @@ -1171,7 +1171,7 @@ static bool MoveOneProperty(XmpMeta stdXMP, XmpMeta extXMP, string schemaURI, st /// estimates the size of an xmp node /// XMP Node Object /// the estimated size of the node - static int EstimateSizeForJPEG(XmpNode xmpNode) + private static int EstimateSizeForJPEG(XmpNode xmpNode) { int estSize = 0; int nameSize = xmpNode.Name.Length; From 41a1e3f6f2512016b40ebc5f132da368f39c65cd Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Thu, 6 Jun 2019 11:10:24 +1000 Subject: [PATCH 03/13] Make field readonly --- XmpCore/Options/ParseOptions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/XmpCore/Options/ParseOptions.cs b/XmpCore/Options/ParseOptions.cs index 56cd01e..2f87316 100644 --- a/XmpCore/Options/ParseOptions.cs +++ b/XmpCore/Options/ParseOptions.cs @@ -38,7 +38,7 @@ public sealed class ParseOptions : Options public const int DisallowDoctypeFlag = 0x0040; /// Map of nodes whose children are to be limited. - private Dictionary mXMPNodesToLimit = new Dictionary(); + private readonly Dictionary mXMPNodesToLimit = new Dictionary(); /// Sets the options to the default values. public ParseOptions() From 503088c4d437d455fef1a5b7bcf81c6853f9fce1 Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Thu, 6 Jun 2019 11:11:40 +1000 Subject: [PATCH 04/13] Simplify code --- XmpCore/Impl/XmpUtils.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/XmpCore/Impl/XmpUtils.cs b/XmpCore/Impl/XmpUtils.cs index 6a264fc..dde0e31 100644 --- a/XmpCore/Impl/XmpUtils.cs +++ b/XmpCore/Impl/XmpUtils.cs @@ -1222,14 +1222,14 @@ private static void PutObjectsInMultiMap(SortedDictionary { if (multiMap == null) return; - List> tempList; // multiMap[key]; - //if (tempList == null) - if (!multiMap.TryGetValue(key, out tempList)) + + if (!multiMap.TryGetValue(key, out List> list)) { - tempList = new List>(); - multiMap[key] = tempList; + list = new List>(); + multiMap[key] = list; } - tempList.Add(stringPair); + + list.Add(stringPair); } /// Utility function for retrieving biggest entry in the multimap From 34df82225062874aa915efbb94807b3511bad28a Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Thu, 6 Jun 2019 11:12:34 +1000 Subject: [PATCH 05/13] Dispose MD5 instance --- XmpCore/Impl/XmpUtils.cs | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/XmpCore/Impl/XmpUtils.cs b/XmpCore/Impl/XmpUtils.cs index dde0e31..9d6aa3f 100644 --- a/XmpCore/Impl/XmpUtils.cs +++ b/XmpCore/Impl/XmpUtils.cs @@ -1444,23 +1444,25 @@ public static void PackageForJPEG(IXmpMeta origXMPImpl, extStr.Append(tempStr); #if NETSTANDARD2_0 - var md = MD5.Create(); - var hashBytes = md.ComputeHash(Encoding.UTF8.GetBytes(tempStr)); - - digestStr.Append(ByteArrayToHexString(hashBytes)); - - string ByteArrayToHexString(byte[] bytes) + using (var md = MD5.Create()) { - var result = new StringBuilder(bytes.Length*2); - const string HexAlphabet = "0123456789ABCDEF"; + var hashBytes = md.ComputeHash(Encoding.UTF8.GetBytes(tempStr)); - foreach (var b in bytes) + digestStr.Append(ByteArrayToHexString(hashBytes)); + + string ByteArrayToHexString(byte[] bytes) { - result.Append(HexAlphabet[b >> 4]); - result.Append(HexAlphabet[b & 0xF]); - } + var result = new StringBuilder(bytes.Length*2); + const string HexAlphabet = "0123456789ABCDEF"; - return result.ToString(); + foreach (var b in bytes) + { + result.Append(HexAlphabet[b >> 4]); + result.Append(HexAlphabet[b & 0xF]); + } + + return result.ToString(); + } } #endif From 14b8768caca655cbc85531216bb048a236070fbb Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Thu, 6 Jun 2019 11:17:34 +1000 Subject: [PATCH 06/13] Replace string concat with StringBuilder --- XmpCore/Impl/ParseRdf.cs | 7 ++++--- XmpCore/Impl/XmpSerializerRdf.cs | 13 +++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/XmpCore/Impl/ParseRdf.cs b/XmpCore/Impl/ParseRdf.cs index 3ccd8d9..baf2287 100644 --- a/XmpCore/Impl/ParseRdf.cs +++ b/XmpCore/Impl/ParseRdf.cs @@ -11,6 +11,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using System.Text; using System.Xml; using System.Xml.Linq; using XmpCore.Options; @@ -565,17 +566,17 @@ private static void Rdf_LiteralPropertyElement(XmpMeta xmp, XmpNode xmpParent, X } // FfF: Can there be more than one text node in a row? - var textValue = string.Empty; + var textValue = new StringBuilder(); foreach (var child in xmlNode.Nodes()) { if (child.NodeType != XmlNodeType.Text) throw new XmpException("Invalid child of literal property element", XmpErrorCode.BadRdf); - textValue += ((XText)child).Value; + textValue.Append(((XText)child).Value); } - newChild.Value = textValue; + newChild.Value = textValue.ToString(); } /// diff --git a/XmpCore/Impl/XmpSerializerRdf.cs b/XmpCore/Impl/XmpSerializerRdf.cs index 66ad5cd..c503ec4 100644 --- a/XmpCore/Impl/XmpSerializerRdf.cs +++ b/XmpCore/Impl/XmpSerializerRdf.cs @@ -10,6 +10,7 @@ using System.Collections.Generic; using System.IO; +using System.Text; using XmpCore.Options; namespace XmpCore.Impl @@ -242,19 +243,19 @@ private string SerializeAsRdf() } // Write the packet trailer PI into the tail string as UTF-8. - var tailStr = string.Empty; + var tailStr = new StringBuilder(); if (!_options.OmitPacketWrapper) { for (level = _options.BaseIndent; level > 0; level--) { - tailStr += _options.Indent; + tailStr.Append(_options.Indent); } - tailStr += PacketTrailer; - tailStr += _options.ReadOnlyPacket ? 'r' : 'w'; - tailStr += PacketTrailer2; + tailStr.Append(PacketTrailer); + tailStr.Append(_options.ReadOnlyPacket ? 'r' : 'w'); + tailStr.Append(PacketTrailer2); } - return tailStr; + return tailStr.ToString(); } /// Serializes the metadata in pretty-printed manner. From d9e745d4c975f285197528d0a0ee15a0a7a8ad0c Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Thu, 6 Jun 2019 11:20:03 +1000 Subject: [PATCH 07/13] Add .editorconfig --- .editorconfig | 60 +++++++++++++++++++++++++++++++++++++++++++++ XmpCore.sln | 8 ++++-- XmpCore/IXmpMeta.cs | 2 +- XmpCore/XmpUtils.cs | 2 +- 4 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..06738bc --- /dev/null +++ b/.editorconfig @@ -0,0 +1,60 @@ +root = true + +[*] +indent_style = space + +[*.cs] +indent_size = 4 +insert_final_newline = true +charset = utf-8 + +[*.{csproj}] +indent_size = 2 + +[*.{props,targets,ruleset,config,resx}] +indent_size = 2 + +[*.json] +indent_size = 2 + +[*.cs] +dotnet_sort_system_directives_first = true + +dotnet_style_qualification_for_field = false:warning +dotnet_style_qualification_for_property = false:warning +dotnet_style_qualification_for_method = false:warning +dotnet_style_qualification_for_event = false:warning + +dotnet_style_predefined_type_for_locals_parameters_members = true:warning +dotnet_style_predefined_type_for_member_access = true:warning + +dotnet_style_object_initializer = true:suggestion +dotnet_style_collection_initializer = true:suggestion +dotnet_style_coalesce_expression = true:suggestion +dotnet_style_null_propagation = true:suggestion +dotnet_style_explicit_tuple_names = true:suggestion + +csharp_style_var_for_built_in_types = false:none +csharp_style_var_when_type_is_apparent = true:none +csharp_style_var_elsewhere = false:none + +csharp_style_expression_bodied_methods = false:none +csharp_style_expression_bodied_constructors = false:none +csharp_style_expression_bodied_operators = false:none + +csharp_style_expression_bodied_properties = false:none +csharp_style_expression_bodied_indexers = false:none +csharp_style_expression_bodied_accessors = false:none + +csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion +csharp_style_pattern_matching_over_as_with_null_check = true:suggestion +csharp_style_inlined_variable_declaration = true:suggestion +csharp_style_throw_expression = true:suggestion +csharp_style_conditional_delegate_call = true:suggestion + +csharp_new_line_before_open_brace = all:warning +csharp_new_line_before_else = true:warning +csharp_new_line_before_catch = true:warning +csharp_new_line_before_finally = true:warning +csharp_new_line_before_members_in_object_initializers = true:warning +csharp_new_line_before_members_in_anonymous_types = true:warning diff --git a/XmpCore.sln b/XmpCore.sln index 6db36ad..07d6a58 100644 --- a/XmpCore.sln +++ b/XmpCore.sln @@ -1,10 +1,11 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.26228.4 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29001.49 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{06DA73A6-87C5-4772-9A59-534F10530ED6}" ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig .gitattributes = .gitattributes .gitignore = .gitignore appveyor.yml = appveyor.yml @@ -33,4 +34,7 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {DD96C38F-B7E1-459C-A3B6-600F0072F51E} + EndGlobalSection EndGlobal diff --git a/XmpCore/IXmpMeta.cs b/XmpCore/IXmpMeta.cs index 5025e25..ea73035 100644 --- a/XmpCore/IXmpMeta.cs +++ b/XmpCore/IXmpMeta.cs @@ -199,7 +199,7 @@ public interface IXmpMeta /// Arrays and non-leaf levels of structs do not have values. /// Must be null if the value is not relevant.
/// The value is automatically detected: Boolean, Integer, Long, Double, and - /// byte[] are handled, on all other is called. + /// byte[] are handled, on all other is called. /// /// Option flags describing the property. See the earlier description. /// Wraps all errors and exceptions that may occur. diff --git a/XmpCore/XmpUtils.cs b/XmpCore/XmpUtils.cs index a278c6b..d4292cd 100644 --- a/XmpCore/XmpUtils.cs +++ b/XmpCore/XmpUtils.cs @@ -478,7 +478,7 @@ static public void ApplyTemplate(IXmpMeta workingXMP, IXmpMeta templateXMP, Temp /// The root location for the destination. May be a general path expression. Defaults to the source location. /// Option flags to control the separation. (For now, this argument is ignored. 0 should be passed. /// Forwards the Exceptions from the metadata processing - public static void DuplicateSubtree(IXmpMeta source, IXmpMeta dest, String sourceNS, String sourceRoot, String destNS, String destRoot, PropertyOptions options) + public static void DuplicateSubtree(IXmpMeta source, IXmpMeta dest, string sourceNS, string sourceRoot, string destNS, string destRoot, PropertyOptions options) { Impl.XmpUtils.DuplicateSubtree(source, dest, sourceNS, sourceRoot, destNS, destRoot, options); } From cf922a258927706176904e5503fa33a9893aab86 Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Thu, 6 Jun 2019 11:22:49 +1000 Subject: [PATCH 08/13] Add build script as solution item --- XmpCore.sln | 1 + 1 file changed, 1 insertion(+) diff --git a/XmpCore.sln b/XmpCore.sln index 07d6a58..5515043 100644 --- a/XmpCore.sln +++ b/XmpCore.sln @@ -9,6 +9,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution .gitattributes = .gitattributes .gitignore = .gitignore appveyor.yml = appveyor.yml + Build.ps1 = Build.ps1 README.md = README.md EndProjectSection EndProject From 40146cf5e67267c6af11cb238c83865c725a43e3 Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Thu, 6 Jun 2019 11:22:58 +1000 Subject: [PATCH 09/13] Formatting --- XmpCore/XmpCore.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/XmpCore/XmpCore.csproj b/XmpCore/XmpCore.csproj index 73b6c12..de50988 100644 --- a/XmpCore/XmpCore.csproj +++ b/XmpCore/XmpCore.csproj @@ -3,7 +3,7 @@ .NET library for working with the Extensible Metadata Platform (XMP) -This library is a port of Adobe's Java XMP SDK to .NET. It was initially ported by Yakov Danila and Nathanael Jones. Now maintained by Drew Noakes and contributors on GitHub. +This library is a port of Adobe's Java XMP SDK to .NET. It was initially ported by Yakov Danila and Nathanael Jones. Now maintained by Drew Noakes and contributors on GitHub. The API should be familiar to users of Adobe's XMPCore, though it has been modified in places to better suit .NET development. Copyright 2015-2017 From 5e85adf509d686c75fc3ca49fbb3396a8e95cd7a Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Thu, 6 Jun 2019 11:23:07 +1000 Subject: [PATCH 10/13] Bump package copyright year --- XmpCore/XmpCore.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/XmpCore/XmpCore.csproj b/XmpCore/XmpCore.csproj index de50988..356633f 100644 --- a/XmpCore/XmpCore.csproj +++ b/XmpCore/XmpCore.csproj @@ -6,7 +6,7 @@ This library is a port of Adobe's Java XMP SDK to .NET. It was initially ported by Yakov Danila and Nathanael Jones. Now maintained by Drew Noakes and contributors on GitHub. The API should be familiar to users of Adobe's XMPCore, though it has been modified in places to better suit .NET development. - Copyright 2015-2017 + Copyright 2015-2019 XmpCore 6.1.10.0 Drew Noakes From f0ea2b4f9a93045904bd9d98d5bfa657fa7c0d84 Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Thu, 6 Jun 2019 11:23:52 +1000 Subject: [PATCH 11/13] Set strong name package ID in build script This attempts to help GitHub's dependency graph work correctly. --- Build.ps1 | 2 +- XmpCore/XmpCore.csproj | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Build.ps1 b/Build.ps1 index 4dafea2..d3189a6 100644 --- a/Build.ps1 +++ b/Build.ps1 @@ -31,6 +31,6 @@ if ((test-path $msbuild) -eq $false) { } &$msbuild XmpCore\XmpCore.csproj /t:Build,Pack /p:Configuration=Release /p:PackageOutputPath=..\artifacts -&$msbuild XmpCore\XmpCore.csproj /t:Build,Pack /p:Configuration=Release /p:PackageOutputPath=..\artifacts /p:Signed=True +&$msbuild XmpCore\XmpCore.csproj /t:Build,Pack /p:Configuration=Release /p:PackageOutputPath=..\artifacts /p:Signed=True /p:PackageId=XmpCore.StrongName Pop-Location diff --git a/XmpCore/XmpCore.csproj b/XmpCore/XmpCore.csproj index 356633f..6e94c3f 100644 --- a/XmpCore/XmpCore.csproj +++ b/XmpCore/XmpCore.csproj @@ -34,7 +34,6 @@ The API should be familiar to users of Adobe's XMPCore, though it has been modif ../XmpCore.snk true true - XmpCore.StrongName From 2b33b5c490217368b9d21e34c3cd7759cad10e8f Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Thu, 6 Jun 2019 11:24:24 +1000 Subject: [PATCH 12/13] Use VS2019 Preview on AppVeyor --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 4efc158..53ea76d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,7 +2,7 @@ version: 2.0.{build} branches: only: - master -image: Visual Studio 2017 +image: Visual Studio 2019 Preview configuration: Release before_build: appveyor-retry nuget restore From fbe7016adef547411bd389fba4d39558dcfa3b28 Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Thu, 6 Jun 2019 11:28:38 +1000 Subject: [PATCH 13/13] Update README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4252197..45c2ead 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ This library is a port of Adobe's XMP SDK to .NET. -The API should be familiar to users of Adobe's XMPCore 5.1.2, though it has been modified +The API should be familiar to users of Adobe's XMPCore 6.1.10, though it has been modified in places to better suit .NET development. ## Sample Usage