- oh how I despise windows, another evil hack to get proper detection of vlc plugins

This commit is contained in:
Mark Vejvoda 2012-05-14 03:36:43 +00:00
parent e3c2719458
commit 093d22ce8b
6 changed files with 181 additions and 64 deletions

View File

@ -506,7 +506,8 @@ Intro::Intro(Program *program):
screen->w,
screen->h,
screen->format->BitsPerPixel,
vlcPluginsPath);
vlcPluginsPath,
SystemFlags::VERBOSE_MODE_ENABLED);
player.PlayVideo();
return;
}

View File

@ -11,6 +11,7 @@
#ifdef WIN32
#include <winsock2.h>
#include <winsock.h>
#include <process.h>
#endif
#include "math_wrapper.h"
@ -2725,6 +2726,75 @@ int glestMain(int argc, char** argv) {
// printf("END ALLOC char 200\n");
// return -1;
#if defined(WIN32)
//printf("*** VLC START ****\n");
//if(verboseEnabled) printf("Trying [%s]\n",getenv("VLC_PLUGIN_PATH"));
if(getenv("VLC_PLUGIN_PATH") == NULL) {
//printf("*** VLC C ****\n");
// For windows check registry for install path
std::string strValue = getRegKey("Software\\VideoLAN\\VLC", "InstallDir");
if(strValue != "") {
if(strValue.length() >= 2) {
if(strValue[0] == '"') {
strValue = strValue.erase(0);
}
if(strValue[strValue.length()-1] == '"') {
strValue = strValue.erase(strValue.length()-1);
}
if(strValue[strValue.length()-1] != '\\') {
strValue += "\\";
}
}
strValue += "plugins";
string newstrValue = "VLC_PLUGIN_PATH=" + strValue;
_putenv(newstrValue.c_str());
//bool result = SetEnvironmentVariableA("VLC_PLUGIN_PATH",strValue.c_str());
//Open the registry key.
wstring subKey = L"Environment";
HKEY keyHandle;
DWORD dwDisposition;
RegCreateKeyEx(HKEY_CURRENT_USER,subKey.c_str(),0, NULL, 0, KEY_ALL_ACCESS, NULL, &keyHandle, &dwDisposition);
//Set the value.
std::auto_ptr<wchar_t> wstr(Ansi2WideString(strValue.c_str()));
wstring vlcPluginPath = wstring(wstr.get());
DWORD len = (DWORD) sizeof(wchar_t) * vlcPluginPath.length() + 1;
RegSetValueEx(keyHandle, L"VLC_PLUGIN_PATH", 0, REG_SZ, (PBYTE)vlcPluginPath.c_str(), len);
RegCloseKey(keyHandle);
subKey = L"System\\CurrentControlSet\\Control\\Session Manager\\Environment";
RegCreateKeyEx(HKEY_LOCAL_MACHINE,subKey.c_str(),0, NULL, 0, KEY_ALL_ACCESS, NULL, &keyHandle, &dwDisposition);
//Set the value.
wstr.reset(Ansi2WideString(strValue.c_str()));
vlcPluginPath = wstring(wstr.get());
len = (DWORD) sizeof(wchar_t) * vlcPluginPath.length() + 1;
RegSetValueEx(keyHandle, L"VLC_PLUGIN_PATH", 0, REG_SZ, (PBYTE)vlcPluginPath.c_str(), len);
RegCloseKey(keyHandle);
RegFlushKey(keyHandle);
string test = "SET " + newstrValue;
system(test.c_str());
DWORD dwReturnValue=0;
LRESULT error1 = SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)
L"Environment", SMTO_ABORTIFHUNG, 5000, &dwReturnValue);
//SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM) "Environment", SMTO_ABORTIFHUNG, 10000, NULL );
//SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM) L"Environment", SMTO_ABORTIFHUNG, 10000, NULL );
//SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM) TEXT("Environment"), SMTO_ABORTIFHUNG,10000, &dwReturnValue);
//printf("*** VLC D [%s] error1 = %d dwReturnValue = %d ****\n",getenv("VLC_PLUGIN_PATH"),error1,dwReturnValue);
//system(argv[0]);
const char *const *newargv = &argv[1];
_execv( argv[0], newargv );
return 0;
}
}
#endif
PlatformExceptionHandler::application_binary= executable_path(argv[0],true);
mg_app_name = GameConstants::application_name;
mailStringSupport = mailString;

View File

@ -26,12 +26,13 @@ protected:
int height;
int colorBits;
string pluginsPath;
bool verboseEnabled;
bool stop;
public:
VideoPlayer(string filename, SDL_Surface *surface, int width, int height,
int colorBits, string pluginsPath);
int colorBits, string pluginsPath,bool verboseEnabled=false);
virtual ~VideoPlayer();
void PlayVideo();

View File

@ -90,6 +90,7 @@ LONG WINAPI UnhandledExceptionFilter2(struct _EXCEPTION_POINTERS *ExceptionInfo)
LPWSTR Ansi2WideString(LPCSTR lpaszString);
std::string utf8_encode(const std::wstring wstr);
std::wstring utf8_decode(const std::string &str);
std::string getRegKey(const std::string& location, const std::string& name);
void message(string message);
bool ask(string message);

View File

@ -14,6 +14,7 @@
#include <SDL.h>
#include <SDL_mutex.h>
#include <vector>
#if defined(WIN32)
#include <windows.h>
#endif
@ -22,6 +23,35 @@
#include <vlc/vlc.h>
#endif
#if defined(WIN32)
/**
* @param location The location of the registry key. For example "Software\\Bethesda Softworks\\Morrowind"
* @param name the name of the registry key, for example "Installed Path"
* @return the value of the key or an empty string if an error occured.
*/
std::string getRegKey(const std::string& location, const std::string& name){
HKEY key;
CHAR value[1024];
DWORD bufLen = 1024*sizeof(CHAR);
long ret;
ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, location.c_str(), 0, KEY_QUERY_VALUE, &key);
if( ret != ERROR_SUCCESS ){
return std::string();
}
ret = RegQueryValueExA(key, name.c_str(), 0, 0, (LPBYTE) value, &bufLen);
RegCloseKey(key);
if ( (ret != ERROR_SUCCESS) || (bufLen > 1024*sizeof(TCHAR)) ){
return std::string();
}
string stringValue = value;
size_t i = stringValue.length();
while( i > 0 && stringValue[i-1] == '\0' ){
--i;
}
return stringValue.substr(0,i);
}
#endif
struct ctx {
GLuint textureId; // Texture ID
SDL_Surface *surf;
@ -77,13 +107,16 @@ static void display(void *data, void *id) {
}
VideoPlayer::VideoPlayer(string filename, SDL_Surface *surface,
int width, int height,int colorBits,string pluginsPath) {
int width, int height,int colorBits,string pluginsPath,
bool verboseEnabled) {
this->filename = filename;
this->surface = surface;
this->width = width;
this->height = height;
this->colorBits = colorBits;
this->pluginsPath = pluginsPath;
this->verboseEnabled = verboseEnabled;
this->stop = false;
}
@ -112,7 +145,10 @@ void VideoPlayer::PlayVideo() {
std::vector<const char *> vlc_argv;
vlc_argv.push_back("--no-xlib" /* tell VLC to not use Xlib */);
vlc_argv.push_back("--no-video-title-show");
// vlc_argv.push_back(pluginParam.c_str());
if(verboseEnabled) vlc_argv.push_back("--verbose=2");
#if defined(WIN32)
if(verboseEnabled) _putenv("VLC_VERBOSE=2");
#endif
int vlc_argc = vlc_argv.size();
// char const *vlc_argv[] =
@ -155,73 +191,55 @@ void VideoPlayer::PlayVideo() {
/*
* Initialise libVLC
*/
if(verboseEnabled) printf("Trying [%s]\n",getenv("VLC_PLUGIN_PATH"));
libvlc = libvlc_new(vlc_argc, &vlc_argv[0]);
#if defined(WIN32)
if(libvlc == NULL) {
// For windows check registry for install path
#if defined(WIN32) && !defined(__MINGW32__)
//Open the registry key.
wstring subKey = L"Software\\VideoLAN\\VLC";
HKEY keyHandle;
//DWORD dwDisposition;
LONG lres = RegOpenKeyEx(HKEY_LOCAL_MACHINE,subKey.c_str(),0, KEY_READ, &keyHandle);
if(lres == ERROR_SUCCESS) {
std::string strValue;
//GetStringRegKey(keyHandle, L"", strValue, L"");
char szBuffer[4096];
DWORD dwBufferSize = sizeof(szBuffer);
ULONG nError = RegQueryValueEx(keyHandle, L"", 0, NULL, (LPBYTE)szBuffer, &dwBufferSize);
if (ERROR_SUCCESS == nError) {
strValue = szBuffer;
}
RegCloseKey(keyHandle);
if(strValue != "") {
#if defined(WIN32)
strValue = "VLC_PLUGIN_PATH=" + strValue;
_putenv(strValue.c_str());
#else
setenv("VLC_PLUGIN_PATH",strValue.c_str(),1);
#endif
libvlc = libvlc_new(vlc_argc, &vlc_argv[0]);
}
}
#endif
if(libvlc == NULL) {
#if defined(WIN32)
_putenv("VLC_PLUGIN_PATH=c:\\program files\\videolan\\vlc\\plugins");
#else
setenv("VLC_PLUGIN_PATH","c:\\program files\\videolan\\vlc\\plugins",1);
#endif
libvlc = libvlc_new(vlc_argc, &vlc_argv[0]);
}
if(libvlc == NULL) {
#if defined(WIN32)
_putenv("VLC_PLUGIN_PATH=\\program files\\videolan\\vlc\\plugins");
#else
setenv("VLC_PLUGIN_PATH","\\program files\\videolan\\vlc\\plugins",1);
#endif
libvlc = libvlc_new(vlc_argc, &vlc_argv[0]);
if(libvlc == NULL) {
#if defined(WIN32)
_putenv("VLC_PLUGIN_PATH=c:\\program files (x86)\\videolan\\vlc\\plugins");
#else
setenv("VLC_PLUGIN_PATH","c:\\program files (x86)\\videolan\\vlc\\plugins",1);
#endif
libvlc = libvlc_new(vlc_argc, &vlc_argv[0]);
if(libvlc == NULL) {
#if defined(WIN32)
_putenv("VLC_PLUGIN_PATH=\\program files (x86)\\videolan\\vlc\\plugins");
#else
setenv("VLC_PLUGIN_PATH","\\program files (x86)\\videolan\\vlc\\plugins",1);
#endif
libvlc = libvlc_new(vlc_argc, &vlc_argv[0]);
std::string strValue = getRegKey("Software\\VideoLAN\\VLC", "InstallDir");
if(strValue != "") {
if(strValue.length() >= 2) {
if(strValue[0] == '"') {
strValue = strValue.erase(0);
}
if(strValue[strValue.length()-1] == '"') {
strValue = strValue.erase(strValue.length()-1);
}
}
strValue = "VLC_PLUGIN_PATH=" + strValue;
_putenv(strValue.c_str());
if(verboseEnabled) printf("Trying [%s]\n",getenv("VLC_PLUGIN_PATH"));
libvlc = libvlc_new(vlc_argc, &vlc_argv[0]);
}
if(libvlc == NULL) {
_putenv("VLC_PLUGIN_PATH=c:\\program files\\videolan\\vlc\\plugins");
if(verboseEnabled) printf("Trying [%s]\n",getenv("VLC_PLUGIN_PATH"));
libvlc = libvlc_new(vlc_argc, &vlc_argv[0]);
}
if(libvlc == NULL) {
_putenv("VLC_PLUGIN_PATH=\\program files\\videolan\\vlc\\plugins");
if(verboseEnabled) printf("Trying [%s]\n",getenv("VLC_PLUGIN_PATH"));
libvlc = libvlc_new(vlc_argc, &vlc_argv[0]);
}
if(libvlc == NULL) {
_putenv("VLC_PLUGIN_PATH=c:\\program files (x86)\\videolan\\vlc\\plugins");
if(verboseEnabled) printf("Trying [%s]\n",getenv("VLC_PLUGIN_PATH"));
libvlc = libvlc_new(vlc_argc, &vlc_argv[0]);
}
if(libvlc == NULL) {
_putenv("VLC_PLUGIN_PATH=\\program files (x86)\\videolan\\vlc\\plugins");
if(verboseEnabled) printf("Trying [%s]\n",getenv("VLC_PLUGIN_PATH"));
libvlc = libvlc_new(vlc_argc, &vlc_argv[0]);
}
}
#endif
if(libvlc != NULL) {
m = libvlc_media_new_path(libvlc, filename.c_str());
mp = libvlc_media_player_new_from_media(m);

View File

@ -75,6 +75,32 @@ std::wstring utf8_decode(const std::string &str) {
return wstrTo;
}
/**
* @param location The location of the registry key. For example "Software\\Bethesda Softworks\\Morrowind"
* @param name the name of the registry key, for example "Installed Path"
* @return the value of the key or an empty string if an error occured.
*/
std::string getRegKey(const std::string& location, const std::string& name){
HKEY key;
CHAR value[1024];
DWORD bufLen = 1024*sizeof(CHAR);
long ret;
ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, location.c_str(), 0, KEY_QUERY_VALUE, &key);
if( ret != ERROR_SUCCESS ){
return std::string();
}
ret = RegQueryValueExA(key, name.c_str(), 0, 0, (LPBYTE) value, &bufLen);
RegCloseKey(key);
if ( (ret != ERROR_SUCCESS) || (bufLen > 1024*sizeof(TCHAR)) ){
return std::string();
}
string stringValue = value;
size_t i = stringValue.length();
while( i > 0 && stringValue[i-1] == '\0' ){
--i;
}
return stringValue.substr(0,i);
}
LONG WINAPI PlatformExceptionHandler::handler(LPEXCEPTION_POINTERS pointers){