Skip to content

Commit

Permalink
Merge pull request #256 from IDEMSInternational/master
Browse files Browse the repository at this point in the history
update
  • Loading branch information
Vitalis95 authored Jul 8, 2024
2 parents 47f2154 + f9ef52f commit 1b11d30
Showing 1 changed file with 35 additions and 19 deletions.
54 changes: 35 additions & 19 deletions instat/frmMain.vb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1b11d30

Please sign in to comment.