35
|
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: CFileSystemImage implementation
|
|
14 |
//
|
|
15 |
//
|
|
16 |
|
|
17 |
#include "filesystemimage.h"
|
|
18 |
#include "debug.h"
|
|
19 |
|
|
20 |
const TInt KImageFileMode = EFileShareReadersOnly | EFileRead;
|
|
21 |
|
|
22 |
CFileSystemImage::CFileSystemImage() :
|
|
23 |
iIsOpened( EFalse )
|
|
24 |
{
|
|
25 |
// No implementation required
|
|
26 |
}
|
|
27 |
|
|
28 |
CFileSystemImage::~CFileSystemImage()
|
|
29 |
{
|
|
30 |
// iFile will be closed with the session if it's still open
|
|
31 |
iFs.Close();
|
|
32 |
delete iFileName;
|
|
33 |
}
|
|
34 |
|
|
35 |
CFileSystemImage* CFileSystemImage::NewL( const TDesC& aFileName )
|
|
36 |
{
|
|
37 |
CFileSystemImage* self = new (ELeave) CFileSystemImage();
|
|
38 |
CleanupStack::PushL( self );
|
|
39 |
self->ConstructL( aFileName );
|
|
40 |
CleanupStack::Pop( self );
|
|
41 |
return self;
|
|
42 |
}
|
|
43 |
|
|
44 |
void CFileSystemImage::ConstructL( const TDesC& aFileName )
|
|
45 |
{
|
|
46 |
TRACE_FUNC
|
|
47 |
User::LeaveIfError( iFs.Connect() );
|
|
48 |
iFileName = aFileName.AllocL();
|
|
49 |
TRACE_INFO(( _L( "Image file is '%S'" ), iFileName ))
|
|
50 |
}
|
|
51 |
|
|
52 |
TInt CFileSystemImage::Open()
|
|
53 |
{
|
|
54 |
TRACE_FUNC
|
|
55 |
if ( iIsOpened )
|
|
56 |
{
|
|
57 |
TRACE_INFO(( _L( "Image already opened" ) ))
|
|
58 |
return KErrNone;
|
|
59 |
}
|
|
60 |
TInt err = iFile.Open( iFs, *iFileName, KImageFileMode );
|
|
61 |
if ( err == KErrNone )
|
|
62 |
{
|
|
63 |
iIsOpened = ETrue;
|
|
64 |
}
|
|
65 |
TRACE_INFO(( _L( "Image opened with error %d" ), err ))
|
|
66 |
return err;
|
|
67 |
}
|
|
68 |
|
|
69 |
TInt CFileSystemImage::Close()
|
|
70 |
{
|
|
71 |
if ( iIsOpened )
|
|
72 |
{
|
|
73 |
iFile.Close();
|
|
74 |
iIsOpened = EFalse;
|
|
75 |
}
|
|
76 |
return KErrNone;
|
|
77 |
}
|
|
78 |
|
|
79 |
TInt CFileSystemImage::Read( const TInt64& aPos, TInt aLength, TDes8& aBuf )
|
|
80 |
{
|
|
81 |
return iFile.Read( aPos, aBuf, aLength );
|
|
82 |
}
|
|
83 |
|
|
84 |
TInt CFileSystemImage::Write( const TInt64& /*aPos*/, TDesC8& /*aBuf*/ )
|
|
85 |
{
|
|
86 |
return KErrAccessDenied;
|
|
87 |
}
|
|
88 |
|
|
89 |
TInt64 CFileSystemImage::Size()
|
|
90 |
{
|
|
91 |
TInt size;
|
|
92 |
iFile.Size( size );
|
|
93 |
return size;
|
|
94 |
}
|