Esempio n. 1
0
void CPixelMetricsMapperAppUi::CreateHeaderFileL() const
    {
    // Open/create resulting file.
    RFile file;
    HBufC* layoutFile = HBufC::NewLC( KMaxFileName );
    *layoutFile = KLayoutSourceFileAndPath;
    TFileName fileName = *layoutFile;
    CleanupStack::PopAndDestroy(layoutFile);
    RFs& fs = CEikonEnv::Static()->FsSession();
    TInt error = file.Open(fs,fileName, EFileWrite|EFileShareAny|EFileStreamText );
    if (error==KErrNotFound)
        {
       file.Create(fs,fileName, EFileWrite|EFileShareAny|EFileStreamText);
        }
    CleanupClosePushL( file );
    file.SetSize( 0 );

    // Make all writes as from textfile.
    TFileText textFile;
    textFile.Set( file );
    textFile.Seek( ESeekStart );

    // Take all layout files from private folder.
    CDir* dirList;
    User::LeaveIfError(fs.GetDir(
        KPixelMetricsDataFiles,
        KEntryAttMaskSupported,
        ESortByName,
        dirList));

    TMySmallBuffer bufferLayoutHdr;
    TMyBigBuffer bufferPMData;
    TInt fileCount = dirList->Count();
    for (TInt i=0;i<fileCount;i++)
        {
        // open sourcefile
        RFile sourceFile;
        TFileName layoutFile = (*dirList)[i].iName;
        User::LeaveIfError( sourceFile.Open(
            fs,layoutFile, EFileRead|EFileShareAny|EFileStreamText ));
        CleanupClosePushL( sourceFile );

        // Make all reads as from textfile.
        TFileText textSourceFile;
        textSourceFile.Set( sourceFile );
        TFileName layoutName = CreateLayoutNameL( textSourceFile );

        // rewind - just in case.
        textSourceFile.Seek( ESeekStart );
        TFileName oneline;
        bufferLayoutHdr.Append(KOpenBrace);
        bufferPMData.Append(KOpenBrace);
        TInt loop = 0;
        FOREVER
            {
            if( textSourceFile.Read(oneline) != KErrNone )
                {
                break;
                }
            // Add commas for all but first line
            if (loop != 0)
                {
                if ( loop <= KHeaderValues-1)
                    {
                    bufferLayoutHdr.Append(KComma);
                    }
                else
                    {
                    if (loop != KHeaderValues)
                        {
                        bufferPMData.Append(KComma);
                        }
                    }
                if (loop==KHeaderValues)
                    {
                    bufferLayoutHdr.Append(_L(",QLatin1String(\""));
                    bufferLayoutHdr.Append(layoutName);
                    bufferLayoutHdr.Append(_L("\")"));
                    }
                }
            // Remove pixel metrics name and ":"
            oneline = oneline.Mid(oneline.Find(KColon)+1);
            // Remove tab
            oneline = oneline.Mid(oneline.Find(KTab)+1);
            // remove crap from the end of line
            TLex lex(oneline);
            TInt nextValue = -666;
            User::LeaveIfError( lex.Val(nextValue) );
            if ( loop <= KHeaderValues-1)
                {
                bufferLayoutHdr.AppendNum(nextValue);
                }
            else
                {
                if (nextValue == -909)
                    bufferPMData.Append(_L("ECommonStyleValue"));
                else
                    bufferPMData.AppendNum(nextValue);
                }
            oneline.Zero();
            loop++;
            }
        file.Flush();
        bufferLayoutHdr.Append(KEndBraceWithCommaAndCRLF);
        bufferPMData.Append(KEndBraceWithCommaAndCRLF);
        CleanupStack::PopAndDestroy(); //sourceFile
        }

    if (fileCount > 0)
        {
        bufferLayoutHdr = bufferLayoutHdr.Left(bufferLayoutHdr.Length()-2);
        bufferPMData = bufferPMData.Left(bufferPMData.Length()-2);
        textFile.Write(bufferLayoutHdr);
        textFile.Write(KCRLF);
        textFile.Write(bufferPMData);
        }
    delete dirList;

    CleanupStack::PopAndDestroy(); //file
    }
Esempio n. 2
0
TFileName CPixelMetricsMapperAppUi::CreateLayoutNameL(TFileText& aFileHandle) const
{
    aFileHandle.Seek(ESeekStart);
    // Layout data is deployed like this:
    // first line - height
    // second line - width
    TFileName lines;
    TFileName layoutName;

    TInt height = -666;
    TInt width = -666;
    // Collect name information.
    for (TInt i=0; i<6; i++)
        {
        User::LeaveIfError(aFileHandle.Read(lines));
        // Remove pixel metrics name and ":"
        lines = lines.Mid(lines.Find(KColon)+1);
        // Remove tab
        lines = lines.Mid(lines.Find(KTab)+1);
        TLex myLexer(lines);
        TInt error = KErrNone;
        if (i==0) //height is first
            {
            error = myLexer.Val(height);
            }
        if (i==1) //width is second
            {
            error = myLexer.Val(width);
            }
        User::LeaveIfError(error);
        }

    // Interpret results and write name to buffer.
    if ( (width == 240 && height == 320) ||
         (width == 320 && height == 240))
        {
        layoutName.Append(_L("QVGA "));
        }
    else if ( (width == 360 && height == 640) ||
         (width == 640 && height == 360))
        {
        layoutName.Append(_L("NHD "));
        }
    else if ( (width == 480 && height == 640) ||
         (width == 640 && height == 480))
        {
        layoutName.Append(_L("VGA "));
        }
    else if ( (width == 800 && height == 352) ||
         (width == 352 && height == 800))
        {
        layoutName.Append(_L("E90 "));
        }
    else if ( (width == 800 && height == 480) ||
         (width == 480 && height == 800) ||
         (width == 848 && height == 480) ||
         (width == 480 && height == 848) ||
         (width == 854 && height == 480) ||
         (width == 480 && height == 854))
        {
        layoutName.Append(_L("WVGA "));
        }
    else if ( (width == 480 && height == 320) ||
         (width == 320 && height == 480) ||
         (width == 640 && height == 240) ||
         (width == 240 && height == 640))
        {
        layoutName.Append(_L("HVGA "));
        }
    else
        {
        layoutName.Append(_L("Unknown "));
        layoutName.AppendNum(height);
        layoutName.Append(_L("x"));
        layoutName.AppendNum(width);
        }
    if (width > height)
        {
        layoutName.Append(_L("Landscape"));
        }
    else
        {
        layoutName.Append(_L("Portrait"));
        }
    return layoutName;
    }
TUid CDeploymentComponentData::SetDataL(const TFileName &aData,
        const TDesC8& aMimeType)
    {
    RDEBUG_2("CDeploymentComponentData::SetDataL() TFileName: (%S)", &aData);
    
    _LIT(KNewPath, "c:\\private\\200267FB\\");

    TUid ret(TUid::Null());
    iMimeType = aMimeType.Left(KMaxMimeLength) ;
    RFs fs;
    User::LeaveIfError(fs.Connect() );
    CleanupClosePushL(fs);
    CFileMan *fm = CFileMan::NewL(fs);
    CleanupStack::PushL(fm);
    TFileName fn;
    fn.Copy(iDataFileName);

    RDEBUG("App Mgmt before copy start");

    
    TInt maxLength = iDataFileName.Length();
    TChar charvaldot = '.';
    TChar charvalslash = '\\';
    
    TInt pos = iDataFileName.LocateReverse(charvaldot);
    
    TInt lengthDeleted = maxLength-pos;
    
    iDataFileName.Delete(pos, lengthDeleted);
    
    TInt srcpos = aData.LocateReverse(charvaldot);
    
    TBuf<15> extn(aData.Mid(srcpos));
    
    iDataFileName.Append(extn);
    
    TFileName newfilepath;
    newfilepath.Copy(iDataFileName);
    
    User::LeaveIfError(fm->Move(aData,KNewPath()));
    
    TFileName oldfilepath(KNewPath());
    oldfilepath.Append(aData.Mid(aData.LocateReverse(charvalslash)));
    
    User::LeaveIfError(fm->Rename(oldfilepath, newfilepath));
   
    
    //User::LeaveIfError(fm->Copy(aData, fn) );

    RDEBUG("App Mgmt before copy End");


    if (IsSISInstallFile(aMimeType) )
        {
        ret = ResolveUidL(fs);
        }

    CleanupStack::PopAndDestroy(fm);
    CleanupStack::PopAndDestroy( &fs);
    RDEBUG_2("CDeploymentComponentData::SetDataL() (%d)", ret.iUid);

    return ret;
    }