Beispiel #1
0
void  WriteLogToFile ( TCHAR* strMessage, LPCTSTR szFileSuffix )
{
	TCHAR* strFolder = GetExeFolder();
	FILE* f = NULL;
	TCHAR strLogName[MAX_PATH];
	TCHAR strCrLf[] = _T("\r\n");
	
	_stprintf(strLogName, 
		_T("%sCommon%s.log"),
		strFolder, szFileSuffix );
	
	while( NULL == ( f = _tfopen( strLogName, _T("ab+") ) ) )
	{
		Sleep(0);
	}
	
	// 	USES_CONVERSION;
	// 	LPCSTR p = T2CA( (LPCTSTR)strMessage );
	
    /* Use strftime to build a customized time string. */
    TCHAR tmpbuf[128];
    time_t ltime;
    struct tm *today;
	
	time( &ltime );
	today = localtime( &ltime );
	
    _tcsftime( tmpbuf, sizeof(tmpbuf),
		_T("%Y.%m.%d %H:%M.%S "), today );
	fwrite( (void*)tmpbuf, _tcslen(tmpbuf), sizeof(TCHAR), f );
	
	_stprintf(tmpbuf, _T("process Id %.8X (%d) "), GetCurrentProcessId(), GetCurrentProcessId());
	fwrite( (void*)tmpbuf, _tcslen(tmpbuf), sizeof(TCHAR), f );
	
	
	fwrite( (void*)strMessage, _tcslen(strMessage), sizeof(TCHAR), f );
	fwrite( (void*)strCrLf, _tcslen(strCrLf), sizeof(TCHAR), f );
	fclose(f);
	f = NULL;
}
static LPSTR FindProgram() {
	static CHAR result[MAX_PATH + 1];

	CHAR path[MAX_PATH + 1];
	LPSTR exefolder = GetExeFolder();
	if (PathCombine(path, exefolder, "vim??") == NULL) {
		Fail("PathCombine");
	}

	WIN32_FIND_DATA fdd;
	HANDLE find;
	if ((find = FindFirstFile(path, &fdd)) == INVALID_HANDLE_VALUE) {
		if (GetLastError() == ERROR_FILE_NOT_FOUND) {
			return NULL;
		}
		Fail("FindFirstFile");
	}

	std::vector<std::string> candidates;
	do {
		candidates.push_back(std::string(fdd.cFileName));
	} while(FindNextFile(find, &fdd));

	if (GetLastError() != ERROR_NO_MORE_FILES) {
		Fail("FindNextFile");
	}
	FindClose(find);

	std::sort(candidates.begin(), candidates.end(), sort_vim_folders);
	if (PathCombine(result, exefolder, candidates[0].c_str()) == NULL) {
		Fail("PathCombine");
	}
	if (PathAppend(result, GetExeName()) == NULL) {
		Fail("PathAppend");
	}
	return result;
}