From 9a8d31defd7c370e7091d53f2c4cabc4035a40ef Mon Sep 17 00:00:00 2001 From: jlewin Date: Mon, 29 Apr 2019 13:13:23 -0700 Subject: [PATCH] Extract PrintRecovery logic for reuse --- MatterControlLib/History/PrintRecovery.cs | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/MatterControlLib/History/PrintRecovery.cs b/MatterControlLib/History/PrintRecovery.cs index 0669b8e73..9b907da9a 100644 --- a/MatterControlLib/History/PrintRecovery.cs +++ b/MatterControlLib/History/PrintRecovery.cs @@ -39,6 +39,22 @@ namespace MatterHackers.MatterControl.PrintHistory { public static class PrintRecovery { + public static bool RecoveryAvailable(PrinterConfig printer) + { + PrintTask lastPrint = PrintHistoryData.Instance.GetHistoryForPrinter(printer.Settings.ID.GetHashCode()).FirstOrDefault(); + return RecoveryAvailable(printer, lastPrint); + } + + public static bool RecoveryAvailable(PrinterConfig printer, PrintTask lastPrint) + { + return !lastPrint.PrintComplete // Top Print History Item is not complete + && !string.IsNullOrEmpty(lastPrint.PrintingGCodeFileName) // PrintingGCodeFileName is set + && File.Exists(lastPrint.PrintingGCodeFileName) // PrintingGCodeFileName is still on disk + && lastPrint.PercentDone > 0 // we are actually part way into the print + && printer.Settings.GetValue(SettingsKey.recover_is_enabled) + && !printer.Settings.GetValue(SettingsKey.has_hardware_leveling); + } + public static void CheckIfNeedToRecoverPrint(PrinterConfig printer) { string recoverPrint = "Recover Print".Localize(); @@ -50,12 +66,7 @@ namespace MatterHackers.MatterControl.PrintHistory PrintTask lastPrint = PrintHistoryData.Instance.GetHistoryForPrinter(printer.Settings.ID.GetHashCode()).FirstOrDefault(); if (lastPrint != null) { - if (!lastPrint.PrintComplete // Top Print History Item is not complete - && !string.IsNullOrEmpty(lastPrint.PrintingGCodeFileName) // PrintingGCodeFileName is set - && File.Exists(lastPrint.PrintingGCodeFileName) // PrintingGCodeFileName is still on disk - && lastPrint.PercentDone > 0 // we are actually part way into the print - && printer.Settings.GetValue(SettingsKey.recover_is_enabled) - && !printer.Settings.GetValue(SettingsKey.has_hardware_leveling)) + if (RecoveryAvailable(printer)) { bool safeHomingDirection = printer.Settings.GetValue(SettingsKey.z_homes_to_max);