2008-08-24 17:42:39 +08:00
|
|
|
/*****************************************************************************
|
2011-05-20 07:40:18 +08:00
|
|
|
* winvlc.c: the Windows VLC media player
|
2008-08-24 17:42:39 +08:00
|
|
|
*****************************************************************************
|
2011-05-20 07:40:18 +08:00
|
|
|
* Copyright (C) 1998-2011 the VideoLAN team
|
2008-08-24 17:42:39 +08:00
|
|
|
*
|
|
|
|
* Authors: Vincent Seguin <seguin@via.ecp.fr>
|
|
|
|
* Samuel Hocevar <sam@zoy.org>
|
|
|
|
* Gildas Bazin <gbazin@videolan.org>
|
|
|
|
* Derk-Jan Hartman <hartman at videolan dot org>
|
|
|
|
* Lots of other people, see the libvlc AUTHORS file
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2014-01-29 00:37:59 +08:00
|
|
|
#ifndef UNICODE
|
2008-08-24 17:42:39 +08:00
|
|
|
#define UNICODE
|
2014-01-29 00:37:59 +08:00
|
|
|
#endif
|
|
|
|
|
2008-08-24 17:42:39 +08:00
|
|
|
#include <vlc/vlc.h>
|
|
|
|
#include <windows.h>
|
2012-01-28 22:56:39 +08:00
|
|
|
#include <shellapi.h>
|
2008-08-24 17:42:39 +08:00
|
|
|
|
2012-09-02 17:14:28 +08:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <io.h>
|
|
|
|
#include <shlobj.h>
|
2017-12-21 18:09:55 +08:00
|
|
|
|
2024-01-31 00:03:59 +08:00
|
|
|
#include "../lib/libvlc_internal.h"
|
|
|
|
|
2017-12-21 18:09:55 +08:00
|
|
|
#ifdef HAVE_BREAKPAD
|
|
|
|
void CheckCrashDump( const wchar_t* crashdump_path );
|
|
|
|
void* InstallCrashHandler( const wchar_t* crashdump_path );
|
|
|
|
void ReleaseCrashHandler( void* handler );
|
|
|
|
#endif
|
2009-02-01 21:30:40 +08:00
|
|
|
|
2008-08-25 02:17:02 +08:00
|
|
|
static char *FromWide (const wchar_t *wide)
|
2008-08-24 17:42:39 +08:00
|
|
|
{
|
2008-08-25 02:17:02 +08:00
|
|
|
size_t len;
|
|
|
|
len = WideCharToMultiByte (CP_UTF8, 0, wide, -1, NULL, 0, NULL, NULL);
|
2008-08-24 17:42:39 +08:00
|
|
|
|
2008-08-25 02:17:02 +08:00
|
|
|
char *out = (char *)malloc (len);
|
|
|
|
if (out)
|
|
|
|
WideCharToMultiByte (CP_UTF8, 0, wide, -1, out, len, NULL, NULL);
|
|
|
|
return out;
|
2008-08-24 17:42:39 +08:00
|
|
|
}
|
|
|
|
|
2016-11-19 02:07:58 +08:00
|
|
|
#if (_WIN32_WINNT < _WIN32_WINNT_WIN8)
|
|
|
|
static BOOL SetDefaultDllDirectories_(DWORD flags)
|
|
|
|
{
|
|
|
|
HMODULE h = GetModuleHandle(TEXT("kernel32.dll"));
|
|
|
|
if (h == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
2017-02-14 20:25:56 +08:00
|
|
|
BOOL (WINAPI * SetDefaultDllDirectoriesReal)(DWORD);
|
2016-11-19 02:07:58 +08:00
|
|
|
|
2019-06-03 15:04:50 +08:00
|
|
|
SetDefaultDllDirectoriesReal = (BOOL (WINAPI *)(DWORD))
|
|
|
|
GetProcAddress(h, "SetDefaultDllDirectories");
|
2016-11-19 02:07:58 +08:00
|
|
|
if (SetDefaultDllDirectoriesReal == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return SetDefaultDllDirectoriesReal(flags);
|
|
|
|
}
|
|
|
|
# define SetDefaultDllDirectories SetDefaultDllDirectories_
|
2017-03-10 21:48:51 +08:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void PrioritizeSystem32(void)
|
|
|
|
{
|
|
|
|
#if _WIN32_WINNT < _WIN32_WINNT_WIN8
|
2023-01-04 14:59:26 +08:00
|
|
|
BOOL (WINAPI *SetProcessMitigationPolicy)(PROCESS_MITIGATION_POLICY, PVOID, SIZE_T);
|
2017-03-10 21:48:51 +08:00
|
|
|
HINSTANCE h_Kernel32 = GetModuleHandle(TEXT("kernel32.dll"));
|
|
|
|
if ( !h_Kernel32 )
|
|
|
|
return;
|
|
|
|
SetProcessMitigationPolicy = (BOOL (WINAPI *)(PROCESS_MITIGATION_POLICY, PVOID, SIZE_T))
|
|
|
|
GetProcAddress(h_Kernel32, "SetProcessMitigationPolicy");
|
|
|
|
if (SetProcessMitigationPolicy == NULL)
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
PROCESS_MITIGATION_IMAGE_LOAD_POLICY m = { .Flags = 0 };
|
|
|
|
m.PreferSystem32Images = 1;
|
2023-12-05 16:54:50 +08:00
|
|
|
SetProcessMitigationPolicy( ProcessImageLoadPolicy, &m, sizeof( m ) );
|
2017-03-10 21:48:51 +08:00
|
|
|
}
|
2016-11-19 02:07:58 +08:00
|
|
|
|
2018-05-09 17:48:13 +08:00
|
|
|
static void vlc_kill(void *data)
|
|
|
|
{
|
|
|
|
HANDLE *semp = data;
|
|
|
|
|
|
|
|
ReleaseSemaphore(*semp, 1, NULL);
|
|
|
|
}
|
|
|
|
|
2008-08-25 02:17:02 +08:00
|
|
|
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
|
|
|
LPSTR lpCmdLine,
|
|
|
|
int nCmdShow )
|
2008-08-24 17:42:39 +08:00
|
|
|
{
|
2010-02-01 05:40:16 +08:00
|
|
|
int argc;
|
2011-07-29 00:47:50 +08:00
|
|
|
|
2012-07-13 03:39:44 +08:00
|
|
|
/* VLC does not change the thread locale, so gettext/libintil will use the
|
|
|
|
* user default locale as reference. */
|
|
|
|
/* gettext versions 0.18-0.18.1 will use the Windows Vista locale name
|
|
|
|
* if the GETTEXT_MUI environment variable is set. If not set or if running
|
|
|
|
* on Windows 2000/XP/2003 an hard-coded language ID list is used. This
|
|
|
|
* putenv() call may become redundant with later versions of gettext. */
|
|
|
|
putenv("GETTEXT_MUI=1");
|
2011-07-29 00:47:50 +08:00
|
|
|
#ifdef TOP_BUILDDIR
|
|
|
|
putenv("VLC_PLUGIN_PATH=Z:"TOP_BUILDDIR"/modules");
|
2012-03-21 02:41:56 +08:00
|
|
|
putenv("VLC_DATA_PATH=Z:"TOP_SRCDIR"/share");
|
2011-07-29 00:47:50 +08:00
|
|
|
#endif
|
|
|
|
|
2017-11-28 18:43:44 +08:00
|
|
|
#ifndef NDEBUG
|
|
|
|
/* Disable stderr buffering. Indeed, stderr can be buffered on Windows (if
|
|
|
|
* connected to a pipe). */
|
|
|
|
setvbuf (stderr, NULL, _IONBF, BUFSIZ);
|
|
|
|
#endif
|
|
|
|
|
2010-01-25 03:05:30 +08:00
|
|
|
HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0);
|
2010-07-02 04:17:38 +08:00
|
|
|
|
2023-07-04 21:07:14 +08:00
|
|
|
/* Enable DEP */
|
|
|
|
SetProcessDEPPolicy(PROCESS_DEP_ENABLE);
|
2010-07-02 04:17:38 +08:00
|
|
|
|
2017-12-11 00:04:10 +08:00
|
|
|
/* Do NOT load any library from cwd. */
|
|
|
|
SetDllDirectory(TEXT(""));
|
|
|
|
|
2017-03-10 20:58:57 +08:00
|
|
|
/***
|
|
|
|
* The LoadLibrary* calls from the modules and the 3rd party code
|
|
|
|
* will search in SYSTEM32 only
|
|
|
|
* */
|
2016-11-19 02:07:58 +08:00
|
|
|
SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_SYSTEM32);
|
2017-03-10 21:48:51 +08:00
|
|
|
/***
|
|
|
|
* Load DLLs from system32 before any other folder (when possible)
|
|
|
|
*/
|
|
|
|
PrioritizeSystem32();
|
2016-11-19 02:07:58 +08:00
|
|
|
|
2011-05-20 07:40:18 +08:00
|
|
|
/* Args */
|
2008-08-25 02:17:02 +08:00
|
|
|
wchar_t **wargv = CommandLineToArgvW (GetCommandLine (), &argc);
|
|
|
|
if (wargv == NULL)
|
|
|
|
return 1;
|
2008-08-24 17:42:39 +08:00
|
|
|
|
2015-03-03 02:28:14 +08:00
|
|
|
char *argv[argc + 3];
|
2009-07-06 21:58:23 +08:00
|
|
|
BOOL crash_handling = TRUE;
|
|
|
|
int j = 0;
|
2023-12-05 16:31:50 +08:00
|
|
|
WCHAR *lang = NULL;
|
2009-10-05 00:56:20 +08:00
|
|
|
|
2023-12-05 16:27:33 +08:00
|
|
|
argv[j++] = strdup("--media-library");
|
|
|
|
argv[j++] = strdup("--no-ignore-config");
|
2009-10-05 00:56:20 +08:00
|
|
|
for (int i = 1; i < argc; i++)
|
2009-07-06 21:58:23 +08:00
|
|
|
{
|
|
|
|
if(!wcscmp(wargv[i], L"--no-crashdump"))
|
|
|
|
{
|
|
|
|
crash_handling = FALSE;
|
2010-10-23 00:08:25 +08:00
|
|
|
continue; /* don't give argument to libvlc */
|
2009-07-06 21:58:23 +08:00
|
|
|
}
|
2013-09-07 01:49:36 +08:00
|
|
|
if (!wcsncmp(wargv[i], L"--language", 10) )
|
|
|
|
{
|
|
|
|
if (i < argc - 1 && wcsncmp( wargv[i + 1], L"--", 2 ))
|
2023-12-05 16:31:50 +08:00
|
|
|
lang = _wcsdup (wargv[++i]);
|
2013-09-07 01:49:36 +08:00
|
|
|
continue;
|
|
|
|
}
|
2010-10-23 00:08:25 +08:00
|
|
|
|
|
|
|
argv[j++] = FromWide (wargv[i]);
|
2009-07-06 21:58:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
argc = j;
|
2008-08-25 02:17:02 +08:00
|
|
|
argv[argc] = NULL;
|
|
|
|
LocalFree (wargv);
|
2009-07-06 21:58:23 +08:00
|
|
|
|
2018-03-16 01:09:31 +08:00
|
|
|
#ifdef HAVE_BREAKPAD
|
2017-12-21 18:09:55 +08:00
|
|
|
void* eh = NULL;
|
2009-07-06 21:58:23 +08:00
|
|
|
if(crash_handling)
|
|
|
|
{
|
2023-12-04 15:24:04 +08:00
|
|
|
wchar_t path[MAX_PATH];
|
2011-11-17 01:15:49 +08:00
|
|
|
if( S_OK != SHGetFolderPathW( NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE,
|
|
|
|
NULL, SHGFP_TYPE_CURRENT, path ) )
|
|
|
|
fprintf( stderr, "Can't open the vlc conf PATH\n" );
|
2023-12-04 15:21:01 +08:00
|
|
|
else if ( !wcscat_s( path, MAX_PATH, L"\\vlc\\crashdump" ) )
|
2023-12-04 14:31:26 +08:00
|
|
|
{
|
|
|
|
CheckCrashDump( path );
|
|
|
|
eh = InstallCrashHandler( path );
|
|
|
|
}
|
2009-07-06 21:58:23 +08:00
|
|
|
}
|
2020-03-27 19:04:33 +08:00
|
|
|
#else
|
|
|
|
(void)crash_handling;
|
2018-03-16 01:09:31 +08:00
|
|
|
#endif
|
2009-07-06 21:58:23 +08:00
|
|
|
|
2014-10-22 21:31:30 +08:00
|
|
|
_setmode( _fileno( stdin ), _O_BINARY ); /* Needed for pipes */
|
2011-11-23 00:09:51 +08:00
|
|
|
|
2013-09-07 01:49:36 +08:00
|
|
|
/* */
|
|
|
|
if (!lang)
|
|
|
|
{
|
|
|
|
HKEY h_key;
|
|
|
|
if( RegOpenKeyEx( HKEY_CURRENT_USER, TEXT("Software\\VideoLAN\\VLC\\"), 0, KEY_READ, &h_key )
|
|
|
|
== ERROR_SUCCESS )
|
|
|
|
{
|
2019-04-03 14:44:31 +08:00
|
|
|
WCHAR szData[256];
|
2013-09-07 01:49:36 +08:00
|
|
|
DWORD len = 256;
|
|
|
|
if( RegQueryValueEx( h_key, TEXT("Lang"), NULL, NULL, (LPBYTE) &szData, &len ) == ERROR_SUCCESS )
|
2023-12-05 16:31:50 +08:00
|
|
|
lang = _wcsdup( szData );
|
2013-09-07 01:49:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-05 16:31:50 +08:00
|
|
|
if (lang && wcsncmp( lang, L"auto", 4 ) )
|
2013-09-07 01:49:36 +08:00
|
|
|
{
|
2013-09-08 03:04:22 +08:00
|
|
|
char tmp[11];
|
2023-12-05 16:31:50 +08:00
|
|
|
snprintf(tmp, 11, "LANG=%ls", lang);
|
2013-09-08 03:04:22 +08:00
|
|
|
putenv(tmp);
|
2013-09-07 01:49:36 +08:00
|
|
|
}
|
|
|
|
free(lang);
|
|
|
|
|
2008-08-24 17:42:39 +08:00
|
|
|
/* Initialize libvlc */
|
2008-08-26 22:55:18 +08:00
|
|
|
libvlc_instance_t *vlc;
|
2010-02-01 05:40:16 +08:00
|
|
|
vlc = libvlc_new (argc, (const char **)argv);
|
2008-08-24 17:42:39 +08:00
|
|
|
if (vlc != NULL)
|
|
|
|
{
|
2018-05-09 17:48:13 +08:00
|
|
|
HANDLE sem = CreateSemaphore(NULL, 0, 1, NULL);
|
|
|
|
|
2024-01-31 00:03:59 +08:00
|
|
|
libvlc_SetExitHandler(vlc->p_libvlc_int, vlc_kill, &sem);
|
2013-06-16 16:11:55 +08:00
|
|
|
libvlc_set_app_id (vlc, "org.VideoLAN.VLC", PACKAGE_VERSION,
|
|
|
|
PACKAGE_NAME);
|
2012-02-04 01:24:54 +08:00
|
|
|
libvlc_set_user_agent (vlc, "VLC media player", "VLC/"PACKAGE_VERSION);
|
2024-01-31 00:03:59 +08:00
|
|
|
libvlc_InternalAddIntf (vlc->p_libvlc_int, NULL);
|
|
|
|
libvlc_InternalPlay (vlc->p_libvlc_int);
|
2018-05-09 17:48:13 +08:00
|
|
|
|
|
|
|
WaitForSingleObject(sem, INFINITE);
|
|
|
|
CloseHandle(sem);
|
|
|
|
|
2008-08-24 17:42:39 +08:00
|
|
|
libvlc_release (vlc);
|
|
|
|
}
|
2013-03-14 23:57:37 +08:00
|
|
|
else
|
|
|
|
MessageBox (NULL, TEXT("VLC media player could not start.\n"
|
|
|
|
"Either the command line options were invalid or no plugins were found.\n"),
|
|
|
|
TEXT("VLC media player"),
|
|
|
|
MB_OK|MB_ICONERROR);
|
|
|
|
|
2008-08-24 17:42:39 +08:00
|
|
|
|
2017-12-21 18:09:55 +08:00
|
|
|
#ifdef HAVE_BREAKPAD
|
|
|
|
ReleaseCrashHandler( eh );
|
|
|
|
#endif
|
2008-08-25 02:17:02 +08:00
|
|
|
for (int i = 0; i < argc; i++)
|
|
|
|
free (argv[i]);
|
|
|
|
|
|
|
|
(void)hInstance; (void)hPrevInstance; (void)lpCmdLine; (void)nCmdShow;
|
2010-02-01 05:40:16 +08:00
|
|
|
return 0;
|
2008-08-24 17:42:39 +08:00
|
|
|
}
|