X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fmisc%2Fwin32_specific.c;h=3317492502082e3e959ed161a084f3995f8b792f;hb=d3fe7f28797d4dba65ffcdd60bf932e758a48a9e;hp=c0793dd0e63a0f31a1f07e67df9511533238bab6;hpb=c1c8211f51f77ba414a894368f16d8a94afd21cf;p=vlc diff --git a/src/misc/win32_specific.c b/src/misc/win32_specific.c index c0793dd0e6..3317492502 100644 --- a/src/misc/win32_specific.c +++ b/src/misc/win32_specific.c @@ -1,11 +1,11 @@ /***************************************************************************** * win32_specific.c: Win32 specific features ***************************************************************************** - * Copyright (C) 2001-2004 VideoLAN - * $Id: win32_specific.c,v 1.31 2004/01/09 12:23:46 gbazin Exp $ + * Copyright (C) 2001-2004 the VideoLAN team + * $Id$ * * Authors: Samuel Hocevar - * Gildas Bazin + * Gildas Bazin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,13 +19,14 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ #include /* strdup() */ #include /* free() */ #include #include "vlc_playlist.h" +#include "charset.h" #ifdef WIN32 /* optind, getopt(), included in unistd.h */ # include "../extras/getopt.h" @@ -34,61 +35,80 @@ #if !defined( UNDER_CE ) # include # include -# include #endif +#include + +extern void __wgetmainargs(int *argc, wchar_t ***wargv, wchar_t ***wenviron, + int expand_wildcards, int *startupinfo); + /***************************************************************************** * system_Init: initialize winsock and misc other things. *****************************************************************************/ -void system_Init( vlc_t *p_this, int *pi_argc, char *ppsz_argv[] ) +void system_Init( libvlc_int_t *p_this, int *pi_argc, char *ppsz_argv[] ) { -#if !defined( UNDER_CE ) WSADATA Data; /* Get our full path */ - if( ppsz_argv[0] ) + char psz_path[MAX_PATH]; + char *psz_vlc; + +#if defined( UNDER_CE ) + wchar_t psz_wpath[MAX_PATH]; + if( GetModuleFileName( NULL, psz_wpath, MAX_PATH ) ) { - char psz_path[MAX_PATH]; - char *psz_vlc; + WideCharToMultiByte( CP_ACP, 0, psz_wpath, -1, + psz_path, MAX_PATH, NULL, NULL ); + } + else psz_path[0] = '\0'; +#else + if( ppsz_argv[0] ) + { GetFullPathName( ppsz_argv[0], MAX_PATH, psz_path, &psz_vlc ); - - if( psz_vlc > psz_path && psz_vlc[-1] == '\\' ) - { - psz_vlc[-1] = '\0'; - p_this->p_libvlc->psz_vlcpath = strdup( psz_path ); - } - else - { - p_this->p_libvlc->psz_vlcpath = strdup( "" ); - } } - else + else if( !GetModuleFileName( NULL, psz_path, MAX_PATH ) ) { - p_this->p_libvlc->psz_vlcpath = strdup( "" ); + psz_path[0] = '\0'; } +#endif + + if( (psz_vlc = strrchr( psz_path, '\\' )) ) *psz_vlc = '\0'; + + p_this->p_libvlc_global->psz_vlcpath = strdup( psz_path ); /* Set the default file-translation mode */ +#if !defined( UNDER_CE ) _fmode = _O_BINARY; _setmode( _fileno( stdin ), _O_BINARY ); /* Needed for pipes */ +#endif /* Call mdate() once to make sure it is initialized properly */ mdate(); + /* Replace argv[1..n] with unicode for Windows NT and above */ + if( GetVersion() < 0x80000000 ) + { + wchar_t **wargv, **wenvp; + int i,i_wargc; + int si = { 0 }; + __wgetmainargs(&i_wargc, &wargv, &wenvp, 0, &si); + + for( i = 1; i < i_wargc; i++ ) + ppsz_argv[i] = FromWide( wargv[i] ); + } + /* WinSock Library Init. */ - if( !WSAStartup( MAKEWORD( 2, 0 ), &Data ) ) + if( !WSAStartup( MAKEWORD( 2, 2 ), &Data ) ) { - /* Confirm that the WinSock DLL supports 2.0.*/ - if( LOBYTE( Data.wVersion ) != 2 || HIBYTE( Data.wVersion ) != 0 ) - { + /* Aah, pretty useless check, we should always have Winsock 2.2 + * since it appeared in Win98. */ + if( LOBYTE( Data.wVersion ) != 2 || HIBYTE( Data.wVersion ) != 2 ) /* We could not find a suitable WinSock DLL. */ WSACleanup( ); - } else - { /* Everything went ok. */ return; - } } /* Let's try with WinSock 1.1 */ @@ -96,22 +116,14 @@ void system_Init( vlc_t *p_this, int *pi_argc, char *ppsz_argv[] ) { /* Confirm that the WinSock DLL supports 1.1.*/ if( LOBYTE( Data.wVersion ) != 1 || HIBYTE( Data.wVersion ) != 1 ) - { /* We could not find a suitable WinSock DLL. */ WSACleanup( ); - } else - { /* Everything went ok. */ return; - } } fprintf( stderr, "error: can't initialize WinSocks\n" ); - - return; - -#endif } /***************************************************************************** @@ -120,11 +132,11 @@ void system_Init( vlc_t *p_this, int *pi_argc, char *ppsz_argv[] ) static void IPCHelperThread( vlc_object_t * ); LRESULT CALLBACK WMCOPYWNDPROC( HWND, UINT, WPARAM, LPARAM ); -void system_Configure( vlc_t *p_this, int *pi_argc, char *ppsz_argv[] ) +void system_Configure( libvlc_int_t *p_this, int *pi_argc, char *ppsz_argv[] ) { #if !defined( UNDER_CE ) - p_this->p_libvlc->b_fast_mutex = config_GetInt( p_this, "fast-mutex" ); - p_this->p_libvlc->i_win9x_cv = config_GetInt( p_this, "win9x-cv-method" ); + p_this->p_libvlc_global->b_fast_mutex = config_GetInt( p_this, "fast-mutex" ); + p_this->p_libvlc_global->i_win9x_cv = config_GetInt( p_this, "win9x-cv-method" ); /* Raise default priority of the current process */ #ifndef ABOVE_NORMAL_PRIORITY_CLASS @@ -143,18 +155,20 @@ void system_Configure( vlc_t *p_this, int *pi_argc, char *ppsz_argv[] ) } } - if( config_GetInt( p_this, "one-instance" ) ) + if( config_GetInt( p_this, "one-instance" ) + || ( config_GetInt( p_this, "one-instance-when-started-from-file" ) + && config_GetInt( p_this, "started-from-file" ) ) ) { HANDLE hmutex; - msg_Info( p_this, "One instance mode ENABLED"); + msg_Info( p_this, "one instance mode ENABLED"); /* Use a named mutex to check if another instance is already running */ - if( ( hmutex = CreateMutex( NULL, TRUE, "VLC ipc "VERSION ) ) == NULL ) + if( !( hmutex = CreateMutex( 0, TRUE, _T("VLC ipc ") _T(VERSION) ) ) ) { /* Failed for some reason. Just ignore the option and go on as * normal. */ - msg_Err( p_this, "One instance mode DISABLED " + msg_Err( p_this, "one instance mode DISABLED " "(mutex couldn't be created)" ); return; } @@ -169,7 +183,7 @@ void system_Configure( vlc_t *p_this, int *pi_argc, char *ppsz_argv[] ) if( vlc_thread_create( p_helper, "IPC helper", IPCHelperThread, VLC_THREAD_PRIORITY_LOW, VLC_TRUE ) ) { - msg_Err( p_this, "One instance mode DISABLED " + msg_Err( p_this, "one instance mode DISABLED " "(IPC helper thread couldn't be created)" ); } @@ -189,10 +203,9 @@ void system_Configure( vlc_t *p_this, int *pi_argc, char *ppsz_argv[] ) /* Locate the window created by the IPC helper thread of the * 1st instance */ - if( ( ipcwindow = FindWindow( NULL, "VLC ipc "VERSION ) ) - == NULL ) + if( !( ipcwindow = FindWindow( 0, _T("VLC ipc ") _T(VERSION) ) ) ) { - msg_Err( p_this, "One instance mode DISABLED " + msg_Err( p_this, "one instance mode DISABLED " "(couldn't find 1st instance of program)" ); ReleaseMutex( hmutex ); return; @@ -251,8 +264,8 @@ static void IPCHelperThread( vlc_object_t *p_this ) MSG message; ipcwindow = - CreateWindow( "STATIC", /* name of window class */ - "VLC ipc "VERSION, /* window title bar text */ + CreateWindow( _T("STATIC"), /* name of window class */ + _T("VLC ipc ") _T(VERSION), /* window title bar text */ 0, /* window style */ 0, /* default X coordinate */ 0, /* default Y coordinate */ @@ -297,7 +310,7 @@ LRESULT CALLBACK WMCOPYWNDPROC( HWND hwnd, UINT uMsg, WPARAM wParam, if( pwm_data->lpData ) { - int i_argc, i_data, i_opt, i_options,i_id,i_pos,j; + int i_argc, i_data, i_opt, i_options; char **ppsz_argv; char *p_data = (char *)pwm_data->lpData; @@ -321,16 +334,21 @@ LRESULT CALLBACK WMCOPYWNDPROC( HWND hwnd, UINT uMsg, WPARAM wParam, { i_options++; } - i_id = playlist_Add( p_playlist, ppsz_argv[ i_opt ], - ppsz_argv[ i_opt ], - PLAYLIST_APPEND | (i_opt? 0 : PLAYLIST_GO), - PLAYLIST_END ); - i_pos = playlist_GetPositionById( p_playlist, i_id ); - for( j = 0 ; j < i_options ; j++ ) + if( i_opt || config_GetInt( p_this, "playlist-enqueue" ) ) { - playlist_AddOption( p_playlist, i_pos , - ppsz_argv[i_opt+1+j] ); + playlist_AddExt( p_playlist, ppsz_argv[i_opt], + NULL, PLAYLIST_APPEND , + PLAYLIST_END, -1, + (char const **)( i_options ? &ppsz_argv[i_opt+1] : NULL ), + i_options, VLC_TRUE ); + } else { + playlist_AddExt( p_playlist, ppsz_argv[i_opt], + NULL, PLAYLIST_APPEND | PLAYLIST_GO, + PLAYLIST_END, -1, + (char const **)( i_options ? &ppsz_argv[i_opt+1] : NULL ), + i_options, VLC_TRUE ); } + i_opt += i_options; } @@ -346,9 +364,13 @@ LRESULT CALLBACK WMCOPYWNDPROC( HWND hwnd, UINT uMsg, WPARAM wParam, /***************************************************************************** * system_End: terminate winsock. *****************************************************************************/ -void system_End( vlc_t *p_this ) +void system_End( libvlc_int_t *p_this ) { -#if !defined( UNDER_CE ) + if( p_this && p_this->p_libvlc_global && p_this->p_libvlc_global->psz_vlcpath ) + { + free( p_this->p_libvlc_global->psz_vlcpath ); + p_this->p_libvlc_global->psz_vlcpath = NULL; + } + WSACleanup(); -#endif }