|
1 /* |
|
2 * Copyright (c) 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <f32file.h> |
|
20 |
|
21 #include "ncdfilestorageimpl.h" |
|
22 #include "ncdstorageowner.h" |
|
23 |
|
24 #include "catalogsdebug.h" |
|
25 |
|
26 // ======== MEMBER FUNCTIONS ======== |
|
27 |
|
28 |
|
29 // --------------------------------------------------------------------------- |
|
30 // ConstructL |
|
31 // --------------------------------------------------------------------------- |
|
32 // |
|
33 void CNcdFileStorage::ConstructL( const TDesC& aUid, const TDesC& aPath ) |
|
34 { |
|
35 DLTRACEIN( ("") ); |
|
36 |
|
37 iRoot.CreateL( aPath ); |
|
38 iUid.CreateL( aUid ); |
|
39 |
|
40 DLTRACEOUT( ( _L("Root: %S"), &iRoot ) ); |
|
41 } |
|
42 |
|
43 |
|
44 // --------------------------------------------------------------------------- |
|
45 // NewL |
|
46 // --------------------------------------------------------------------------- |
|
47 // |
|
48 CNcdFileStorage* CNcdFileStorage::NewL( MNcdStorageOwner& aOwner, |
|
49 const TDesC& aUid, const TDesC& aPath ) |
|
50 { |
|
51 CNcdFileStorage* self = CNcdFileStorage::NewLC( aOwner, aUid, aPath ); |
|
52 CleanupStack::Pop( self ); |
|
53 return self; |
|
54 } |
|
55 |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 // NewLC |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 CNcdFileStorage* CNcdFileStorage::NewLC( MNcdStorageOwner& aOwner, |
|
62 const TDesC& aUid, const TDesC& aPath ) |
|
63 { |
|
64 CNcdFileStorage* self = new( ELeave ) CNcdFileStorage( aOwner ); |
|
65 CleanupStack::PushL( self ); |
|
66 self->ConstructL( aUid, aPath ); |
|
67 return self; |
|
68 } |
|
69 |
|
70 |
|
71 // --------------------------------------------------------------------------- |
|
72 // Destructor |
|
73 // --------------------------------------------------------------------------- |
|
74 // |
|
75 CNcdFileStorage::~CNcdFileStorage() |
|
76 { |
|
77 DLTRACEIN( ( "" ) ); |
|
78 iRoot.Close(); |
|
79 iUid.Close(); |
|
80 } |
|
81 |
|
82 |
|
83 // --------------------------------------------------------------------------- |
|
84 // AddFileL |
|
85 // --------------------------------------------------------------------------- |
|
86 // |
|
87 void CNcdFileStorage::AddFileL( const TDesC& aFilepath, TBool aOverwrite ) |
|
88 { |
|
89 if ( !aFilepath.Length() ) |
|
90 { |
|
91 User::Leave( KErrBadName ); |
|
92 } |
|
93 |
|
94 DLTRACEIN( ( "" ) ); |
|
95 TParse destPath; |
|
96 |
|
97 // Minimize stack usage |
|
98 { |
|
99 TParsePtrC source( aFilepath ); |
|
100 User::LeaveIfError( destPath.Set( source.NameAndExt(), NULL, &iRoot ) ); |
|
101 } |
|
102 |
|
103 DLTRACE( ( _L("Target: %S"), &destPath.FullName() ) ); |
|
104 |
|
105 |
|
106 TUint overwrite( 0 ); |
|
107 if ( aOverwrite ) |
|
108 { |
|
109 overwrite = CFileMan::EOverWrite; |
|
110 } |
|
111 |
|
112 User::LeaveIfError( iOwner.FileManager().Move( aFilepath, |
|
113 destPath.FullName(), overwrite ) ); |
|
114 DLTRACEOUT( ( "" ) ); |
|
115 } |
|
116 |
|
117 |
|
118 // --------------------------------------------------------------------------- |
|
119 // RemoveFileL |
|
120 // --------------------------------------------------------------------------- |
|
121 // |
|
122 void CNcdFileStorage::RemoveFileL( const TDesC& aFilename ) |
|
123 { |
|
124 if ( !aFilename.Length() ) |
|
125 { |
|
126 User::Leave( KErrBadName ); |
|
127 } |
|
128 |
|
129 TParse path; |
|
130 User::LeaveIfError( path.Set( aFilename, NULL, &iRoot ) ); |
|
131 //path.AddDir( iRoot ); |
|
132 DLTRACE( ( _L("Trying to remove: %S"), &path.FullName() ) ); |
|
133 User::LeaveIfError( iOwner.FileManager().Delete( path.FullName() ) ); |
|
134 } |
|
135 |
|
136 |
|
137 // --------------------------------------------------------------------------- |
|
138 // OpenFileL |
|
139 // --------------------------------------------------------------------------- |
|
140 // |
|
141 RFile CNcdFileStorage::OpenFileL( RFs& aFs, const TDesC& aFilename, |
|
142 TUint aFileMode ) |
|
143 { |
|
144 DLTRACEIN(( _L("File: %S"), &aFilename )); |
|
145 if ( !aFilename.Length() ) |
|
146 { |
|
147 User::Leave( KErrBadName ); |
|
148 } |
|
149 |
|
150 TParse path; |
|
151 User::LeaveIfError( path.Set( aFilename, NULL, &iRoot ) ); |
|
152 //path.AddDir( iRoot ); |
|
153 DLTRACE( ( _L("Filepath: %S"), &path.FullName() ) ); |
|
154 |
|
155 // Open the file |
|
156 RFile file; |
|
157 User::LeaveIfError( file.Open( aFs, path.FullName(), |
|
158 aFileMode ) ); |
|
159 return file; |
|
160 } |
|
161 |
|
162 |
|
163 // --------------------------------------------------------------------------- |
|
164 // UID getter |
|
165 // --------------------------------------------------------------------------- |
|
166 // |
|
167 const TDesC& CNcdFileStorage::Uid() const |
|
168 { |
|
169 return iUid; |
|
170 } |
|
171 |
|
172 |
|
173 // --------------------------------------------------------------------------- |
|
174 // Constructor |
|
175 // --------------------------------------------------------------------------- |
|
176 // |
|
177 CNcdFileStorage::CNcdFileStorage( MNcdStorageOwner& aOwner ) : |
|
178 iOwner( aOwner ) |
|
179 { |
|
180 } |
|
181 |
|
182 |