зеркало из https://github.com/mozilla/pjs.git
bug 465874 - WinCE Environment Variables Have To Be Passed On Command Line r=bsmedberg
This commit is contained in:
Родитель
5dbd18df59
Коммит
5ae7fa36dc
|
@ -103,6 +103,8 @@ MOZCE_SHUNT_API int _unlink(const char *filename );
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
MOZCE_SHUNT_API unsigned short* mozce_GetEnvironmentCL();
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -36,9 +36,8 @@
|
||||||
*
|
*
|
||||||
* ***** END LICENSE BLOCK ***** */
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
#include "stdlib.h"
|
||||||
#include "stdlib.h"
|
#include "Windows.h"
|
||||||
#include "Windows.h"
|
|
||||||
|
|
||||||
#include "mozce_shunt.h"
|
#include "mozce_shunt.h"
|
||||||
#include "time_conversions.h"
|
#include "time_conversions.h"
|
||||||
|
@ -65,14 +64,11 @@ static mapping initial_map[] = {
|
||||||
{"NS_TIMELINE_LOG_FILE","\\bin\\timeline.log",initial_map + (init_i++)},
|
{"NS_TIMELINE_LOG_FILE","\\bin\\timeline.log",initial_map + (init_i++)},
|
||||||
{"NS_TIMELINE_ENABLE", "1",initial_map + (init_i++)},
|
{"NS_TIMELINE_ENABLE", "1",initial_map + (init_i++)},
|
||||||
#endif
|
#endif
|
||||||
{"tmp", "/Temp",initial_map + (init_i++)},
|
|
||||||
{"GRE_HOME",".",initial_map + (init_i++)},
|
|
||||||
{"NSS_DEFAULT_DB_TYPE", "sql",initial_map + (init_i++)},
|
{"NSS_DEFAULT_DB_TYPE", "sql",initial_map + (init_i++)},
|
||||||
{"NSPR_FD_CACHE_SIZE_LOW", "10",initial_map + (init_i++)},
|
{"NSPR_FD_CACHE_SIZE_LOW", "10",initial_map + (init_i++)},
|
||||||
{"NSPR_FD_CACHE_SIZE_HIGH", "30",initial_map + (init_i++)},
|
{"NSPR_FD_CACHE_SIZE_HIGH", "30",initial_map + (init_i++)},
|
||||||
{"XRE_PROFILE_PATH", "\\Application Data\\Mozilla\\Profiles",initial_map + (init_i++)},
|
{"XRE_PROFILE_NAME","default",initial_map + (init_i++)},
|
||||||
{"XRE_PROFILE_LOCAL_PATH","./profile",initial_map + (init_i++)},
|
{"tmp", "/Temp", 0 }
|
||||||
{"XRE_PROFILE_NAME","default",0}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static mapping* head = initial_map;
|
static mapping* head = initial_map;
|
||||||
|
@ -146,22 +142,21 @@ MOZCE_SHUNT_API char GetEnvironmentVariableW(const unsigned short * lpName, unsi
|
||||||
256,
|
256,
|
||||||
NULL,
|
NULL,
|
||||||
NULL);
|
NULL);
|
||||||
if(rv < 0)
|
if(rv <= 0)
|
||||||
return rv;
|
return 0;
|
||||||
|
|
||||||
char* val = map_get(key);
|
char* val = map_get(key);
|
||||||
|
|
||||||
if(val)
|
if(val)
|
||||||
{
|
{
|
||||||
MultiByteToWideChar(CP_ACP,
|
return MultiByteToWideChar(CP_ACP,
|
||||||
0,
|
0,
|
||||||
val,
|
val,
|
||||||
strlen(val)+1,
|
strlen(val)+1,
|
||||||
lpBuffer,
|
lpBuffer,
|
||||||
nSize );
|
nSize);
|
||||||
return ERROR_SUCCESS;
|
|
||||||
}
|
}
|
||||||
return -1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
MOZCE_SHUNT_API char SetEnvironmentVariableW( const unsigned short * name, const unsigned short * value )
|
MOZCE_SHUNT_API char SetEnvironmentVariableW( const unsigned short * name, const unsigned short * value )
|
||||||
|
@ -584,8 +579,37 @@ MOZCE_SHUNT_API struct lconv * localeconv(void)
|
||||||
{
|
{
|
||||||
return &s_locale_conv;
|
return &s_locale_conv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
MOZCE_SHUNT_API
|
||||||
|
unsigned short* mozce_GetEnvironmentCL()
|
||||||
|
{
|
||||||
|
mapping* cur = head;
|
||||||
|
int len = 0;
|
||||||
|
while(cur != NULL){
|
||||||
|
len+=strlen(cur->key);
|
||||||
|
len+=strlen(cur->value);
|
||||||
|
len+=15;
|
||||||
|
cur = cur->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned short* env = (unsigned short*)malloc(sizeof(wchar_t)*(len +1));
|
||||||
|
cur = head;
|
||||||
|
int pos = 0;
|
||||||
|
while(cur != NULL){
|
||||||
|
wcscpy(env+pos, L" --environ:\"");
|
||||||
|
pos+=12;
|
||||||
|
pos+=MultiByteToWideChar( CP_ACP, 0, cur->key, -1, env+pos, len-pos );
|
||||||
|
env[pos-1] = '=';
|
||||||
|
pos+=MultiByteToWideChar( CP_ACP, 0, cur->value, -1, env+pos, len-pos );
|
||||||
|
env[pos-1]='\"';
|
||||||
|
|
||||||
|
cur = cur->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
env[pos] = '\0';
|
||||||
|
return env;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
BOOL WINAPI DllMain(HANDLE hinstDLL, DWORD fdwReason, LPVOID lpReserved)
|
BOOL WINAPI DllMain(HANDLE hinstDLL, DWORD fdwReason, LPVOID lpReserved)
|
||||||
{
|
{
|
||||||
|
|
|
@ -172,6 +172,11 @@ MakeCommandLine(int argc, PRUnichar **argv)
|
||||||
for (i = 0; i < argc; ++i)
|
for (i = 0; i < argc; ++i)
|
||||||
len += ArgStrLen(argv[i]) + 1;
|
len += ArgStrLen(argv[i]) + 1;
|
||||||
|
|
||||||
|
#ifdef WINCE
|
||||||
|
wchar_t *env = mozce_GetEnvironmentCL();
|
||||||
|
len += (wcslen(env));
|
||||||
|
#endif
|
||||||
|
|
||||||
// Protect against callers that pass 0 arguments
|
// Protect against callers that pass 0 arguments
|
||||||
if (len == 0)
|
if (len == 0)
|
||||||
len = 1;
|
len = 1;
|
||||||
|
@ -191,6 +196,9 @@ MakeCommandLine(int argc, PRUnichar **argv)
|
||||||
|
|
||||||
*c = '\0';
|
*c = '\0';
|
||||||
|
|
||||||
|
#ifdef WINCE
|
||||||
|
wcscat(s, env);
|
||||||
|
#endif
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,6 +265,19 @@ WinLaunchChild(const PRUnichar *exePath, int argc, PRUnichar **argv)
|
||||||
{
|
{
|
||||||
PRUnichar *cl;
|
PRUnichar *cl;
|
||||||
BOOL ok;
|
BOOL ok;
|
||||||
|
|
||||||
|
#ifdef WINCE
|
||||||
|
// Windows Mobile Issue:
|
||||||
|
// When passing both an image name and a command line to
|
||||||
|
// CreateProcessW, you need to make sure that the image name
|
||||||
|
// identially matches the first argument of the command line. If
|
||||||
|
// they do not match, Windows Mobile will send two "argv[0]" values.
|
||||||
|
// To avoid this problem, we will strip off the argv here, and
|
||||||
|
// depend only on the exePath.
|
||||||
|
argv = argv + 1;
|
||||||
|
argc--;
|
||||||
|
#endif
|
||||||
|
|
||||||
cl = MakeCommandLine(argc, argv);
|
cl = MakeCommandLine(argc, argv);
|
||||||
if (!cl)
|
if (!cl)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -278,6 +299,19 @@ WinLaunchChild(const PRUnichar *exePath, int argc, PRUnichar **argv)
|
||||||
if (ok) {
|
if (ok) {
|
||||||
CloseHandle(pi.hProcess);
|
CloseHandle(pi.hProcess);
|
||||||
CloseHandle(pi.hThread);
|
CloseHandle(pi.hThread);
|
||||||
|
} else {
|
||||||
|
LPVOID lpMsgBuf;
|
||||||
|
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||||
|
FORMAT_MESSAGE_FROM_SYSTEM |
|
||||||
|
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||||
|
NULL,
|
||||||
|
GetLastError(),
|
||||||
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||||
|
(LPTSTR) &lpMsgBuf,
|
||||||
|
0,
|
||||||
|
NULL
|
||||||
|
);
|
||||||
|
wprintf(L"Error restarting: %s\n", lpMsgBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(cl);
|
free(cl);
|
||||||
|
|
|
@ -62,8 +62,28 @@ FreeAllocStrings(int argc, char **argv)
|
||||||
delete [] argv;
|
delete [] argv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef WINCE
|
||||||
|
/** argc/argv are in/out parameters */
|
||||||
|
void ExtractEnvironmentFromCL(int &argc, WCHAR **&argv)
|
||||||
|
{
|
||||||
|
for (int x = 0; x < argc; ++x) {
|
||||||
|
if (!wcsncmp(argv[x], L"--environ:",10)) {
|
||||||
|
char* key_val = AllocConvertUTF16toUTF8(argv[x]+10);
|
||||||
|
putenv(key_val);
|
||||||
|
free(key_val);
|
||||||
|
argc -= 1;
|
||||||
|
memcpy(&argv[x], &argv[x+1], (argc - x) * sizeof(WCHAR*));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
int wmain(int argc, WCHAR **argv)
|
int wmain(int argc, WCHAR **argv)
|
||||||
{
|
{
|
||||||
|
#ifdef WINCE
|
||||||
|
ExtractEnvironmentFromCL(argc, argv);
|
||||||
|
#endif
|
||||||
char **argvConverted = new char*[argc + 1];
|
char **argvConverted = new char*[argc + 1];
|
||||||
if (!argvConverted)
|
if (!argvConverted)
|
||||||
return 127;
|
return 127;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче