From 901835aedcbb6c0d27209c125b6f46bbd4df92cb Mon Sep 17 00:00:00 2001 From: Lars Brubaker Date: Mon, 8 Jun 2015 17:52:28 -0700 Subject: [PATCH] removed dead code added FileHashCode to print item Made hash code for print item wrapper 64 bit (long). --- DataStorage/Models.cs | 2 ++ MatterControlApplication.cs | 12 +----------- PrintQueue/PrintItemWrapper.cs | 35 +++++++++++++++++++++++++++------- Submodules/agg-sharp | 2 +- 4 files changed, 32 insertions(+), 19 deletions(-) diff --git a/DataStorage/Models.cs b/DataStorage/Models.cs index a564df070..10ec9630b 100644 --- a/DataStorage/Models.cs +++ b/DataStorage/Models.cs @@ -189,6 +189,8 @@ namespace MatterHackers.MatterControl.DataStorage public string FileLocation { get; set; } + public long FileHashCode { get; set; } + public DateTime DateAdded { get; set; } public int PrintCount { get; set; } diff --git a/MatterControlApplication.cs b/MatterControlApplication.cs index 1bf71ccd0..5f343abda 100644 --- a/MatterControlApplication.cs +++ b/MatterControlApplication.cs @@ -534,7 +534,7 @@ namespace MatterHackers.MatterControl } } - if (firstDraw && commandLineArgs.Length < 2) + if (firstDraw) { UiThread.RunOnIdle(DoAutoConnectIfRequired); @@ -550,16 +550,6 @@ namespace MatterHackers.MatterControl } TerminalWindow.ShowIfLeftOpen(); - -#if false - foreach (CreatorInformation creatorInfo in RegisteredCreators.Instance.Creators) - { - if (creatorInfo.description.Contains("Image")) - { - creatorInfo.functionToLaunchCreator(null, null); - } - } -#endif } //msGraph.AddData("ms", totalDrawTime.ElapsedMilliseconds); diff --git a/PrintQueue/PrintItemWrapper.cs b/PrintQueue/PrintItemWrapper.cs index 9875ebf4d..cb13b7b45 100644 --- a/PrintQueue/PrintItemWrapper.cs +++ b/PrintQueue/PrintItemWrapper.cs @@ -47,7 +47,7 @@ namespace MatterHackers.MatterControl.PrintQueue private String fileType; - private int fileHashCode; + private long fileHashCode; private long writeTime = 0; public bool CurrentlySlicing { get; set; } @@ -152,14 +152,15 @@ namespace MatterHackers.MatterControl.PrintQueue set { this.PrintItem.FileLocation = value; } } - public int FileHashCode + public long FileHashCode { get { - long currentWriteTime = File.GetLastWriteTime(this.FileLocation).ToBinary(); bool fileExists = System.IO.File.Exists(this.FileLocation); if (fileExists) { + long currentWriteTime = File.GetLastWriteTime(this.FileLocation).ToBinary(); + if (this.fileHashCode == 0 || writeTime != currentWriteTime) { writeTime = currentWriteTime; @@ -167,7 +168,7 @@ namespace MatterHackers.MatterControl.PrintQueue { long sizeOfFile = fileStream.Length; int sizeOfRead = 1 << 16; - byte[] readData = new byte[sizeOfRead * 3]; + byte[] readData = new byte[Math.Max(64, sizeOfRead * 3)]; // get a chuck from the begining fileStream.Read(readData, sizeOfRead, sizeOfRead); @@ -187,12 +188,29 @@ namespace MatterHackers.MatterControl.PrintQueue readData[i] = fileSizeAsBytes[i]; } - int hashCode = agg_basics.ComputeHash(readData); - int fileSizeInt = (int)sizeOfFile; - this.fileHashCode = new { hashCode, currentWriteTime, fileSizeInt }.GetHashCode(); + // push the file size into the first bytes + byte[] writeTimeAsBytes = BitConverter.GetBytes(currentWriteTime); + for (int i = 0; i < writeTimeAsBytes.Length; i++) + { + readData[fileSizeAsBytes.Length + i] = fileSizeAsBytes[i]; + } + + this.fileHashCode = agg_basics.ComputeHash(readData); } } } + else + { + this.fileHashCode = 0; + } + + if (PrintItem != null + && PrintItem.FileHashCode != this.fileHashCode) + { + PrintItem.FileHashCode = this.fileHashCode; + PrintItem.Commit(); + } + return this.fileHashCode; } @@ -260,6 +278,9 @@ namespace MatterHackers.MatterControl.PrintQueue public void OnFileHasChanged() { + // Get the hashcode so we can save it if it has changed. + long fileHashCode = FileHashCode; + if (FileHasChanged != null) { FileHasChanged.CallEvents(this, null); diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index c6b7b4331..9774d0611 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit c6b7b43313bb2f899277066c8a89c48b70ecf42b +Subproject commit 9774d0611c17b73bf7fb3dd088d6890fa9a9a4e6