@@ -49,7 +49,7 @@ extern "C"
49
49
#define G__setenv (name,value ) G__setenv( ( char * ) (name), (char *) (value) )
50
50
#endif
51
51
52
- #if defined(WIN32)
52
+ #ifdef Q_OS_WIN
53
53
#include < windows.h>
54
54
QString GRASS_LIB_EXPORT QgsGrass::shortPath ( const QString &path )
55
55
{
@@ -119,7 +119,7 @@ void GRASS_LIB_EXPORT QgsGrass::init( void )
119
119
// This is set when QGIS is run from within GRASS
120
120
// or when set explicitly by the user.
121
121
// This value should always take precedence.
122
- #if WIN32
122
+ #ifdef Q_OS_WIN
123
123
QString gisBase = getenv ( " WINGISBASE" ) ? getenv ( " WINGISBASE" ) : getenv ( " GISBASE" );
124
124
gisBase = shortPath ( gisBase );
125
125
#else
@@ -138,7 +138,7 @@ void GRASS_LIB_EXPORT QgsGrass::init( void )
138
138
// Erase gisbase from settings because it does not exists
139
139
settings.setValue ( " /GRASS/gisbase" , " " );
140
140
141
- #ifdef WIN32
141
+ #ifdef Q_OS_WIN
142
142
// Use the applicationDirPath()/grass
143
143
gisBase = shortPath ( QCoreApplication::applicationDirPath () + " /grass" );
144
144
QgsDebugMsg ( QString ( " GRASS gisBase = %1" ).arg ( gisBase ) );
@@ -179,7 +179,7 @@ void GRASS_LIB_EXPORT QgsGrass::init( void )
179
179
userGisbase = false ;
180
180
break ;
181
181
}
182
- #if defined(WIN32)
182
+ #ifdef Q_OS_WIN32
183
183
gisBase = shortPath ( gisBase );
184
184
#endif
185
185
}
@@ -200,7 +200,7 @@ void GRASS_LIB_EXPORT QgsGrass::init( void )
200
200
putEnv ( " GISBASE" , gisBase );
201
201
202
202
// Add path to GRASS modules
203
- #ifdef WIN32
203
+ #ifdef Q_OS_WIN
204
204
QString sep = " ;" ;
205
205
#else
206
206
QString sep = " :" ;
@@ -213,7 +213,7 @@ void GRASS_LIB_EXPORT QgsGrass::init( void )
213
213
// QgsApplication::prefixPath(), we have to add them
214
214
// to PATH to enable running of GRASS modules
215
215
// and database drivers
216
- #ifdef WIN32
216
+ #ifdef Q_OS_WIN
217
217
// It seems that QgsApplication::prefixPath()
218
218
// is not initialized at this point
219
219
path.append ( sep + shortPath ( QCoreApplication::applicationDirPath () ) );
@@ -343,7 +343,7 @@ void QgsGrass::setLocation( QString gisdbase, QString location )
343
343
init ();
344
344
345
345
// Set principal GRASS variables (in memory)
346
- #if defined(WIN32)
346
+ #ifdef Q_OS_WIN
347
347
G__setenv ( " GISDBASE" , shortPath ( gisdbase ).toLocal8Bit ().data () );
348
348
#else
349
349
// 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 )
364
364
init ();
365
365
366
366
// Set principal GRASS variables (in memory)
367
- #if defined(WIN32)
367
+ #ifdef Q_OS_WIN
368
368
G__setenv ( " GISDBASE" , shortPath ( gisdbase ).toUtf8 ().data () );
369
369
#else
370
370
G__setenv ( " GISDBASE" , gisdbase.toUtf8 ().data () );
@@ -453,15 +453,21 @@ QString GRASS_LIB_EXPORT QgsGrass::openMapset( QString gisdbase, QString locatio
453
453
return QObject::tr ( " %1 is not a GRASS mapset." ).arg ( mapsetPath );
454
454
}
455
455
456
- #ifndef Q_OS_WIN
457
456
QString lock = mapsetPath + " /.gislock" ;
458
- QFile lockFile ( lock );
459
- QProcess *process = new QProcess ();
460
- QString lockProgram ( gisBase + " /etc/lock" );
461
457
458
+ #ifndef _MSC_VER
462
459
int pid = getpid ();
460
+ #else
461
+ int pid = GetCurrentProcessId ();
462
+ #endif
463
+
463
464
QgsDebugMsg ( QString ( " pid = %1" ).arg ( pid ) );
464
465
466
+ #ifndef Q_OS_WIN
467
+ QFile lockFile ( lock );
468
+ QProcess *process = new QProcess ();
469
+ QString lockProgram ( gisBase + " /etc/lock" );
470
+
465
471
process->start ( lockProgram, QStringList () << lock << QString::number ( pid ) );
466
472
if ( !process->waitForStarted () )
467
473
{
@@ -477,7 +483,7 @@ QString GRASS_LIB_EXPORT QgsGrass::openMapset( QString gisdbase, QString locatio
477
483
478
484
if ( status > 0 )
479
485
return QObject::tr ( " Mapset is already in use." );
480
- #endif // !WIN32
486
+ #endif // Q_OS_WIN
481
487
482
488
// Create temporary directory
483
489
QFileInfo info ( mapsetPath );
@@ -490,13 +496,17 @@ QString GRASS_LIB_EXPORT QgsGrass::openMapset( QString gisdbase, QString locatio
490
496
QFileInfo dirInfo ( mTmp );
491
497
if ( !dirInfo.isWritable () )
492
498
{
499
+ #ifndef Q_OS_WIN
493
500
lockFile.remove ();
501
+ #endif
494
502
return QObject::tr ( " Temporary directory %1 exists but is not writable" ).arg ( mTmp );
495
503
}
496
504
}
497
505
else if ( !dir.mkdir ( mTmp ) )
498
506
{
507
+ #ifndef Q_OS_WIN
499
508
lockFile.remove ();
509
+ #endif
500
510
return QObject::tr ( " Cannot create temporary directory %1" ).arg ( mTmp );
501
511
}
502
512
@@ -510,7 +520,9 @@ QString GRASS_LIB_EXPORT QgsGrass::openMapset( QString gisdbase, QString locatio
510
520
QFile out ( mGisrc );
511
521
if ( !out.open ( QIODevice::WriteOnly ) )
512
522
{
523
+ #ifndef Q_OS_WIN
513
524
lockFile.remove ();
525
+ #endif
514
526
return QObject::tr ( " Cannot create %1" ).arg ( mGisrc );
515
527
}
516
528
QTextStream stream ( &out );
@@ -556,7 +568,7 @@ QString GRASS_LIB_EXPORT QgsGrass::openMapset( QString gisdbase, QString locatio
556
568
557
569
// Reinitialize GRASS
558
570
G__setenv ( " GISRC" , mGisrc .toUtf8 ().data () );
559
- #if defined(WIN32)
571
+ #ifdef Q_OS_WIN
560
572
G__setenv ( " GISDBASE" , shortPath ( gisdbase ).toLocal8Bit ().data () );
561
573
#else
562
574
G__setenv ( " GISDBASE" , gisdbase.toUtf8 ().data () );
@@ -569,12 +581,14 @@ QString GRASS_LIB_EXPORT QgsGrass::openMapset( QString gisdbase, QString locatio
569
581
570
582
active = true ;
571
583
584
+ #ifndef Q_OS_WIN
572
585
// Close old mapset
573
586
if ( mMapsetLock .length () > 0 )
574
587
{
575
588
QFile file ( mMapsetLock );
576
589
file.remove ();
577
590
}
591
+ #endif
578
592
579
593
mMapsetLock = lock;
580
594
@@ -587,11 +601,13 @@ QString QgsGrass::closeMapset( )
587
601
588
602
if ( mMapsetLock .length () > 0 )
589
603
{
604
+ #ifndef Q_OS_WIN
590
605
QFile file ( mMapsetLock );
591
606
if ( !file.remove () )
592
607
{
593
608
return QObject::tr ( " Cannot remove mapset lock: %1" ).arg ( mMapsetLock );
594
609
}
610
+ #endif
595
611
mMapsetLock = " " ;
596
612
597
613
putenv (( char * ) " GISRC" );
@@ -788,7 +804,7 @@ QStringList GRASS_LIB_EXPORT QgsGrass::vectorLayers( QString gisdbase,
788
804
// Vect_close here is correct, it should work, but it seems to cause
789
805
// crash on win http://trac.osgeo.org/qgis/ticket/2003
790
806
// disabled on win test it
791
- #if !defined(WIN32)
807
+ #ifndef Q_OS_WIN
792
808
Vect_close ( &map );
793
809
#endif
794
810
return list;
@@ -1130,7 +1146,7 @@ QProcess GRASS_LIB_EXPORT *QgsGrass::startModule( QString gisdbase, QString loca
1130
1146
QgsDebugMsg ( QString ( " gisdbase = %1 location = %2" ).arg ( gisdbase ).arg ( location ) );
1131
1147
QProcess *process = new QProcess ();
1132
1148
1133
- #ifdef WIN32
1149
+ #ifdef Q_OS_WIN
1134
1150
module += " .exe" ;
1135
1151
#endif
1136
1152
0 commit comments