]> git.sesse.net Git - vlc/blobdiff - bin/winvlc.c
demux: ts: only interpolate PCR on missing PCR
[vlc] / bin / winvlc.c
index b1631e1f9e3b14a57db6d6097d401fc3a2aa5796..33784e294d41c12914bc7ede89871ecfbd6bc62b 100644 (file)
 # include "config.h"
 #endif
 
+#ifndef UNICODE
 #define UNICODE
+#endif
+
 #include <vlc/vlc.h>
 #include <windows.h>
 #include <shellapi.h>
@@ -76,6 +79,7 @@ int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
     putenv("VLC_DATA_PATH=Z:"TOP_SRCDIR"/share");
 #endif
 
+    SetErrorMode(SEM_FAILCRITICALERRORS);
     HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0);
 
     /* SetProcessDEPPolicy */
@@ -86,13 +90,13 @@ int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
         BOOL (WINAPI * mySetDllDirectoryA)(const char* lpPathName);
 # define PROCESS_DEP_ENABLE 1
 
-        mySetProcessDEPPolicy = (BOOL WINAPI (*)(DWORD))
+        mySetProcessDEPPolicy = (BOOL (WINAPI *)(DWORD))
                             GetProcAddress(h_Kernel32, "SetProcessDEPPolicy");
         if(mySetProcessDEPPolicy)
             mySetProcessDEPPolicy(PROCESS_DEP_ENABLE);
 
         /* Do NOT load any library from cwd. */
-        mySetDllDirectoryA = (BOOL WINAPI (*)(const char*))
+        mySetDllDirectoryA = (BOOL (WINAPI *)(const char*))
                             GetProcAddress(h_Kernel32, "SetDllDirectoryA");
         if(mySetDllDirectoryA)
             mySetDllDirectoryA("");
@@ -108,6 +112,7 @@ int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
     char *argv[argc + 3];
     BOOL crash_handling = TRUE;
     int j = 0;
+    char *lang = NULL;
 
     argv[j++] = FromWide( L"--media-library" );
     argv[j++] = FromWide( L"--no-ignore-config" );
@@ -118,6 +123,12 @@ int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
             crash_handling = FALSE;
             continue; /* don't give argument to libvlc */
         }
+        if (!wcsncmp(wargv[i], L"--language", 10) )
+        {
+            if (i < argc - 1 && wcsncmp( wargv[i + 1], L"--", 2 ))
+                lang = FromWide (wargv[++i]);
+            continue;
+        }
 
         argv[j++] = FromWide (wargv[i]);
     }
@@ -132,20 +143,44 @@ int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
         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" );
-        swprintf( path+wcslen( path ), L"%s", L"\\vlc\\crashdump" );
+        _snwprintf( path+wcslen( path ), MAX_PATH,  L"%s", L"\\vlc\\crashdump" );
         crashdump_path = &path[0];
 
         check_crashdump();
         SetUnhandledExceptionFilter(vlc_exception_filter);
     }
 
-    _setmode( STDIN_FILENO, _O_BINARY ); /* Needed for pipes */
+    _setmode( _fileno( stdin ), _O_BINARY ); /* Needed for pipes */
+
+    /* */
+    if (!lang)
+    {
+        HKEY h_key;
+        if( RegOpenKeyEx( HKEY_CURRENT_USER, TEXT("Software\\VideoLAN\\VLC\\"), 0, KEY_READ, &h_key )
+                == ERROR_SUCCESS )
+        {
+            TCHAR szData[256];
+            DWORD len = 256;
+            if( RegQueryValueEx( h_key, TEXT("Lang"), NULL, NULL, (LPBYTE) &szData, &len ) == ERROR_SUCCESS )
+                lang = FromWide( szData );
+        }
+    }
+
+    if (lang && strncmp( lang, "auto", 4 ) )
+    {
+        char tmp[11];
+        snprintf(tmp, 11, "LANG=%s", lang);
+        putenv(tmp);
+    }
+    free(lang);
 
     /* Initialize libvlc */
     libvlc_instance_t *vlc;
     vlc = libvlc_new (argc, (const char **)argv);
     if (vlc != NULL)
     {
+        libvlc_set_app_id (vlc, "org.VideoLAN.VLC", PACKAGE_VERSION,
+                           PACKAGE_NAME);
         libvlc_set_user_agent (vlc, "VLC media player", "VLC/"PACKAGE_VERSION);
         libvlc_add_intf (vlc, "hotkeys,none");
         libvlc_add_intf (vlc, "globalhotkeys,none");
@@ -154,6 +189,12 @@ int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
         libvlc_wait (vlc);
         libvlc_release (vlc);
     }
+    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);
+
 
     for (int i = 0; i < argc; i++)
         free (argv[i]);
@@ -165,13 +206,20 @@ int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
 /* Crashdumps handling */
 static void check_crashdump(void)
 {
-    FILE * fd = _wfopen ( crashdump_path, L"r, ccs=UTF-8" );
+    wchar_t mv_crashdump_path[MAX_PATH];
+    wcscpy (mv_crashdump_path, crashdump_path);
+    wcscat (mv_crashdump_path, L".mv");
+
+    if (_wrename (crashdump_path, mv_crashdump_path))
+        return;
+
+    FILE * fd = _wfopen ( mv_crashdump_path, L"r, ccs=UTF-8" );
     if( !fd )
         return;
     fclose( fd );
 
-    int answer = MessageBox( NULL, L"VLC media player just crashed." \
-    " Do you want to send a bug report to the developers team?",
+    int answer = MessageBox( NULL, L"Ooops: VLC media player just crashed.\n" \
+    "Would you like to send a bug report to the developers team?",
     L"VLC crash reporting", MB_YESNO);
 
     if(answer == IDYES)
@@ -188,27 +236,27 @@ static void check_crashdump(void)
                 SYSTEMTIME now;
                 GetSystemTime(&now);
                 wchar_t remote_file[MAX_PATH];
-                swprintf(remote_file,
+                _snwprintf(remote_file, MAX_PATH,
                         L"/crashes-win32/%04d%02d%02d%02d%02d%02d",
                         now.wYear, now.wMonth, now.wDay, now.wHour,
                         now.wMinute, now.wSecond );
 
-                if( FtpPutFile( ftp, crashdump_path, remote_file,
+                if( FtpPutFile( ftp, mv_crashdump_path, remote_file,
                             FTP_TRANSFER_TYPE_BINARY, 0) )
-                    MessageBox( NULL, L"Report sent correctly. Thanks a lot \
-                            for the help.", L"Report sent", MB_OK);
+                    MessageBox( NULL, L"Report sent correctly. Thanks a lot \
+                                "for the help.", L"Report sent", MB_OK);
                 else
-                    MessageBox( NULL, L"There was an error while \
-                            transferring to the FTP server. "\
-                                "Thanks a lot for the help anyway.",
+                    MessageBox( NULL, L"There was an error while "\
+                                "transferring the data to the FTP server.\n"\
+                                "Thanks a lot for the help.",
                                 L"Report sending failed", MB_OK);
                 InternetCloseHandle(ftp);
             }
             else
             {
-                MessageBox( NULL, L"There was an error while connecting to \
-                        the FTP server. "\
-                                "Thanks a lot for the help anyway.",
+                MessageBox( NULL, L"There was an error while connecting to \
+                                "the FTP server. "\
+                                "Thanks a lot for the help.",
                                 L"Report sending failed", MB_OK);
                 fprintf(stderr,"Can't connect to FTP server 0x%08lu\n",
                         (unsigned long)GetLastError());
@@ -217,14 +265,13 @@ static void check_crashdump(void)
         }
         else
         {
-              MessageBox( NULL, L"There was an error while connecting to the \
-                      Internet. "\
+              MessageBox( NULL, L"There was an error while connecting to the Internet.\n"\
                                 "Thanks a lot for the help anyway.",
                                 L"Report sending failed", MB_OK);
         }
     }
 
-    _wremove(crashdump_path);
+    _wremove(mv_crashdump_path);
 }
 
 /*****************************************************************************
@@ -255,7 +302,7 @@ LONG WINAPI vlc_exception_filter(struct _EXCEPTION_POINTERS *lpExceptionInfo)
         osvi.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );
         GetVersionEx( &osvi );
 
-        fwprintf( fd, L"[version]\nOS=%d.%d.%d.%d.%s\nVLC=" VERSION_MESSAGE,
+        fwprintf( fd, L"[version]\nOS=%d.%d.%d.%d.%ls\nVLC=" VERSION_MESSAGE,
                 osvi.dwMajorVersion, osvi.dwMinorVersion, osvi.dwBuildNumber,
                 osvi.dwPlatformId, osvi.szCSDVersion);
 
@@ -270,7 +317,7 @@ LONG WINAPI vlc_exception_filter(struct _EXCEPTION_POINTERS *lpExceptionInfo)
         for( unsigned int i = 0; i < pException->NumberParameters; i++ )
             fwprintf( fd, L" | %p", pException->ExceptionInformation[i] );
 
-#ifdef WIN64
+#ifdef _WIN64
         fwprintf( fd, L"\n\n[context]\nRDI:%px\nRSI:%px\n" \
                     "RBX:%px\nRDX:%px\nRCX:%px\nRAX:%px\n" \
                     "RBP:%px\nRIP:%px\nRSP:%px\nR8:%px\n" \
@@ -293,7 +340,7 @@ LONG WINAPI vlc_exception_filter(struct _EXCEPTION_POINTERS *lpExceptionInfo)
 
         fwprintf( fd, L"\n[stacktrace]\n#EIP|base|module\n" );
 
-#ifdef WIN64
+#ifdef _WIN64
         LPCVOID caller = (LPCVOID)pContext->Rip;
         LPVOID *pBase  = (LPVOID*)pContext->Rbp;
 #else
@@ -306,13 +353,18 @@ LONG WINAPI vlc_exception_filter(struct _EXCEPTION_POINTERS *lpExceptionInfo)
             wchar_t module[ 256 ];
             VirtualQuery( caller, &mbi, sizeof( mbi ) ) ;
             GetModuleFileName( mbi.AllocationBase, module, 256 );
-            fwprintf( fd, L"%p|%s\n", caller, module );
+            fwprintf( fd, L"%p|%ls\n", caller, module );
+
+            if( IsBadReadPtr( pBase, 2 * sizeof( void* ) ) )
+                break;
 
             /*The last BP points to NULL!*/
             caller = *(pBase + 1);
             if( !caller )
                 break;
             pBase = *pBase;
+            if( !pBase )
+                break;
         }
 
         HANDLE hpid = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,
@@ -325,7 +377,7 @@ LONG WINAPI vlc_exception_filter(struct _EXCEPTION_POINTERS *lpExceptionInfo)
                 for (unsigned int i = 0; i < size / sizeof(HMODULE); i++) {
                     wchar_t module[ 256 ];
                     GetModuleFileName(mods[i], module, 256);
-                    fwprintf( fd, L"%p|%s\n", mods[i], module);
+                    fwprintf( fd, L"%p|%ls\n", mods[i], module);
                 }
             }
             CloseHandle(hpid);