[chronojump] Extra checks to forbid edit/delete/export a missing session (after delete and maybe reboot chronojum



commit 3d2592405ec3f5b910aecb984ce2d3496c5c8695
Author: Xavier de Blas <xaviblas gmail com>
Date:   Tue Jul 20 19:28:18 2021 +0200

    Extra checks to forbid edit/delete/export a missing session (after delete and maybe reboot chronojump)

 src/gui/app1/chronojump.cs     | 27 +++++++++++++++++++++------
 src/gui/app1/session/delete.cs |  8 ++++++++
 src/gui/app1/session/export.cs |  5 +++++
 3 files changed, 34 insertions(+), 6 deletions(-)
---
diff --git a/src/gui/app1/chronojump.cs b/src/gui/app1/chronojump.cs
index 0b8aab0b2..cc219222f 100644
--- a/src/gui/app1/chronojump.cs
+++ b/src/gui/app1/chronojump.cs
@@ -779,12 +779,16 @@ public partial class ChronoJumpWindow
                        // 1) to avoid impossibility to start Chronojump if there's any problem with this 
session, first put this to false
                        SqlitePreferences.Update(SqlitePreferences.LoadLastSessionAtStart, false, false);
 
-                       // 2) load the session
-                       currentSession = SqliteSession.Select (preferences.lastSessionID.ToString());
-                       on_load_session_accepted();
+                       // 2) load the session (but check if it really exists (extra check))
+                       Session sessionLoading = SqliteSession.Select (preferences.lastSessionID.ToString());
+                       if(sessionLoading.UniqueID != -1)
+                       {
+                               currentSession = sessionLoading;
+                               on_load_session_accepted();
 
-                       // 3) put preference to true again
-                       SqlitePreferences.Update(SqlitePreferences.LoadLastSessionAtStart, true, false);
+                               // 3) put preference to true again
+                               SqlitePreferences.Update(SqlitePreferences.LoadLastSessionAtStart, true, 
false);
+                       }
                }
 
                if(! showSendLog && ! showSocialNetworkPoll && preferences.loadLastModeAtStart &&
@@ -2726,6 +2730,11 @@ public partial class ChronoJumpWindow
        {
                LogB.Information("edit session");
                
+               if(currentSession == null || currentSession.UniqueID == -1) {
+                       new DialogMessage(Constants.MessageTypes.WARNING, "Cannot edit a missing session");
+                       return;
+               }
+
                if(currentSession.Name == Constants.SessionSimulatedName)
                        new DialogMessage(Constants.MessageTypes.INFO, Constants.SessionProtectedStr());
                else {
@@ -2895,7 +2904,13 @@ public partial class ChronoJumpWindow
                }
        }
 
-       private void on_export_session_accepted(object o, EventArgs args) {
+       private void on_export_session_accepted(object o, EventArgs args)
+       {
+               if(currentSession == null || currentSession.UniqueID == -1) {
+                       new DialogMessage(Constants.MessageTypes.WARNING, "Cannot edit a missing session");
+                       return;
+               }
+
                new ExportSessionCSV(currentSession, app1, preferences);
        }
 
diff --git a/src/gui/app1/session/delete.cs b/src/gui/app1/session/delete.cs
index c18065c19..77a58ce6a 100644
--- a/src/gui/app1/session/delete.cs
+++ b/src/gui/app1/session/delete.cs
@@ -37,6 +37,11 @@ public partial class ChronoJumpWindow
        //not called from load
        private void on_app1s_delete_session_confirm_start (object o, EventArgs args)
        {
+               if(currentSession == null || currentSession.UniqueID == -1) {
+                       new DialogMessage(Constants.MessageTypes.WARNING, "Cannot delete a missing session");
+                       return;
+               }
+
                deleteSessionCalledFromLoad = false;
                tempDeletingSession = currentSession;
 
@@ -87,6 +92,9 @@ public partial class ChronoJumpWindow
 
                app1s_label_delete_done.Visible = true;
                app1s_button_delete_close.Visible = true;
+
+               //update LastSessionID to avoid try to loading this session on new Chronojump boot
+               SqlitePreferences.Update(SqlitePreferences.LastSessionID, "-1", false);
        }
 
        private void on_app1s_button_delete_cancel_clicked (object o, EventArgs args)
diff --git a/src/gui/app1/session/export.cs b/src/gui/app1/session/export.cs
index 88fa89176..065986e2e 100644
--- a/src/gui/app1/session/export.cs
+++ b/src/gui/app1/session/export.cs
@@ -53,6 +53,11 @@ public partial class ChronoJumpWindow
 
        private void on_app1s_button_export_select_clicked (object o, EventArgs args)
        {
+               if(currentSession == null || currentSession.UniqueID == -1) {
+                       new DialogMessage(Constants.MessageTypes.WARNING, "Cannot edit a missing session");
+                       return;
+               }
+
                app1s_fc = new Gtk.FileChooserDialog(Catalog.GetString("Export session to:"),
                                app1,
                                FileChooserAction.SelectFolder,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]