[chronojump] less calls to UtilAll.GetOSEnum() on chronojump.cs, util.cs



commit 9c0db855dc7e552d29a804c1f99031e35a522b7e
Author: Xavier de Blas <xaviblas gmail com>
Date:   Sat Jul 4 03:15:19 2020 +0200

    less calls to UtilAll.GetOSEnum() on chronojump.cs, util.cs

 src/chronojump.cs | 13 ++++++++++---
 src/util.cs       |  8 +++++---
 2 files changed, 15 insertions(+), 6 deletions(-)
---
diff --git a/src/chronojump.cs b/src/chronojump.cs
index 578fe075..5c18ae9f 100644
--- a/src/chronojump.cs
+++ b/src/chronojump.cs
@@ -38,6 +38,7 @@ public class ChronoJump
        
        private static string progVersion = ""; //now in "version" file
        private static string progName = "Chronojump";
+       private static UtilAll.OperatingSystems operatingSystem;
        
        private string runningFileName; //useful for knowing if there are two chronojump instances
        private string messageToShowOnBoot = "";
@@ -77,6 +78,12 @@ public class ChronoJump
 
                var envPath = Environment.GetEnvironmentVariable ("PATH");
                var rBinPath = "";
+
+               //record GetOsEnum on variables to not call it all the time
+               operatingSystem = UtilAll.GetOSEnum();
+               Util.operatingSystem = operatingSystem;
+
+               //we need to set Util.operatingSytem before GetPrefixDir()
                baseDirectory = Util.GetPrefixDir();
 
                /*
@@ -113,7 +120,7 @@ public class ChronoJump
                        Environment.SetEnvironmentVariable ("R_HOME", baseDirectory);
                        LogB.Information("R_HOME:", baseDirectory);
                } else {
-                       switch (UtilAll.GetOSEnum()) {
+                       switch (operatingSystem) {
                                case UtilAll.OperatingSystems.MACOSX:
                                        LogB.Information(Environment.GetEnvironmentVariable("R_HOME"));
                                        rBinPath = "/Library/Frameworks/R.Framework/Libraries";
@@ -574,11 +581,11 @@ public class ChronoJump
                LogB.SQL("all SQL done! starting Chronojump");
 
                string topMessage = "";
-               if(UtilAll.GetOSEnum() == UtilAll.OperatingSystems.LINUX && ! linuxUserHasDialout())
+               if(operatingSystem == UtilAll.OperatingSystems.LINUX && ! linuxUserHasDialout())
                        topMessage = Catalog.GetString("Need dialout permissions to read from device.") + 
"\n" +
                                Catalog.GetString("Check software page on Chronojump website");
 
-               bool showCameraStop = (ExecuteProcess.IsRunning3 (-1, 
WebcamFfmpeg.GetExecutableCapture(UtilAll.GetOSEnum())));
+               bool showCameraStop = (ExecuteProcess.IsRunning3 (-1, 
WebcamFfmpeg.GetExecutableCapture(operatingSystem)));
 
                new ChronoJumpWindow(progVersion, progName, runningFileName, splashWin, sendLog, 
messageToShowOnBoot, topMessage, showCameraStop);
        }
diff --git a/src/util.cs b/src/util.cs
index 326dcf29..35e08adb 100644
--- a/src/util.cs
+++ b/src/util.cs
@@ -30,6 +30,8 @@ using System.Globalization;   //Unicode
 //this class tries to be a space for methods that are used in different classes
 public class Util
 {
+       public static UtilAll.OperatingSystems operatingSystem;
+
        /*
         * sometimes two doubles are similar "human eye" but different when they are compared with equal
         * just return true if the difference between them is lower than 0.001
@@ -1259,7 +1261,7 @@ public class Util
        public static string GetPrefixDir()
        {
                //on mac with the bundle we use this method to return PrefixDir, as BaseDirectory and 
GetCurrentDirectory() do not work
-               if(UtilAll.GetOSEnum() == UtilAll.OperatingSystems.MACOSX)
+               if(operatingSystem == UtilAll.OperatingSystems.MACOSX)
                        return (System.IO.Path.Combine(
                                                
Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName),
                                                ".."));
@@ -1450,7 +1452,7 @@ public class Util
  
                if (UtilAll.IsWindows())
                        rBin=System.IO.Path.Combine(GetPrefixDir(), "bin/R.exe");
-               else if(UtilAll.GetOSEnum() == UtilAll.OperatingSystems.MACOSX)
+               else if(operatingSystem == UtilAll.OperatingSystems.MACOSX)
                        rBin = Constants.ROSX;
 
                pinfo = new ProcessStartInfo();
@@ -1503,7 +1505,7 @@ public class Util
                 * and some MacOSX users have 300% CPU
                 */
 
-               if(UtilAll.GetOSEnum() == UtilAll.OperatingSystems.WINDOWS ||
+               if(operatingSystem == UtilAll.OperatingSystems.WINDOWS ||
                                gstreamer == Preferences.GstreamerTypes.SYSTEMSOUNDS)
                        return playSoundWindows(mySound);
                else


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