Skip to content

Commit

Permalink
append .exe on Windows
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@4750 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek committed Jan 25, 2006
1 parent d4ae2c7 commit 10735e4
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 3 deletions.
60 changes: 57 additions & 3 deletions src/plugins/grass/qgsgrassmodule.cpp
Expand Up @@ -84,6 +84,38 @@ extern "C" {
#include "qgsgrassmapcalc.h"
#include "qgsgrasstools.h"

bool QgsGrassModule::mExecPathInited = 0;
QStringList QgsGrassModule::mExecPath;

bool QgsGrassModule::inExecPath ( QString file )
{
#ifdef QGISDEBUG
std::cerr << "QgsGrassModule::inExecPath()" << std::endl;
#endif
// Init mExecPath
// Windows searches first in current directory
if ( !mExecPathInited )
{
QString path = getenv("PATH");
std::cerr << "path = " << path.ascii() << std::endl;

mExecPath = path.split ( ";" );
mExecPath.prepend ( QgsApplication::applicationDirPath() );
mExecPathInited = true;
}

// Search for module
for ( QStringList::iterator it = mExecPath.begin();
it != mExecPath.end(); ++it )
{
if ( QFile::exists ( *it + "/" + file ) )
{
return true;
}
}
return false;
}

QgsGrassModule::QgsGrassModule ( QgsGrassTools *tools, QgisApp *qgisApp, QgisIface *iface,
QString path, QWidget * parent, const char * name, Qt::WFlags f )
//:QgsGrassModuleBase ( parent, name, f )
Expand Down Expand Up @@ -133,9 +165,31 @@ QgsGrassModule::QgsGrassModule ( QgsGrassTools *tools, QgisApp *qgisApp, QgisIfa
QDomElement qDocElem = qDoc.documentElement();

// Read GRASS module description
mXName = qDocElem.attribute("module");
QString xName = qDocElem.attribute("module");

// Binary modules on windows has .exe extension
// but not all modules have to be binary (can be scripts)
// => test if the module is in path and if it is not
// add .exe and test again
#ifdef WIN32
if ( inExecPath ( xName ) )
{
mXName = xName;
}
else if ( inExecPath ( xName + ".exe" ) )
{
mXName = xName + ".exe";
}
else
{
std::cerr << "Module " << xName.ascii() << " not found" << std::endl;
return;
}
#else
mXName = xName;
#endif

if ( mXName == "r.mapcalc" )
if ( xName == "r.mapcalc" )
{
QGridLayout *layout = new QGridLayout ( mTabWidget->page(0), 1, 1 );

Expand All @@ -156,7 +210,7 @@ QgsGrassModule::QgsGrassModule ( QgsGrassTools *tools, QgisApp *qgisApp, QgisIfa

// Create manual if available
QString gisBase = getenv("GISBASE");
QString manPath = gisBase + "/docs/html/" + mXName + ".html";
QString manPath = gisBase + "/docs/html/" + xName + ".html";
QFile manFile ( manPath );
if ( manFile.exists() ) {
mManualTextBrowser->setSource ( manPath );
Expand Down
7 changes: 7 additions & 0 deletions src/plugins/grass/qgsgrassmodule.h
Expand Up @@ -85,6 +85,13 @@ class QgsGrassModule: public QDialog, private Ui::QgsGrassModuleBase
// ! Options widget
QgsGrassModuleOptions *options() { return mOptions; }

// ! List of directories in PATH variable + current directory on Windows
static QStringList mExecPath;
static bool mExecPathInited;

// ! Check if file is in mExecPath
bool inExecPath ( QString file );

public slots:
//! Run the module with current options
void on_mRunButton_clicked() { run(); }
Expand Down

0 comments on commit 10735e4

Please sign in to comment.