unoapploader.c (599cc5b4) | unoapploader.c (2e9bc605) |
---|---|
1/************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance --- 58 unchanged lines hidden (view full) --- 67 */ 68int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, 69 LPSTR lpCmdLine, int nCmdShow ) 70{ 71 const char* ENVVARNAME = "PATH"; 72 const char* PATHSEPARATOR = ";"; 73 74 char const* path = NULL; | 1/************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance --- 58 unchanged lines hidden (view full) --- 67 */ 68int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, 69 LPSTR lpCmdLine, int nCmdShow ) 70{ 71 const char* ENVVARNAME = "PATH"; 72 const char* PATHSEPARATOR = ";"; 73 74 char const* path = NULL; |
75 char path2[MAX_PATH]; | |
76 char* value = NULL; 77 char* envstr = NULL; 78 char* cmdline = NULL; 79 int size; 80 STARTUPINFO startup_info; 81 PROCESS_INFORMATION process_info; | 75 char* value = NULL; 76 char* envstr = NULL; 77 char* cmdline = NULL; 78 int size; 79 STARTUPINFO startup_info; 80 PROCESS_INFORMATION process_info; |
82 BOOL bCreate; 83 | 81 BOOL bCreate; 82 |
84 (void) hInstance; /* unused */ 85 (void) hPrevInstance; /* unused */ 86 (void) nCmdShow; /* unused */ 87 88 /* get the path of the UNO installation */ 89 path = getPath(); | 83 (void) hInstance; /* unused */ 84 (void) hPrevInstance; /* unused */ 85 (void) nCmdShow; /* unused */ 86 87 /* get the path of the UNO installation */ 88 path = getPath(); |
90 | 89 |
91 if ( path != NULL ) 92 { | 90 if ( path != NULL ) 91 { |
93 wchar_t cmd[ 94 MY_LENGTH(L"\"") + MAX_PATH + 95 MY_LENGTH(L"\\unoinfo.exe\" c++")]; 96 /* hopefully does not overflow */ 97 int pathsize; 98 SECURITY_ATTRIBUTES sec; 99 HANDLE temp; 100 HANDLE stdoutRead; 101 HANDLE stdoutWrite; 102 STARTUPINFOW startinfo; 103 PROCESS_INFORMATION procinfo; 104 int ret; 105 cmd[0] = L'"'; 106 pathsize = MultiByteToWideChar(CP_ACP, 0, path, -1, cmd + 1, MAX_PATH); 107 if (pathsize == 0) { 108 writeError("Error: MultiByteToWideChar failed!\n"); 109 closeErrorFile(); 110 return 1; 111 } 112 if (wcschr(cmd + 1, L'"') != NULL) { 113 writeError("Error: bad characters in UNO installation path!\n"); 114 closeErrorFile(); 115 return 1; 116 } 117 wcscpy( 118 cmd + pathsize, 119 (L"\\unoinfo.exe\" c++" + 120 (pathsize == 1 || cmd[pathsize - 1] != L'\\' ? 0 : 1))); 121 sec.nLength = sizeof (SECURITY_ATTRIBUTES); 122 sec.lpSecurityDescriptor = NULL; 123 sec.bInheritHandle = TRUE; 124 if (CreatePipe(&temp, &stdoutWrite, &sec, 0) == 0 || 125 DuplicateHandle( 126 GetCurrentProcess(), temp, GetCurrentProcess(), &stdoutRead, 0, 127 FALSE, DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS) == 0) 128 { 129 writeError("Error: CreatePipe/DuplicateHandle failed!\n"); 130 closeErrorFile(); 131 return 1; 132 } 133 memset(&startinfo, 0, sizeof (STARTUPINFOW)); 134 startinfo.cb = sizeof (STARTUPINFOW); 135 startinfo.lpDesktop = L""; 136 startinfo.dwFlags = STARTF_USESTDHANDLES; 137 startinfo.hStdOutput = stdoutWrite; 138 ret = CreateProcessW( 139 NULL, cmd, NULL, NULL, TRUE, 0, NULL, NULL, &startinfo, &procinfo); 140 if (ret != 0) { 141 char * buf = NULL; 142 size_t n = 1000; 143 size_t k = 0; 144 DWORD exitcode; 145 int path2size; 146 CloseHandle(stdoutWrite); 147 CloseHandle(procinfo.hThread); 148 for (;;) { 149 DWORD m; 150 buf = realloc(buf, n); 151 if (buf == NULL) { 152 writeError( 153 "Error: out of memory reading unoinfo output!\n"); 154 closeErrorFile(); 155 return 1; 156 } 157 if (!ReadFile(stdoutRead, buf + k, n - k, &m, NULL)) 158 { 159 DWORD err = GetLastError(); 160 if (err == ERROR_HANDLE_EOF || err == ERROR_BROKEN_PIPE) { 161 break; 162 } 163 writeError("Error: cannot read unoinfo output!\n"); 164 closeErrorFile(); 165 return 1; 166 } 167 if (m == 0) { 168 break; 169 } 170 k += m; 171 if (k >= n) { 172 if (n >= SAL_MAX_SIZE / 2) { 173 writeError( 174 "Error: out of memory reading unoinfo output!\n"); 175 closeErrorFile(); 176 return 1; 177 } 178 n *= 2; 179 } 180 } 181 if ((k & 1) == 1) { 182 writeError("Error: bad unoinfo output!\n"); 183 closeErrorFile(); 184 return 1; 185 } 186 CloseHandle(stdoutRead); 187 if (!GetExitCodeProcess(procinfo.hProcess, &exitcode) || 188 exitcode != 0) 189 { 190 writeError("Error: executing unoinfo failed!\n"); 191 closeErrorFile(); 192 return 1; 193 } 194 if (k == 0) { 195 path2size = 0; 196 } else { 197 path2size = WideCharToMultiByte( 198 CP_ACP, 0, (wchar_t *) buf, k / 2, path2, MAX_PATH - 1, 199 NULL, NULL); 200 if (path2size == 0) { 201 writeError("Error: converting unoinfo output failed!\n"); 202 closeErrorFile(); 203 return 1; 204 } 205 } 206 path2[path2size] = '\0'; 207 path = path2; 208 } else { 209 if (GetLastError() != ERROR_FILE_NOT_FOUND) { 210 writeError("Error: calling unoinfo failed!\n"); 211 closeErrorFile(); 212 return 1; 213 } 214 CloseHandle(stdoutRead); 215 CloseHandle(stdoutWrite); 216 } 217 | 92 /* The former code to call unoinfo first is removed because we can use the office path 93 from the registry or from the UNO_PATH variable directly. 94 Further cleanup can remove unoinfo from the installation when all places where it is 95 used are checked. 96 */ 97 |
218 /* get the value of the PATH environment variable */ 219 value = getenv( ENVVARNAME ); 220 221 /* 222 * add the UNO installation path to the PATH environment variable; 223 * note that this only affects the environment variable of the current 224 * process, the command processor's environment is not changed 225 */ --- 49 unchanged lines hidden (view full) --- 275 * Gets the path of a UNO installation. 276 * 277 * @return the installation path or NULL, if no installation was specified or 278 * found, or if an error occured 279 */ 280char const* getPath() 281{ 282 char const* path = cppuhelper_detail_findSofficePath(); | 98 /* get the value of the PATH environment variable */ 99 value = getenv( ENVVARNAME ); 100 101 /* 102 * add the UNO installation path to the PATH environment variable; 103 * note that this only affects the environment variable of the current 104 * process, the command processor's environment is not changed 105 */ --- 49 unchanged lines hidden (view full) --- 155 * Gets the path of a UNO installation. 156 * 157 * @return the installation path or NULL, if no installation was specified or 158 * found, or if an error occured 159 */ 160char const* getPath() 161{ 162 char const* path = cppuhelper_detail_findSofficePath(); |
283 | 163 |
284 if ( path == NULL ) 285 writeError( "Warning: getting path from Windows Registry failed!\n" ); 286 287 return path; 288} 289 290/* 291 * Creates the command line for the application process including the absolute --- 128 unchanged lines hidden --- | 164 if ( path == NULL ) 165 writeError( "Warning: getting path from Windows Registry failed!\n" ); 166 167 return path; 168} 169 170/* 171 * Creates the command line for the application process including the absolute --- 128 unchanged lines hidden --- |