1 /* |
|
2 * Copyright (c) 2007 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: Class wraps rename operation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDES |
|
20 #include <e32std.h> |
|
21 #include "CFileManagerActiveRename.h" |
|
22 #include "CFileManagerEngine.h" |
|
23 #include "CFileManagerUtils.h" |
|
24 #include "CFileManagerCommonDefinitions.h" |
|
25 #include "FileManagerDebug.h" |
|
26 |
|
27 |
|
28 // ============================ MEMBER FUNCTIONS =============================== |
|
29 |
|
30 // ----------------------------------------------------------------------------- |
|
31 // CFileManagerActiveRename::CFileManagerActiveRename |
|
32 // ----------------------------------------------------------------------------- |
|
33 // |
|
34 CFileManagerActiveRename::CFileManagerActiveRename( |
|
35 CFileManagerEngine& aEngine, |
|
36 CFileManagerUtils& aUtils ) : |
|
37 iEngine( aEngine ), |
|
38 iUtils( aUtils ), |
|
39 iFs( aEngine.Fs() ) |
|
40 { |
|
41 FUNC_LOG |
|
42 } |
|
43 |
|
44 // ----------------------------------------------------------------------------- |
|
45 // CFileManagerActiveRename::~CFileManagerActiveRename |
|
46 // ----------------------------------------------------------------------------- |
|
47 // |
|
48 CFileManagerActiveRename::~CFileManagerActiveRename() |
|
49 { |
|
50 FUNC_LOG |
|
51 |
|
52 delete iName; |
|
53 delete iNewName; |
|
54 } |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // CFileManagerActiveRename::NewL |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 CFileManagerActiveRename* CFileManagerActiveRename::NewL( |
|
61 CFileManagerEngine& aEngine, |
|
62 CFileManagerUtils& aUtils, |
|
63 const TDesC& aName, |
|
64 const TDesC& aNewName ) |
|
65 { |
|
66 FUNC_LOG |
|
67 |
|
68 CFileManagerActiveRename* self = new ( ELeave ) CFileManagerActiveRename( |
|
69 aEngine, aUtils ); |
|
70 CleanupStack::PushL( self ); |
|
71 self->ConstructL( aName, aNewName ); |
|
72 CleanupStack::Pop( self ); |
|
73 return self; |
|
74 } |
|
75 |
|
76 // ----------------------------------------------------------------------------- |
|
77 // CFileManagerActiveRename::ConstructL |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 void CFileManagerActiveRename::ConstructL( |
|
81 const TDesC& aName, const TDesC& aNewName ) |
|
82 { |
|
83 FUNC_LOG |
|
84 |
|
85 iName = aName.AllocL(); |
|
86 iNewName = aNewName.AllocL(); |
|
87 // Remove white spaces from end, file server also ignores those |
|
88 iNewName->Des().TrimRight(); |
|
89 iName->Des().TrimRight(); |
|
90 |
|
91 iIsRemoteDrive = iUtils.IsRemoteDrive( aName ); |
|
92 BaseConstructL(); |
|
93 } |
|
94 |
|
95 // ----------------------------------------------------------------------------- |
|
96 // CFileManagerActiveRename::ThreadFunctionL |
|
97 // ----------------------------------------------------------------------------- |
|
98 // |
|
99 void CFileManagerActiveRename::ThreadFunctionL( const TBool& aCanceled ) |
|
100 { |
|
101 FUNC_LOG |
|
102 |
|
103 TInt maxSubPath( 0 ); |
|
104 TBool isFolder( CFileManagerUtils::HasFinalBackslash( *iName ) ); |
|
105 if ( isFolder && !iIsRemoteDrive ) |
|
106 { |
|
107 // On local drives, solve maximum subfolder path to avoid too long paths |
|
108 maxSubPath = ThreadGetMaxSubfolderPathL( aCanceled ); |
|
109 } |
|
110 if ( iNewName->Length() + maxSubPath > KMaxFileName ) |
|
111 { |
|
112 User::Leave( KErrBadName ); |
|
113 } |
|
114 if ( isFolder ) |
|
115 { |
|
116 User::LeaveIfError( iFs.Rename( *iName, *iNewName ) ); |
|
117 } |
|
118 else |
|
119 { |
|
120 // Replace the target item if exist |
|
121 // if we have came here, it is already asked that |
|
122 // user want's to overwrite other item |
|
123 User::LeaveIfError( iFs.Replace( *iName, *iNewName ) ); |
|
124 } |
|
125 } |
|
126 |
|
127 // ----------------------------------------------------------------------------- |
|
128 // CFileManagerActiveRename::ThreadGetMaxSubfolderPathL |
|
129 // ----------------------------------------------------------------------------- |
|
130 // |
|
131 TInt CFileManagerActiveRename::ThreadGetMaxSubfolderPathL( |
|
132 const TBool& aCanceled ) |
|
133 { |
|
134 FUNC_LOG |
|
135 |
|
136 CDirScan* dirScan = CDirScan::NewLC( iFs ); |
|
137 |
|
138 // Set scanning from current directory, |
|
139 // take files and folder including the hidden and system files |
|
140 // No sorting needed |
|
141 dirScan->SetScanDataL( |
|
142 *iName, |
|
143 KEntryAttNormal | KEntryAttDir | KEntryAttHidden | KEntryAttSystem, |
|
144 ESortNone ); |
|
145 |
|
146 TInt ret( 0 ); |
|
147 CDir* dir = NULL; |
|
148 dirScan->NextL( dir ); |
|
149 while( dir ) |
|
150 { |
|
151 CleanupStack::PushL( dir ); |
|
152 if ( aCanceled ) |
|
153 { |
|
154 User::Leave( KErrCancel ); |
|
155 } |
|
156 TInt count( dir->Count() ); |
|
157 for ( TInt i( 0 ); i < count; ++i ) |
|
158 { |
|
159 if ( aCanceled ) |
|
160 { |
|
161 User::Leave( KErrCancel ); |
|
162 } |
|
163 const TEntry& entry( ( *dir )[ i ] ); |
|
164 TPtrC abbrPath( dirScan->AbbreviatedPath() ); |
|
165 TInt abbrPathLen( abbrPath.Length() ); |
|
166 if ( abbrPathLen && abbrPath[ 0 ] == KFmgrBackslash()[ 0 ] ) |
|
167 { |
|
168 --abbrPathLen; // Initial backslash is already included |
|
169 } |
|
170 TInt pathLen( abbrPathLen + entry.iName.Length() ); |
|
171 if( entry.IsDir() ) // Add space for trailing backslash |
|
172 { |
|
173 ++pathLen; |
|
174 } |
|
175 if( pathLen > ret ) |
|
176 { |
|
177 ret = pathLen; |
|
178 } |
|
179 if ( pathLen > KMaxFileName ) |
|
180 { |
|
181 User::Leave( KErrBadName ); |
|
182 } |
|
183 } |
|
184 CleanupStack::PopAndDestroy( dir ); |
|
185 dirScan->NextL( dir ); |
|
186 } |
|
187 CleanupStack::PopAndDestroy( dirScan ); |
|
188 return ret; |
|
189 } |
|
190 |
|
191 // ----------------------------------------------------------------------------- |
|
192 // CFileManagerActiveRename::CancelThreadFunction |
|
193 // ----------------------------------------------------------------------------- |
|
194 // |
|
195 void CFileManagerActiveRename::CancelThreadFunction() |
|
196 { |
|
197 FUNC_LOG |
|
198 |
|
199 if ( iName ) |
|
200 { |
|
201 iEngine.CancelTransfer( *iName ); |
|
202 } |
|
203 } |
|
204 |
|
205 // End of File |
|