[chronojump] System.Diagnostics.Process.Start with try/catch avoiding mono linux problem



commit da6167c0c00cb12406adabfc1bf5242ac7f6c31e
Author: Xavier de Blas <xaviblas gmail com>
Date:   Mon Jan 27 20:20:57 2020 +0100

    System.Diagnostics.Process.Start with try/catch avoiding mono linux problem

 src/gui/app1/forceSensor.cs | 16 ++++++++++++++--
 src/gui/preferences.cs      | 20 +++++++++++++++-----
 src/gui/runEncoder.cs       | 17 ++++++++++++++---
 src/gui/splash.cs           | 18 ++++++++++++++----
 4 files changed, 57 insertions(+), 14 deletions(-)
---
diff --git a/src/gui/app1/forceSensor.cs b/src/gui/app1/forceSensor.cs
index 1f682f47..bf3045d5 100644
--- a/src/gui/app1/forceSensor.cs
+++ b/src/gui/app1/forceSensor.cs
@@ -2176,13 +2176,25 @@ LogB.Information(" fs R ");
        {
                if(currentSession == null || currentSession.UniqueID == -1)
                {
-                       System.Diagnostics.Process.Start(ForceSensorGraph.GetDataDir(-1));
+                       try {
+                               System.Diagnostics.Process.Start(ForceSensorGraph.GetDataDir(-1));
+                       } catch {
+                               new DialogMessage(Constants.MessageTypes.WARNING,
+                                               Catalog.GetString("Error. Cannot open directory.") + "\n\n" + 
ForceSensorGraph.GetDataDir(-1));
+                       }
                        return;
                }
 
                string dataDir = ForceSensorGraph.GetDataDir(currentSession.UniqueID);
                if(dataDir != "")
-                       System.Diagnostics.Process.Start(dataDir);
+               {
+                       try {
+                               System.Diagnostics.Process.Start(dataDir);
+                       } catch {
+                               new DialogMessage(Constants.MessageTypes.WARNING,
+                                               Catalog.GetString("Error. Cannot open directory.") + "\n\n" + 
dataDir);
+                       }
+               }
                else
                        new DialogMessage(Constants.MessageTypes.WARNING, Constants.DirectoryCannotOpenStr());
        }
diff --git a/src/gui/preferences.cs b/src/gui/preferences.cs
index 7d081a5c..0086513a 100644
--- a/src/gui/preferences.cs
+++ b/src/gui/preferences.cs
@@ -1239,14 +1239,24 @@ public class PreferencesWindow
                System.IO.FileInfo file1 = new System.IO.FileInfo(databaseURL); //potser cal una arrobar 
abans (a windows)
                System.IO.FileInfo file2 = new System.IO.FileInfo(databaseTempURL); //potser cal una arrobar 
abans (a windows)
 
+               if(! file1.Exists && ! file2.Exists)
+                       new DialogMessage(Constants.MessageTypes.WARNING, Constants.DatabaseNotFoundStr());
+
+               string dir = "";
                if(file1.Exists)
-                       System.Diagnostics.Process.Start(Util.GetParentDir(false)); 
+                       dir = Util.GetParentDir(false);
                else if(file2.Exists)
-                       System.Diagnostics.Process.Start(Util.GetDatabaseTempDir()); 
-               else
-                       new DialogMessage(Constants.MessageTypes.WARNING, Constants.DatabaseNotFoundStr());
+                       dir = Util.GetDatabaseTempDir();
+
+               try {
+                       System.Diagnostics.Process.Start(dir);
+               } catch {
+                       new DialogMessage(Constants.MessageTypes.WARNING,
+                                       Catalog.GetString("Error. Cannot open directory.") + "\n\n" + dir);
+                       return;
+               }
        }
-       
+
        void on_button_db_restore_clicked (object o, EventArgs args)
        {
                /*
diff --git a/src/gui/runEncoder.cs b/src/gui/runEncoder.cs
index bdeac573..a91a3a96 100644
--- a/src/gui/runEncoder.cs
+++ b/src/gui/runEncoder.cs
@@ -1208,14 +1208,25 @@ LogB.Information(" re R ");
        {
                if(currentSession == null || currentSession.UniqueID == -1)
                {
-                       System.Diagnostics.Process.Start(RunEncoderGraph.GetDataDir(-1));
+                       try {
+                               System.Diagnostics.Process.Start(RunEncoderGraph.GetDataDir(-1));
+                       } catch {
+                               new DialogMessage(Constants.MessageTypes.WARNING,
+                                               Catalog.GetString("Error. Cannot open directory.") + "\n\n" + 
RunEncoderGraph.GetDataDir(-1));
+                       }
                        return;
                }
 
                string dataDir = RunEncoderGraph.GetDataDir(currentSession.UniqueID);
                if(dataDir != "")
-                       System.Diagnostics.Process.Start(dataDir);
-               else
+               {
+                       try {
+                               System.Diagnostics.Process.Start(dataDir);
+                       } catch {
+                               new DialogMessage(Constants.MessageTypes.WARNING,
+                                               Catalog.GetString("Error. Cannot open directory.") + "\n\n" + 
dataDir);
+                       }
+               } else
                        new DialogMessage(Constants.MessageTypes.WARNING, Constants.DirectoryCannotOpenStr());
        }
 
diff --git a/src/gui/splash.cs b/src/gui/splash.cs
index e225ae76..c5979b56 100644
--- a/src/gui/splash.cs
+++ b/src/gui/splash.cs
@@ -127,12 +127,22 @@ public class SplashWindow
                System.IO.FileInfo file1 = new System.IO.FileInfo(database_url); //potser cal una arrobar 
abans (a windows)
                System.IO.FileInfo file2 = new System.IO.FileInfo(database_temp_url); //potser cal una 
arrobar abans (a windows)
 
+               if(! file1.Exists && ! file2.Exists)
+                       new DialogMessage(Constants.MessageTypes.WARNING, Constants.DatabaseNotFoundStr());
+
+               string dir = "";
                if(file1.Exists)
-                       System.Diagnostics.Process.Start(Util.GetDatabaseDir());
+                       dir = Util.GetDatabaseDir();
                else if(file2.Exists)
-                       System.Diagnostics.Process.Start(Util.GetDatabaseTempDir());
-               else
-                       new DialogMessage(Constants.MessageTypes.WARNING, Constants.DatabaseNotFoundStr());
+                       dir = Util.GetDatabaseTempDir();
+
+               try {
+                       System.Diagnostics.Process.Start(dir);
+               } catch {
+                       new DialogMessage(Constants.MessageTypes.WARNING,
+                                       Catalog.GetString("Error. Cannot open directory.") + "\n\n" + dir);
+                       return;
+               }
        }
 
        public void Show_button_open_docs_folder () {


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