diff --git a/libmsstyle/VisualStyle.cs b/libmsstyle/VisualStyle.cs index 9403ca8..f9db27d 100644 --- a/libmsstyle/VisualStyle.cs +++ b/libmsstyle/VisualStyle.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Security.Cryptography; using System.Text; namespace libmsstyle @@ -621,5 +622,68 @@ public void QueueResourceUpdate(int nameId, StyleResourceType type, string pathT var key = new StyleResource(null, nameId, type); m_resourceUpdates[key] = pathToNew; } + + public string GetImageHash(StyleProperty prop) + { + // determine type for resource update + StyleResourceType resType = StyleResourceType.None; + if (prop.Header.typeID == (int)IDENTIFIER.FILENAME || + prop.Header.typeID == (int)IDENTIFIER.FILENAME_LITE) + { + resType = StyleResourceType.Image; + } + else if (prop.Header.typeID == (int)IDENTIFIER.DISKSTREAM) + { + resType = StyleResourceType.Atlas; + } + else return string.Empty; + + byte[] data = null; + + // see if there is a pending update to the resource + string file = GetQueuedResourceUpdate(prop.Header.shortFlag, resType); + if (!String.IsNullOrEmpty(file) && File.Exists(file)) + { + try + { + data = File.ReadAllBytes(file); + } + catch (Exception) + { + return string.Empty; + } + } + else + { + var resource = GetResourceFromProperty(prop); + if (resource?.Data != null) + { + data = resource.Data; + } + } + + if (data != null) + { + using (var hashAlgorithm = HashAlgorithm.Create("SHA256")) + { + if (hashAlgorithm == null) + return string.Empty; + + byte[] hashBytes = hashAlgorithm.ComputeHash(data); + + if (hashBytes != null) + { + // Convert hash bytes to hex string + StringBuilder sb = new StringBuilder(hashBytes.Length * 2); + foreach (byte b in hashBytes) + sb.AppendFormat("{0:x2}", b); + + return sb.ToString(); + } + } + } + + return string.Empty; + } } } diff --git a/msstyleEditorSharp/Exporter.cs b/msstyleEditorSharp/Exporter.cs index 156eeac..2c628ea 100644 --- a/msstyleEditorSharp/Exporter.cs +++ b/msstyleEditorSharp/Exporter.cs @@ -42,19 +42,28 @@ public static void ExportLogicalStructure(string path, VisualStyle style) PropertyInfo typeInfo; bool ht = VisualStyleProperties.PROPERTY_INFO_MAP.TryGetValue(prop.Header.typeID, out typeInfo); + string hash = string.Empty; + + if (prop.IsImageProperty()) + { + hash = String.Format(" Hash ({0})", style.GetImageHash(prop)); + } + if (!hp || !ht) - { - txt.AppendFormat("\t\t\tProp {0} ({1}) ({2})\n" + { + txt.AppendFormat("\t\t\tProp {0} ({1}) ({2}){3}\n" , prop.Header.nameID , prop.Header.typeID - , prop.GetValueAsString()); + , prop.GetValueAsString() + , hash); continue; } - txt.AppendFormat("\t\t\tProp {0} ({1}) ({2})\n" + txt.AppendFormat("\t\t\tProp {0} ({1}) ({2}){3}\n" , propInfo.Name , typeInfo.Name - , prop.GetValueAsString()); + , prop.GetValueAsString() + , hash); } } txt.Append("\n");