Changeset 38241

Show
Ignore:
Timestamp:
08/10/10 11:09:46 (3 years ago)
Author:
saturday06
Message:

asdfaf

Location:
lang/c/NetworkUpdater/trunk/Build
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • lang/c/NetworkUpdater/trunk/Build/Common.h

    r38186 r38241  
    7676    int pending; 
    7777#ifdef NUI_WINDOWS 
     78    TCHAR* system_temp_dir_path; 
    7879    HANDLE extracter_process; 
    7980#else 
     
    100101void NUI_Unlock(NUI_SharedData* object); 
    101102NU_Error NUI_Extract(NUI_ThreadData* object); 
    102 NU_Error NUI_CreateTemporaryDirectory(TCHAR** result_dir); 
     103NU_Error NUI_CreateTemporaryDirectory(NUI_ThreadData* object); 
    103104NU_Error NUI_Download(NUI_DownloadContext* object); 
    104105NU_Error NUI_CreateDownloadContext(NUI_DownloadContext** context_output, const TCHAR* url, const TCHAR* file_path); 
  • lang/c/NetworkUpdater/trunk/Build/Copy.c

    r38173 r38241  
    44 
    55#include <windows.h> 
     6#ifndef __CYGWIN__ 
    67#include <tchar.h> 
     8#else 
     9#define _T(x) TEXT(x) 
     10#endif 
    711#include <commctrl.h> 
    812 
     
    7781} 
    7882 
     83void 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 
    7995BOOL CopyDirectory(const TCHAR* from, const TCHAR* to) { 
    8096    TCHAR* glob = NULL; 
     
    140156    TCHAR* update_from = NULL; 
    141157    TCHAR* update_to = NULL; 
    142     TCHAR* clean_after = NULL; 
    143158    TCHAR* pid_string = NULL; 
    144159    DWORD pid = 0; 
    145160    int complete = 0; 
    146161    TCHAR* clean_command = NULL; 
    147     TCHAR* temp_path = NULL; 
    148     TCHAR* log_full_path = NULL; 
    149162    PVOID log_name = NULL; 
    150163    TCHAR* command = NULL; 
     164    TCHAR* system_temp_path = NULL; 
     165    TCHAR* my_dir = NULL; 
    151166 
    152167    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     } 
    163168 
    164169    { 
     
    167172        if (FormatMessage( 
    168173                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,  
    178177                    FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); 
    179178            } 
     
    183182    NUI_Debug(_T("***** UpdaterProcess start: pid=0x%x *****\n"), GetCurrentProcessId()); 
    184183 
     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    } 
    185217 
    186218    hFile = CreateFile(_T("NetworkUpdater.txt"), GENERIC_READ, 0, NULL,  
     
    203235 
    204236    { 
    205         TCHAR* lines[6]; 
     237        TCHAR* lines[5]; 
    206238        size_t i = 0; 
    207239        size_t data_count = (bytes / sizeof(data[0])); 
     
    228260        new_program    = lines[3]; 
    229261        new_program_cd = lines[4]; 
    230         clean_after    = lines[5]; 
    231262    } 
    232263 
    233264    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); 
    235266     
    236267    if (pid_string) { 
     
    246277    } 
    247278 
    248     if (clean_after) { 
     279    if (my_dir) { 
    249280        TCHAR comspec[MAX_PATH]; 
    250281        TCHAR rd_command[] = _T("\"%s\" /c rd /s /q \"%s\""); 
     
    254285        } 
    255286 
    256         clean_command_len = lstrlen(comspec) + lstrlen(rd_command) + lstrlen(clean_after); 
     287        clean_command_len = lstrlen(comspec) + lstrlen(rd_command) + lstrlen(my_dir); 
    257288        clean_command = (TCHAR*)HeapAlloc(GetProcessHeap(),  
    258289            HEAP_ZERO_MEMORY, clean_command_len * sizeof(TCHAR)); 
     
    260291            goto clean_up; 
    261292        } 
    262         wsprintf(clean_command, rd_command, comspec, clean_after);  
     293        wsprintf(clean_command, rd_command, comspec, my_dir);  
    263294    } 
    264295 
     
    275306    } 
    276307 
     308    if (system_temp_path) { 
     309        SetCurrentDirectory(system_temp_path); /* XXX clean */ 
     310    } 
    277311clean_up: 
    278312    if (new_program && new_program_cd) { 
     
    334368        si.wShowWindow = SW_HIDE;  
    335369        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); 
    338372            CloseHandle(pi.hThread); 
    339373            CloseHandle(pi.hProcess); 
     
    343377        CloseHandle(LogFile); 
    344378        if (complete) { 
    345             //DeleteFile(log_full_path); 
     379            /* DeleteFile(log_full_path); */ 
    346380        } 
    347381    } 
  • lang/c/NetworkUpdater/trunk/Build/MSW.c

    r38234 r38241  
    191191} 
    192192 
    193 NU_Error NUI_CreateTemporaryDirectory(TCHAR** result_dir) { 
     193NU_Error NUI_CreateTemporaryDirectory(NUI_ThreadData* object) { 
    194194    NU_Error error = NU_NO_ERROR; 
    195195    TCHAR* dir = NULL; 
    196     TCHAR* system_temp_path = NULL; 
    197196    TCHAR* temp_path = NULL; 
    198197    unsigned int retry = 0; 
    199  
    200     *result_dir = NULL; 
    201198 
    202199#ifdef __CYGWIN__ 
     
    209206            goto clean_up; 
    210207        } 
    211         system_temp_path = (TCHAR*)calloc((size_t)bytes, 1); 
     208        object->system_temp_dir_path = (TCHAR*)calloc((size_t)bytes, 1); 
    212209        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)) { 
    214211            error = NU_ERROR_BAD_ALLOC; 
    215212            goto clean_up; 
     
    219216    { 
    220217        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) { 
    223220            error = NU_ERROR_BAD_ALLOC; 
    224221            goto clean_up; 
    225222        } 
    226         GetTempPath(system_temp_path_chars, system_temp_path); 
     223        GetTempPath(system_temp_path_chars, object->system_temp_dir_path); 
    227224    } 
    228225#endif 
     
    246243        } 
    247244 
    248         temp_path = NUI_PathAppendDup(system_temp_path, dir); 
     245        temp_path = NUI_PathAppendDup(object->system_temp_dir_path, dir); 
    249246        if (!temp_path) { 
    250247            error = NU_ERROR_BAD_ALLOC; 
     
    262259    } 
    263260 
    264     *result_dir = temp_path; 
     261    object->temp_dir_path = temp_path; 
    265262    error = NU_NO_ERROR; 
    266263clean_up: 
    267     if (system_temp_path) { 
    268         free(system_temp_path); 
    269     } 
    270264    if (dir) { 
    271265        free(dir); 
     
    13021296            _T("%4!s!\r\n") 
    13031297            _T("%5!s!\r\n") 
    1304             _T("%6!s!\r\n"),         
     1298            ,         
    13051299            (unsigned int)GetCurrentProcessId(), 
    13061300            object->extracted_dir_path, 
    13071301            target, 
    13081302            myname, 
    1309             cd, 
    1310             object->temp_dir_path); 
     1303            cd); 
    13111304    if (!allocated) { 
    13121305        error = NU_ERROR_BAD_ALLOC; 
     
    13341327        si.cb = sizeof(si); 
    13351328        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); 
    13371330        CloseHandle(pi.hThread); 
    13381331        CloseHandle(pi.hProcess); 
     
    14061399    } 
    14071400 
    1408     error = NUI_CreateTemporaryDirectory(&data->temp_dir_path); 
     1401    error = NUI_CreateTemporaryDirectory(data); 
    14091402    if (error) { 
    14101403        goto clean_up; 
  • lang/c/NetworkUpdater/trunk/Build/Test.cpp

    r38216 r38241  
    55#include <cassert> 
    66#include <cstdio> 
    7 #include <unistd.h> 
     7 
     8#ifdef __unix__ 
     9#  include <unistd.h> 
     10#else 
     11void sleep(int s) { 
     12    Sleep(s * 1000); 
     13} 
     14#endif 
    815 
    916#ifdef TEXT 
     
    4350        assert(NU_Destroy(&object2)); 
    4451                assert(!NU_StartSearch(&object1)); 
    45                 assert(object1.error == NU_ERROR_INVALID_OPTION); 
     52                assert(object1.error == NU_ERROR_INVALID_UPDATER); 
    4653    } 
    4754 
     
    5360        assert(NU_Destroy(&object2)); 
    5461                assert(!NU_StartSearch(&object1)); 
    55                 assert(object1.error == NU_ERROR_INVALID_OPTION); 
     62                assert(object1.error == NU_ERROR_INVALID_UPDATER); 
    5663                assert(!NU_StartSearch(&object2)); 
    57                 assert(object2.error == NU_ERROR_INVALID_OPTION); 
     64                assert(object2.error == NU_ERROR_INVALID_UPDATER); 
    5865    } 
    5966 
     
    128135        assert(s->error == NU_ERROR_INVALID_UPDATER); 
    129136        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); 
    130179    } 
    131180}