+ return VLC_SUCCESS;
+ }
+
+#if defined(__APPLE__) || defined(SYS_BEOS)
+ if( !val.psz_string )
+ {
+ if( asprintf( &val.psz_string, "%s/Desktop",
+ config_GetHomeDir() ) == -1 )
+ val.psz_string = NULL;
+ }
+
+#elif defined(WIN32) && !defined(UNDER_CE)
+ if( !val.psz_string )
+ {
+ /* Get the My Pictures folder path */
+
+ char *p_mypicturesdir = NULL;
+ typedef HRESULT (WINAPI *SHGETFOLDERPATH)( HWND, int, HANDLE, DWORD,
+ LPWSTR );
+ #ifndef CSIDL_FLAG_CREATE
+ # define CSIDL_FLAG_CREATE 0x8000
+ #endif
+ #ifndef CSIDL_MYPICTURES
+ # define CSIDL_MYPICTURES 0x27
+ #endif
+ #ifndef SHGFP_TYPE_CURRENT
+ # define SHGFP_TYPE_CURRENT 0
+ #endif
+
+ HINSTANCE shfolder_dll;
+ SHGETFOLDERPATH SHGetFolderPath ;
+
+ /* load the shfolder dll to retrieve SHGetFolderPath */
+ if( ( shfolder_dll = LoadLibrary( _T("SHFolder.dll") ) ) != NULL )
+ {
+ wchar_t wdir[PATH_MAX];
+ SHGetFolderPath = (void *)GetProcAddress( shfolder_dll,
+ _T("SHGetFolderPathW") );
+ if ((SHGetFolderPath != NULL )
+ && SUCCEEDED (SHGetFolderPath (NULL,
+ CSIDL_MYPICTURES | CSIDL_FLAG_CREATE,
+ NULL, SHGFP_TYPE_CURRENT,
+ wdir)))
+ p_mypicturesdir = FromWide (wdir);
+
+ FreeLibrary( shfolder_dll );
+ }
+
+ if( p_mypicturesdir == NULL )
+ val.psz_string = strdup( config_GetHomeDir() );
+ else
+ val.psz_string = p_mypicturesdir;
+ }
+
+#else
+ /* XXX: This saves in the data directory. Shouldn't we try saving
+ * to psz_homedir/Desktop or something nicer ? */
+ char *psz_datadir = config_GetUserDataDir();
+ if( !val.psz_string && psz_datadir )
+ {
+ if( asprintf( &val.psz_string, "%s", psz_datadir ) == -1 )
+ val.psz_string = NULL;
+ }
+ free( psz_datadir );
+#endif
+
+ if( !val.psz_string )
+ {
+ msg_Err( p_vout, "no path specified for snapshots" );
+ image_HandlerDelete( p_image );
+ return VLC_EGENERIC;
+ }
+ var_Get( p_vout, "snapshot-format", &format );
+ if( !format.psz_string || !*format.psz_string )
+ {
+ free( format.psz_string );
+ format.psz_string = strdup( "png" );
+ }
+
+ /*
+ * Did the user specify a directory? If not, path = NULL.
+ */
+ path = utf8_opendir ( (const char *)val.psz_string );
+ if( path != NULL )
+ {
+ char *psz_prefix = var_GetNonEmptyString( p_vout, "snapshot-prefix" );
+ if( psz_prefix == NULL )
+ psz_prefix = strdup( "vlcsnap-" );
+ else
+ {
+ char *psz_tmp = str_format( p_vout, psz_prefix );
+ filename_sanitize( psz_tmp );
+ free( psz_prefix );
+ psz_prefix = psz_tmp;
+ }
+
+ closedir( path );
+ if( var_GetBool( p_vout, "snapshot-sequential" ) == true )
+ {
+ int i_num = var_GetInteger( p_vout, "snapshot-num" );
+ FILE *p_file;
+ do
+ {
+ if( asprintf( &psz_filename, "%s" DIR_SEP "%s%05d.%s",
+ val.psz_string, psz_prefix, i_num++,
+ format.psz_string ) == -1 )
+ {
+ msg_Err( p_vout, "could not create snapshot" );
+ image_HandlerDelete( p_image );
+ return VLC_EGENERIC;
+ }
+ }
+ while( ( p_file = utf8_fopen( psz_filename, "r" ) ) && !fclose( p_file ) );
+ var_SetInteger( p_vout, "snapshot-num", i_num );
+ }
+ else
+ {
+ if( asprintf( &psz_filename, "%s" DIR_SEP "%s%u.%s",
+ val.psz_string, psz_prefix,
+ (unsigned int)(p_pic->date / 100000) & 0xFFFFFF,
+ format.psz_string ) == -1 )
+ {
+ msg_Err( p_vout, "could not create snapshot" );
+ image_HandlerDelete( p_image );
+ return VLC_EGENERIC;
+ }
+ }
+
+ free( psz_prefix );
+ }
+ else // The user specified a full path name (including file name)
+ {
+ psz_filename = str_format( p_vout, val.psz_string );
+ path_sanitize( psz_filename );