Skip to content

Commit

Permalink
fix #1005 by making GRASS work in paths with blanks (windows-only)
Browse files Browse the repository at this point in the history
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 5d6e78e
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 15 deletions.
15 changes: 13 additions & 2 deletions src/plugins/grass/qgsgrassmodule.cpp
Expand Up @@ -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;

Expand All @@ -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;
}

Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions src/plugins/grass/qgsgrassnewmapset.cpp
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
14 changes: 14 additions & 0 deletions src/plugins/grass/qgsgrasstools.cpp
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
Expand Down
45 changes: 32 additions & 13 deletions src/providers/grass/qgsgrass.cpp
Expand Up @@ -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 )
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -148,6 +154,9 @@ void GRASS_EXPORT QgsGrass::init( void )
userGisbase = false;
break;
}
#if defined(WIN32)
gisBase = getShortPath(gisBase);
#endif
}

if (!valid)
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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

Expand All @@ -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() );

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 5d6e78e

Please sign in to comment.