@@ -49,7 +49,7 @@ extern "C"
4949#define G__setenv (name,value ) G__setenv( ( char * ) (name), (char *) (value) )
5050#endif
5151
52- #if defined(WIN32)
52+ #ifdef Q_OS_WIN
5353#include < windows.h>
5454QString GRASS_LIB_EXPORT QgsGrass::shortPath ( const QString &path )
5555{
@@ -119,7 +119,7 @@ void GRASS_LIB_EXPORT QgsGrass::init( void )
119119 // This is set when QGIS is run from within GRASS
120120 // or when set explicitly by the user.
121121 // This value should always take precedence.
122- #if WIN32
122+ #ifdef Q_OS_WIN
123123 QString gisBase = getenv ( " WINGISBASE" ) ? getenv ( " WINGISBASE" ) : getenv ( " GISBASE" );
124124 gisBase = shortPath ( gisBase );
125125#else
@@ -138,7 +138,7 @@ void GRASS_LIB_EXPORT QgsGrass::init( void )
138138 // Erase gisbase from settings because it does not exists
139139 settings.setValue ( " /GRASS/gisbase" , " " );
140140
141- #ifdef WIN32
141+ #ifdef Q_OS_WIN
142142 // Use the applicationDirPath()/grass
143143 gisBase = shortPath ( QCoreApplication::applicationDirPath () + " /grass" );
144144 QgsDebugMsg ( QString ( " GRASS gisBase = %1" ).arg ( gisBase ) );
@@ -179,7 +179,7 @@ void GRASS_LIB_EXPORT QgsGrass::init( void )
179179 userGisbase = false ;
180180 break ;
181181 }
182- #if defined(WIN32)
182+ #ifdef Q_OS_WIN32
183183 gisBase = shortPath ( gisBase );
184184#endif
185185 }
@@ -200,7 +200,7 @@ void GRASS_LIB_EXPORT QgsGrass::init( void )
200200 putEnv ( " GISBASE" , gisBase );
201201
202202 // Add path to GRASS modules
203- #ifdef WIN32
203+ #ifdef Q_OS_WIN
204204 QString sep = " ;" ;
205205#else
206206 QString sep = " :" ;
@@ -213,7 +213,7 @@ void GRASS_LIB_EXPORT QgsGrass::init( void )
213213 // QgsApplication::prefixPath(), we have to add them
214214 // to PATH to enable running of GRASS modules
215215 // and database drivers
216- #ifdef WIN32
216+ #ifdef Q_OS_WIN
217217 // It seems that QgsApplication::prefixPath()
218218 // is not initialized at this point
219219 path.append ( sep + shortPath ( QCoreApplication::applicationDirPath () ) );
@@ -343,7 +343,7 @@ void QgsGrass::setLocation( QString gisdbase, QString location )
343343 init ();
344344
345345 // Set principal GRASS variables (in memory)
346- #if defined(WIN32)
346+ #ifdef Q_OS_WIN
347347 G__setenv ( " GISDBASE" , shortPath ( gisdbase ).toLocal8Bit ().data () );
348348#else
349349 // This does not work for GISBASE with non ascii chars on Windows XP,
@@ -364,7 +364,7 @@ void QgsGrass::setMapset( QString gisdbase, QString location, QString mapset )
364364 init ();
365365
366366 // Set principal GRASS variables (in memory)
367- #if defined(WIN32)
367+ #ifdef Q_OS_WIN
368368 G__setenv ( " GISDBASE" , shortPath ( gisdbase ).toUtf8 ().data () );
369369#else
370370 G__setenv ( " GISDBASE" , gisdbase.toUtf8 ().data () );
@@ -453,15 +453,21 @@ QString GRASS_LIB_EXPORT QgsGrass::openMapset( QString gisdbase, QString locatio
453453 return QObject::tr ( " %1 is not a GRASS mapset." ).arg ( mapsetPath );
454454 }
455455
456- #ifndef Q_OS_WIN
457456 QString lock = mapsetPath + " /.gislock" ;
458- QFile lockFile ( lock );
459- QProcess *process = new QProcess ();
460- QString lockProgram ( gisBase + " /etc/lock" );
461457
458+ #ifndef _MSC_VER
462459 int pid = getpid ();
460+ #else
461+ int pid = GetCurrentProcessId ();
462+ #endif
463+
463464 QgsDebugMsg ( QString ( " pid = %1" ).arg ( pid ) );
464465
466+ #ifndef Q_OS_WIN
467+ QFile lockFile ( lock );
468+ QProcess *process = new QProcess ();
469+ QString lockProgram ( gisBase + " /etc/lock" );
470+
465471 process->start ( lockProgram, QStringList () << lock << QString::number ( pid ) );
466472 if ( !process->waitForStarted () )
467473 {
@@ -477,7 +483,7 @@ QString GRASS_LIB_EXPORT QgsGrass::openMapset( QString gisdbase, QString locatio
477483
478484 if ( status > 0 )
479485 return QObject::tr ( " Mapset is already in use." );
480- #endif // !WIN32
486+ #endif // Q_OS_WIN
481487
482488 // Create temporary directory
483489 QFileInfo info ( mapsetPath );
@@ -490,13 +496,17 @@ QString GRASS_LIB_EXPORT QgsGrass::openMapset( QString gisdbase, QString locatio
490496 QFileInfo dirInfo ( mTmp );
491497 if ( !dirInfo.isWritable () )
492498 {
499+ #ifndef Q_OS_WIN
493500 lockFile.remove ();
501+ #endif
494502 return QObject::tr ( " Temporary directory %1 exists but is not writable" ).arg ( mTmp );
495503 }
496504 }
497505 else if ( !dir.mkdir ( mTmp ) )
498506 {
507+ #ifndef Q_OS_WIN
499508 lockFile.remove ();
509+ #endif
500510 return QObject::tr ( " Cannot create temporary directory %1" ).arg ( mTmp );
501511 }
502512
@@ -510,7 +520,9 @@ QString GRASS_LIB_EXPORT QgsGrass::openMapset( QString gisdbase, QString locatio
510520 QFile out ( mGisrc );
511521 if ( !out.open ( QIODevice::WriteOnly ) )
512522 {
523+ #ifndef Q_OS_WIN
513524 lockFile.remove ();
525+ #endif
514526 return QObject::tr ( " Cannot create %1" ).arg ( mGisrc );
515527 }
516528 QTextStream stream ( &out );
@@ -556,7 +568,7 @@ QString GRASS_LIB_EXPORT QgsGrass::openMapset( QString gisdbase, QString locatio
556568
557569 // Reinitialize GRASS
558570 G__setenv ( " GISRC" , mGisrc .toUtf8 ().data () );
559- #if defined(WIN32)
571+ #ifdef Q_OS_WIN
560572 G__setenv ( " GISDBASE" , shortPath ( gisdbase ).toLocal8Bit ().data () );
561573#else
562574 G__setenv ( " GISDBASE" , gisdbase.toUtf8 ().data () );
@@ -569,12 +581,14 @@ QString GRASS_LIB_EXPORT QgsGrass::openMapset( QString gisdbase, QString locatio
569581
570582 active = true ;
571583
584+ #ifndef Q_OS_WIN
572585 // Close old mapset
573586 if ( mMapsetLock .length () > 0 )
574587 {
575588 QFile file ( mMapsetLock );
576589 file.remove ();
577590 }
591+ #endif
578592
579593 mMapsetLock = lock;
580594
@@ -587,11 +601,13 @@ QString QgsGrass::closeMapset( )
587601
588602 if ( mMapsetLock .length () > 0 )
589603 {
604+ #ifndef Q_OS_WIN
590605 QFile file ( mMapsetLock );
591606 if ( !file.remove () )
592607 {
593608 return QObject::tr ( " Cannot remove mapset lock: %1" ).arg ( mMapsetLock );
594609 }
610+ #endif
595611 mMapsetLock = " " ;
596612
597613 putenv (( char * ) " GISRC" );
@@ -788,7 +804,7 @@ QStringList GRASS_LIB_EXPORT QgsGrass::vectorLayers( QString gisdbase,
788804 // Vect_close here is correct, it should work, but it seems to cause
789805 // crash on win http://trac.osgeo.org/qgis/ticket/2003
790806 // disabled on win test it
791- #if !defined(WIN32)
807+ #ifndef Q_OS_WIN
792808 Vect_close ( &map );
793809#endif
794810 return list;
@@ -1130,7 +1146,7 @@ QProcess GRASS_LIB_EXPORT *QgsGrass::startModule( QString gisdbase, QString loca
11301146 QgsDebugMsg ( QString ( " gisdbase = %1 location = %2" ).arg ( gisdbase ).arg ( location ) );
11311147 QProcess *process = new QProcess ();
11321148
1133- #ifdef WIN32
1149+ #ifdef Q_OS_WIN
11341150 module += " .exe" ;
11351151#endif
11361152
0 commit comments