Skip to content
Permalink
Browse files
fix #1005 by making GRASS work in paths with blanks (windows-only)
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@8256 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Mar 20, 2008
1 parent bab084c commit 5d6e78e401b56a8aeb162cdb1b18e7727e1fa6b7
Showing with 73 additions and 15 deletions.
  1. +13 −2 src/plugins/grass/qgsgrassmodule.cpp
  2. +14 −0 src/plugins/grass/qgsgrassnewmapset.cpp
  3. +14 −0 src/plugins/grass/qgsgrasstools.cpp
  4. +32 −13 src/providers/grass/qgsgrass.cpp
@@ -91,6 +91,16 @@ extern "C" {

#include <gdal.h> // to collect version information

#if defined(WIN32)
#include <windows.h>
static QString getShortPath(const QString &path)
{
TCHAR buf[MAX_PATH];
GetShortPathName( path.ascii(), buf, MAX_PATH);
return buf;
}
#endif

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

@@ -107,10 +117,11 @@ QString QgsGrassModule::findExec ( QString file )

#ifdef WIN32
mExecPath = path.split ( ";" );
mExecPath.prepend ( getShortPath(QgsApplication::applicationDirPath()) );
#else
mExecPath = path.split ( ":" );
#endif
mExecPath.prepend ( QgsApplication::applicationDirPath() );
#endif
mExecPathInited = true;
}

@@ -168,7 +179,7 @@ QStringList QgsGrassModule::execArguments ( QString module )
}
else // script
{
QString cmd = QgsApplication::applicationDirPath() + "/msys/bin/sh";
QString cmd = getShortPath(QgsApplication::applicationDirPath()) + "/msys/bin/sh";
arguments.append ( cmd );

// Important! Otherwise it does not find DLL even if it is in PATH
@@ -72,6 +72,16 @@ QString temp3(GRASS_VERSION_MINOR);
QString temp4(GRASS_VERSION_RELEASE);
#endif

#if defined(WIN32)
#include <windows.h>
static QString getShortPath(const QString &path)
{
TCHAR buf[MAX_PATH];
GetShortPathName( path.ascii(), buf, MAX_PATH);
return buf;
}
#endif

bool QgsGrassNewMapset::mRunning = false;

QgsGrassNewMapset::QgsGrassNewMapset ( QgisInterface *iface,
@@ -1348,7 +1358,11 @@ void QgsGrassNewMapset::createMapset()
// TODO: add QgsGrass::setLocation or G_make_location with
// database path
QgsGrass::activeMode(); // because it calls private gsGrass::init()
#if defined(WIN32)
G__setenv( "GISDBASE", (char *) getShortPath(mDatabaseLineEdit->text()).ascii() );
#else
G__setenv( "GISDBASE", (char *) mDatabaseLineEdit->text().ascii() );
#endif

QgsGrass::resetError();
int ret = G_make_location( (char *) location.ascii(), &mCellHead,
@@ -71,6 +71,16 @@ extern "C" {
#include "qgsgrassmodel.h"
#include "qgsgrassbrowser.h"

#if defined(WIN32)
#include <windows.h>
static QString getShortPath(const QString &path)
{
TCHAR buf[MAX_PATH];
GetShortPathName( path.ascii(), buf, MAX_PATH);
return buf;
}
#endif

QgsGrassToolsTabWidget::QgsGrassToolsTabWidget( QWidget * parent ):
QTabWidget(parent)
{
@@ -391,7 +401,11 @@ QgsGrassTools::~QgsGrassTools()

QString QgsGrassTools::appDir(void)
{
#if defined(WIN32)
return getShortPath(QgsApplication::applicationDirPath());
#else
return QgsApplication::applicationDirPath();
#endif
}

void QgsGrassTools::close(void)
@@ -41,8 +41,14 @@ extern "C" {
#include <grass/version.h>
}

#if defined(_MSC_VER)
#include <windows.h> // for GetCurrentProcessId()
#if defined(WIN32)
#include <windows.h>
static QString getShortPath(const QString &path)
{
TCHAR buf[MAX_PATH];
GetShortPathName( path.ascii(), buf, MAX_PATH);
return buf;
}
#endif

void GRASS_EXPORT QgsGrass::init( void )
@@ -104,7 +110,7 @@ void GRASS_EXPORT QgsGrass::init( void )

#ifdef WIN32
// Use the applicationDirPath()/grass
gisBase = QCoreApplication::applicationDirPath() + "/grass";
gisBase = getShortPath( QCoreApplication::applicationDirPath() + "/grass" );
#ifdef QGISDEBUG
std::cerr << "GRASS gisBase = " << gisBase.ascii() << std::endl;
#endif
@@ -148,6 +154,9 @@ void GRASS_EXPORT QgsGrass::init( void )
userGisbase = false;
break;
}
#if defined(WIN32)
gisBase = getShortPath(gisBase);
#endif
}

if (!valid)
@@ -187,14 +196,11 @@ void GRASS_EXPORT QgsGrass::init( void )
#ifdef WIN32
// It seems that QgsApplication::prefixPath()
// is not initialized at this point
path.append ( sep + QCoreApplication::applicationDirPath() );
#endif
path.append ( sep + getShortPath(QCoreApplication::applicationDirPath()) );

#ifdef WIN32
// Add path to MSYS bin
// Warning: MSYS sh.exe will translate this path to '/bin'
path.append ( sep + QCoreApplication::applicationDirPath()
+ "/msys/bin/" );
path.append ( sep + getShortPath(QCoreApplication::applicationDirPath() + "/msys/bin/") );
#endif

QString p = getenv ("PATH");
@@ -262,7 +268,8 @@ bool QgsGrass::isValidGrassBaseDir(QString const gisBase)
#ifdef QGISDEBUG
std::cerr << "isValidGrassBaseDir()" << std::endl;
#endif
if ( gisBase.isEmpty() )
// GRASS currently doesn't handle paths with blanks
if ( gisBase.isEmpty() || gisBase.contains(" ") )
{
return FALSE;
}
@@ -316,7 +323,11 @@ void QgsGrass::setLocation( QString gisdbase, QString location )
init();

// Set principal GRASS variables (in memory)
G__setenv( "GISDBASE", (char *) gisdbase.ascii() );
#if defined(WIN32)
G__setenv( "GISDBASE", (char *) getShortPath(gisdbase).ascii() );
#else
G__setenv( "GISDBASE", (char *) gisdbase.ascii() );
#endif
G__setenv( "LOCATION_NAME", (char *) location.ascii() );
G__setenv( "MAPSET", "PERMANENT"); // PERMANENT must always exist

@@ -334,7 +345,11 @@ void QgsGrass::setMapset( QString gisdbase, QString location, QString mapset )
init();

// Set principal GRASS variables (in memory)
G__setenv( "GISDBASE", (char *) gisdbase.ascii() );
#if defined(WIN32)
G__setenv( "GISDBASE", (char *) getShortPath(gisdbase).ascii() );
#else
G__setenv( "GISDBASE", (char *) gisdbase.ascii() );
#endif
G__setenv( "LOCATION_NAME", (char *) location.ascii() );
G__setenv( "MAPSET", (char *) mapset.ascii() );

@@ -539,8 +554,12 @@ QString GRASS_EXPORT QgsGrass::openMapset ( QString gisdbase, QString location,
putenv( gisrcEnvChar );

// Reinitialize GRASS
G__setenv( "GISRC", const_cast<char *>(gisrcEnv.ascii()) );
G__setenv( "GISDBASE", const_cast<char *>(gisdbase.ascii()) );
G__setenv( "GISRC", const_cast<char *>(gisrcEnv.ascii()) );
#if defined(WIN32)
G__setenv( "GISDBASE", const_cast<char *>(getShortPath(gisdbase).ascii()) );
#else
G__setenv( "GISDBASE", const_cast<char *>(gisdbase.ascii()) );
#endif
G__setenv( "LOCATION_NAME", const_cast<char *>(location.ascii()) );
G__setenv( "MAPSET", const_cast<char *>(mapset.ascii()) );
defaultGisdbase = gisdbase;

0 comments on commit 5d6e78e

Please sign in to comment.