-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
osgeo4w: add a minimal exe wrapper to initialize the enviroment and load
qgis_app.dll (inspired by Nathan's PR #4156) On install each shortcut/configuration gets a own copy of the (small) exe. That exe is started through the batch file that originally was used to start the app at runtime. Argument --exit will cause the wrapper to just dump the environment to an .env file next to the copy of the .exe. The created shortcuts now point at those .exes instead of the batch files. At runtime the .exes source their .env file to get a working environment to run QGIS (ie. qgis_app.dll). This for example allows the application to be pinned to the taskbar and avoids the of necessity of batch files at runtime to start the app.
- Loading branch information
Showing
13 changed files
with
208 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
PATH | ||
GDAL_DATA | ||
GDAL_DRIVER_PATH | ||
GDAL_FILENAME_IS_UTF8 | ||
GEOTIFF_CSV | ||
GISBASE | ||
GRASS_HTML_BROWSER | ||
GRASS_PROJSHARE | ||
GRASS_PYTHON | ||
GRASS_SH | ||
GRASS_WISH | ||
JPEGMEM | ||
NLS_LANG | ||
OSGEO4W_ROOT | ||
PROJ_LIB | ||
PYTHONHOME | ||
PYTHONPATH | ||
QGIS_PREFIX_PATH | ||
QT_PLUGIN_PATH | ||
QT_RASTER_CLIP_LIMIT | ||
VSI_CACHE | ||
VSI_CACHE_SIZE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
#include <windows.h> | ||
#include <io.h> | ||
|
||
#include <sstream> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <list> | ||
|
||
std::string moduleExeBaseName( void ) | ||
{ | ||
DWORD l = MAX_PATH; | ||
std::auto_ptr<char> filepath; | ||
for ( ;; ) | ||
{ | ||
filepath.reset( new char[l] ); | ||
if ( GetModuleFileName( nullptr, filepath.get(), l ) < l ) | ||
break; | ||
|
||
l += MAX_PATH; | ||
} | ||
|
||
std::string basename( filepath.get() ); | ||
basename.resize( basename.length() - 4 ); | ||
return basename; | ||
} | ||
|
||
|
||
int CALLBACK WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) | ||
{ | ||
std::string basename( moduleExeBaseName() ); | ||
|
||
if ( getenv( "OSGEO4W_ROOT" ) ) | ||
{ | ||
std::string envfile( basename + ".env" ); | ||
|
||
// write or update environment file | ||
if ( _access( envfile.c_str(), 0 ) < 0 || _access( envfile.c_str(), 2 ) == 0 ) | ||
{ | ||
std::list<std::string> vars; | ||
|
||
try | ||
{ | ||
std::ifstream varfile; | ||
varfile.open( basename + ".vars" ); | ||
|
||
std::string var; | ||
while ( std::getline( varfile, var ) ) | ||
{ | ||
vars.push_back( var ); | ||
} | ||
|
||
varfile.close(); | ||
} | ||
catch ( std::ifstream::failure e ) | ||
{ | ||
std::cerr << "could read environment variable list " << basename + ".vars" << " [" << e.what() << "]" << std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
|
||
try | ||
{ | ||
std::ofstream file; | ||
file.open( envfile, std::ifstream::out ); | ||
|
||
for ( std::list<std::string>::const_iterator it = vars.begin(); it != vars.end(); ++it ) | ||
{ | ||
if ( getenv( it->c_str() ) ) | ||
file << *it << "=" << getenv( it->c_str() ) << std::endl; | ||
} | ||
} | ||
catch ( std::ifstream::failure e ) | ||
{ | ||
std::cerr << "could not write environment file " << basename + ".env" << " [" << e.what() << "]" << std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
} | ||
|
||
if ( __argc == 2 && strcmp( __argv[1], "--exit" ) == 0 ) | ||
{ | ||
return EXIT_SUCCESS; | ||
} | ||
} | ||
else | ||
{ | ||
try | ||
{ | ||
std::ifstream file; | ||
file.open( basename + ".env" ); | ||
|
||
std::string var; | ||
while ( std::getline( file, var ) ) | ||
{ | ||
if ( _putenv( var.c_str() ) < 0 ) | ||
{ | ||
std::cerr << "could not set environment variable:" << var << std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
} | ||
} | ||
catch ( std::ifstream::failure e ) | ||
{ | ||
std::cerr << "could not read environment file " << basename + ".env" << " [" << e.what() << "]" << std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
} | ||
|
||
HINSTANCE hGetProcIDDLL = LoadLibrary( "qgis_app.dll" ); | ||
if ( !hGetProcIDDLL ) | ||
{ | ||
std::cerr << "Could not load the qgis_app.dll" << std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
|
||
int ( *realmain )( int, char*[] ) = ( int ( * )( int, char * [] ) ) GetProcAddress( hGetProcIDDLL, "main" ); | ||
if ( !realmain ) | ||
{ | ||
std::cerr << "could not locate main function in qgis_app.dll" << std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
|
||
return realmain( __argc, __argv ); | ||
} |
801184a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jef-n the standalone browser will also need to be updated to match, right?
Can we use a similar approach with the python libraries? It'd be nice to only have to set the python path and not all the other env variables to be able to import qgis libraries...
801184a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nyalldawson done for the browser.