@@ -41,8 +41,14 @@ extern "C" {
41
41
#include < grass/version.h>
42
42
}
43
43
44
- #if defined(_MSC_VER)
45
- #include < windows.h> // for GetCurrentProcessId()
44
+ #if defined(WIN32)
45
+ #include < windows.h>
46
+ static QString getShortPath (const QString &path)
47
+ {
48
+ TCHAR buf[MAX_PATH];
49
+ GetShortPathName ( path.ascii (), buf, MAX_PATH);
50
+ return buf;
51
+ }
46
52
#endif
47
53
48
54
void GRASS_EXPORT QgsGrass::init ( void )
@@ -104,7 +110,7 @@ void GRASS_EXPORT QgsGrass::init( void )
104
110
105
111
#ifdef WIN32
106
112
// Use the applicationDirPath()/grass
107
- gisBase = QCoreApplication::applicationDirPath () + " /grass" ;
113
+ gisBase = getShortPath ( QCoreApplication::applicationDirPath () + " /grass" ) ;
108
114
#ifdef QGISDEBUG
109
115
std::cerr << " GRASS gisBase = " << gisBase.ascii () << std::endl;
110
116
#endif
@@ -148,6 +154,9 @@ void GRASS_EXPORT QgsGrass::init( void )
148
154
userGisbase = false ;
149
155
break ;
150
156
}
157
+ #if defined(WIN32)
158
+ gisBase = getShortPath (gisBase);
159
+ #endif
151
160
}
152
161
153
162
if (!valid)
@@ -187,14 +196,11 @@ void GRASS_EXPORT QgsGrass::init( void )
187
196
#ifdef WIN32
188
197
// It seems that QgsApplication::prefixPath()
189
198
// is not initialized at this point
190
- path.append ( sep + QCoreApplication::applicationDirPath () );
191
- #endif
199
+ path.append ( sep + getShortPath (QCoreApplication::applicationDirPath ()) );
192
200
193
- #ifdef WIN32
194
201
// Add path to MSYS bin
195
202
// Warning: MSYS sh.exe will translate this path to '/bin'
196
- path.append ( sep + QCoreApplication::applicationDirPath ()
197
- + " /msys/bin/" );
203
+ path.append ( sep + getShortPath (QCoreApplication::applicationDirPath () + " /msys/bin/" ) );
198
204
#endif
199
205
200
206
QString p = getenv (" PATH" );
@@ -262,7 +268,8 @@ bool QgsGrass::isValidGrassBaseDir(QString const gisBase)
262
268
#ifdef QGISDEBUG
263
269
std::cerr << " isValidGrassBaseDir()" << std::endl;
264
270
#endif
265
- if ( gisBase.isEmpty () )
271
+ // GRASS currently doesn't handle paths with blanks
272
+ if ( gisBase.isEmpty () || gisBase.contains (" " ) )
266
273
{
267
274
return FALSE ;
268
275
}
@@ -316,7 +323,11 @@ void QgsGrass::setLocation( QString gisdbase, QString location )
316
323
init ();
317
324
318
325
// Set principal GRASS variables (in memory)
319
- G__setenv ( " GISDBASE" , (char *) gisdbase.ascii () );
326
+ #if defined(WIN32)
327
+ G__setenv ( " GISDBASE" , (char *) getShortPath (gisdbase).ascii () );
328
+ #else
329
+ G__setenv ( " GISDBASE" , (char *) gisdbase.ascii () );
330
+ #endif
320
331
G__setenv ( " LOCATION_NAME" , (char *) location.ascii () );
321
332
G__setenv ( " MAPSET" , " PERMANENT" ); // PERMANENT must always exist
322
333
@@ -334,7 +345,11 @@ void QgsGrass::setMapset( QString gisdbase, QString location, QString mapset )
334
345
init ();
335
346
336
347
// Set principal GRASS variables (in memory)
337
- G__setenv ( " GISDBASE" , (char *) gisdbase.ascii () );
348
+ #if defined(WIN32)
349
+ G__setenv ( " GISDBASE" , (char *) getShortPath (gisdbase).ascii () );
350
+ #else
351
+ G__setenv ( " GISDBASE" , (char *) gisdbase.ascii () );
352
+ #endif
338
353
G__setenv ( " LOCATION_NAME" , (char *) location.ascii () );
339
354
G__setenv ( " MAPSET" , (char *) mapset.ascii () );
340
355
@@ -539,8 +554,12 @@ QString GRASS_EXPORT QgsGrass::openMapset ( QString gisdbase, QString location,
539
554
putenv ( gisrcEnvChar );
540
555
541
556
// Reinitialize GRASS
542
- G__setenv ( " GISRC" , const_cast <char *>(gisrcEnv.ascii ()) );
543
- G__setenv ( " GISDBASE" , const_cast <char *>(gisdbase.ascii ()) );
557
+ G__setenv ( " GISRC" , const_cast <char *>(gisrcEnv.ascii ()) );
558
+ #if defined(WIN32)
559
+ G__setenv ( " GISDBASE" , const_cast <char *>(getShortPath (gisdbase).ascii ()) );
560
+ #else
561
+ G__setenv ( " GISDBASE" , const_cast <char *>(gisdbase.ascii ()) );
562
+ #endif
544
563
G__setenv ( " LOCATION_NAME" , const_cast <char *>(location.ascii ()) );
545
564
G__setenv ( " MAPSET" , const_cast <char *>(mapset.ascii ()) );
546
565
defaultGisdbase = gisdbase;
0 commit comments