Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update my master #95

Merged
merged 8 commits into from
Jul 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading