diff options
author | RĂ¼diger Timm <rt@openoffice.org> | 2004-09-20 13:38:08 +0000 |
---|---|---|
committer | RĂ¼diger Timm <rt@openoffice.org> | 2004-09-20 13:38:08 +0000 |
commit | a06fa210cc9d71108cf9580a31a23a6311022a10 (patch) | |
tree | 23fb1b69aa936b22954c4c0200664d219182d0e1 /cli_ure | |
parent | fd754d129579c5961a05f33c0b4e773d95984804 (diff) |
INTEGRATION: CWS jl12 (1.5.8); FILE MERGED
2004/08/30 13:13:26 jl 1.5.8.1: #i33134# #i33485#
Diffstat (limited to 'cli_ure')
-rw-r--r-- | cli_ure/source/native/native_bootstrap.cxx | 179 |
1 files changed, 117 insertions, 62 deletions
diff --git a/cli_ure/source/native/native_bootstrap.cxx b/cli_ure/source/native/native_bootstrap.cxx index 5f6c81fbe..f64b3f892 100644 --- a/cli_ure/source/native/native_bootstrap.cxx +++ b/cli_ure/source/native/native_bootstrap.cxx @@ -2,9 +2,9 @@ * * $RCSfile: native_bootstrap.cxx,v $ * - * $Revision: 1.5 $ + * $Revision: 1.6 $ * - * last change: $Author: rt $ $Date: 2004-07-12 13:05:55 $ + * last change: $Author: rt $ $Date: 2004-09-20 14:38:08 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -64,6 +64,7 @@ #include "rtl/bootstrap.hxx" #include "cppuhelper/bootstrap.hxx" #include <windows.h> +//#include <winreg.h> #include <delayimp.h> #include <stdio.h> @@ -74,78 +75,130 @@ using namespace ::com::sun::star::uno; #define OFFICE_LOCATION_REGISTRY_KEY "Software\\OpenOffice.org\\UNO\\InstallPath" -#pragma unmanaged namespace { + char* getLibraryPath() { - static char* sPath; + static char* sPath = NULL; + //do not use oslMutex here. That would cause to load sal and we would //run in a loop with delayLoadHook if (sPath == NULL) { - bool failed = false; - HKEY hKey = 0; - if (RegOpenKeyExA(HKEY_CURRENT_USER,OFFICE_LOCATION_REGISTRY_KEY, - 0, KEY_READ, &hKey) != ERROR_SUCCESS) + //First we try the environment variable UNO_PATH. It overrides all other settings. + //Get the UNO_PATH environment variable, do not use CRT, use Kernel library + char * sEnvUnoPath = NULL; + DWORD cChars = GetEnvironmentVariableA("UNO_PATH", sEnvUnoPath, 0); + if (cChars > 0) + { + sEnvUnoPath = new char[cChars]; + cChars = GetEnvironmentVariableA("UNO_PATH", sEnvUnoPath, cChars); + } + //store the UNO_PATH in the static variable that will be returned from now on. + if (cChars > 0) + { + sPath = new char[cChars + 1]; + sPath[0] = 0; + lstrcatA(sPath, sEnvUnoPath); + } + delete[] sEnvUnoPath; + + //try registry + if (sPath == NULL) { - if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, OFFICE_LOCATION_REGISTRY_KEY, + bool failed = false; + HKEY hKey = 0; + if (RegOpenKeyExA(HKEY_CURRENT_USER,OFFICE_LOCATION_REGISTRY_KEY, 0, KEY_READ, &hKey) != ERROR_SUCCESS) { - OSL_ASSERT(0); - fprintf(stderr, "cli_cppuhelper: Office not properly installed. " - "Could not open registry keys."); - failed = true; + if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, OFFICE_LOCATION_REGISTRY_KEY, + 0, KEY_READ, &hKey) != ERROR_SUCCESS) + { + OSL_ASSERT(0); +#if OSL_DEBUG_LEVEL >= 2 + fprintf(stderr, "cli_cppuhelper: Office not properly installed. " + "Could not open registry keys."); +#endif + failed = true; + } } - } - if (failed) - return NULL; - - DWORD dwType = 0; - DWORD dwLen = 0; - char *arData = NULL; - //get the length for the path to office - if (RegQueryValueExA(hKey, NULL, NULL, &dwType, NULL, - &dwLen) == ERROR_SUCCESS) - { - arData = new char[dwLen]; - if (RegQueryValueExA(hKey, NULL, NULL, &dwType, (LPBYTE) arData, - & dwLen) == ERROR_SUCCESS) + if (failed) + return NULL; + + DWORD dwType = 0; + DWORD dwLen = 0; + char *arData = NULL; + //get the length for the path to office + if (RegQueryValueExA(hKey, NULL, NULL, &dwType, NULL, + &dwLen) == ERROR_SUCCESS) { - sPath = strdup(arData); + arData = new char[dwLen]; + if (RegQueryValueExA(hKey, NULL, NULL, &dwType, (LPBYTE) arData, + & dwLen) == ERROR_SUCCESS) + { + sPath = new char[dwLen]; + lstrcpyA(sPath, arData); #if OSL_DEBUG_LEVEL >=2 - fprintf(stdout,"[cli_cppuhelper]: Using path %s to load office libraries.", sPath); + fprintf(stdout,"[cli_cppuhelper]: Using path %s to load office libraries.", sPath); #endif + } + delete [] arData; } - delete [] arData; + RegCloseKey(hKey); } - RegCloseKey(hKey); - - //We extend the path to contain the program directory of the office, - //so that components can use osl_loadModule with arguments, such as - //"reg3.dll". That is, the arguments are only the library names. - char * sEnvPath = getenv("PATH"); - char * buff = NULL; - if (sEnvPath) - buff = new char[sizeof("PATH=") + strlen(sEnvPath) + strlen(sPath) + 2]; - else - buff = new char[sizeof("PATH=") + strlen(sPath) + 2]; - buff[0] = 0; - strcat(buff, "PATH="); - strcat(buff, sPath); - if (sEnvPath) + if (sPath) { - strcat(buff, ";"); - strcat(buff, sEnvPath); + //We extend the path to contain the program directory of the office, + //so that components can use osl_loadModule with arguments, such as + //"reg3.dll". That is, the arguments are only the library names. + + //Get the PATH environment variable, do not use CRT, use Kernel library + char * sEnvPath = NULL; + DWORD cChars = GetEnvironmentVariableA("PATH", sEnvPath, 0); + if (cChars > 0) + { + sEnvPath = new char[cChars]; + cChars = GetEnvironmentVariableA("PATH", sEnvPath, cChars); + } + if (cChars == 0 && GetLastError() != ERROR_ENVVAR_NOT_FOUND) + { + delete[] sEnvPath; + return NULL; + } + + //prepare the new PATH, including the path to the program folder + char * sNewPath = NULL; + int lenPath = lstrlenA(sEnvPath); + if (lenPath > 0) + sNewPath = new char[lenPath + lstrlenA(sPath) + 2]; + else + sNewPath = new char[lenPath + 1]; + sNewPath[0] = 0; + + lstrcatA(sNewPath, sPath); + if (lenPath) + { + lstrcatA(sNewPath, ";"); + lstrcatA(sNewPath, sEnvPath); + } + + BOOL bSet = SetEnvironmentVariableA("PATH", sNewPath); + + delete[] sEnvPath; + delete[] sNewPath; + + if (bSet == FALSE) + return NULL; } - putenv(buff); } return sPath; } + //Hook for delayed loading of libraries which this library is linked with. extern "C" FARPROC WINAPI delayLoadHook( unsigned dliNotify, @@ -155,19 +208,22 @@ extern "C" FARPROC WINAPI delayLoadHook( if (dliNotify == dliFailLoadLib) { char* sPath = getLibraryPath(); - int lenPath = strlen(sPath); - //create string to contain the full path to cppuhelper - int lenLib = strlen(pdli->szDll); - char* sFullPath = new char[lenLib + lenPath + 2]; - sFullPath[0] = 0; - sFullPath = strcat(sFullPath, sPath); - sFullPath = strcat(sFullPath, "\\"); - sFullPath = strcat(sFullPath, pdli->szDll); - - HMODULE handle = LoadLibraryExA(sFullPath, NULL, - LOAD_WITH_ALTERED_SEARCH_PATH); - delete[] sFullPath; - return (FARPROC) handle; + if (sPath) + { + int lenPath = lstrlenA(sPath); + //create string to contain the full path to cppuhelper + int lenLib = lstrlenA(pdli->szDll); + char* sFullPath = new char[lenLib + lenPath + 2]; + sFullPath[0] = 0; + sFullPath = lstrcatA(sFullPath, sPath); + sFullPath = lstrcatA(sFullPath, "\\"); + sFullPath = lstrcatA(sFullPath, pdli->szDll); + + HMODULE handle = LoadLibraryExA(sFullPath, NULL, + LOAD_WITH_ALTERED_SEARCH_PATH); + delete[] sFullPath; + return (FARPROC) handle; + } } return 0; } @@ -175,7 +231,6 @@ extern "C" FARPROC WINAPI delayLoadHook( ExternC PfnDliHook __pfnDliFailureHook2 = delayLoadHook; -#pragma managed namespace uno { |