Changeset 37963
- Timestamp:
- 07/19/10 16:35:46 (3 years ago)
- Location:
- lang/c/AutoUpdater/trunk
- Files:
-
- 2 modified
-
Makefile.am (modified) (2 diffs)
-
UpdaterProcess.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/c/AutoUpdater/trunk/Makefile.am
r37957 r37963 1 bin_PROGRAMS = test updater 1 bin_PROGRAMS = test updater wtest 2 2 3 3 test_SOURCES = Test.cpp AutoUpdater.c … … 5 5 6 6 updater_SOURCES = UpdaterProcess.c 7 7 wtest_SOURCES = wtest.c -
lang/c/AutoUpdater/trunk/UpdaterProcess.c
r37962 r37963 93 93 94 94 if (FILE_ATTRIBUTE_DIRECTORY & find_data.dwFileAttributes) { 95 AUI_Debug(_T("dir \n"));95 AUI_Debug(_T("dir error\n")); 96 96 result = result && CreateDirectory(to2, NULL) && CopyDirectory(from2, to2); 97 97 } else if(!CopyFile(from2, to2, FALSE)) { 98 AUI_Debug(_T("file \n"));98 AUI_Debug(_T("file error\n")); 99 99 result = FALSE; 100 100 } … … 108 108 FindClose(hFind); 109 109 HeapFree(GetProcessHeap(), 0, glob); 110 return TRUE;110 return result; 111 111 } 112 112 … … 117 117 DWORD bytes_got = 0; 118 118 TCHAR* data = NULL; 119 TCHAR* lines[5] = { 0};119 TCHAR* lines[5] = {NULL, NULL, NULL, NULL, NULL}; 120 120 DWORD pid = 0; 121 121 int complete = 0; 122 TCHAR* clean_command = NULL; 123 TCHAR* temp_path = NULL; 124 TCHAR* command = NULL; 122 125 123 126 AUI_Debug(_T("***** UpdaterProcess start: pid=0x%x *****\n"), GetCurrentProcessId()); 127 { 128 size_t temp_path_chars = GetTempPath(0, NULL); 129 temp_path = (TCHAR*)HeapAlloc(GetProcessHeap(), 130 HEAP_ZERO_MEMORY, (temp_path_chars * sizeof(TCHAR))); 131 if (!temp_path) { 132 goto clean_up; 133 } 134 GetTempPath(temp_path_chars, temp_path); 135 } 124 136 125 137 hFile = CreateFile(_T("updater.txt"), GENERIC_READ, 0, NULL, … … 131 143 132 144 bytes = GetFileSize(hFile, NULL); 133 data = (TCHAR*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, bytes + sizeof(TCHAR));145 data = (TCHAR*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, bytes + (/* null terminate */ sizeof(TCHAR))); 134 146 if (!data) { 135 147 goto clean_up; … … 177 189 } 178 190 191 192 { 193 TCHAR comspec[MAX_PATH]; 194 TCHAR rd_command[] = _T("\"%s\" /c rd /s /q \"%s\""); 195 size_t clean_command_len = 0; 196 if (GetEnvironmentVariable(_T("COMSPEC"), comspec, sizeof(comspec) / sizeof(comspec[0])) == 0) { 197 goto clean_up; 198 } 199 200 clean_command_len = lstrlen(comspec) + lstrlen(rd_command) + lstrlen(lines[4]); 201 clean_command = (TCHAR*)HeapAlloc(GetProcessHeap(), 202 HEAP_ZERO_MEMORY, clean_command_len * sizeof(TCHAR)); 203 if (!clean_command) { 204 goto clean_up; 205 } 206 wsprintf(clean_command, rd_command, comspec, lines[4]); 207 } 208 179 209 AUI_Debug(L"waiting\n"); 180 210 hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | SYNCHRONIZE, FALSE, pid); … … 190 220 191 221 clean_up: 192 { 193 STARTUPINFO si; 194 PROCESS_INFORMATION pi; 195 DWORD e = 0; 196 TCHAR* command = NULL; 222 if (lines[3] && lines[4]) { 197 223 TCHAR* arg = NULL; 198 TCHAR complete_arg[] = _T(" UPDATE_COMPLETE"); 199 TCHAR error_arg[] = _T(" UPDATE_ERROR"); 224 TCHAR command_format[] = _T("\"%s\" %s"); 225 TCHAR complete_arg[] = _T("UPDATE_COMPLETE"); 226 TCHAR error_arg[] = _T("UPDATE_ERROR"); 200 227 int command_len = 0; 201 228 SetLastError(0); … … 205 232 arg = error_arg; 206 233 } 207 command_len = lstrlen( lines[3]);208 command_len += 2; /* double quotation */234 command_len = lstrlen(command_format); 235 command_len += lstrlen(lines[3]); 209 236 command_len += lstrlen(arg); 210 237 211 238 command = (TCHAR*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (unsigned)command_len * sizeof(TCHAR)); 212 lstrcat(command, _T("\"")); 213 lstrcat(command, lines[3]); 214 lstrcat(command, _T("\"")); 215 lstrcat(command, arg); 216 239 if (command) { 240 wsprintf(command, command_format, lines[3], arg); 241 } 242 } 243 244 if (command && lines[4]) { 245 STARTUPINFO si; 246 PROCESS_INFORMATION pi; 247 DWORD e; 217 248 memset(&si, 0, sizeof(si)); 218 249 si.cb = sizeof(si); … … 223 254 AUI_Debug(_T("CreateProcess(): command=%s, cd=%s, error=%d\n"), command, lines[4], e); 224 255 256 CloseHandle(pi.hThread); 257 CloseHandle(pi.hProcess); 258 } 259 260 CloseHandle(hFile); 261 CloseHandle(hProcess); 262 263 if (clean_command) { 264 STARTUPINFO si; 265 PROCESS_INFORMATION pi; 266 memset(&si, 0, sizeof(si)); 267 si.cb = sizeof(si); 268 si.dwFlags = STARTF_USESHOWWINDOW; 269 si.wShowWindow = SW_HIDE; 270 memset(&pi, 0, sizeof(pi)); 271 CreateProcess(NULL, clean_command, NULL, NULL, FALSE, 0, NULL, temp_path, &si, &pi); 272 /* 225 273 CloseHandle(pi.hThread); 226 274 CloseHandle(pi.hProcess); 227 228 /* HeapFree(GetProcessHeap(), 0, command); */ 229 } 230 231 CloseHandle(hFile); 232 CloseHandle(hProcess); 233 275 */ 276 } 277 278 /* 234 279 if (data) { 235 280 HeapFree(GetProcessHeap(), 0, data); 236 281 } 237 238 /* 239 { 240 memset(&si, 0, sizeof(si)); 241 si.cb = sizeof(si); 242 memset(&pi, 0, sizeof(pi)); 243 244 CreateProcess(NULL, command, NULL, NULL, FALSE, 0, NULL, lines[4], &si, &pi); 245 e = GetLastError(); 246 AUI_Debug(_T("CreateProcess(): command=%s, cd=%s, error=%d\n"), command, lines[4], e); 247 248 CloseHandle(pi.hThread); 249 CloseHandle(pi.hProcess); 250 251 } 252 */ 282 if (command) { 283 HeapFree(GetProcessHeap(), 0, command); 284 } 285 if (clean_command) { 286 HeapFree(GetProcessHeap(), 0, clean_command); 287 } 288 if (temp_path) { 289 HeapFree(GetProcessHeap(), 0, clean_cd); 290 } 291 */ 253 292 254 293 return 0;
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)