diff --git a/instat/frmMain.vb b/instat/frmMain.vb index b1a58b1cc0c..c2351ac4d28 100644 --- a/instat/frmMain.vb +++ b/instat/frmMain.vb @@ -54,6 +54,8 @@ Public Class frmMain Public strAutoSaveLogFolderPath As String = Path.Combine(Path.GetTempPath, "R-Instat_log_auto_save") Public strAutoSaveInternalLogFolderPath As String = Path.Combine(Path.GetTempPath, "R-Instat_debug_log_auto_save") + Private strMarkerFilePath As String = Path.Combine(strAutoSaveLogFolderPath, "app_marker.log") + Public strCurrentAutoSaveDataFilePath As String = "" Private strLatestVersion As String = "" @@ -457,32 +459,41 @@ Public Class frmMain '--------------------------------------- 'prompt user for recovery selection - If (strAutoSavedLogFilePaths.Length > 0 OrElse - strAutoSavedDataFilePaths.Length > 0) AndAlso - MsgBox("We have detected that R-Instat may have closed unexpectedly last time." & Environment.NewLine & - "Would you like to see auto recovery options?", - MessageBoxButtons.YesNo, "Auto Recovery") = MsgBoxResult.Yes Then - - dlgAutoSaveRecovery.strAutoSavedLogFilePaths = strAutoSavedLogFilePaths - dlgAutoSaveRecovery.strAutoSavedDataFilePaths = strAutoSavedDataFilePaths - dlgAutoSaveRecovery.strAutoSavedInternalLogFilePaths = strAutoSavedInternalLogFilePaths - dlgAutoSaveRecovery.ShowDialog() - - 'todo. the dialog design is meant to only return just one option; script, data file path or new session. - 'refactor the dialog to enforce the design - - 'get the R script from read file if selected by the user - strScript = dlgAutoSaveRecovery.GetScript() - 'get the data file path if selected by the user - strDataFilePath = dlgAutoSaveRecovery.GetDataFilePath() + 'Check if the marker file exists + If File.Exists(strMarkerFilePath) Then + Dim lastExitStatus As String = File.ReadAllText(strMarkerFilePath).Trim() + If lastExitStatus <> "CleanExit" AndAlso + MsgBox("We have detected that R-Instat may have closed unexpectedly last time." & Environment.NewLine & + "Would you like to see auto recovery options?", + MessageBoxButtons.YesNo, "Auto Recovery") = MsgBoxResult.Yes Then + + dlgAutoSaveRecovery.strAutoSavedLogFilePaths = strAutoSavedLogFilePaths + dlgAutoSaveRecovery.strAutoSavedDataFilePaths = strAutoSavedDataFilePaths + dlgAutoSaveRecovery.strAutoSavedInternalLogFilePaths = strAutoSavedInternalLogFilePaths + dlgAutoSaveRecovery.ShowDialog() + + 'todo. the dialog design is meant to only return just one option; script, data file path or new session. + 'refactor the dialog to enforce the design + + 'get the R script from read file if selected by the user + strScript = dlgAutoSaveRecovery.GetScript() + 'get the data file path if selected by the user + strDataFilePath = dlgAutoSaveRecovery.GetDataFilePath() + End If End If + + Using writer As StreamWriter = New StreamWriter(strMarkerFilePath, False) + writer.WriteLine("Running") + End Using + '--------------------------------------- + '--------------------------------------- 'delete the recovery files If strAutoSavedLogFilePaths.Length > 0 Then Try - File.Delete(strAutoSavedLogFilePaths(0)) + File.Delete(strAutoSavedLogFilePaths(1)) '1 to avoid deleting app_marker file Catch ex As Exception MsgBox("Could not delete backup log file" & Environment.NewLine, "Error deleting file") End Try @@ -1078,6 +1089,11 @@ Public Class frmMain If RuntimeInformation.IsOSPlatform(OSPlatform.Windows) Then CefRuntimeWrapper.ShutDownCef() End If + + Using writer As StreamWriter = New StreamWriter(strMarkerFilePath, False) + writer.WriteLine("CleanExit") + End Using + Catch ex As Exception MsgBox("Error attempting to save setting files to App Data folder." & Environment.NewLine & "System error message: " & ex.Message, MsgBoxStyle.Critical, "Error saving settings") End Try