[QGIS Commit] r8256 - in trunk/qgis/src: plugins/grass
providers/grass
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Thu Mar 20 17:39:51 EDT 2008
Author: jef
Date: 2008-03-20 17:39:51 -0400 (Thu, 20 Mar 2008)
New Revision: 8256
Modified:
trunk/qgis/src/plugins/grass/qgsgrassmodule.cpp
trunk/qgis/src/plugins/grass/qgsgrassnewmapset.cpp
trunk/qgis/src/plugins/grass/qgsgrasstools.cpp
trunk/qgis/src/providers/grass/qgsgrass.cpp
Log:
fix #1005 by making GRASS work in paths with blanks (windows-only)
Modified: trunk/qgis/src/plugins/grass/qgsgrassmodule.cpp
===================================================================
--- trunk/qgis/src/plugins/grass/qgsgrassmodule.cpp 2008-03-20 07:55:02 UTC (rev 8255)
+++ trunk/qgis/src/plugins/grass/qgsgrassmodule.cpp 2008-03-20 21:39:51 UTC (rev 8256)
@@ -91,6 +91,16 @@
#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 @@
#ifdef WIN32
mExecPath = path.split ( ";" );
+ mExecPath.prepend ( getShortPath(QgsApplication::applicationDirPath()) );
#else
mExecPath = path.split ( ":" );
+ mExecPath.prepend ( QgsApplication::applicationDirPath() );
#endif
- mExecPath.prepend ( QgsApplication::applicationDirPath() );
mExecPathInited = true;
}
@@ -168,7 +179,7 @@
}
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
Modified: trunk/qgis/src/plugins/grass/qgsgrassnewmapset.cpp
===================================================================
--- trunk/qgis/src/plugins/grass/qgsgrassnewmapset.cpp 2008-03-20 07:55:02 UTC (rev 8255)
+++ trunk/qgis/src/plugins/grass/qgsgrassnewmapset.cpp 2008-03-20 21:39:51 UTC (rev 8256)
@@ -72,6 +72,16 @@
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 @@
// 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,
Modified: trunk/qgis/src/plugins/grass/qgsgrasstools.cpp
===================================================================
--- trunk/qgis/src/plugins/grass/qgsgrasstools.cpp 2008-03-20 07:55:02 UTC (rev 8255)
+++ trunk/qgis/src/plugins/grass/qgsgrasstools.cpp 2008-03-20 21:39:51 UTC (rev 8256)
@@ -71,6 +71,16 @@
#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 @@
QString QgsGrassTools::appDir(void)
{
+#if defined(WIN32)
+ return getShortPath(QgsApplication::applicationDirPath());
+#else
return QgsApplication::applicationDirPath();
+#endif
}
void QgsGrassTools::close(void)
Modified: trunk/qgis/src/providers/grass/qgsgrass.cpp
===================================================================
--- trunk/qgis/src/providers/grass/qgsgrass.cpp 2008-03-20 07:55:02 UTC (rev 8255)
+++ trunk/qgis/src/providers/grass/qgsgrass.cpp 2008-03-20 21:39:51 UTC (rev 8256)
@@ -41,8 +41,14 @@
#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 @@
#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 @@
userGisbase = false;
break;
}
+#if defined(WIN32)
+ gisBase = getShortPath(gisBase);
+#endif
}
if (!valid)
@@ -187,14 +196,11 @@
#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 @@
#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 @@
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 @@
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 @@
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;
More information about the QGIS-commit
mailing list