Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions libmsstyle/VisualStyle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;

namespace libmsstyle
Expand Down Expand Up @@ -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;
}
}
}
19 changes: 14 additions & 5 deletions msstyleEditorSharp/Exporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down