brandingserver/BSServer/cbsibywriter.cpp
author hgs
Sun, 11 Apr 2010 15:33:49 +0530
changeset 31 9dbc70490d9a
permissions -rw-r--r--
201014
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
* Copyright (c) 2006-2006 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     3
* All rights reserved.
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
*
hgs
parents:
diff changeset
     9
* Initial Contributors:
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
*
hgs
parents:
diff changeset
    12
* Contributors:
hgs
parents:
diff changeset
    13
*
hgs
parents:
diff changeset
    14
* Description:   Writes IBY files
hgs
parents:
diff changeset
    15
*
hgs
parents:
diff changeset
    16
*/
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
hgs
parents:
diff changeset
    19
hgs
parents:
diff changeset
    20
#include <f32file.h>
hgs
parents:
diff changeset
    21
#include <bautils.h>
hgs
parents:
diff changeset
    22
#include <utf.h>
hgs
parents:
diff changeset
    23
hgs
parents:
diff changeset
    24
#include "cbsibywriter.h"
hgs
parents:
diff changeset
    25
#include "bsimportconstants.h"
hgs
parents:
diff changeset
    26
//#include "importlogwriter.h"
hgs
parents:
diff changeset
    27
#include "DebugTrace.h"
hgs
parents:
diff changeset
    28
hgs
parents:
diff changeset
    29
// CONSTANTS
hgs
parents:
diff changeset
    30
_LIT8( KIBYHeader1,           "\n#ifndef __BRAND_" );
hgs
parents:
diff changeset
    31
_LIT8( KIBYHeader2,           "\n#define __BRAND_" );
hgs
parents:
diff changeset
    32
_LIT8( KIBYHeaderEnd,         "_IBY_" );
hgs
parents:
diff changeset
    33
_LIT8( KIBYFileItem,          "\nfile=" );
hgs
parents:
diff changeset
    34
_LIT8( KIBYEmptyLine,         "\n" );
hgs
parents:
diff changeset
    35
_LIT8( KIBYSpace,             " \t\t " );
hgs
parents:
diff changeset
    36
_LIT8( KIBYFooter,            "\n#endif //__BRAND_" );
hgs
parents:
diff changeset
    37
hgs
parents:
diff changeset
    38
// File & dir
hgs
parents:
diff changeset
    39
_LIT8( KIBYBaseSource,        "\\epoc32\\winscw\\c" );
hgs
parents:
diff changeset
    40
hgs
parents:
diff changeset
    41
// ======== MEMBER FUNCTIONS ========
hgs
parents:
diff changeset
    42
hgs
parents:
diff changeset
    43
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    44
// CBSIBYWriter::NewL
hgs
parents:
diff changeset
    45
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    46
//
hgs
parents:
diff changeset
    47
CBSIBYWriter* CBSIBYWriter::NewL()
hgs
parents:
diff changeset
    48
    {
hgs
parents:
diff changeset
    49
    CBSIBYWriter* self = NewLC();
hgs
parents:
diff changeset
    50
    CleanupStack::Pop();
hgs
parents:
diff changeset
    51
    return self;
hgs
parents:
diff changeset
    52
    }
hgs
parents:
diff changeset
    53
hgs
parents:
diff changeset
    54
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    55
// CBSIBYWriter::NewLC
hgs
parents:
diff changeset
    56
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    57
//
hgs
parents:
diff changeset
    58
CBSIBYWriter* CBSIBYWriter::NewLC()
hgs
parents:
diff changeset
    59
    {
hgs
parents:
diff changeset
    60
    CBSIBYWriter* self = new (ELeave) CBSIBYWriter();
hgs
parents:
diff changeset
    61
    CleanupStack::PushL( self );
hgs
parents:
diff changeset
    62
    self->ConstructL();
hgs
parents:
diff changeset
    63
    return self;
hgs
parents:
diff changeset
    64
    }
hgs
parents:
diff changeset
    65
hgs
parents:
diff changeset
    66
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    67
// CBSIBYWriter::ConstructL
hgs
parents:
diff changeset
    68
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    69
//
hgs
parents:
diff changeset
    70
void CBSIBYWriter::ConstructL()
hgs
parents:
diff changeset
    71
    {
hgs
parents:
diff changeset
    72
    }
hgs
parents:
diff changeset
    73
hgs
parents:
diff changeset
    74
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    75
// CBSIBYWriter::CBSIBYWriter
hgs
parents:
diff changeset
    76
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    77
//
hgs
parents:
diff changeset
    78
CBSIBYWriter::CBSIBYWriter()
hgs
parents:
diff changeset
    79
    {
hgs
parents:
diff changeset
    80
    }
hgs
parents:
diff changeset
    81
hgs
parents:
diff changeset
    82
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    83
// CBSIBYWriter::~CBSIBYWriter
hgs
parents:
diff changeset
    84
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    85
//
hgs
parents:
diff changeset
    86
CBSIBYWriter::~CBSIBYWriter()
hgs
parents:
diff changeset
    87
    {
hgs
parents:
diff changeset
    88
    iSourcePath.ResetAndDestroy();
hgs
parents:
diff changeset
    89
    iSourceFiles.ResetAndDestroy();
hgs
parents:
diff changeset
    90
    iDestinations.ResetAndDestroy();
hgs
parents:
diff changeset
    91
    delete iIbyFile;
hgs
parents:
diff changeset
    92
    }
hgs
parents:
diff changeset
    93
hgs
parents:
diff changeset
    94
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    95
// CBSIBYWriter::SetFileItemL
hgs
parents:
diff changeset
    96
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    97
//
hgs
parents:
diff changeset
    98
void CBSIBYWriter::SetFileItemL( const TDesC& aSrc, const TDesC& aDest )
hgs
parents:
diff changeset
    99
    {
hgs
parents:
diff changeset
   100
    TRACE( T_LIT( "CBSIBYWriter::SetFileItemL begin") );
hgs
parents:
diff changeset
   101
    // Parse and construct filenames
hgs
parents:
diff changeset
   102
    TParse srcparse;
hgs
parents:
diff changeset
   103
    srcparse.Set( aSrc, NULL, NULL );
hgs
parents:
diff changeset
   104
hgs
parents:
diff changeset
   105
    TParse dstparse;
hgs
parents:
diff changeset
   106
    dstparse.Set( aDest, NULL, NULL );
hgs
parents:
diff changeset
   107
hgs
parents:
diff changeset
   108
    // Path
hgs
parents:
diff changeset
   109
    HBufC8* srcpath = HBufC8::NewLC( srcparse.Path().Length() );
hgs
parents:
diff changeset
   110
    TPtr8 ptr( srcpath->Des() );
hgs
parents:
diff changeset
   111
    CnvUtfConverter::ConvertFromUnicodeToUtf8( ptr, srcparse.Path() );
hgs
parents:
diff changeset
   112
hgs
parents:
diff changeset
   113
    HBufC8* src = HBufC8::NewLC( srcparse.NameAndExt().Length() );
hgs
parents:
diff changeset
   114
    ptr.Set( src->Des() );
hgs
parents:
diff changeset
   115
    CnvUtfConverter::ConvertFromUnicodeToUtf8( ptr, srcparse.NameAndExt() );
hgs
parents:
diff changeset
   116
hgs
parents:
diff changeset
   117
    HBufC8* dst = HBufC8::NewLC( aDest.Length() );
hgs
parents:
diff changeset
   118
    ptr.Set( dst->Des() );
hgs
parents:
diff changeset
   119
    
hgs
parents:
diff changeset
   120
    HBufC* newDst = HBufC::NewLC( aDest.Length() );
hgs
parents:
diff changeset
   121
    TPtr dstPtr( newDst->Des() );
hgs
parents:
diff changeset
   122
    TPtrC name = dstparse.NameAndExt();
hgs
parents:
diff changeset
   123
	TPtrC path = dstparse.Path();
hgs
parents:
diff changeset
   124
	dstPtr.Append( KBSZDrive );
hgs
parents:
diff changeset
   125
	dstPtr.Append( path );
hgs
parents:
diff changeset
   126
	dstPtr.Append( name );
hgs
parents:
diff changeset
   127
	
hgs
parents:
diff changeset
   128
    CnvUtfConverter::ConvertFromUnicodeToUtf8( ptr, dstPtr );
hgs
parents:
diff changeset
   129
    
hgs
parents:
diff changeset
   130
    TRACE( T_LIT( "CBSIBYWriter::SetFileItemL - setting source file %S"), &aSrc );
hgs
parents:
diff changeset
   131
    TRACE( T_LIT( "CBSIBYWriter::SetFileItemL - setting destination file %S"), newDst );
hgs
parents:
diff changeset
   132
	CleanupStack::PopAndDestroy( newDst );
hgs
parents:
diff changeset
   133
    CleanupStack::Pop( 3 );
hgs
parents:
diff changeset
   134
hgs
parents:
diff changeset
   135
    // Append filepair
hgs
parents:
diff changeset
   136
    iSourcePath.Append( srcpath );
hgs
parents:
diff changeset
   137
    iSourceFiles.Append( src );
hgs
parents:
diff changeset
   138
    iDestinations.Append( dst );
hgs
parents:
diff changeset
   139
    
hgs
parents:
diff changeset
   140
    TRACE( T_LIT( "CBSIBYWriter::SetFileItemL end") );
hgs
parents:
diff changeset
   141
    }
hgs
parents:
diff changeset
   142
hgs
parents:
diff changeset
   143
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   144
// CBSIBYWriter::WriteIBYFile()
hgs
parents:
diff changeset
   145
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   146
//
hgs
parents:
diff changeset
   147
void CBSIBYWriter::WriteIBYFileL( RFs& aFs, const TDesC& aFileName )
hgs
parents:
diff changeset
   148
    {
hgs
parents:
diff changeset
   149
	TRACE( T_LIT( "CBSIBYWriter::WriteIBYFileL begin") );
hgs
parents:
diff changeset
   150
	
hgs
parents:
diff changeset
   151
    TInt count = iSourceFiles.Count();
hgs
parents:
diff changeset
   152
    if( count == 0 )
hgs
parents:
diff changeset
   153
    	{
hgs
parents:
diff changeset
   154
    	TRACE( T_LIT( "CBSIBYWriter::WriteIBYFileL - No file elements, nothing to do.") );
hgs
parents:
diff changeset
   155
    	return;
hgs
parents:
diff changeset
   156
    	}
hgs
parents:
diff changeset
   157
    if( count != iDestinations.Count() )
hgs
parents:
diff changeset
   158
        {
hgs
parents:
diff changeset
   159
		TRACE( T_LIT("Internal error: IBY filename count mismatch ( %d != %d )"),
hgs
parents:
diff changeset
   160
            count, iDestinations.Count() );
hgs
parents:
diff changeset
   161
        User::Leave( KErrCorrupt );
hgs
parents:
diff changeset
   162
        }
hgs
parents:
diff changeset
   163
hgs
parents:
diff changeset
   164
	RFile outfile;
hgs
parents:
diff changeset
   165
	TInt err = outfile.Open( aFs, aFileName, EFileWrite );
hgs
parents:
diff changeset
   166
	if( err == KErrNotFound )
hgs
parents:
diff changeset
   167
		{
hgs
parents:
diff changeset
   168
		TRACE( T_LIT( "CBSIBYWriter::WriteIBYFileL - IBY file not initialized!") );
hgs
parents:
diff changeset
   169
		// if the file is not initialized -> not ready
hgs
parents:
diff changeset
   170
		err = KErrNotReady;
hgs
parents:
diff changeset
   171
		}
hgs
parents:
diff changeset
   172
	User::LeaveIfError( err );
hgs
parents:
diff changeset
   173
hgs
parents:
diff changeset
   174
    // write data
hgs
parents:
diff changeset
   175
    TInt size = -1;
hgs
parents:
diff changeset
   176
    User::LeaveIfError( outfile.Size( size ) );
hgs
parents:
diff changeset
   177
hgs
parents:
diff changeset
   178
    outfile.Write( size, KIBYEmptyLine );
hgs
parents:
diff changeset
   179
    
hgs
parents:
diff changeset
   180
	TRACE( T_LIT( "CBSIBYWriter::WriteIBYFileL - start writing files to IBY") );
hgs
parents:
diff changeset
   181
    
hgs
parents:
diff changeset
   182
    for( TInt i = 0; i < count; i++ )
hgs
parents:
diff changeset
   183
        {
hgs
parents:
diff changeset
   184
        outfile.Write( KIBYFileItem );
hgs
parents:
diff changeset
   185
        outfile.Write( KIBYBaseSource );
hgs
parents:
diff changeset
   186
        outfile.Write( iSourcePath[i]->Des() );
hgs
parents:
diff changeset
   187
        outfile.Write( iSourceFiles[i]->Des() );
hgs
parents:
diff changeset
   188
        outfile.Write( KIBYSpace );
hgs
parents:
diff changeset
   189
        outfile.Write( iDestinations[i]->Des() );
hgs
parents:
diff changeset
   190
        TRACE( T_LIT( "CBSIBYWriter::WriteIBYFileL - %S"), iDestinations[i] );
hgs
parents:
diff changeset
   191
        }
hgs
parents:
diff changeset
   192
hgs
parents:
diff changeset
   193
	TRACE( T_LIT( "CBSIBYWriter::WriteIBYFileL - writing IBY file footer") );
hgs
parents:
diff changeset
   194
    outfile.Write( KIBYEmptyLine );
hgs
parents:
diff changeset
   195
    outfile.Write( KIBYFooter );
hgs
parents:
diff changeset
   196
    outfile.Write( KIBYHeaderEnd );
hgs
parents:
diff changeset
   197
hgs
parents:
diff changeset
   198
    // cleanup
hgs
parents:
diff changeset
   199
    outfile.Close();
hgs
parents:
diff changeset
   200
    TRACE( T_LIT( "CBSIBYWriter::WriteIBYFileL end") );
hgs
parents:
diff changeset
   201
    }
hgs
parents:
diff changeset
   202
hgs
parents:
diff changeset
   203
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   204
// CBSIBYWriter::WriteIBYFile()
hgs
parents:
diff changeset
   205
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   206
//
hgs
parents:
diff changeset
   207
void CBSIBYWriter::InitIbyFileL( RFs& aFs, const TDesC& aFileName )
hgs
parents:
diff changeset
   208
	{
hgs
parents:
diff changeset
   209
	TRACE( T_LIT( "CBSIBYWriter::InitIbyFileL begin") );
hgs
parents:
diff changeset
   210
	HBufC* temp = aFileName.AllocL();
hgs
parents:
diff changeset
   211
	delete iIbyFile;
hgs
parents:
diff changeset
   212
	iIbyFile = temp;
hgs
parents:
diff changeset
   213
hgs
parents:
diff changeset
   214
    TInt err = aFs.MkDir( KBSIbyDirectory );
hgs
parents:
diff changeset
   215
    if( err == KErrAlreadyExists )
hgs
parents:
diff changeset
   216
    	{
hgs
parents:
diff changeset
   217
    	err = KErrNone;
hgs
parents:
diff changeset
   218
    	}
hgs
parents:
diff changeset
   219
    User::LeaveIfError( err );
hgs
parents:
diff changeset
   220
	
hgs
parents:
diff changeset
   221
	TRACE( T_LIT( "CBSIBYWriter::InitIbyFileL IBY directory (%S) created"), &KBSIbyDirectory() );
hgs
parents:
diff changeset
   222
	
hgs
parents:
diff changeset
   223
	// Open file for writing
hgs
parents:
diff changeset
   224
	RFile outfile;
hgs
parents:
diff changeset
   225
    User::LeaveIfError( outfile.Replace( aFs, aFileName, EFileWrite ) );
hgs
parents:
diff changeset
   226
    
hgs
parents:
diff changeset
   227
    TRACE( T_LIT( "CBSIBYWriter::InitIbyFileL IBY file (%S) created"), &aFileName );
hgs
parents:
diff changeset
   228
    
hgs
parents:
diff changeset
   229
    outfile.Write( KIBYHeader1 );
hgs
parents:
diff changeset
   230
    outfile.Write( KIBYHeaderEnd );
hgs
parents:
diff changeset
   231
    outfile.Write( KIBYHeader2 );
hgs
parents:
diff changeset
   232
    outfile.Write( KIBYHeaderEnd );
hgs
parents:
diff changeset
   233
    outfile.Close();
hgs
parents:
diff changeset
   234
    TRACE( T_LIT( "CBSIBYWriter::InitIbyFileL end") );
hgs
parents:
diff changeset
   235
	}
hgs
parents:
diff changeset
   236
// End of file