better prefix guessing on Windows

see https://github.com/tumagonx/pygi-mingw-patches/issues/5
This commit is contained in:
John Cupitt 2017-05-13 11:11:32 +01:00
parent 82994e4c33
commit 6dbdc173a2
4 changed files with 22 additions and 31 deletions

View File

@ -7,6 +7,7 @@
- vips_conv(), vips_compass(), vips_convsep() default to FLOAT precision
- add FORCE resize mode to break aspect ratio
- add vips_thumbnail_image()
- better prefix guessing on Windows, thanks tumagonx
23/4/17 started 8.5.5
- doc polishing

View File

@ -332,7 +332,7 @@ guint32 vips__random( guint32 seed );
guint32 vips__random_add( guint32 seed, int value );
const char *vips__icc_dir( void );
const char *vips__locale_dir( void );
const char *vips__windows_prefix( void );
#ifdef __cplusplus
}

View File

@ -267,6 +267,7 @@ vips_init( const char *argv0 )
char *prgname;
const char *prefix;
const char *libdir;
char *locale;
/* Two stage done handling: 'done' means we've completed, 'started'
* means we're currently initialising. Use this to prevent recursive
@ -341,7 +342,9 @@ vips_init( const char *argv0 )
/* Get i18n .mo files from $VIPSHOME/share/locale/.
*/
bindtextdomain( GETTEXT_PACKAGE, vips__locale_dir() );
locale = g_build_filename( prefix, "share", "locale", NULL );
bindtextdomain( GETTEXT_PACKAGE, locale );
g_free( locale );
bind_textdomain_codeset( GETTEXT_PACKAGE, "UTF-8" );
/* Deprecated, this is just for compat.
@ -953,8 +956,6 @@ const char *
vips_guess_prefix( const char *argv0, const char *env_name )
{
const char *prefix;
char *basename;
char name[VIPS_PATH_MAX];
/* Already set?
*/
@ -966,29 +967,18 @@ vips_guess_prefix( const char *argv0, const char *env_name )
return( prefix );
}
/* Get the program name from argv0.
*/
#ifdef OS_WIN32
prefix = vips__windows_prefix();
#else
{
char *basename;
basename = g_path_get_basename( argv0 );
/* Add the exe suffix, if it's missing.
*/
if( strlen( VIPS_EXEEXT ) > 0 ) {
const char *olds[] = { VIPS_EXEEXT };
vips__change_suffix( basename, name,
VIPS_PATH_MAX, VIPS_EXEEXT, olds, 1 );
}
else
vips_strncpy( name, basename, VIPS_PATH_MAX );
prefix = guess_prefix( argv0, basename );
g_free( basename );
}
#endif
#ifdef DEBUG
printf( "vips_guess_prefix: argv0 = %s\n", argv0 );
printf( "vips_guess_prefix: name = %s\n", name );
#endif /*DEBUG*/
prefix = guess_prefix( argv0, name );
g_setenv( env_name, prefix, TRUE );
return( prefix );

View File

@ -1970,13 +1970,13 @@ vips__icc_dir( void )
}
#ifdef OS_WIN32
static HMODULE vips_dll = NULL;
static HMODULE vips__dll = NULL;
#ifdef DLL_EXPORT
BOOL WINAPI
DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved )
{
if( fdwReason == DLL_PROCESS_ATTACH )
vips_dll = hinstDLL;
vips__dll = hinstDLL;
return( TRUE );
}
@ -1984,25 +1984,25 @@ DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved )
#endif
static void *
vips_locale_dir_once( void *null )
vips__windows_prefix_once( void *null )
{
char *prefix;
#ifdef OS_WIN32
prefix = g_win32_get_package_installation_directory_of_module(
vips_dll ),
vips__dll ),
#else
prefix = (char *) g_getenv( "VIPSHOME" );
#endif
return( (void *) g_build_filename( prefix, "share", "locale", NULL ) );
return( (void *) prefix );
}
const char *
vips__locale_dir( void )
vips__windows_prefix( void )
{
static GOnce once = G_ONCE_INIT;
return( (const char *) g_once( &once,
(GThreadFunc) vips_locale_dir_once, NULL ) );
(GThreadFunc) vips__windows_prefix_once, NULL ) );
}