]> Creatis software - crea.git/blobdiff - lib/creaDevManagerLib/CDMUtilities.cpp
Feature #1711 CreaDevManager application implementation
[crea.git] / lib / creaDevManagerLib / CDMUtilities.cpp
index 29ed9c0371ffafc1c8dc9c973566fc8ca256d402..b4696b1104177d6949398c58a0d5638d631cef95 100644 (file)
@@ -41,6 +41,9 @@
 #include<algorithm>
 #include<cstdlib>
 
+#include<creaWx.h>
+#include<wx/config.h>
+
 namespace CDMUtilities
 {
   template <typename Container>
@@ -78,7 +81,7 @@ namespace CDMUtilities
   {
     std::string pathFixed = "";
 
-#if(_WIN32)
+#ifdef _WIN32
     // ------ Windows
     std::vector<std::string> pathSplit;
 
@@ -109,48 +112,82 @@ namespace CDMUtilities
 
   int openTextEditor(const std::string& file)
   {
-    std::string command = TEXT_EDITOR;
+#ifdef _WIN32
+    wxConfigBase* pConfig =  wxConfigBase::Get();
+    std::string command = "start " + crea::wx2std(pConfig->Read(wxT("TEXT_EDITOR"), crea::std2wx(CDMUtilities::TEXT_EDITOR)));
 
     if(file != "")
-      command += " \"" + file + "\" &";
+      command += " \"" + file + "\"";
+#else
+    wxConfigBase* pConfig =  wxConfigBase::Get();
+    std::string command = crea::wx2std(pConfig->Read(wxT("TEXT_EDITOR"), crea::std2wx(CDMUtilities::TEXT_EDITOR)));
 
+    if(file != "")
+      command += " \"" + file + "\"";
+    command += " &";
+#endif
     return system(command.c_str());
   }
 
   int openFileExplorer(const std::string& file)
   {
-    std::string command = FILE_EXPLORER;
+#ifdef _WIN32
+    wxConfigBase* pConfig =  wxConfigBase::Get();
+    std::string command = "start " + crea::wx2std(pConfig->Read(wxT("FILE_EXPLORER"), crea::std2wx(CDMUtilities::FILE_EXPLORER)));
 
     if(file != "")
-      command += " \"" + file + "\" &";
+      command += " \"" + file + "\"";
+#else
+    wxConfigBase* pConfig =  wxConfigBase::Get();
+    std::string command = crea::wx2std(pConfig->Read(wxT("FILE_EXPLORER"), crea::std2wx(CDMUtilities::FILE_EXPLORER)));
 
+    if(file != "")
+      command += " \"" + file + "\"";
+    command += " &";
+#endif
     return system(command.c_str());
   }
 
   int openFileWithCommand(const std::string& file, const std::string& command)
   {
+#ifdef _WIN32
+    std::string comm = "start " + command;
+    if(file != "")
+      comm += " \"" + file + "\"";
+#else
     std::string comm = command;
     if(file != "")
-      comm += " \"" + file + "\" &";
-
+      comm += " \"" + file + "\"";
+    comm += " &";
+#endif
     return system(comm.c_str());
   }
 
   int openBBEditor()
   {
-    std::string comm = "bbEditor &";
+#ifdef _WIN32
+    std::string comm = "start bbEditor";
+#else
+       std::string comm = "bbEditor &";
+#endif
     return system(comm.c_str());
   }
 
   int openCreaToolsTools()
   {
+#ifdef _WIN32
+    std::string comm = "start creaTools";
+#else
     std::string comm = "creaTools.sh &";
+#endif
+    
     return system(comm.c_str());
   }
 
   int openTerminal(const std::string& command)
   {
-    std::string comm = TERMINAL;
+    wxConfigBase* pConfig =  wxConfigBase::Get();
+    std::string comm = crea::wx2std(pConfig->Read(wxT("TERMINAl"), crea::std2wx(CDMUtilities::TERMINAL)));
     if (command != "")
       comm += + " " + command;
     comm += " &";
@@ -305,4 +342,18 @@ namespace CDMUtilities
     return true;
   }
 
+  std::string stringify(const std::string& line)
+  {
+       std::string res;
+       for (int i = 0; i < (int)(line.size()); i++)
+       {
+         if(line[i] == '\\')
+           res.push_back('\\');
+         if(line[i] == '\"')
+           res.push_back('\\');
+         res.push_back(line[i]);
+       }
+       return res;
+  }
+
 }