Exemplo n.º 1
0
// -----------------------------------------------------------------------------
// CDirectoryDesc::Read : Reading from a Directory
// -----------------------------------------------------------------------------
void CDirectoryDesc::Read(TDes8& aDesc, TRequestStatus& aStatus)
{
    TInt errorNum = KErrNone;
    const TInt16 KDirentSize = 8;
    TInt readLen = aDesc.MaxLength();
    TUint8* bufPtr = const_cast<TUint8*>(aDesc.Ptr());
    TInt copiedInfo = 0;
    TEntryArray entries;
    errorNum = iDir.Read( entries );
    TDirent direntEntry;

    if (errorNum == KErrNone || errorNum == KErrEof)
    {
        errorNum = KErrNone;
        TEntry entry;
        TInt len = 0;
        TInt count = entries.Count();
        TBuf8<KMaxFileName> fileName;
        TInt index = 0;
        TInt copyLen = 0;
        //Loop through each entry and get all the informations
        for (; index<count && copiedInfo<readLen; index++, copiedInfo += copyLen)
        {
            entry = entries[index];
            //Copy File's UID
            TUid fileUID = entry.iType.MostDerived();
            direntEntry.iEntryNum = fileUID.iUid;
            HBufC8 *name;
            if(ConvertUnicodeToUtf8(entry.iName,name,errorNum) == -1)
            {
                break;
            }
            //Copy entry type and record Length
            fileName.Copy( name->Des() );
            delete name;
            len = fileName.Length();
            direntEntry.iRecLen = KDirentSize + len + 1;
            //Maintaing a four byte boundary.
            direntEntry.iRecLen = Align4(direntEntry.iRecLen);
            direntEntry.iEntryType = 0;
            direntEntry.iNameLen = len;
            //Copy entry name
            Mem::Copy( direntEntry.iEntryName, fileName.PtrZ(), len+1);

            //Copy structure on to the buffer
            copyLen = Min(direntEntry.iRecLen, (readLen - copiedInfo));
            Mem::Copy( bufPtr, &direntEntry, copyLen );
            bufPtr += copyLen;
        }
    }

    //Set the Length
    aDesc.SetLength( copiedInfo );
    TRequestStatus* status = &aStatus;
    User::RequestComplete(status, errorNum);
}
Exemplo n.º 2
0
	std::string ConvertUnicodeToAscii(const wchar_t* unicodeString)
	{
		if (unicodeString == 0)
			return "";
		std::string result = ConvertUnicodeToUtf8(unicodeString);
		#ifdef _DEBUG
		for (std::string::size_type i = 0; i < result.size(); ++i)
		{
		  assert( IsAsciiCharacter( result[i] ) );
		}
		#endif
		return result;
	}
Exemplo n.º 3
0
CMString::operator const CHAR*()
{
    if(m_cdata)
    {
        delete []m_cdata;
        m_cdata = NULL;
    }
    if(m_sData)
    {
       INT32 len = GetLength();
       m_cdata = new CHAR[len*3+1];
       ASSERT(m_cdata!=NULL);
       memset(m_cdata,0,len*3+1);
       ConvertUnicodeToUtf8(m_sData,m_cdata,len*3+1);
    }
	if(!m_cdata)
	{
		 m_cdata = new CHAR[1];
		 m_cdata[0] = '\0';
	}
    return (const CHAR*)m_cdata;
          
}