Skip to content

Commit

Permalink
performance. new version of heightmap2stl.jar is faster than fast
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremysimmons committed Jun 6, 2017
1 parent cd12105 commit 7d1a9ae
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

[assembly: AssemblyTitle("heightmap2stl-gui")]
[assembly: AssemblyProduct("heightmap2stl-gui")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyVersion("1.2.0.0")]
[assembly: AssemblyFileVersion("1.2.0.0")]

namespace app
{
Expand Down Expand Up @@ -217,32 +217,29 @@ private bool EnsureHeightmap2StlBinary()
{
if (BinaryMatchesEmbeddedVersion(path) == false)
{
AppendLog("Warning: Heightmap2STL.jar already exists, but doesn't match embedded version.");
AppendLog($"Current path: {path}");
AppendLog("Warning: Replacing heightmap2stl.jar at {path}.");
AppendLog($"Current hash: {Md5HashFile(path)}");
AppendLog($"Embedded hash: {EmbeddedHeightmap2StlBinaryHash()}");

DialogResult result =
MessageBox.Show(this,
"The embedded version of Heightmap2STL doesn't match the temporarily unpacked version at '" +
path + "'.\n" +
"Do you want to overwrite this file with a trusted version?",
"Heightmap2STL",
MessageBoxButtons.YesNo);
if (result == DialogResult.No)
{
AppendLog("Info: Operation Cancelled. Prevented overwriting existing STL file.");
return false;
}
File.Delete(path);
CopyEmbeddedHeightmap2StlBinaryToTemp(path);
AppendLog($"Replaced");
}
}
else
CopyEmbeddedHeightmap2StlBinaryToTemp(path);

return BinaryMatchesEmbeddedVersion(path);
}

private void CopyEmbeddedHeightmap2StlBinaryToTemp(string path)
{
using (Stream app = EmbeddedHeightmap2StlBinary())
using (Stream writer = File.OpenWrite(path))
{
app?.CopyTo(writer);
}
return BinaryMatchesEmbeddedVersion(path);
AppendLog($"Deployed heightmap2stl.jar with hash: {Md5HashFile(path)}");

}

private bool BinaryMatchesEmbeddedVersion(string path)
Expand Down Expand Up @@ -300,7 +297,7 @@ private static string Md5HashStream(Stream stream)
using (var md5 = MD5.Create())
{
var hash = md5.ComputeHash(stream);
return BitConverter.ToString(hash);
return BitConverter.ToString(hash).Replace("-", "");
}
}
}
Expand Down
Binary file modified heightmap2stl.jar
Binary file not shown.

0 comments on commit 7d1a9ae

Please sign in to comment.