|
1 // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 // |
|
16 |
|
17 /** |
|
18 @file |
|
19 CFileSystemImage implementation |
|
20 */ |
|
21 |
|
22 #include "FileSystemImage.h" |
|
23 #include "debug.h" |
|
24 |
|
25 const TInt KImageFileMode = EFileShareReadersOnly | EFileRead; |
|
26 |
|
27 CFileSystemImage::CFileSystemImage() : |
|
28 iIsOpened( EFalse ) |
|
29 { |
|
30 // No implementation required |
|
31 } |
|
32 |
|
33 CFileSystemImage::~CFileSystemImage() |
|
34 { |
|
35 // iFile will be closed with the session if it's still open |
|
36 iFs.Close(); |
|
37 delete iFileName; |
|
38 } |
|
39 |
|
40 CFileSystemImage* CFileSystemImage::NewL( const TDesC& aFileName ) |
|
41 { |
|
42 CFileSystemImage* self = new (ELeave) CFileSystemImage(); |
|
43 CleanupStack::PushL( self ); |
|
44 self->ConstructL( aFileName ); |
|
45 CleanupStack::Pop( self ); |
|
46 return self; |
|
47 } |
|
48 |
|
49 void CFileSystemImage::ConstructL( const TDesC& aFileName ) |
|
50 { |
|
51 TRACE_FUNC |
|
52 User::LeaveIfError( iFs.Connect() ); |
|
53 iFileName = aFileName.AllocL(); |
|
54 TRACE_INFO(( _L( "Image file is '%S'" ), iFileName )) |
|
55 } |
|
56 |
|
57 TInt CFileSystemImage::Open() |
|
58 { |
|
59 TRACE_FUNC |
|
60 if ( iIsOpened ) |
|
61 { |
|
62 TRACE_INFO(( _L( "Image already opened" ) )) |
|
63 return KErrNone; |
|
64 } |
|
65 TInt err = iFile.Open( iFs, *iFileName, KImageFileMode ); |
|
66 if ( err == KErrNone ) |
|
67 { |
|
68 iIsOpened = ETrue; |
|
69 } |
|
70 TRACE_INFO(( _L( "Image opened with error %d" ), err )) |
|
71 return err; |
|
72 } |
|
73 |
|
74 TInt CFileSystemImage::Close() |
|
75 { |
|
76 if ( iIsOpened ) |
|
77 { |
|
78 iFile.Close(); |
|
79 iIsOpened = EFalse; |
|
80 } |
|
81 return KErrNone; |
|
82 } |
|
83 |
|
84 TInt CFileSystemImage::Read( const TInt64& aPos, TInt aLength, TDes8& aBuf ) |
|
85 { |
|
86 return iFile.Read( aPos, aBuf, aLength ); |
|
87 } |
|
88 |
|
89 TInt CFileSystemImage::Write( const TInt64& /*aPos*/, TDesC8& /*aBuf*/ ) |
|
90 { |
|
91 return KErrAccessDenied; |
|
92 } |
|
93 |
|
94 TInt64 CFileSystemImage::Size() |
|
95 { |
|
96 TInt size; |
|
97 iFile.Size( size ); |
|
98 return size; |
|
99 } |