bool  isDownLoadOK()
{
	DWORD dwType;
	DWORD dwReturnBytes = sizeof(DWORD);
	DWORD dwUpdate = 0;

	if (ERROR_SUCCESS != ::SHGetValue(HKEY_CURRENT_USER, _T("Software\\Bank\\Update"), _T("InstallFlag"), &dwType, &dwUpdate, &dwReturnBytes))
		return 0;

	if(!dwUpdate)
		return false;

	TCHAR szCmdline[1024];
    dwReturnBytes = sizeof(szCmdline);

	if (ERROR_SUCCESS != ::SHGetValue(HKEY_CURRENT_USER, _T("Software\\Bank\\Update"), 
		_T("InstallPack"), &dwType, szCmdline, &dwReturnBytes)
		|| dwType != REG_SZ)
		return false;

	//非主程序升级
	if(0 == _tcscmp(szCmdline,_T("modules") ) )
		return true;

// 	wchar_t * sp = wcsrchr(szCmdline,'/');
// 	if(!sp)         
// 		return false;
// 	*(szCmdline + (sp - szCmdline) -1) = L'\0';
	CString strExe = szCmdline;
	strExe.Trim('"');

	if (_taccess_s(strExe, 0) != 0)
		return false;
	return true;
}
Beispiel #2
0
void CMainFrame::OnFileOpen()
{
    CString filter;
    filter.LoadString(IDS_OPEN_FILE_FILTER);

    CFileDialog fileDlg(TRUE, 0, 0, OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, filter, this, 0);
    if (fileDlg.DoModal() != IDOK)
        return;

    CString path = fileDlg.GetPathName();
    SHOWBMP_TRACE("path=%s", (const TCHAR*) path);

    CString err;
    if (_taccess_s(path, 4) != 0) {
        _TCHAR buf[BUF_SIZE];
        __tcserror_s(buf, (const _TCHAR*) 0);
        err.Format(_T("Cannot read file: %s\n%s (%d)"), path, buf, errno);
        MessageBox(err, _T("Error"), MB_ICONERROR | MB_OK);
        return;
    }

    if (!m_ClientView.LoadBmp(path)) {
        err.Format(_T("Cannot load bitmap: %s"), path);
        MessageBox(err, _T("Error"), MB_ICONERROR | MB_OK);
    }
}
Beispiel #3
0
// ValidDirectory function
ValidDirectory isValid(const wchar_t *path)
{
  // if path is NULL, return NO_DIR that means it isn't directory
  if(NULL == path)
    return NO_DIR;

  // if directory hasn't been existed, return no access
  if(0 == _taccess_s(path, 0)) {
    // if directory hasn't got read permission, return no read
    if(0 == _taccess_s(path, 4))
      return OK;
    return NOREAD;
  }

  return NOEXIST;
}
Beispiel #4
0
// Registry key 지우기
// 지우기 전에 자동으로 '내보내기' 처리를 한다.
bool CEnvironmentValue::DeleteRegKey( LPCTSTR /*in_*/lpszSubKey )
{
	assert( lpszSubKey != NULL );

	SYSTEMTIME tSystemTime;
	TCHAR szCurrentProcessPath[MAX_PATH] = {0,};
	TCHAR szBackupFileName[MAX_PATH] = {0,};
	TCHAR szRegFileFullPath[520] = {0,};
	size_t unLengthOfString = 0;
	DWORD dwResult = ERROR_SUCCESS;

	// 내보내기 경로 구성
	GetCurrentDirectory( MAX_PATH, szCurrentProcessPath );

	GetLocalTime( &tSystemTime );
	_stprintf_s( szBackupFileName, MAX_PATH,
				 PRE_PHRASE_FORMAT,
				 tSystemTime.wYear, tSystemTime.wMonth, tSystemTime.wDay,
				 tSystemTime.wHour, tSystemTime.wMinute, tSystemTime.wSecond, tSystemTime.wMilliseconds,
				 DEFAULT_EXPORTFILENAME );

	_stprintf_s( szRegFileFullPath, 520, TEXT( "%s\\%s" ), szCurrentProcessPath, szBackupFileName );
	unLengthOfString = _tcsclen( szRegFileFullPath );  // 경로의 최대 길이 검사
	if( MAX_PATH < unLengthOfString )
	{
		g_Log.WriteLog( false,
						LOG_CLASS_WARNING,
						TEXT( "%s | The length of the file path is invalid. | %d\n" ),
						TEXT( __FUNCTION__ ),
						unLengthOfString );
		return false;
	}

	// szRegFileFullPath 존재 여부 검사
	if( _taccess_s( szRegFileFullPath, 0 ) == 0 )
	{
		g_Log.WriteLog( false,
						LOG_CLASS_WARNING,
						TEXT( "%s | Exist the same file as file that want to backup. " )
						TEXT( "Because could not complete the backup, can not delete.\n" ),
						TEXT( __FUNCTION__ ) );
		return false;
	}

	// 내보내기
	if( ExportRegKeyToFile( lpszSubKey, szRegFileFullPath ) == false )
		return false;

	// 지우기
	dwResult = SHDeleteKey( HKEY_CURRENT_USER, lpszSubKey );
	if( dwResult != ERROR_SUCCESS )
	{
		g_Log.PrintErrorMsg( TEXT( __FUNCTION__ ), true, dwResult );
		return false;
	}

	return true;
}
// Procedure function for the message history location page in the wizard
BOOL CALLBACK wlmDBProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) {
	BOOL result = FALSE;

	switch(message) {
		// Message to initialize dialog
		case WM_INITDIALOG:
			TranslateDialogDefault(hdlg);
			{
				TCHAR *defaultPath;

				#ifdef _DEBUG
					defaultPath = replaceVariable(_T("C:\\Documents and Settings\\Very Crazy Dog\\My Documents\\我已接收的檔案\\Very Crazy Dog's Message History"));
				#else
					defaultPath = replaceVariable(_T("%USERPROFILE%\\My Received Files"));
				#endif			
				SetDlgItemText(hdlg, IDC_FOLDERNAME, defaultPath);
				mir_free(defaultPath);
			}
			result = TRUE;
			break;
		// Message when a button is pressed
		case WM_COMMAND:
			switch(LOWORD(wParam)) {
				case IDC_BROWSER:
					{
						BROWSEINFO binfo;
						LPITEMIDLIST pidl;

						ZeroMemory(&binfo, sizeof(binfo));
						binfo.hwndOwner = hdlg;
						binfo.ulFlags = BIF_USENEWUI | BIF_NONEWFOLDERBUTTON | BIF_RETURNONLYFSDIRS;
						binfo.lpszTitle = TranslateT("Please select the Windows Live Messenger message history directory:");
						pidl = SHBrowseForFolder(&binfo);
						if(pidl != NULL) {
							// Get the name of the folder
							TCHAR path[MAX_PATH];

							if (SHGetPathFromIDList(pidl, path)) {
								SetDlgItemText(hdlg, IDC_FOLDERNAME, path);
							}
							GlobalFree(pidl);
						}
					}
					break;
				case IDC_BACK:
					PostMessage(GetParent(hdlg), WIZM_GOTOPAGE, IDD_IMPORTACC, (LPARAM)importAccountPageProc);
					break;
				case IDOK:
					{
						TCHAR path[MAX_PATH];
						UINT pathLen;
						TCHAR *realPath;

						pathLen = GetDlgItemText(hdlg, IDC_FOLDERNAME, path, SIZEOF(path));
						_tcscat_s(path, MAX_PATH, _T("\\MessageLog.xsl"));
						realPath = replaceVariable(path);
						if(_taccess_s(realPath, 4)) {
							MessageBox(hdlg, 
								TranslateT("File 'MessageLog.xsl' is missing.\r\nIs this a Windows Live Messenger message history folder?"), 
								TranslateT("WLM History Importer"), MB_OK | MB_ICONINFORMATION);
						}
						else {
							// Remove the appended file name
							if(pathLen <= MAX_PATH) {
								path[pathLen] = '\0';
							}
							mir_free(realPath);
							realPath = replaceVariable(path);
							_tcscpy_s(importFolderPath, MAX_PATH, realPath);
							_tcscat_s(importFolderPath, MAX_PATH, _T("\\"));
							PostMessage(GetParent(hdlg), WIZM_GOTOPAGE, IDD_OPTIONS, (LPARAM)wlmOptionsPageProc);
						}
						mir_free(realPath);
					}
					break;
				case IDCANCEL:
					PostMessage(GetParent(hdlg), WM_CLOSE, 0, 0);
					break;
			}
			break;
	}
	return result;
}
Beispiel #6
0
int _tmain (int argc, _TCHAR *argv []) {
#else
int main (int argc, char *argv []) {
#endif
	bool bLoop =true ;
	utility::string_t inFile ;
	utility::string_t outDir ;
	utility::string_t name ;
	bool angleInDegree =false ;
	bool reverseTransparency =false ;
	bool defaultLighting =false ;
	bool copyMedia =false ;
	bool embedMedia =false ;
	while ( bLoop ) {
		int option_index =0 ;
		// http://www.gnu.org/software/libc/manual/html_node/Argument-Syntax.html
		// http://www.gnu.org/software/libc/manual/html_node/Argp-Examples.html#Argp-Examples
		// http://stackoverflow.com/questions/13251732/c-how-to-specify-an-optstring-in-the-getopt-function
		int c =getopt_long (argc, argv, U ("f:o:n:tlcehv"), long_options, &option_index) ;
		// Check for end of operation or error
		if ( c == -1 )
			break ;
		
		// Handle options
		switch ( c ) {
			case 0:
				break ;
			case U('?'):
				// getopt_long already printed an error message.
				break ;
			case U(':'): // missing option argument
				ucout << U("option \'") << optopt << U("\' requires an argument") << std::endl ;
				break ;
			default:
				bLoop =false ;
				break ;
				
			case U('h'): // help message
				usage () ;
				return (0) ;
			case U('f'): // file to convert to glTF [string]
				inFile =optarg ;
				break ;
			case U('o'): // path of output directory argument [string]
				outDir =optarg ;
				break ;
			case U('n'): // override the scene name [string]
				name =optarg ;
				break ;
			case U('d'): // invert transparency
				angleInDegree =true ;
				break ;
			case U('t'): // invert transparency
				reverseTransparency =true ;
				break ;
			case U('l'): // enable default lighting (if no lights in scene)
				defaultLighting =true ;
				break ;
			case U('c'): // copy all media to the target directory (cannot be combined with --embed)
				copyMedia =!embedMedia ;
				break ;
			case U('e'): // embed all resources as Data URIs (cannot be combined with --copy)
				embedMedia =!copyMedia ;
				break ;
		}
	}
#if defined(_WIN32) || defined(_WIN64)
	if ( inFile.length () == 0  || _taccess_s (inFile.c_str (), 0) == ENOENT )
		return (-1) ;
#else
	if ( inFile.length () == 0  || access (inFile.c_str (), 0) == ENOENT )
		return (-1) ;
#endif
	if ( outDir.length () == 0 )
		outDir =utility::conversions::to_string_t (FbxPathUtils::GetFolderName (utility::conversions::to_utf8string (inFile).c_str ()).Buffer ()) ;
#if defined(_WIN32) || defined(_WIN64)
	if ( outDir [outDir.length () - 1] != U('\\') )
		outDir +=U('\\') ;
#else
	if ( outDir [outDir.length () - 1] != U('/') )
		outDir +=U('/') ;
#endif
	
	std::shared_ptr <gltfPackage> asset (new gltfPackage ()) ;
	asset->ioSettings (name.c_str (), angleInDegree, reverseTransparency, defaultLighting, copyMedia, embedMedia) ;

	ucout << U("Loading file: ") << inFile << U("...") << std::endl ;
	bool bRet =asset->load (inFile) ;
	ucout << U("Converting to GLTF ...") << std::endl ;
	bRet =asset->save (outDir) ;
	ucout << U("done!") << std::endl ;
	return (0) ;
}
Beispiel #7
0
FILE * __cdecl _tpopen (
        const _TSCHAR *cmdstring,
        const _TSCHAR *type
        )
{

        int phdls[2];             /* I/O handles for pipe */
        int ph_open[2];           /* flags, set if correspond phdls is open */
        int i1;                   /* index into phdls[] */
        int i2;                   /* index into phdls[] */

        int tm = 0;               /* flag indicating text or binary mode */

        int stdhdl;               /* either STDIN or STDOUT */

        HANDLE newhnd;            /* ...in calls to DuplicateHandle API */

        FILE *pstream = NULL;     /* stream to be associated with pipe */

        HANDLE prochnd;           /* handle for current process */

        _TSCHAR *cmdexe;          /* pathname for the command processor */
        _TSCHAR *envbuf = NULL;   /* buffer for the env variable */
        intptr_t childhnd;        /* handle for child process (cmd.exe) */

        IDpair *locidpair;        /* pointer to IDpair table entry */
        _TSCHAR *buf = NULL, *pfin, *env;
        _TSCHAR *CommandLine;
        size_t CommandLineSize = 0;
        _TSCHAR _type[3] = {0, 0, 0};

        /* Info for spawning the child. */
        STARTUPINFO StartupInfo;  /* Info for spawning a child */
        BOOL childstatus = 0;
        PROCESS_INFORMATION ProcessInfo; /* child process information */

        errno_t save_errno;

        int fh_lock_held = 0;
        int popen_lock_held = 0;

        /* first check for errors in the arguments
         */
        _VALIDATE_RETURN((cmdstring != NULL), EINVAL,NULL);
        _VALIDATE_RETURN((type != NULL), EINVAL,NULL);

        while (*type == _T(' '))
        {
            type++;
        }
        _VALIDATE_RETURN(((*type == _T('w')) || (*type == _T('r'))), EINVAL,NULL);
        _type[0] = *type;
        ++type;
        while (*type == _T(' '))
        {
            ++type;
        }
        _VALIDATE_RETURN(((*type == 0) || (*type == _T('t')) || (*type == _T('b'))), EINVAL, NULL);
        _type[1] = *type;

        /* do the _pipe(). note that neither of the resulting handles will
         * be inheritable.
         */

        if ( _type[1] == _T('t') )
                tm = _O_TEXT;
        else if ( _type[1] == _T('b') )
                tm = _O_BINARY;

        tm |= _O_NOINHERIT;

        if ( _pipe( phdls, PSIZE, tm ) == -1 )
                goto error1;

        /* test _type[0] and set stdhdl, i1 and i2 accordingly.
         */
        if ( _type[0] == _T('w') ) {
                stdhdl = STDIN;
                i1 = 0;
                i2 = 1;
        }
        else {
                stdhdl = STDOUT;
                i1 = 1;
                i2 = 0;
        }

        /* ASSERT LOCK FOR IDPAIRS HERE!!!!
         */
        if ( !_mtinitlocknum( _POPEN_LOCK )) {
            _close( phdls[0] );
            _close( phdls[1] );
            return NULL;
        }
        _mlock( _POPEN_LOCK );
        __try
        {

        /* set flags to indicate pipe handles are open. note, these are only
         * used for error recovery.
         */
        ph_open[ 0 ] = ph_open[ 1 ] = 1;


        /* get the process handle, it will be needed in some API calls
         */
        prochnd = GetCurrentProcess();



        if ( !DuplicateHandle( prochnd,
                               (HANDLE)_osfhnd( phdls[i1] ),
                               prochnd,
                               &newhnd,
                               0L,
                               TRUE,                    /* inheritable */
                               DUPLICATE_SAME_ACCESS )
        ) {
                goto error2;
        }
        (void)_close( phdls[i1] );
        ph_open[ i1 ] = 0;

        /* associate a stream with phdls[i2]. note that if there are no
         * errors, pstream is the return value to the caller.
         */
        if ( (pstream = _tfdopen( phdls[i2], _type )) == NULL )
                goto error2;

        /* next, set locidpair to a free entry in the idpairs table.
         */
        if ( (locidpair = idtab( NULL )) == NULL )
                goto error3;


        /* Find what to use. command.com or cmd.exe */
        if ( (_ERRCHECK_EINVAL(_tdupenv_s_crt(&envbuf, NULL, _T("COMSPEC"))) != 0) || (envbuf == NULL) )
        {
            unsigned int osver = 0;
            _get_osver(&osver);
            cmdexe = ( osver & 0x8000 ) ? _T("command.com") : _T("cmd.exe");
        }
        else
        {
            cmdexe = envbuf;
        }

        /*
         * Initialise the variable for passing to CreateProcess
         */

        memset(&StartupInfo, 0, sizeof(StartupInfo));
        StartupInfo.cb = sizeof(StartupInfo);

        /* Used by os for duplicating the Handles. */

        StartupInfo.dwFlags = STARTF_USESTDHANDLES;
        StartupInfo.hStdInput = stdhdl == STDIN ? (HANDLE) newhnd
                                                : (HANDLE) _osfhnd(0);
        StartupInfo.hStdOutput = stdhdl == STDOUT ? (HANDLE) newhnd
                                                  : (HANDLE) _osfhnd(1);
        StartupInfo.hStdError = (HANDLE) _osfhnd(2);


        CommandLineSize = _tcslen(cmdexe) + _tcslen(_T(" /c ")) + (_tcslen(cmdstring)) +1;
        if ((CommandLine = _calloc_crt( CommandLineSize, sizeof(_TSCHAR))) == NULL)
            goto error3;
        _ERRCHECK(_tcscpy_s(CommandLine, CommandLineSize, cmdexe));
        _ERRCHECK(_tcscat_s(CommandLine, CommandLineSize, _T(" /c ")));
        _ERRCHECK(_tcscat_s(CommandLine, CommandLineSize, cmdstring));

        /* Check if cmdexe can be accessed. If yes CreateProcess else try
         * searching path.
         */
        save_errno = errno;
        if (_taccess_s(cmdexe, 0) == 0) {
            childstatus = CreateProcess( (LPTSTR) cmdexe,
                                         (LPTSTR) CommandLine,
                                         NULL,
                                         NULL,
                                         TRUE,
                                         0,
                                         NULL,
                                         NULL,
                                         &StartupInfo,
                                         &ProcessInfo
                                         );
        }
        else {
            TCHAR* envPath = NULL;
            size_t envPathSize = 0;
            if ((buf = _calloc_crt(_MAX_PATH, sizeof(_TSCHAR))) == NULL)
            {
                _free_crt(buf);
                _free_crt(CommandLine);
                _free_crt(envbuf);
                cmdexe = NULL;
                errno = save_errno;
                goto error3;
            }
            if (_ERRCHECK_EINVAL(_tdupenv_s_crt(&envPath, NULL, _T("PATH"))) != 0)
            {
                _free_crt(envPath);
                _free_crt(buf);
                _free_crt(CommandLine);
                _free_crt(envbuf);
                cmdexe = NULL;
                errno = save_errno;
                goto error3;
            }
            env = envPath;

#ifdef WPRFLAG
            while ( (env = _wgetpath(env, buf, _MAX_PATH -1)) && (*buf) ) {
#else  /* WPRFLAG */
            while ( (env = _getpath(env, buf, _MAX_PATH -1)) && (*buf) ) {
#endif  /* WPRFLAG */
                pfin = buf + _tcslen(buf) -1;

#ifdef _MBCS
                if (*pfin == SLASHCHAR) {
                    if (pfin != _mbsrchr(buf, SLASHCHAR))
                        _ERRCHECK(strcat_s(buf, _MAX_PATH, SLASH));
                }
                else if (*pfin != XSLASHCHAR)
                    _ERRCHECK(strcat_s(buf, _MAX_PATH, SLASH));

#else  /* _MBCS */
                if (*pfin != SLASHCHAR && *pfin != XSLASHCHAR)
                    _ERRCHECK(_tcscat_s(buf, _MAX_PATH, SLASH));
#endif  /* _MBCS */
                /* check that the final path will be of legal size. if so,
                 * build it. otherwise, return to the caller (return value
                 * and errno rename set from initial call to _spawnve()).
                 */
                if ( (_tcslen(buf) + _tcslen(cmdexe)) < _MAX_PATH )
                    _ERRCHECK(_tcscat_s(buf, _MAX_PATH, cmdexe));
                else
                    break;

                /* Check if buf can be accessed. If yes CreateProcess else try
                 * again.
                 */
                if (_taccess_s(buf, 0) == 0) {
                    childstatus = CreateProcess( (LPTSTR) buf,
                                                 CommandLine,
                                                 NULL,
                                                 NULL,
                                                 TRUE,
                                                 0,
                                                 NULL,
                                                 NULL,
                                                 &StartupInfo,
                                                 &ProcessInfo
                                                 );
                    break;
                }
            }
            _free_crt(envPath);
            _free_crt(buf);
        }
        _free_crt(CommandLine);
        _free_crt(envbuf);
        cmdexe = NULL;
        CloseHandle((HANDLE)newhnd);
        CloseHandle((HANDLE)ProcessInfo.hThread);
                errno = save_errno;

        /* check if the CreateProcess was sucessful.
         */
        if ( childstatus)
            childhnd = (intptr_t)ProcessInfo.hProcess;
        else
            goto error4;
        locidpair->prochnd = childhnd;
        locidpair->stream = pstream;

        /* success, return the stream to the caller
         */
        goto done;

        /**
         * error handling code. all detected errors end up here, entering
         * via a goto one of the labels. note that the logic is currently
         * a straight fall-thru scheme (e.g., if entered at error4, the
         * code for error4, error3,...,error1 is all executed).
         **********************************************************************/

error4:         /* make sure locidpair is reusable
                 */
                locidpair->stream = NULL;

error3:         /* close pstream (also, clear ph_open[i2] since the stream
                 * close will also close the pipe handle)
                 */
                (void)fclose( pstream );
                ph_open[ i2 ] = 0;
                pstream = NULL;

error2:         /* close handles on pipe (if they are still open)
                 */

                if ( ph_open[i1] )
                        _close( phdls[i1] );
                if ( ph_open[i2] )
                        _close( phdls[i2] );
done:

        ;}
        __finally {
            _munlock(_POPEN_LOCK);
        }


error1:
        return pstream;
}

#ifndef _UNICODE

/***
*int _pclose(pstream) - wait on a child command and close the stream on the
*   associated pipe
*
*Purpose:
*       Closes pstream then waits on the associated child command. The
*       argument, pstream, must be the return value from a previous call to
*       _popen. _pclose first looks up the process handle of child command
*       started by that _popen and does a cwait on it. Then, it closes pstream
*       and returns the exit status of the child command to the caller.
*
*Entry:
*       FILE *pstream - file stream returned by a previous call to _popen
*
*Exit:
*       If successful, _pclose returns the exit status of the child command.
*       The format of the return value is that same as for cwait, except that
*       the low order and high order bytes are swapped.
*
*       If an error occurs, -1 is returned.
*
*Exceptions:
*
*******************************************************************************/

int __cdecl _pclose (
        FILE *pstream
        )
{
        IDpair *locidpair;        /* pointer to entry in idpairs table */
        int termstat;             /* termination status word */
        int retval = -1;          /* return value (to caller) */
        errno_t save_errno;

        _VALIDATE_RETURN((pstream != NULL), EINVAL, -1);

        if (!_mtinitlocknum(_POPEN_LOCK))
            return -1;
        _mlock(_POPEN_LOCK);
        __try {

        if ((locidpair = idtab(pstream)) == NULL)
        {
                /* invalid pstream, exit with retval == -1
                 */
                errno = EBADF;
                goto done;
        }

        /* close pstream
         */
        (void)fclose(pstream);

        /* wait on the child (copy of the command processor) and all of its
         * children.
         */
        save_errno = errno;
        errno = 0;
        if ( (_cwait(&termstat, locidpair->prochnd, _WAIT_GRANDCHILD) != -1) ||
             (errno == EINTR) )
                retval = termstat;
        errno = save_errno;

        /* Mark the IDpairtable entry as free (note: prochnd was closed by the
         * preceding call to _cwait).
         */
        locidpair->stream = NULL;
        locidpair->prochnd = 0;

        /* only return path!
         */
        done:

        ; }
        __finally {
            _munlock(_POPEN_LOCK);
        }
        return(retval);
}
Beispiel #8
0
int downloadFile(TCHAR *inUrl, TCHAR *filepath, TCHAR *uuid, TCHAR *file_name) {
	int download_result = 0;
	char* url = WcharToChar_New(inUrl);
	TCHAR *doc_id = GetDocId(url);
	int downloadType = GetDownloadType(url);
	char* char_uuid = WcharToChar_New(uuid);
	DownloadInfo *downloadInfo = new DownloadInfo(url, filepath, doc_id);
	downloadInfo->downloadType = downloadType;
	//LOGI("%d\n", downloadType);
	downloadInfo->SetUUid(char_uuid);
	if (_taccess_s(filepath, 0) != 0) { //如果文件夹不存在
		int res = CreateMultiplePath(filepath);
		if (res == 0) {
			Log(_T("%s, %s"), _T("文件夹不存在,创建文件夹失败"), filepath);
			fprintf(stdout, "%s\n", BuildFailedResponseJson(downloadInfo, 4, _T("create floder failed")).c_str());
			delete[] url;
			delete[] char_uuid;
			download_result = -1;
			return download_result;
		}
	}
	if (file_name) {
		int length = _tcslen(file_name) + 1;
		TCHAR *fileName = new TCHAR[length];
		_tcscpy_s(fileName, length, file_name);
		downloadInfo->SetFileName(fileName);
	}

	while (1) {
		Log(_T("%s %s"), _T("开始下载"), inUrl);
		if (DownLoad(url, downloadInfo)) {
			if (fp)
				fclose(fp);
			if (downloadInfo->RenameFileAfterDownload() == 0) {
				fprintf(stdout, "%s\n", BuildSuccessResponseJson(downloadInfo).c_str());
				break;
			} else {
				download_result = -1;
				fprintf(stdout, "%s\n", BuildRenameFailedJson(downloadInfo).c_str());
				break;
			}
		} else {
			Log(_T("%s %d"), _T("下载失败,判断是否需要重新下载"), is_need_reload);
			if (is_need_reload) {//重新连接 下载
				delete downloadInfo;
				if (fp) {
					fclose(fp);
					fp = NULL;
				}
				doc_id = GetDocId(url);
				downloadInfo = new DownloadInfo(url, filepath, doc_id);
				downloadInfo->SetUUid(char_uuid);
				downloadInfo->downloadType = downloadType;
				if (file_name) {
					int length = _tcslen(file_name) + 1;
					TCHAR *fileName = new TCHAR[length];
					_tcscpy_s(fileName, length, file_name);
					downloadInfo->SetFileName(fileName);
				}
				receive_no_data_times = 0;
				is_need_reload = false;
				time_out_times = 0;
			} else {
				fprintf(stdout, "%s\n", BuildFailedResponseJson(downloadInfo).c_str());
				download_result = -1;
				break;
			}
		}
	}
	if (downloadInfo)
		delete downloadInfo;
	if (url)
		delete[] url;
	if (char_uuid)
		delete[] char_uuid;
	return download_result;
}