Changeset 38241
- Timestamp:
- 08/10/10 11:09:46 (3 years ago)
- Location:
- lang/c/NetworkUpdater/trunk/Build
- Files:
-
- 4 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/c/NetworkUpdater/trunk/Build/Common.h
r38186 r38241 76 76 int pending; 77 77 #ifdef NUI_WINDOWS 78 TCHAR* system_temp_dir_path; 78 79 HANDLE extracter_process; 79 80 #else … … 100 101 void NUI_Unlock(NUI_SharedData* object); 101 102 NU_Error NUI_Extract(NUI_ThreadData* object); 102 NU_Error NUI_CreateTemporaryDirectory( TCHAR** result_dir);103 NU_Error NUI_CreateTemporaryDirectory(NUI_ThreadData* object); 103 104 NU_Error NUI_Download(NUI_DownloadContext* object); 104 105 NU_Error NUI_CreateDownloadContext(NUI_DownloadContext** context_output, const TCHAR* url, const TCHAR* file_path); -
lang/c/NetworkUpdater/trunk/Build/Copy.c
r38173 r38241 4 4 5 5 #include <windows.h> 6 #ifndef __CYGWIN__ 6 7 #include <tchar.h> 8 #else 9 #define _T(x) TEXT(x) 10 #endif 7 11 #include <commctrl.h> 8 12 … … 77 81 } 78 82 83 void NUI_PathRemoveFileSpec(TCHAR* path) { 84 size_t len = 0; 85 len = lstrlen(path); 86 for (; len != 0; --len) { 87 TCHAR c = path[len]; 88 path[len] = 0; 89 if (c == _T('\\') || c == _T('/')) { 90 break; 91 } 92 } 93 } 94 79 95 BOOL CopyDirectory(const TCHAR* from, const TCHAR* to) { 80 96 TCHAR* glob = NULL; … … 140 156 TCHAR* update_from = NULL; 141 157 TCHAR* update_to = NULL; 142 TCHAR* clean_after = NULL;143 158 TCHAR* pid_string = NULL; 144 159 DWORD pid = 0; 145 160 int complete = 0; 146 161 TCHAR* clean_command = NULL; 147 TCHAR* temp_path = NULL;148 TCHAR* log_full_path = NULL;149 162 PVOID log_name = NULL; 150 163 TCHAR* command = NULL; 164 TCHAR* system_temp_path = NULL; 165 TCHAR* my_dir = NULL; 151 166 152 167 InitCommonControls(); 153 154 {155 size_t temp_path_chars = GetTempPath(0, NULL);156 temp_path = (TCHAR*)HeapAlloc(GetProcessHeap(),157 HEAP_ZERO_MEMORY, (temp_path_chars * sizeof(TCHAR)));158 if (!temp_path) {159 goto clean_up;160 }161 GetTempPath(temp_path_chars, temp_path);162 }163 168 164 169 { … … 167 172 if (FormatMessage( 168 173 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY, 169 _T("NetworkUpdaterLog.%1!x!.txt"), 170 0, 171 0, 172 (TCHAR*)&log_name, 173 0, 174 (va_list*)&arg)) { 175 log_full_path = NUI_PathAppend(temp_path, (TCHAR*)log_name); 176 if (log_full_path) { 177 LogFile = CreateFile(log_full_path, GENERIC_WRITE, 174 _T("NetworkUpdaterLog.%1!x!.txt"), 0, 0, (TCHAR*)&log_name, 0, (va_list*)&arg)) { 175 if (log_name) { 176 LogFile = CreateFile((const TCHAR*)log_name, GENERIC_WRITE, 178 177 FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); 179 178 } … … 183 182 NUI_Debug(_T("***** UpdaterProcess start: pid=0x%x *****\n"), GetCurrentProcessId()); 184 183 184 { 185 size_t system_temp_path_chars = GetCurrentDirectory(0, NULL); 186 system_temp_path = (TCHAR*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, system_temp_path_chars * sizeof(TCHAR)); 187 if (!system_temp_path) { 188 NUI_Debug(_T("calloc() system_temp_path failed\n")); 189 goto clean_up; 190 } 191 if (!GetCurrentDirectory(system_temp_path_chars, system_temp_path)) { 192 NUI_Debug(_T("GetCurrentDirectory()\n")); 193 goto clean_up; 194 } 195 NUI_Debug(_T("system_temp_path: %s\n"), system_temp_path); 196 } 197 198 { 199 /* http://msdn.microsoft.com/ja-jp/library/cc429127.aspx */ 200 size_t size = 33000; 201 my_dir = (TCHAR*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size * sizeof(TCHAR)); 202 if (!my_dir) { 203 NUI_Debug(_T("calloc() GetModuleFileName failed\n")); 204 goto clean_up; 205 } 206 if (!GetModuleFileName(GetModuleHandle(NULL), my_dir, size - 1)) { 207 NUI_Debug(_T("GetModuleFileName() failed\n")); 208 goto clean_up; 209 } 210 NUI_Debug(_T("GetModuleFileName(): %s\n"), my_dir); 211 NUI_PathRemoveFileSpec(my_dir); 212 NUI_Debug(_T("NUI_PathRemoveFileSpec(): %s\n"), my_dir); 213 if (!SetCurrentDirectory(my_dir)) { 214 NUI_Debug(_T("SetCurrentDirectory() failed\n")); 215 } 216 } 185 217 186 218 hFile = CreateFile(_T("NetworkUpdater.txt"), GENERIC_READ, 0, NULL, … … 203 235 204 236 { 205 TCHAR* lines[ 6];237 TCHAR* lines[5]; 206 238 size_t i = 0; 207 239 size_t data_count = (bytes / sizeof(data[0])); … … 228 260 new_program = lines[3]; 229 261 new_program_cd = lines[4]; 230 clean_after = lines[5];231 262 } 232 263 233 264 NUI_Debug(_T("pid=%s, from=%s, to=%s\nnewproc=%s, cd=%s clean=%s\n"), 234 pid_string, update_from, update_to, new_program, new_program_cd, clean_after);265 pid_string, update_from, update_to, new_program, new_program_cd, my_dir); 235 266 236 267 if (pid_string) { … … 246 277 } 247 278 248 if ( clean_after) {279 if (my_dir) { 249 280 TCHAR comspec[MAX_PATH]; 250 281 TCHAR rd_command[] = _T("\"%s\" /c rd /s /q \"%s\""); … … 254 285 } 255 286 256 clean_command_len = lstrlen(comspec) + lstrlen(rd_command) + lstrlen( clean_after);287 clean_command_len = lstrlen(comspec) + lstrlen(rd_command) + lstrlen(my_dir); 257 288 clean_command = (TCHAR*)HeapAlloc(GetProcessHeap(), 258 289 HEAP_ZERO_MEMORY, clean_command_len * sizeof(TCHAR)); … … 260 291 goto clean_up; 261 292 } 262 wsprintf(clean_command, rd_command, comspec, clean_after);293 wsprintf(clean_command, rd_command, comspec, my_dir); 263 294 } 264 295 … … 275 306 } 276 307 308 if (system_temp_path) { 309 SetCurrentDirectory(system_temp_path); /* XXX clean */ 310 } 277 311 clean_up: 278 312 if (new_program && new_program_cd) { … … 334 368 si.wShowWindow = SW_HIDE; 335 369 memset(&pi, 0, sizeof(pi)); 336 NUI_Debug(_T("CreateProcess(del): command=%s, cd=%s\n"), clean_command, temp_path);337 CreateProcess(NULL, clean_command, NULL, NULL, FALSE, 0, NULL, temp_path, &si, &pi);370 NUI_Debug(_T("CreateProcess(del): command=%s, cd=%s\n"), clean_command, system_temp_path); 371 CreateProcess(NULL, clean_command, NULL, NULL, FALSE, 0, NULL, system_temp_path, &si, &pi); 338 372 CloseHandle(pi.hThread); 339 373 CloseHandle(pi.hProcess); … … 343 377 CloseHandle(LogFile); 344 378 if (complete) { 345 / /DeleteFile(log_full_path);379 /* DeleteFile(log_full_path); */ 346 380 } 347 381 } -
lang/c/NetworkUpdater/trunk/Build/MSW.c
r38234 r38241 191 191 } 192 192 193 NU_Error NUI_CreateTemporaryDirectory( TCHAR** result_dir) {193 NU_Error NUI_CreateTemporaryDirectory(NUI_ThreadData* object) { 194 194 NU_Error error = NU_NO_ERROR; 195 195 TCHAR* dir = NULL; 196 TCHAR* system_temp_path = NULL;197 196 TCHAR* temp_path = NULL; 198 197 unsigned int retry = 0; 199 200 *result_dir = NULL;201 198 202 199 #ifdef __CYGWIN__ … … 209 206 goto clean_up; 210 207 } 211 system_temp_path = (TCHAR*)calloc((size_t)bytes, 1);208 object->system_temp_dir_path = (TCHAR*)calloc((size_t)bytes, 1); 212 209 if (cygwin_conv_path(NUI_CCP_POSIX_TO_WIN, 213 tmp, system_temp_path, (size_t)bytes)) {210 tmp, object->system_temp_dir_path, (size_t)bytes)) { 214 211 error = NU_ERROR_BAD_ALLOC; 215 212 goto clean_up; … … 219 216 { 220 217 size_t system_temp_path_chars = GetTempPath(0, NULL); 221 system_temp_path = (TCHAR*)calloc(system_temp_path_chars * sizeof(TCHAR), 1);222 if (! system_temp_path) {218 object->system_temp_dir_path = (TCHAR*)calloc(system_temp_path_chars * sizeof(TCHAR), 1); 219 if (!object->system_temp_dir_path) { 223 220 error = NU_ERROR_BAD_ALLOC; 224 221 goto clean_up; 225 222 } 226 GetTempPath(system_temp_path_chars, system_temp_path);223 GetTempPath(system_temp_path_chars, object->system_temp_dir_path); 227 224 } 228 225 #endif … … 246 243 } 247 244 248 temp_path = NUI_PathAppendDup( system_temp_path, dir);245 temp_path = NUI_PathAppendDup(object->system_temp_dir_path, dir); 249 246 if (!temp_path) { 250 247 error = NU_ERROR_BAD_ALLOC; … … 262 259 } 263 260 264 *result_dir= temp_path;261 object->temp_dir_path = temp_path; 265 262 error = NU_NO_ERROR; 266 263 clean_up: 267 if (system_temp_path) {268 free(system_temp_path);269 }270 264 if (dir) { 271 265 free(dir); … … 1302 1296 _T("%4!s!\r\n") 1303 1297 _T("%5!s!\r\n") 1304 _T("%6!s!\r\n"),1298 , 1305 1299 (unsigned int)GetCurrentProcessId(), 1306 1300 object->extracted_dir_path, 1307 1301 target, 1308 1302 myname, 1309 cd, 1310 object->temp_dir_path); 1303 cd); 1311 1304 if (!allocated) { 1312 1305 error = NU_ERROR_BAD_ALLOC; … … 1334 1327 si.cb = sizeof(si); 1335 1328 memset(&pi, 0, sizeof(pi)); 1336 CreateProcess(object->updater_file_path, NULL, NULL, NULL, FALSE, 0, NULL, object-> temp_dir_path, &si, &pi);1329 CreateProcess(object->updater_file_path, NULL, NULL, NULL, FALSE, 0, NULL, object->system_temp_dir_path, &si, &pi); 1337 1330 CloseHandle(pi.hThread); 1338 1331 CloseHandle(pi.hProcess); … … 1406 1399 } 1407 1400 1408 error = NUI_CreateTemporaryDirectory( &data->temp_dir_path);1401 error = NUI_CreateTemporaryDirectory(data); 1409 1402 if (error) { 1410 1403 goto clean_up; -
lang/c/NetworkUpdater/trunk/Build/Test.cpp
r38216 r38241 5 5 #include <cassert> 6 6 #include <cstdio> 7 #include <unistd.h> 7 8 #ifdef __unix__ 9 # include <unistd.h> 10 #else 11 void sleep(int s) { 12 Sleep(s * 1000); 13 } 14 #endif 8 15 9 16 #ifdef TEXT … … 43 50 assert(NU_Destroy(&object2)); 44 51 assert(!NU_StartSearch(&object1)); 45 assert(object1.error == NU_ERROR_INVALID_ OPTION);52 assert(object1.error == NU_ERROR_INVALID_UPDATER); 46 53 } 47 54 … … 53 60 assert(NU_Destroy(&object2)); 54 61 assert(!NU_StartSearch(&object1)); 55 assert(object1.error == NU_ERROR_INVALID_ OPTION);62 assert(object1.error == NU_ERROR_INVALID_UPDATER); 56 63 assert(!NU_StartSearch(&object2)); 57 assert(object2.error == NU_ERROR_INVALID_ OPTION);64 assert(object2.error == NU_ERROR_INVALID_UPDATER); 58 65 } 59 66 … … 128 135 assert(s->error == NU_ERROR_INVALID_UPDATER); 129 136 free(s); 137 } 138 139 { 140 NU_NetworkUpdater object; 141 NU_Option valid_option; 142 memset(&valid_option, 0, sizeof(valid_option)); 143 valid_option.url = CONTEXT_URL; 144 assert(NU_Create(&object, &valid_option)); 145 assert(NU_Destroy(&object)); 146 } 147 148 { 149 NU_NetworkUpdater o1, o2, o3; 150 NU_Option valid_option; 151 memset(&valid_option, 0, sizeof(valid_option)); 152 valid_option.url = CONTEXT_URL; 153 assert(NU_Create(&o1, &valid_option)); 154 assert(NU_Create(&o2, &valid_option)); 155 assert(NU_Destroy(&o1)); 156 assert(NU_Create(&o3, &valid_option)); 157 assert(NU_Destroy(&o3)); 158 assert(NU_Destroy(&o2)); 159 } 160 161 { 162 NU_NetworkUpdater *o1, *o2, *o3; 163 NU_Option valid_option; 164 o1 = (NU_NetworkUpdater*)calloc(sizeof(NU_NetworkUpdater), 1); 165 o2 = (NU_NetworkUpdater*)calloc(sizeof(NU_NetworkUpdater), 1); 166 o3 = (NU_NetworkUpdater*)calloc(sizeof(NU_NetworkUpdater), 1); 167 assert(o1); 168 assert(o2); 169 assert(o3); 170 assert(NU_Create(o1, &valid_option)); 171 assert(NU_Create(o2, &valid_option)); 172 assert(NU_Destroy(o1)); 173 assert(NU_Create(o3, &valid_option)); 174 assert(NU_Destroy(o3)); 175 assert(NU_Destroy(o2)); 176 free(o1); 177 free(o2); 178 free(o3); 130 179 } 131 180 }
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)