|
1 /* |
|
2 * Copyright (c) 2008-2009 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 the License "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 * Implementation of the adorned filename handling utility functions |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 /** |
|
21 @file |
|
22 */ |
|
23 |
|
24 #include "adornedutilities.h" |
|
25 #include "log.h" |
|
26 |
|
27 _LIT(KAdornedWildCharString, "{????????}"); |
|
28 const TInt Swi::FileNameUnadornedPartLength = 10; |
|
29 |
|
30 void Swi::GetUnadornedFileName(const TDesC& aAdornedFilename, TDes& aUnadornedFilename) |
|
31 { |
|
32 aUnadornedFilename = aAdornedFilename; |
|
33 // Check this name is not adorned, if it is remove version no |
|
34 TInt startVersion = aAdornedFilename.Locate('{'); |
|
35 if (startVersion != KErrNotFound) |
|
36 { |
|
37 TInt endVersion = aAdornedFilename.Locate('}'); |
|
38 if (( endVersion != KErrNotFound ) && (endVersion - startVersion == (Swi::FileNameUnadornedPartLength-1))) |
|
39 { |
|
40 // get the name without the version |
|
41 aUnadornedFilename = aAdornedFilename.Left(startVersion); |
|
42 //for names ending with } i.e: DummyFile{12345678} |
|
43 //nothing is to be appended to aUnadornedFilename |
|
44 //in such a case aAdornedFilename.Mid(endVersion+1) would panic |
|
45 if(endVersion < (aAdornedFilename.Length()-1)) |
|
46 { |
|
47 aUnadornedFilename.Append(aAdornedFilename.Mid(endVersion+1)); |
|
48 } |
|
49 } |
|
50 } |
|
51 } |
|
52 |
|
53 TBool Swi::IsAdornedVariationOfL(const TDesC& aFileName1, const TDesC& aFileName2) |
|
54 { |
|
55 RBuf unadornedFileName1; |
|
56 RBuf unadornedFileName2; |
|
57 |
|
58 unadornedFileName1.CreateL(KMaxFileName); |
|
59 CleanupClosePushL(unadornedFileName1); |
|
60 unadornedFileName2.CreateL(KMaxFileName); |
|
61 CleanupClosePushL(unadornedFileName2); |
|
62 |
|
63 Swi::GetUnadornedFileName(aFileName1, unadornedFileName1); |
|
64 Swi::GetUnadornedFileName(aFileName2, unadornedFileName2); |
|
65 |
|
66 //Checks whether filename2 is a variant of filename1 |
|
67 //e.g: d:\sys\bin\DummyDll{000A0001}.dll is considered a variant of c:\sys\bin\DummyDll.dll |
|
68 //because they both break down to \sys\bin\DummyDll.dll |
|
69 TParsePtrC parsePtr1(unadornedFileName1); |
|
70 TParsePtrC parsePtr2(unadornedFileName2); |
|
71 TBool ret = (parsePtr1.Path() == parsePtr2.Path()) && (parsePtr1.NameAndExt() == parsePtr2.NameAndExt()); |
|
72 CleanupStack::PopAndDestroy(2, &unadornedFileName1); |
|
73 return ret; |
|
74 } |
|
75 |
|
76 void Swi::FindAllAdornedVariantsL(RFs& aFs, const TDesC& aSearchNameWild, const TDesC& aSearchPath, RPointerArray<HBufC>& aAdornedFileNamesFound) |
|
77 { |
|
78 TFindFile finder(aFs); |
|
79 CDir* dirList=0; |
|
80 TBool matchFound = (finder.FindWildByDir( aSearchNameWild, aSearchPath, *&dirList) == KErrNone); |
|
81 CleanupStack::PushL(dirList); |
|
82 |
|
83 while(matchFound) |
|
84 { |
|
85 TParsePtrC fileFound(finder.File()); |
|
86 |
|
87 TInt count = dirList->Count(); |
|
88 for(TInt d=0; d<count; ++d) |
|
89 { |
|
90 const TEntry& entry = (*dirList)[d]; |
|
91 if(!entry.IsDir()) //dirlist theoretically might contain not only file names but also nested directory entries that we are not interested in |
|
92 { |
|
93 HBufC* adornedFileName=HBufC::NewLC(fileFound.DriveAndPath().Length()+entry.iName.Length()); |
|
94 TPtr ptr = adornedFileName->Des(); |
|
95 ptr.Append(fileFound.DriveAndPath()); |
|
96 ptr.Append(entry.iName); |
|
97 aAdornedFileNamesFound.AppendL(adornedFileName); |
|
98 CleanupStack::Pop(adornedFileName); |
|
99 } |
|
100 } |
|
101 CleanupStack::PopAndDestroy(dirList); |
|
102 dirList = 0; |
|
103 matchFound = (finder.FindWild(dirList) == KErrNone); |
|
104 CleanupStack::PushL(dirList); |
|
105 } |
|
106 CleanupStack::PopAndDestroy(dirList); |
|
107 } |
|
108 |
|
109 void Swi::GenerateSearchNameWildL(const TDesC& aFileName, TDes& aSearchNameWild) |
|
110 { |
|
111 RBuf unadornedFileName; |
|
112 unadornedFileName.CreateL(aFileName.Length()); //unadorned filename is never longer than aFileName |
|
113 unadornedFileName.CleanupClosePushL(); |
|
114 Swi::GetUnadornedFileName(aFileName, unadornedFileName); |
|
115 TParsePtrC unadornedFileNameParse(unadornedFileName); |
|
116 |
|
117 aSearchNameWild = unadornedFileNameParse.Name(); |
|
118 aSearchNameWild.Append(KAdornedWildCharString); |
|
119 aSearchNameWild.Append( unadornedFileNameParse.Ext() ); |
|
120 CleanupStack::PopAndDestroy(&unadornedFileName); |
|
121 } |