Ejemplo n.º 1
0
// TODO: add line number to output
void SFMFile::logParseFailure(LPCTSTR lpszParserName,
								LPCTSTR lpszMarker,
								LPCTSTR lpszField,
								LPCTSTR lpszMoreInfo)
{
	USES_CONVERSION_U8;
	ostrstream sout;

	if(m_bNothingLogged)
	{
		m_bNothingLogged=FALSE;
		sout << "The following possible problem(s) occurred while parsing the file " << T2CA(m_pathName) << "\r\n";
	}

	sout << "The parser " << T2CA(lpszParserName) << " cannot understand ";
	sout << "\r\n\\" << T2CA(lpszMarker) << " " << T2CA(lpszField) << "\r\n";
	if(lpszMoreInfo)
		sout << T2CU8(lpszMoreInfo) << "\r\n";
	// to do: add line number?
#ifndef rde270
	// I'm just not sure if sout.str is going to be null terminated, so do it the long way.
	int nLen = sout.pcount();
	char* pSout = (char*)alloca(nLen + 1);
	strncpy(pSout, sout.str(), nLen);
	pSout[nLen] = '\0';
	CString sError(U82CT(pSout));
#else   // rde270
	CString sError (sout.str(), sout.pcount());
#endif  // rde270
	sout.rdbuf()->freeze(0); // else get a memory leak
	LOG2(sError,_T(""));
}
Ejemplo n.º 2
0
// TODO: add line number to output
void SFMFile::throwParseFailure(LPCTSTR lpszParserName,
								LPCTSTR lpszMarker,
								LPCTSTR lpszField,
								LPCTSTR lpszMoreInfo)
{
	USES_CONVERSION_U8;
	ostrstream sout;

	sout << "The parser " << T2CA(lpszParserName) << " cannot understand ";
	sout << "\n\\" << T2CA(lpszMarker) << " " << T2CA(lpszField) << '\n';
	if(lpszMoreInfo)
		sout << T2CU8(lpszMoreInfo) << '\n';
	sout << "File: " << T2CA(m_pathName) << '\n';
	// to do: add line number?
#ifndef rde270
	// I'm just not sure if sout.str is going to be null terminated, so do it the long way.
	int nLen = sout.pcount();
	char* pSout = (char*)alloca(nLen + 1);
	strncpy(pSout, sout.str(), nLen);
	pSout[nLen] = '\0';
	CString sError(U82CT(pSout));
#else   // rde270
	CString sError (sout.str(), sout.pcount());
#endif  // rde270
	sout.rdbuf()->freeze(0); // else get a memory leak
	throw(sError);
}
Ejemplo n.º 3
0
BOOL CSbproAux::ReportError(CException* e)
{
	HWND hwnd = (HWND)m_sbpro.GetHWnd();
	if (hwnd != NULL)
	{
		SbproReportError re;
		memset(&re,0,sizeof(re));
		if (e->IsKindOf(RUNTIME_CLASS(COleException)))
		{
			re.scode = ((COleException*)e)->m_sc;
			return (BOOL)::SendMessage(hwnd,SB_MCM_REPORTERROR,0,(LPARAM)&re);
		}

		if (e->IsKindOf(RUNTIME_CLASS(COleDispatchException)))
		{
			USES_CONVERSION;
			COleDispatchException* ode = (COleDispatchException*)e;
			re.scode = 0;
			re.wCode = ode->m_wCode;
			re.lpszDescription = T2CA((LPCTSTR)ode->m_strDescription);
			re.lpszSource = T2CA((LPCTSTR)ode->m_strSource);
			re.dwHelpContext = ode->m_dwHelpContext;
			re.lpszHelpFile = T2CA((LPCTSTR)ode->m_strHelpFile);
			return (BOOL)::SendMessage(hwnd,SB_MCM_REPORTERROR,0,(LPARAM)&re);
		}
	}

	// this should never happen?
	e->ReportError();
	return FALSE;
}
Ejemplo n.º 4
0
   bool Create(const TCHAR* file)
   {
      USES_CONVERSION;
      int array_count = GetFieldCount();
      DBaseFieldVector vector;

      vector.resize(array_count);
	  for (int i = 0; i < array_count; i++)
      {
         CDaoFieldInfo info;
         DBF_FIELD_INFO* item = &vector[i];
	  
         GetFieldInfo(i, info);
         strncpy(item->name, T2CA(info.m_strName), _countof(item->name));
         item->name[_countof(item->name) - 1] = 0;
         item->decimals = 0;
         item->length = info.m_lSize;
         item->type = GetFieldType(i, info, &item->length);
      }

      zlib_filefunc_def api;
      fill_fopen_filefunc(&api);
      void* stream = api.zopen_file(api.opaque, T2CA(file), ZLIB_FILEFUNC_MODE_CREATE | ZLIB_FILEFUNC_MODE_WRITE);
      bool ok = (NULL != stream);

      if (ok)
         ok = m_dbf.Create(file, stream, &api, vector);
      return ok;
   }
Ejemplo n.º 5
0
void CIni::WriteStringUTF8(LPCTSTR strEntry, LPCTSTR psz, LPCTSTR strSection/* = NULL*/)
{
	USES_CONVERSION;
	if(strSection != NULL) 
		m_strSection = strSection;
	CString str(psz);
	WritePrivateProfileStringA(T2CA(m_strSection), T2CA(strEntry), StrToUtf8(str), T2CA(m_strFileName));
}
Ejemplo n.º 6
0
BOOL CPPgProxy::OnApply()
{
	USES_CONVERSION;
	thePrefs.SetProxyASCWOP(IsDlgButtonChecked(IDC_ASCWOP));
	proxy.UseProxy=(IsDlgButtonChecked(IDC_ENABLEPROXY));
	proxy.EnablePassword = ((CButton*)GetDlgItem(IDC_ENABLEAUTH))->GetCheck();
	proxy.type = ((CComboBox*)GetDlgItem(IDC_PROXYTYPE))->GetCurSel();

	if(GetDlgItem(IDC_PROXYNAME)->GetWindowTextLength())
	{ 
		GetDlgItem(IDC_PROXYNAME)->GetWindowText(proxy.name, ARRSIZE(proxy.name));
	}
	else
	{
		proxy.name[0] = _T('\0');
        proxy.UseProxy = false;
	}

	if(GetDlgItem(IDC_PROXYPORT)->GetWindowTextLength())
	{ 
		TCHAR buffer[6];
		GetDlgItem(IDC_PROXYPORT)->GetWindowText(buffer,ARRSIZE(buffer));
		proxy.port = (_tstoi(buffer)) ? _tstoi(buffer) : 1080;
	}
	else
		proxy.port = 1080;

	if(GetDlgItem(IDC_USERNAME_A)->GetWindowTextLength())
	{ 
		CString strUser;
		GetDlgItem(IDC_USERNAME_A)->GetWindowText(strUser);
		_snprintf(proxy.user, ARRSIZE(proxy.user), "%s", T2CA(strUser));
	}
	else
	{
		proxy.user[0] = '\0';
		proxy.EnablePassword = false;
	}

	if(GetDlgItem(IDC_PASSWORD)->GetWindowTextLength())
	{ 
		CString strPasswd;
		GetDlgItem(IDC_PASSWORD)->GetWindowText(strPasswd);
		_snprintf(proxy.password, ARRSIZE(proxy.password), "%s", T2CA(strPasswd));
	}
	else
	{
		proxy.password[0] = '\0';
		proxy.EnablePassword = false;
	}
	thePrefs.SetProxySettings(proxy);
	LoadSettings();
	return TRUE;
}
Ejemplo n.º 7
0
CString CIni::GetStringUTF8(LPCTSTR strEntry, LPCTSTR strDefault/*=NULL*/, LPCTSTR strSection/* = NULL*/)
{
	USES_CONVERSION;
	if(strSection != NULL)
		m_strSection = strSection;

	CStringA strUTF8;
	GetPrivateProfileStringA(T2CA(m_strSection), T2CA(strEntry), T2CA(strDefault), 
							 strUTF8.GetBufferSetLength(MAX_INI_BUFFER), MAX_INI_BUFFER, T2CA(m_strFileName));
	strUTF8.ReleaseBuffer();
	return OptUtf8ToStr(strUTF8);
}
Ejemplo n.º 8
0
BOOL CSqlite3Recordset::Open(LPCTSTR pstrSQL, long lType /*= DB_OPEN_TYPE_FORWARD_ONLY*/, long lOptions /*= DB_OPTION_DEFAULT*/)
{
   _ASSERTE(m_pDb);
   _ASSERTE(!::IsBadStringPtr(pstrSQL,(UINT)-1));

   USES_CONVERSION;
#if _ATL_VER > 0x0700 && WINVER >= 0x0500
   _acp = CP_UTF8;
#endif

   Close();

   m_ppSnapshot = NULL;
   m_pVm = NULL;
   m_nCols = 0;
   m_nRows = 0;
   m_fEOF = TRUE;
   m_lType = lType;
   m_lOptions = lOptions;

   switch( lType ) {
   case DB_OPEN_TYPE_FORWARD_ONLY:
      {
         LPCSTR pTrail = NULL;
         LPCSTR pstrZSQL = T2CA(pstrSQL);
         int iErr = ::sqlite3_prepare(*m_pDb, pstrZSQL, strlen(pstrZSQL), &m_pVm, &pTrail);
         if( iErr != SQLITE_OK ) return _Error(::sqlite3_errcode(*m_pDb), iErr, ::sqlite3_errmsg(*m_pDb));
         _ASSERTE(strlen(pTrail)==0);  // We don't really support batch SQL statements
         m_iPos = -1;
         m_fEOF = FALSE;
         m_nCols = ::sqlite3_column_count(m_pVm);
         MoveNext();
         return TRUE;
      }
      break;
   default:
      {
         LPSTR pstrErrorMsg = NULL;
         int iErr = ::sqlite3_get_table(*m_pDb, T2CA(pstrSQL), &m_ppSnapshot, &m_nRows, &m_nCols, &pstrErrorMsg);
         if( iErr != SQLITE_OK ) {
            _Error(::sqlite3_errcode(*m_pDb), iErr, pstrErrorMsg);
            if( pstrErrorMsg != NULL ) ::sqlite3_free(pstrErrorMsg);
            return FALSE;
         }
         m_iPos = 0;
         return TRUE;
      }
   }
}
Ejemplo n.º 9
0
bool CMinizip::Extract(LPCTSTR FileName, LPCTSTR DestPath, UINT BufSize)
{
    USES_CONVERSION;
    if (unzLocateFile(m_ZipFile, T2CA(FileName), 0) != UNZ_OK)
        return(FALSE);
    if (unzOpenCurrentFile(m_ZipFile) != UNZ_OK)
        return(FALSE);
    CByteArray	ba;
    ba.SetSize(BufSize);
    bool	retc = FALSE;	// assume failure
    TRY {
        CFile	DestFile(DestPath, CFile::modeCreate | CFile::modeWrite);
        int	BytesRead;
        while ((BytesRead = unzReadCurrentFile(m_ZipFile, ba.GetData(), BufSize)) > 0) {
            DestFile.Write(ba.GetData(), BytesRead);
        }
        if (!BytesRead)	// if EOF
            retc = TRUE;	// success provided current file closes OK
    }
    CATCH (CFileException, e) {
        e->ReportError();
    }
    END_CATCH
    if (unzCloseCurrentFile(m_ZipFile) != UNZ_OK)	// close fails if bad CRC
        return(FALSE);
    return(retc);
}
Ejemplo n.º 10
0
BOOL CNetwork::AsyncResolve(LPCTSTR pszAddress, WORD nPort, PROTOCOLID nProtocol, BYTE nCommand)
{
	CSingleLock pLock( &m_pSection );
	if ( ! pLock.Lock( 250 ) ) return FALSE;
	
	BYTE* pResolve = (BYTE*)malloc( MAXGETHOSTSTRUCT + 8 );
	
	USES_CONVERSION;
	
	HANDLE hAsync = WSAAsyncGetHostByName( AfxGetMainWnd()->GetSafeHwnd(), WM_WINSOCK,
		T2CA(pszAddress), (LPSTR)pResolve + 8, MAXGETHOSTSTRUCT );
	
	if ( hAsync != NULL )
	{
		*((CString**)&pResolve[0])	= new CString( pszAddress );
		*((WORD*)&pResolve[4])		= nPort;
		*((BYTE*)&pResolve[6])		= nProtocol;
		*((BYTE*)&pResolve[7])		= nCommand;
		
		m_pLookups.SetAt( (LPVOID)hAsync, (LPVOID)pResolve );
		return TRUE;
	}
	else
	{
		free( pResolve );
		return FALSE;
	}
}
Ejemplo n.º 11
0
static GURL
RegOpenReadConfig ( HKEY hParentKey )
{
  GURL retval;
   // To do:  This needs to be shared with SetProfile.cpp
  LPCTSTR path = registrypath;

  HKEY hKey = 0;
  // MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,argv[1],strlen(argv[1])+1,wszSrcFile,sizeof(wszSrcFile));
  if (RegOpenKeyEx(hParentKey, path, 0,
              KEY_READ, &hKey) == ERROR_SUCCESS )
  {
    TCHAR path[1024];
    // Success
    TCHAR *szPathValue = path;
    LPCTSTR lpszEntry = (LPCTSTR &)TEXT("");
    DWORD dwCount = (sizeof(path)/sizeof(TCHAR))-1;
    DWORD dwType;

    LONG lResult = RegQueryValueEx(hKey, lpszEntry, NULL,
             &dwType, (LPBYTE) szPathValue, &dwCount);

    RegCloseKey(hKey);

    if ((lResult == ERROR_SUCCESS))
    {
      szPathValue[dwCount] = 0;
      USES_CONVERSION;
      retval=GURL::Filename::Native(T2CA(path));
    }
  } 
//  if (hKey)  RegCloseKey(hKey); 
  return retval;
}
Ejemplo n.º 12
0
void CServer::ShowStatus(_int64 eventDate, LPCTSTR msg, int nType)
{
	USES_CONVERSION;
	TIME_ZONE_INFORMATION tzInfo;
	BOOL res=GetTimeZoneInformation(&tzInfo);
	_int64 offset = tzInfo.Bias+((res==TIME_ZONE_ID_DAYLIGHT)?tzInfo.DaylightBias:tzInfo.StandardBias);
	offset*=60*10000000;
	eventDate-=offset;
	LPCSTR str=T2CA(msg);
	char *pBuffer=new char[strlen(str) + 1 + 8];
	*pBuffer=nType;
	memcpy(pBuffer + 1, &eventDate, 8);
	memcpy(pBuffer + 1 + 8, str, strlen(str));
	if (m_pAdminInterface)
		m_pAdminInterface->SendCommand(2, 4, pBuffer, strlen(str) + 1 + 8);
	delete [] pBuffer;

	//Log string
	if (m_pFileLogger)
	{
		FILETIME fFileTime;
		SYSTEMTIME sFileTime;
		fFileTime.dwHighDateTime = (DWORD)(eventDate>>32);
		fFileTime.dwLowDateTime = (DWORD)(eventDate %0xFFFFFFFF);
		FileTimeToSystemTime(&fFileTime, &sFileTime);
		char text[80];
		if (!GetDateFormat(
			LOCALE_USER_DEFAULT,               // locale for which date is to be formatted
			DATE_SHORTDATE,             // flags specifying function options
			&sFileTime,  // date to be formatted
			0,          // date format string
			text,          // buffer for storing formatted string
			80                // size of buffer
			))
			return;
		
		CStdString text2=" ";
		text2+=text;
		
		if (!GetTimeFormat(
			LOCALE_USER_DEFAULT,               // locale for which date is to be formatted
			TIME_FORCE24HOURFORMAT,             // flags specifying function options
			&sFileTime,  // date to be formatted
			0,          // date format string
			text,          // buffer for storing formatted string
			80                // size of buffer
			))
			return;

		text2+=" ";
		text2+=text;
		CStdString str = msg;
		int pos=str.Find("-");
		if (pos!=-1)
		{
			str.Insert(pos, text2 + " ");
		}
		m_pFileLogger->Log(str);
	}
}
Ejemplo n.º 13
0
STDMETHODIMP CBmpCtxMenuExt::GetCommandString (
                               UINT uCmd, UINT uFlags, UINT* puReserved,
                               LPSTR pszName, UINT cchMax )
{
static LPCTSTR szHelpString = _T("Click the thumbnail to view the entire picture.");

    USES_CONVERSION;

    // Check idCmd, it must be 0 since we have only one menu item.
    if ( 0 != uCmd )
        return E_INVALIDARG;

    // If Explorer is asking for a help string, copy our string into the
    // supplied buffer.
    if ( uFlags & GCS_HELPTEXT )
        {
        if ( uFlags & GCS_UNICODE )
            {
            // We need to cast pszName to a Unicode string, and then use the
            // Unicode string copy API.
            lstrcpynW ( (LPWSTR) pszName, T2CW(szHelpString), cchMax );
            }
        else
            {
            // Use the ANSI string copy API to return the help string.
            lstrcpynA ( pszName, T2CA(szHelpString), cchMax );
            }
        }

    return S_OK;
}
Ejemplo n.º 14
0
void CMidiFile::WriteTrack(const CMidiEventArray& Event, LPCTSTR Name)
{
	static bool	HasP2[8] = {1, 1, 1, 1, 0, 0, 1, 1};
	FILE_POS	StartPos = BeginTrack();	// write track header
	USES_CONVERSION;
	if (Name != NULL) {	// if track name specified
		int	len = UINT64TO32(_tcslen(Name));
		if (len) {	// if track name has non-zero length
			WriteMeta(ME_TRACK_NAME, len);	// write meta header
			Write(T2CA(Name), len);	// write track name
		}
	}
	BYTE	RunningStatus = 0;	// init running status
	int	nEvents = Event.GetSize();
	for (int iEvent = 0; iEvent < nEvents; iEvent++) {	// for each event
		const MIDI_EVENT&	ev = Event[iEvent];
		WriteVarLen(ev.DeltaT);	// write variable-length delta time
		BYTE	status = MIDI_STAT(ev.Msg);	// get message status
		if (status != RunningStatus) {	// if status changed
			WriteByte(status);
			RunningStatus = status;
		}
		WriteByte(MIDI_P1(ev.Msg));	// write message 1st parameter
		if (HasP2[(status >> 4) - 8])	// if message has 2nd parameter
			WriteByte(MIDI_P2(ev.Msg));	// write message 2nd parameter
	}
	EndTrack(StartPos);	// finish track and fix header
}
Ejemplo n.º 15
0
void SFMFile::logCommentSkip(LPCTSTR lpszField, LPCTSTR lpszMoreInfo)
{
	USES_CONVERSION_U8;
	ostrstream sout;
	if(m_bNothingLogged)
	{
		m_bNothingLogged=FALSE;
		sout << "The following possible problem(s) occurred while parsing the file " << T2CA(m_pathName) << "\r\n";
	}

	if(!m_bDidOutputSkippedCommentNotice)
	{
		m_bDidOutputSkippedCommentNotice = TRUE;
		sout << "Sorry, CarlaStudio did not know where to locate one or more comments.\r\n";
		sout << "You will need to copy these 'skipped comments' and paste them where you want them.\r\n";
	}
	sout << "Skipped comment: \"" << T2CU8(lpszField) << "\"\r\n";
	if(lpszMoreInfo)
				sout << "    " << T2CU8(lpszMoreInfo) <<  "\r\n";
	// to do: add line number?
	sout << "\r\n";
#ifndef rde270
	// I'm just not sure if sout.str is going to be null terminated, so do it the long way.
	int nLen = sout.pcount();
	char* pSout = (char*)alloca(nLen + 1);
	strncpy(pSout, sout.str(), nLen);
	pSout[nLen] = '\0';
	CString sError(U82CT(pSout));
#else   // rde270
	CString sError (sout.str(), sout.pcount());
#endif  // rde270
	sout.rdbuf()->freeze(0); // else get a memory leak
	LOG(sError);
}
Ejemplo n.º 16
0
void CStatusCtrl::OnOutputcontextClearall()
{
    USES_CONVERSION;

    CString rtfstr = m_RTFHeader;

    rtfstr += "} ";

    char *buffer = new char[rtfstr.GetLength() + 5];
    strcpy(buffer + 4, T2CA(rtfstr));
    *(int *)buffer = 0;

    EDITSTREAM es;
    es.dwCookie = (DWORD)buffer; // Pass a pointer to the CString to the callback function
    es.pfnCallback = RichEditStreamInCallback; // Specify the pointer to the callback function.

    StreamIn(SF_RTF, es); // Perform the streaming
    SetSel(-1, -1);
    LimitText(1000*1000);
    int res = GetLimitText();

    delete [] buffer;

    m_bEmpty = TRUE;
    m_nMoveToBottom = 0;
}
Ejemplo n.º 17
0
HRESULT CSimpleShlExt::GetCommandString( UINT  idCmd,      UINT uFlags,
										 UINT* pwReserved, LPSTR pszName,
										 UINT  cchMax )
{
	USES_CONVERSION;

	// Check idCmd, it must be 0 since we have only one menu item.
	if (idCmd != 0)
		return E_INVALIDARG;

	// If Explorer is asking for a help string, copy our string into the
	// supplied buffer.
	if (uFlags & GCS_HELPTEXT)
	{
		TCHAR szBuffer[256];
		::LoadString(NULL, IDS_COMMAND_STRING, szBuffer, sizeof(szBuffer)/sizeof(szBuffer[0]));

		if (uFlags & GCS_UNICODE)
			// We need to cast pszName to a Unicode string, and then use the
			// Unicode string copy API.
			lstrcpynW( (LPWSTR) pszName, T2CW(szBuffer), cchMax );
		else
			// Use the ANSI string copy API to return the help string.
			lstrcpynA( pszName, T2CA(szBuffer), cchMax );

		return S_OK;
	}

	return E_INVALIDARG;
}
Ejemplo n.º 18
0
STDMETHODIMP CSimpleShlExt::GetCommandString (
    UINT_PTR idCmd, UINT uFlags, UINT* pwReserved, LPSTR pszName, UINT cchMax )
{
USES_CONVERSION;

    // Check idCmd, it must be 0 since we have only one menu item.
    if ( 0 != idCmd )
        return E_INVALIDARG;

    // If Explorer is asking for a help string, copy our string into the
    // supplied buffer.
    if ( uFlags & GCS_HELPTEXT )
        {
        LPCTSTR szText = _T("Git shell extensions");

        if ( uFlags & GCS_UNICODE )
            {
            // We need to cast pszName to a Unicode string, and then use the
            // Unicode string copy API.
            lstrcpynW ( (LPWSTR) pszName, T2CW(szText), cchMax );
            }
        else
            {
            // Use the ANSI string copy API to return the help string.
            lstrcpynA ( pszName, T2CA(szText), cchMax );	
            }

        return S_OK;
        }

    return E_INVALIDARG;
}
Ejemplo n.º 19
0
CConverter::CConverter(LPCSTR pszLibName, CFrameWnd* pWnd) : CTrackFile(pWnd)
{
	USES_CONVERSION;
	m_hBuff = NULL;
	m_pBuf = NULL;
	m_nBytesAvail = 0;
	m_nBytesWritten = 0;
	m_nPercent = 0;
	m_hEventFile = NULL;
	m_hEventConv = NULL;
	m_bDone = TRUE;
	m_bConvErr = FALSE;
	m_hFileName = NULL;
	OFSTRUCT ofs;
	if (OpenFile(pszLibName, &ofs, OF_EXIST) == HFILE_ERROR)
	{
		m_hLibCnv = NULL;
		return;
	}
	m_hLibCnv = LoadLibraryA(pszLibName);
	if (m_hLibCnv < (HINSTANCE)HINSTANCE_ERROR)
		m_hLibCnv = NULL;
	else
	{
		LoadFunctions();
		ASSERT(m_pInitConverter != NULL);
		if (m_pInitConverter != NULL)
		{
			CString str = AfxGetAppName();
			str.MakeUpper();
			VERIFY(m_pInitConverter(AfxGetMainWnd()->GetSafeHwnd(), T2CA(str)));
		}
	}
}
Ejemplo n.º 20
0
void CLicenseKey::InitUID()
{
	USES_CONVERSION;

	TCHAR szDir [MAX_PATH];
	::GetWindowsDirectory (szDir, MAX_PATH);
	
	TCHAR szDrive [MAX_PATH];  
	_tsplitpath_s (szDir, szDrive,MAX_PATH, NULL,0, NULL,0, NULL,0);
	
	DWORD dwSerialNumber=0;
    ::GetVolumeInformation (szDrive, NULL, 0, &dwSerialNumber, NULL, NULL, NULL, 0 );

	int nLen = _tcslen (szDrive);
	if (nLen < MAX_PATH)
	{
		szDrive[nLen] = _T('\\');
		szDrive[nLen+1] = _T('\0');
	}

	CString m_strUID;
	m_strUID.Format (_T("%s%X%s%s"), m_szAppName, dwSerialNumber, 
		(LPCTSTR)theApp.GetUser(), (LPCTSTR)theApp.GetCompany() );

	LPCSTR szUID = T2CA (   m_strUID );

	long nUID = CalcCRC32(szUID, m_strUID.GetLength() );
	nUID = nUID < 0 ? -nUID : nUID;

	m_nUID = nUID;
}
Ejemplo n.º 21
0
HRESULT CSimpleShlExt::GetCommandString( UINT idCmd, UINT uFlags,UINT* pwReserved, LPSTR pszName, UINT cchMax ) 
{
	USES_CONVERSION; 
	//检查 idCmd, 它必须是0,因为我们仅有一个添加的菜单项. 
	if ( 0 != idCmd ) 
		return E_INVALIDARG; 

	// 如果 Explorer 要求帮助字符串,就将它拷贝到提供的缓冲区中. 
	if ( uFlags & GCS_HELPTEXT ) 
	{
		LPCTSTR szText = _T("This is the simple shell extension's help");              
		if ( uFlags & GCS_UNICODE )
		{ 
			// 我们需要将 pszName 转化为一个 Unicode 字符串, 接着使用Unicode字符串拷贝 API. 
			lstrcpynW ( (LPWSTR) pszName, T2CW(szText), cchMax ); 
		} 
		else
		{ 
			// 使用 ANSI 字符串拷贝API 来返回帮助字符串. 
			lstrcpynA ( pszName, T2CA(szText), cchMax ); 
		} 
		return S_OK;
	} 
	return E_INVALIDARG; 
}
Ejemplo n.º 22
0
CString CCrypt::decrypt(CString str)
{
    USES_CONVERSION;

    LPCSTR lpszAscii=T2CA(str);
    int pos=(strlen(lpszAscii)/3)%strlen(m_key);
    CString ret;
    TCHAR tmp[2];
    tmp[1] = 0;
    for (unsigned int i=0; i<strlen(lpszAscii)/3; i++)
    {
        int digit;
        int number = 0;
        digit = lpszAscii[i * 3];
        if (digit < '0' || digit > '9')
            return _T("");
        number += (digit - '0') * 100;
        digit = lpszAscii[i * 3 + 1];
        if (digit < '0' || digit > '9')
            return _T("");
        number += (digit - '0') * 10;
        digit = lpszAscii[i * 3 + 2];
        if (digit < '0' || digit > '9')
            return _T("");
        number += digit - '0';
        tmp[0] = number^m_key[(i+pos)%strlen(m_key)];
        ret += tmp;
    }
    return ret;
}
Ejemplo n.º 23
0
STDMETHODIMP ExifShellExtension::GetCommandString(
   UINT idCmd, UINT uFlags, UINT* /*pwReserved*/, LPSTR pszName, UINT cchMax)
{
   // If Explorer is asking for a help string, copy our string into the
   // supplied buffer.
   if (uFlags & GCS_HELPTEXT)
   {
      CString cszText;
      if (idCmd == m_uidMenuCopyExif)
         cszText = _T("Copies Exif data to clipboard");
      else if (idCmd == m_uidMenuPasteExif)
         cszText = _T("Pastes Exif data from clipboard");
      else
         return E_INVALIDARG;

      USES_CONVERSION;
      if (uFlags & GCS_UNICODE)
      {
         // We need to cast pszName to a Unicode string, and then use the
         // Unicode string copy API.
         lstrcpynW(reinterpret_cast<LPWSTR>(pszName), T2CW(cszText), cchMax);
      }
      else
      {
         // Use the ANSI string copy API to return the help string.
         lstrcpynA(pszName, T2CA(cszText), cchMax);
      }

      return S_OK;
   }

   return E_INVALIDARG;
}
Ejemplo n.º 24
0
bool CUrlClient::SendHttpBlockRequests()
{
	USES_CONVERSION;
	m_dwLastBlockReceived = ::GetTickCount();
	if (reqfile == NULL)
		throw CString(_T("Failed to send block requests - No 'reqfile' attached"));

	CreateBlockRequests(PARTSIZE / EMBLOCKSIZE);
	if (m_PendingBlocks_list.IsEmpty()){
//==> Extended Failed/Success Statistic by NetF [shadow2004]
#ifdef FSSTATS
		SetDownloadState(DS_NONEEDEDPARTS, REASON_NoNeededParts);
#else
		SetDownloadState(DS_NONEEDEDPARTS);
#endif
//<== Extended Failed/Success Statistic by NetF [shadow2004]
        SwapToAnotherFile(_T("A4AF for NNP file. UrlClient::SendHttpBlockRequests()"), true, false, false, NULL, true, true);
		return false;
	}
	
	POSITION pos = m_PendingBlocks_list.GetHeadPosition();
	Pending_Block_Struct* pending = m_PendingBlocks_list.GetNext(pos);
	m_uReqStart = pending->block->StartOffset;
	m_uReqEnd = pending->block->EndOffset;
	bool bMergeBlocks = true;
	while (pos)
	{
		POSITION posLast = pos;
		pending = m_PendingBlocks_list.GetNext(pos);
		if (bMergeBlocks && pending->block->StartOffset == m_uReqEnd + 1)
			m_uReqEnd = pending->block->EndOffset;
		else
		{
			bMergeBlocks = false;
			reqfile->RemoveBlockFromList(pending->block->StartOffset, pending->block->EndOffset);
			delete pending->block;
			delete pending;
			m_PendingBlocks_list.RemoveAt(posLast);
		}
	}

	m_nUrlStartPos = m_uReqStart;

	CStringA strHttpRequest;
	strHttpRequest.AppendFormat("GET %s HTTP/1.0\r\n", m_strUrlPath);
	strHttpRequest.AppendFormat("Accept: */*\r\n");
	strHttpRequest.AppendFormat("Range: bytes=%u-%u\r\n", m_uReqStart, m_uReqEnd);
	strHttpRequest.AppendFormat("Connection: Keep-Alive\r\n");
	strHttpRequest.AppendFormat("Host: %s\r\n", T2CA(m_strHost));
	strHttpRequest.AppendFormat("\r\n");

	if (thePrefs.GetDebugClientTCPLevel() > 0)
		Debug(_T("Sending HTTP request:\n%hs"), strHttpRequest);
	CRawPacket* pHttpPacket = new CRawPacket(strHttpRequest);
	theStats.AddUpDataOverheadFileRequest(pHttpPacket->size);
	socket->SendPacket(pHttpPacket);
	STATIC_DOWNCAST(CHttpClientDownSocket, socket)->SetHttpState(HttpStateRecvExpected);
	return true;
}
Ejemplo n.º 25
0
BOOL CConverter::Open(LPCTSTR pszFileName, UINT nOpenFlags,
	CFileException* pException)
{
	USES_CONVERSION;
	// we convert to oem and back because of the following case
	// test(c).txt becomes testc.txt in OEM and stays testc.txt to Ansi
	char buf[_MAX_PATH];
	strcpy(buf, T2CA(pszFileName));
	CharToOemA(buf, buf);
	OemToCharA(buf, buf);

	LPTSTR lpszFileNameT = A2T(buf);

	// let's make sure we could do what is wanted directly even though we aren't
	m_bCloseOnDelete = FALSE;
#if _MSC_VER >= 1400
	m_hFile = hFileNull;
#else
	m_hFile = (UINT)hFileNull;
#endif

	BOOL bOpen = CFile::Open(lpszFileNameT, nOpenFlags, pException);
	CFile::Close();
	if (!bOpen)
		return FALSE;

	m_bForeignToRtf = !(nOpenFlags & (CFile::modeReadWrite | CFile::modeWrite));

	// check for reading empty file
	if (m_bForeignToRtf)
	{
		CFileStatus stat;
		if (CFile::GetStatus(lpszFileNameT, stat) && stat.m_size == 0)
			return TRUE;
	}

	//set security attributes to inherit handle
	SECURITY_ATTRIBUTES sa = {sizeof(SECURITY_ATTRIBUTES), NULL, TRUE};
	//create the events
	m_hEventFile = CreateEvent(&sa, TRUE, FALSE, NULL);
	m_hEventConv = CreateEvent(&sa, TRUE, FALSE, NULL);
	//create the converter thread and create the events

	CharToOemA(buf, buf);
	ASSERT(m_hFileName == NULL);
	m_hFileName = StringToHGLOBAL(buf);

	m_pThis = this;
	m_bDone = FALSE;
	m_hBuff = GlobalAlloc(GHND, BUFFSIZE);
	ASSERT(m_hBuff != NULL);

	AfxBeginThread(ConverterThread, this, THREAD_PRIORITY_NORMAL, 0, 0, &sa);

	return TRUE;
}
Ejemplo n.º 26
0
void YouTubeWebPageView::LoadVideo(const VideoInfo& info)
{
   m_bLoaded = false;

   ATLTRACE(_T("%08x: LoadVideo: \"%s\" (%s)\n"),
      m_hWnd,
      info.Name(),
      info.Address());

   m_iLastError = 0;

   CString cszHtml = GetHtmlTemplate();

   cszHtml.Replace(_T("{..$address..}"), info.Address());
   cszHtml.Replace(_T("{..$name..}"), info.Name());
   cszHtml.Replace(_T("\r\n"), _T("\n"));

   // generate temp name
   CString cszTempFolder;
   GetTempPath(MAX_PATH, cszTempFolder.GetBuffer(MAX_PATH));
   cszTempFolder.ReleaseBuffer();

   CString cszFilename;
   GetTempFileName(cszTempFolder, _T("YTP"), 0, cszFilename.GetBuffer(MAX_PATH));
   cszFilename.ReleaseBuffer();

   // write to temporary file
   {
      FILE* fd = NULL;
	  errno_t err = _tfopen_s(&fd, cszFilename, _T("wt"));
	  ATLVERIFY(err == 0 && fd != NULL);

      USES_CONVERSION;
      fprintf(fd, T2CA(cszHtml));
      fclose(fd);
   }

   // navigate to page
   CComPtr<IWebBrowser2> spWebBrowser2;
   HRESULT hr = GetWebBrowser2(spWebBrowser2);
   if (SUCCEEDED(hr))
   {
      CString cszURL = _T("file:///") + cszFilename;
      cszURL.Replace(_T("\\"), _T("/"));

      CComBSTR bstrURL = cszURL;

      CComVariant varFlags(static_cast<int>(navNoHistory | navNoWriteToCache));

      hr = spWebBrowser2->Navigate(bstrURL, &varFlags, NULL, NULL, NULL);
   }

   if (!m_cszHtmlFilename.IsEmpty())
      DeleteFile(m_cszHtmlFilename);
   m_cszHtmlFilename = cszFilename;
}
Ejemplo n.º 27
0
void CPrintANAProcess::writeToStream(ostream& fout) const
{
    fout << "\\+Process "<< ID() << PROC_ENABLED_STATUS << "\n";
    outputInt(fout, "DisplayBeginColumn", m_nDisplayBeginColumn);
    outputBool(fout, "DisplayAnalysesOnly", m_bDisplayAnalysesOnly);
    USES_CONVERSION;
    fout <<"\\EXEName " << T2CA(m_sEXEName) << '\n';

    fout << "\\-Process "<< ID() << "\n";
}
Ejemplo n.º 28
0
bool CGZIPFile::Open(LPCTSTR pszFilePath)
{
	ASSERT( m_gzFile == 0 );
	Close();

	USES_CONVERSION;
	m_gzFile = gzopen(T2CA(pszFilePath), "rb");
	if (m_gzFile)
		m_strGzFilePath = pszFilePath;
	return m_gzFile != 0;
}
Ejemplo n.º 29
0
   /// writes UTF-8 encoded string
   void WriteString(const CString& csz)
   {
      if (csz.GetLength() > std::numeric_limits<unsigned short>::max())
         throw Exception(_T("string too long!"), __FILE__, __LINE__);
      Write16(static_cast<unsigned short>(csz.GetLength()));

      USES_CONVERSION;
      LPCSTR pszaText = T2CA(static_cast<LPCTSTR>(csz));

      const unsigned char* p = reinterpret_cast<const unsigned char*>(pszaText);
      WriteBlock(p, csz.GetLength());
   }
Ejemplo n.º 30
0
int CFileZillaApi::Connect(const t_server &server)
{
	//Check parameters
	if (server.host==_MPT("") || server.port<1 || server.port>65535)
		return FZ_REPLY_INVALIDPARAM;

#ifndef MPEXT_NO_GSS
	BOOL bUseGSS = FALSE;
	if (COptions::GetOptionVal(OPTION_USEGSS))
	{
		USES_CONVERSION;

		CString GssServers = COptions::GetOption(OPTION_GSSSERVERS);
		hostent *fullname = gethostbyname(T2CA(server.host));
		CString host;
		if (fullname)
			host = fullname->h_name;
		else
			host = server.host;
		host.MakeLower();
		int i;
		while ((i=GssServers.Find( _T(";") ))!=-1)
		{
			if ((_MPT(".")+GssServers.Left(i))==host.Right(GssServers.Left(i).GetLength()+1) || GssServers.Left(i)==host)
			{
				bUseGSS = TRUE;
				break;
			}
			GssServers = GssServers.Mid(i+1);
		}
	}
	if (!bUseGSS && server.user == _MPT(""))
		return FZ_REPLY_INVALIDPARAM;
#endif

	if (!(server.nServerType&FZ_SERVERTYPE_HIGHMASK))
		return FZ_REPLY_INVALIDPARAM;

	//Check if call allowed
	if (!m_bInitialized)
		return FZ_REPLY_NOTINITIALIZED;
	if (m_pMainThread->IsBusy())
		return FZ_REPLY_BUSY;

	t_command command;
	command.id=FZ_COMMAND_CONNECT;
	command.server=server;
	m_pMainThread->Command(command);
	if (m_hOwnerWnd)
		return FZ_REPLY_WOULDBLOCK;
	else
		return m_pMainThread->LastOperationSuccessful()?FZ_REPLY_OK:FZ_REPLY_ERROR;
}