2015-03-29 15:34:58 +00:00
|
|
|
#include <windows.h>
|
|
|
|
|
2015-05-02 16:54:00 +00:00
|
|
|
#ifndef BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE
|
|
|
|
#define BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE (0x0001)
|
|
|
|
#endif
|
|
|
|
|
2015-05-02 16:47:57 +00:00
|
|
|
#include "common/common.h"
|
2015-03-29 11:36:46 +00:00
|
|
|
#include "osdep/io.h"
|
2015-03-29 14:19:29 +00:00
|
|
|
#include "osdep/terminal.h"
|
2015-05-02 16:47:57 +00:00
|
|
|
#include "osdep/main-fn.h"
|
2015-03-29 15:34:58 +00:00
|
|
|
|
|
|
|
static bool is_valid_handle(HANDLE h)
|
|
|
|
{
|
2015-04-11 04:35:50 +00:00
|
|
|
return h != INVALID_HANDLE_VALUE && h != NULL &&
|
|
|
|
GetFileType(h) != FILE_TYPE_UNKNOWN;
|
2015-03-29 15:34:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool has_redirected_stdio(void)
|
|
|
|
{
|
|
|
|
return is_valid_handle(GetStdHandle(STD_INPUT_HANDLE)) ||
|
|
|
|
is_valid_handle(GetStdHandle(STD_OUTPUT_HANDLE)) ||
|
|
|
|
is_valid_handle(GetStdHandle(STD_ERROR_HANDLE));
|
|
|
|
}
|
|
|
|
|
2015-05-02 16:54:00 +00:00
|
|
|
static void microsoft_nonsense(void)
|
|
|
|
{
|
|
|
|
// stop Windows from showing all kinds of annoying error dialogs
|
|
|
|
SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
|
|
|
|
|
|
|
|
// Enable heap corruption detection
|
|
|
|
HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0);
|
|
|
|
|
|
|
|
HMODULE kernel32 = GetModuleHandleW(L"kernel32.dll");
|
|
|
|
WINBOOL (WINAPI *pSetSearchPathMode)(DWORD Flags) =
|
|
|
|
(WINBOOL (WINAPI *)(DWORD))GetProcAddress(kernel32, "SetSearchPathMode");
|
|
|
|
|
|
|
|
// Always use safe search paths for DLLs and other files, ie. never use the
|
|
|
|
// current directory
|
2015-12-06 00:36:30 +00:00
|
|
|
SetDllDirectoryW(L"");
|
2015-05-02 16:54:00 +00:00
|
|
|
if (pSetSearchPathMode)
|
|
|
|
pSetSearchPathMode(BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE);
|
|
|
|
}
|
|
|
|
|
2019-06-29 23:29:06 +00:00
|
|
|
int main(int argc_, char **argv_)
|
2015-03-29 11:36:46 +00:00
|
|
|
{
|
2015-05-02 16:54:00 +00:00
|
|
|
microsoft_nonsense();
|
|
|
|
|
2015-03-29 14:19:29 +00:00
|
|
|
// If started from the console wrapper (see osdep/win32-console-wrapper.c),
|
|
|
|
// attach to the console and set up the standard IO handles
|
2015-03-29 15:34:58 +00:00
|
|
|
bool has_console = terminal_try_attach();
|
|
|
|
|
|
|
|
// If mpv is started from Explorer, the Run dialog or the Start Menu, it
|
|
|
|
// will have no console and no standard IO handles. In this case, the user
|
|
|
|
// is expecting mpv to show some UI, so enable the pseudo-GUI profile.
|
|
|
|
bool gui = !has_console && !has_redirected_stdio();
|
|
|
|
|
2019-06-29 23:29:06 +00:00
|
|
|
int argc = 0;
|
|
|
|
wchar_t **argv = CommandLineToArgvW(GetCommandLineW(), &argc);
|
|
|
|
|
2015-03-29 15:34:58 +00:00
|
|
|
int argv_len = 0;
|
|
|
|
char **argv_u8 = NULL;
|
2015-03-29 14:19:29 +00:00
|
|
|
|
2015-03-29 15:34:58 +00:00
|
|
|
// Build mpv's UTF-8 argv, and add the pseudo-GUI profile if necessary
|
2019-06-29 23:29:06 +00:00
|
|
|
if (argc > 0 && argv[0])
|
2015-03-29 15:34:58 +00:00
|
|
|
MP_TARRAY_APPEND(NULL, argv_u8, argv_len, mp_to_utf8(argv_u8, argv[0]));
|
2016-09-23 19:24:50 +00:00
|
|
|
if (gui) {
|
|
|
|
MP_TARRAY_APPEND(NULL, argv_u8, argv_len,
|
|
|
|
"--player-operation-mode=pseudo-gui");
|
|
|
|
}
|
2015-03-29 15:34:58 +00:00
|
|
|
for (int i = 1; i < argc; i++)
|
|
|
|
MP_TARRAY_APPEND(NULL, argv_u8, argv_len, mp_to_utf8(argv_u8, argv[i]));
|
|
|
|
MP_TARRAY_APPEND(NULL, argv_u8, argv_len, NULL);
|
2015-03-29 11:36:46 +00:00
|
|
|
|
2015-03-29 15:34:58 +00:00
|
|
|
int ret = mpv_main(argv_len - 1, argv_u8);
|
2015-03-29 11:36:46 +00:00
|
|
|
|
|
|
|
talloc_free(argv_u8);
|
|
|
|
return ret;
|
|
|
|
}
|