- a compromise for libvlc, only fallback to retarded env var code if plugins folder is missing. However we plan to ship that folder next install.

This commit is contained in:
Mark Vejvoda 2012-05-14 07:28:34 +00:00
parent 093d22ce8b
commit b91f816f3e
1 changed files with 136 additions and 99 deletions

View File

@ -12,6 +12,7 @@
#include <winsock2.h>
#include <winsock.h>
#include <process.h>
#include <io.h>
#endif
#include "math_wrapper.h"
@ -2725,75 +2726,43 @@ int glestMain(int argc, char** argv) {
//char *ptr = new char[200];
// printf("END ALLOC char 200\n");
// return -1;
SystemFlags::VERBOSE_MODE_ENABLED = false;
if(hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_VERBOSE_MODE]) == true) {
SystemFlags::VERBOSE_MODE_ENABLED = true;
}
if( hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_MASTERSERVER_MODE])) == true) {
//isMasterServerModeEnabled = true;
//Window::setMasterserverMode(isMasterServerModeEnabled);
GlobalStaticFlags::setIsNonGraphicalModeEnabled(true);
#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");
int foundParamIndIndex = -1;
hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_MASTERSERVER_MODE]) + string("="),&foundParamIndIndex);
if(foundParamIndIndex < 0) {
hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_MASTERSERVER_MODE]),&foundParamIndIndex);
}
string paramValue = argv[foundParamIndIndex];
vector<string> paramPartTokens;
Tokenize(paramValue,paramPartTokens,"=");
if(paramPartTokens.size() >= 2 && paramPartTokens[1].length() > 0) {
string headless_command_list = paramPartTokens[1];
// 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);
vector<string> paramHeadlessCommandList;
Tokenize(headless_command_list,paramHeadlessCommandList,",");
for(unsigned int i = 0; i < paramHeadlessCommandList.size(); ++i) {
string headless_command = paramHeadlessCommandList[i];
if(headless_command == "exit") {
printf("Forcing quit after game has completed [%s]\n",headless_command.c_str());
Program::setWantShutdownApplicationAfterGame(true);
}
if(strValue[strValue.length()-1] == '"') {
strValue = strValue.erase(strValue.length()-1);
}
if(strValue[strValue.length()-1] != '\\') {
strValue += "\\";
else if(headless_command == "vps") {
printf("Disabled reading from console [%s]\n",headless_command.c_str());
disableheadless_console = true;
}
}
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;
@ -2806,11 +2775,112 @@ int glestMain(int argc, char** argv) {
Properties::setApplicationPath(executable_path(argv[0]));
Properties::setGameVersion(glestVersionString);
#if defined(WIN32)
printf("Path [%s]\n",executable_path(argv[0]).c_str());
if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false &&
folderExists(executable_path(argv[0]) + "plugins\\") == false) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("*** VLC START ****\n");
if(SystemFlags::VERBOSE_MODE_ENABLED) 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);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("*** VLC D [%s] error1 = %d dwReturnValue = %d ****\n",getenv("VLC_PLUGIN_PATH"),error1,dwReturnValue);
//system(argv[0]);
SDL_Quit();
_flushall();
// Gotta do this or else the process hangs on exit
// Windows has no support for FD_CLOEXEC :(
fclose(stdin);
fclose(stdout);
fclose(stderr);
/*
int myin = _dup(_fileno(stdin));
int myout = _dup(_fileno(stdout));
int myerr = _dup(_fileno(stderr));
fclose(stdin);
fclose(stdout);
fclose(stderr);
_dup2(myin,0);
_dup2(myout,1);
_dup2(myerr,2);
*/
//fcntl(fd, F_SETFD, FD_CLOEXEC);
//fcntl(fd, F_SETFL, fcntl(fd, F_GETFD) | FD_CLOEXEC));
const char *const *newargv = argv;
if(_execv(argv[0], newargv) == -1) {
perror("Unable to relaunch!");
}
abort();
}
}
else {
//fclose(stdin);
//fclose(stdout);
//fclose(stderr);
}
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("*** VLC E [%s]\n",getenv("VLC_PLUGIN_PATH"));
}
#endif
ServerSocket::setMaxPlayerCount(GameConstants::maxPlayers);
SystemFlags::VERBOSE_MODE_ENABLED = false;
if(hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_VERBOSE_MODE]) == true) {
SystemFlags::VERBOSE_MODE_ENABLED = true;
}
//vector<string> results;
//findAll("/home/softcoder/Code/megaglest/trunk/mk/linux//äöüß/maps/*.gbm", results, false, true);
@ -2860,39 +2930,6 @@ int glestMain(int argc, char** argv) {
return -1;
}
if( hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_MASTERSERVER_MODE])) == true) {
//isMasterServerModeEnabled = true;
//Window::setMasterserverMode(isMasterServerModeEnabled);
GlobalStaticFlags::setIsNonGraphicalModeEnabled(true);
int foundParamIndIndex = -1;
hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_MASTERSERVER_MODE]) + string("="),&foundParamIndIndex);
if(foundParamIndIndex < 0) {
hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_MASTERSERVER_MODE]),&foundParamIndIndex);
}
string paramValue = argv[foundParamIndIndex];
vector<string> paramPartTokens;
Tokenize(paramValue,paramPartTokens,"=");
if(paramPartTokens.size() >= 2 && paramPartTokens[1].length() > 0) {
string headless_command_list = paramPartTokens[1];
vector<string> paramHeadlessCommandList;
Tokenize(headless_command_list,paramHeadlessCommandList,",");
for(unsigned int i = 0; i < paramHeadlessCommandList.size(); ++i) {
string headless_command = paramHeadlessCommandList[i];
if(headless_command == "exit") {
printf("Forcing quit after game has completed [%s]\n",headless_command.c_str());
Program::setWantShutdownApplicationAfterGame(true);
}
else if(headless_command == "vps") {
printf("Disabled reading from console [%s]\n",headless_command.c_str());
disableheadless_console = true;
}
}
}
}
//off_t fileSize = getFileSize(argv[0]);
//double fSize = ((double)fileSize / 1048576.0);
//printf("[%ld] [%.2f]\n",fileSize,fSize);