Don't invalidate image object if image didn't change

This commit is contained in:
Lars Brubaker 2022-02-21 08:52:49 -08:00
parent 6b3a6e525e
commit f7b63eb0a0
4 changed files with 90 additions and 7 deletions

View file

@ -123,7 +123,10 @@ namespace MatterHackers.MatterControl
{
if (!this.FreezeGCode)
{
ApplicationController.Instance.Thumbnails.DeleteCache(this.SourceItem);
if (this.SourceItem != null)
{
ApplicationController.Instance.Thumbnails.DeleteCache(this.SourceItem);
}
// Call save on the provider
this.ContentStore?.Save(this.SourceItem, scene);

View file

@ -1,5 +1,5 @@
/*
Copyright (c) 2017, Lars Brubaker, John Lewin
Copyright (c) 2022 Lars Brubaker, John Lewin
All rights reserved.
Redistribution and use in source and binary forms, with or without
@ -143,6 +143,83 @@ namespace MatterHackers.MatterControl.DesignTools
}
}
public static string GetFileOrAsset(string file)
{
if (!File.Exists(file))
{
var path = Path.Combine(ApplicationDataStorage.Instance.LibraryAssetsPath, file);
if (File.Exists(path))
{
return path;
}
// can't find a real file
return null;
}
return file;
}
public static bool FilesAreEqual(string first, string second)
{
if (string.IsNullOrEmpty(first)
|| string.IsNullOrEmpty(second))
{
return false;
}
var diskFirst = GetFileOrAsset(first);
var diskSecond = GetFileOrAsset(second);
if (File.Exists(diskFirst) && File.Exists(diskSecond))
{
return FilesAreEqual(new FileInfo(diskFirst), new FileInfo(diskSecond));
}
return false;
}
public static bool FilesAreEqual(FileInfo first, FileInfo second)
{
if (first.Length != second.Length)
{
return false;
}
if (string.Equals(first.FullName, second.FullName, StringComparison.OrdinalIgnoreCase))
{
return true;
}
int readSize = 1 << 16;
int numReads = (int)Math.Ceiling((double)first.Length / readSize);
using (var firstFs = first.OpenRead())
{
using (var secondFs = second.OpenRead())
{
byte[] one = new byte[readSize];
byte[] two = new byte[readSize];
for (int i = 0; i < numReads; i++)
{
firstFs.Read(one, 0, readSize);
secondFs.Read(two, 0, readSize);
for (int j = 0; j < readSize; j++)
{
if (one[j] != two[j])
{
return false;
}
}
}
}
}
return true;
}
[DisplayName("Open new image")]
[Description("Open")]
@ -153,12 +230,15 @@ namespace MatterHackers.MatterControl.DesignTools
{
if (_assetPath != value)
{
var oldAsset = _assetPath;
_assetPath = value;
_image = null;
InitMesh(this.Image);
this.Invalidate(InvalidateType.DisplayValues);
if (!FilesAreEqual(oldAsset, value))
{
InitMesh(this.Image);
this.Invalidate(InvalidateType.DisplayValues);
}
}
}
}

@ -1 +1 @@
Subproject commit a86abaeaad60171fa523ffca733dbbbca639cf5a
Subproject commit aaaaa7db0cef2489fd36f6443381de919d0756ca

@ -1 +1 @@
Subproject commit 37a06c821f9ca9c8c3312082360b92cf7b631aed
Subproject commit 609f985e9b15b6ef778869290d10e9cacfda2695