Example #1
0
void EbookController::HandleFinishedMobiLoadingMsg(FinishedMobiLoadingData *finishedMobiLoading)
{
    str::ReplacePtr(&fileBeingLoaded, NULL);
    if (NULL == finishedMobiLoading->doc) {
        // TODO: a better way to notify about this, should be a transient message
        ScopedMem<TCHAR> s(str::Format(_T("Failed to load %s!"), finishedMobiLoading->fileName));
        ctrls->status->SetText(AsWStrQ(s.Get()));
        return;
    }
    SetDoc(*finishedMobiLoading->doc);
}
Example #2
0
bool CMarkupSTL::Load( const char * szFileName )
{
	CStdString csDoc;
	HANDLE hFile = CreateFile(szFileName, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
	if (hFile == INVALID_HANDLE_VALUE)
		return false;
	//The following will not work for files larger than 2GB
	int nLength = GetFileSize(hFile, NULL);

#if defined(_UNICODE)
	// Allocate Buffer for UTF-8 file data
	unsigned char* pBuffer = new unsigned char[nLength + 1];
	DWORD numread;
	if (ReadFile(hFile, pBuffer, nLength, &numread, 0))
		nLength = numread;
	else
		nLength = 0;
	pBuffer[nLength] = '\0';

	// Convert file from UTF-8 to Windows UNICODE (AKA UCS-2)
	int nWideLength = MultiByteToWideChar(CP_UTF8,0,(const char*)pBuffer,nLength,NULL,0);
	nLength = MultiByteToWideChar(CP_UTF8,0,(const char*)pBuffer,nLength,
		csDoc.GetBuffer(nWideLength),nWideLength);
	ASSERT( nLength == nWideLength );
	delete [] pBuffer;
#else
	DWORD numread;
	if (ReadFile(hFile, csDoc.GetBuffer(nLength), nLength, &numread, 0))
		nLength = numread;
	else
		nLength = 0;
#endif
	csDoc.ReleaseBuffer(nLength);
	CloseHandle(hFile);

	return SetDoc( csDoc );
}