Skip to content

Commit

Permalink
osgeo4w: fix postinstall scripts (fixes #17993)
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Jan 31, 2018
1 parent 70fc32b commit 2a52a62
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 28 deletions.
2 changes: 1 addition & 1 deletion ms-windows/osgeo4w/postinstall-desktop.bat
Expand Up @@ -6,7 +6,7 @@ REM get short path without blanks
for %%i in ("%OSGEO4W_ROOT%") do set O4W_ROOT=%%~fsi for %%i in ("%OSGEO4W_ROOT%") do set O4W_ROOT=%%~fsi
if "%OSGEO4W_DESKTOP%"=="" set OSGEO4W_DESKTOP=~$folder.common_desktop$ if "%OSGEO4W_DESKTOP%"=="" set OSGEO4W_DESKTOP=~$folder.common_desktop$


"%OSGEO4W_ROOT%\bin\@package@.bat" --exit call "%OSGEO4W_ROOT%\bin\@package@.bat" --postinstall


if not %OSGEO4W_MENU_LINKS%==0 mkdir "%OSGEO4W_STARTMENU%" if not %OSGEO4W_MENU_LINKS%==0 mkdir "%OSGEO4W_STARTMENU%"
if not %OSGEO4W_DESKTOP_LINKS%==0 mkdir "%OSGEO4W_DESKTOP%" if not %OSGEO4W_DESKTOP_LINKS%==0 mkdir "%OSGEO4W_DESKTOP%"
Expand Down
2 changes: 1 addition & 1 deletion ms-windows/osgeo4w/postinstall-dev.bat
Expand Up @@ -10,7 +10,7 @@ for %%g in (@grassversions@) do (
copy "%OSGEO4W_ROOT%\bin\@package@-bin.exe" "%OSGEO4W_ROOT%\bin\@package@-bin-g%%g.exe" copy "%OSGEO4W_ROOT%\bin\@package@-bin.exe" "%OSGEO4W_ROOT%\bin\@package@-bin-g%%g.exe"
copy "%OSGEO4W_ROOT%\bin\@package@-bin.vars" "%OSGEO4W_ROOT%\bin\@package@-bin-g%%g.vars" copy "%OSGEO4W_ROOT%\bin\@package@-bin.vars" "%OSGEO4W_ROOT%\bin\@package@-bin-g%%g.vars"
textreplace -std -t bin\@package@-g%%g.bat textreplace -std -t bin\@package@-g%%g.bat
"%OSGEO4W_ROOT%\bin\@package@-g%%g.bat" --exit call "%OSGEO4W_ROOT%\bin\@package@-g%%g.bat" --postinstall


if not %OSGEO4W_MENU_LINKS%==0 nircmd shortcut "%OSGEO4W_ROOT%\bin\@package@-bin-g%%g.exe" "%OSGEO4W_STARTMENU%" "QGIS Desktop @version@ with GRASS %%g (Nightly)" if not %OSGEO4W_MENU_LINKS%==0 nircmd shortcut "%OSGEO4W_ROOT%\bin\@package@-bin-g%%g.exe" "%OSGEO4W_STARTMENU%" "QGIS Desktop @version@ with GRASS %%g (Nightly)"
if not %OSGEO4W_DESKTOP_LINKS%==0 nircmd shortcut "%OSGEO4W_ROOT%\bin\@package@-bin-g%%g.exe" "%OSGEO4W_DESKTOP%" "QGIS Desktop @version@ with GRASS %%g (Nightly)" if not %OSGEO4W_DESKTOP_LINKS%==0 nircmd shortcut "%OSGEO4W_ROOT%\bin\@package@-bin-g%%g.exe" "%OSGEO4W_DESKTOP%" "QGIS Desktop @version@ with GRASS %%g (Nightly)"
Expand Down
2 changes: 1 addition & 1 deletion ms-windows/osgeo4w/postinstall-grass.bat
Expand Up @@ -4,7 +4,7 @@ if "%OSGEO4W_DESKTOP%"=="" set OSGEO4W_DESKTOP=~$folder.common_desktop$


copy bin\@package@-bin.exe bin\@package@-bin-grass@grassmajor@.exe copy bin\@package@-bin.exe bin\@package@-bin-grass@grassmajor@.exe
copy bin\@package@-bin.vars bin\@package@-bin-grass@grassmajor@.vars copy bin\@package@-bin.vars bin\@package@-bin-grass@grassmajor@.vars
"%OSGEO4W_ROOT%\bin\@package@-grass@grassmajor@.bat" --exit call "%OSGEO4W_ROOT%\bin\@package@-grass@grassmajor@.bat" --postinstall


if not %OSGEO4W_MENU_LINKS%==0 mkdir "%OSGEO4W_STARTMENU%" if not %OSGEO4W_MENU_LINKS%==0 mkdir "%OSGEO4W_STARTMENU%"
if not %OSGEO4W_DESKTOP_LINKS%==0 mkdir "%OSGEO4W_DESKTOP%" if not %OSGEO4W_DESKTOP_LINKS%==0 mkdir "%OSGEO4W_DESKTOP%"
Expand Down
45 changes: 20 additions & 25 deletions src/app/mainwin.cpp
Expand Up @@ -42,7 +42,7 @@ int CALLBACK WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdL
{ {
std::string basename( moduleExeBaseName() ); std::string basename( moduleExeBaseName() );


if ( getenv( "OSGEO4W_ROOT" ) ) if ( getenv( "OSGEO4W_ROOT" ) && __argc == 2 && strcmp( __argv[1], "--postinstall" ) == 0 )
{ {
std::string envfile( basename + ".env" ); std::string envfile( basename + ".env" );


Expand Down Expand Up @@ -90,41 +90,36 @@ int CALLBACK WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdL
} }
} }


if ( __argc == 2 && strcmp( __argv[1], "--exit" ) == 0 ) return EXIT_SUCCESS;
{
return EXIT_SUCCESS;
}
} }
else
try
{ {
try std::ifstream file;
{ file.open( basename + ".env" );
std::ifstream file;
file.open( basename + ".env" );


std::string var; std::string var;
while ( std::getline( file, var ) ) while ( std::getline( file, var ) )
{
if ( _putenv( var.c_str() ) < 0 )
{ {
if ( _putenv( var.c_str() ) < 0 ) std::string message = "Could not set environment variable:" + var;
{ showError( message, "Error loading QGIS" );
std::string message = "Could not set environment variable:" + var; return EXIT_FAILURE;
showError( message, "Error loading QGIS" );
return EXIT_FAILURE;
}
} }
} }
catch ( std::ifstream::failure e ) }
{ catch ( std::ifstream::failure e )
std::string message = "Could not read environment file " + basename + ".env" + " [" + e.what() + "]"; {
showError( message, "Error loading QGIS" ); std::string message = "Could not read environment file " + basename + ".env" + " [" + e.what() + "]";
return EXIT_FAILURE; showError( message, "Error loading QGIS" );
} return EXIT_FAILURE;
} }


#ifdef _MSC_VER #ifdef _MSC_VER
HINSTANCE hGetProcIDDLL = LoadLibrary( "qgis_app.dll" ); HINSTANCE hGetProcIDDLL = LoadLibrary( "qgis_app.dll" );
#else #else
// MinGW // MinGW
HINSTANCE hGetProcIDDLL = LoadLibrary( "libqgis_app.dll" ); HINSTANCE hGetProcIDDLL = LoadLibrary( "libqgis_app.dll" );
#endif #endif


Expand Down

0 comments on commit 2a52a62

Please sign in to comment.