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