Skip to content
Snippets Groups Projects
Commit d71d2045 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

try to find client executable in same directory as argv0

this amkes it easier to ship bundles (e.g. gmsh+getdp)
parent 29e58385
No related branches found
No related tags found
No related merge requests found
...@@ -268,6 +268,7 @@ void GetOptions(int argc, char *argv[]) ...@@ -268,6 +268,7 @@ void GetOptions(int argc, char *argv[])
#if defined(HAVE_PARSER) #if defined(HAVE_PARSER)
if(argc && argv){ if(argc && argv){
CTX::instance()->argv0 = std::string(argv[0]);
// parse session and option file (if argc/argv is not provided skip this // parse session and option file (if argc/argv is not provided skip this
// step: this is usually what is expected when using Gmsh as a library) // step: this is usually what is expected when using Gmsh as a library)
ParseFile(CTX::instance()->homeDir + CTX::instance()->sessionFileName, true); ParseFile(CTX::instance()->homeDir + CTX::instance()->sessionFileName, true);
......
...@@ -79,6 +79,7 @@ class CTX { ...@@ -79,6 +79,7 @@ class CTX {
std::string bgmFileName, outputFileName, defaultFileName, tmpFileName; std::string bgmFileName, outputFileName, defaultFileName, tmpFileName;
std::string sessionFileName, optionsFileName, errorFileName; std::string sessionFileName, optionsFileName, errorFileName;
std::string meshStatReportFileName; std::string meshStatReportFileName;
std::string argv0;
// the home directory // the home directory
std::string homeDir; std::string homeDir;
// file history // file history
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
typedef unsigned long intptr_t; typedef unsigned long intptr_t;
#endif #endif
#include <ctype.h>
#include "GmshMessage.h" #include "GmshMessage.h"
#include "onelab.h" #include "onelab.h"
#include "gmshLocalNetworkClient.h" #include "gmshLocalNetworkClient.h"
...@@ -864,20 +865,47 @@ static void onelab_choose_executable_cb(Fl_Widget *w, void *data) ...@@ -864,20 +865,47 @@ static void onelab_choose_executable_cb(Fl_Widget *w, void *data)
#if defined(WIN32) #if defined(WIN32)
pattern += ".exe"; pattern += ".exe";
#endif #endif
const char *old = 0;
if(!c->getExecutable().empty()) old = c->getExecutable().c_str();
if(!w){ std::string exe = "";
const char *old = fl_close;
if(!w){ // we entered here automatically because no executable is given
// try to find an executable automatically (this is really useful for
// beginners)
if(CTX::instance()->argv0.size()){
std::vector<std::string> split = SplitFileName(CTX::instance()->argv0);
std::string name = c->getName();
for(unsigned int i = 0; i < name.size(); i++)
name[i] = tolower(name[i]);
std::string path = split[0] + name;
#if defined(WIN32)
path += ".exe";
#endif
if(!StatFile(path)){
exe = path;
Msg::Info("Automatically found %s executable: %s", c->getName().c_str(),
exe.c_str());
}
}
if(exe.empty()){
const char *o = fl_close;
fl_close = "OK"; fl_close = "OK";
fl_message("This appears to be the first time you are trying to run %s.\n\n" fl_message("This appears to be the first time you are trying to run %s.\n\n"
"Please select the path to the executable.", c->getName().c_str()); "Please select the path to the executable.", c->getName().c_str());
fl_close = old; fl_close = o;
}
} }
if(exe.empty()){
const char *old = 0;
if(c->getExecutable().size()) old = c->getExecutable().c_str();
std::string title = "Choose location of " + c->getName() + " executable"; std::string title = "Choose location of " + c->getName() + " executable";
if(fileChooser(FILE_CHOOSER_SINGLE, title.c_str(), pattern.c_str(), old)){ if(fileChooser(FILE_CHOOSER_SINGLE, title.c_str(), pattern.c_str(), old))
std::string exe = fileChooserGetName(1); exe = fileChooserGetName(1);
}
if(exe.size()){
c->setExecutable(exe); c->setExecutable(exe);
if(c->getIndex() >= 0 && c->getIndex() < 5) if(c->getIndex() >= 0 && c->getIndex() < 5)
opt_solver_executable(c->getIndex(), GMSH_SET, exe); opt_solver_executable(c->getIndex(), GMSH_SET, exe);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment