|
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 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "adornedutilities.h" |
|
21 #include <algorithm> |
|
22 #include <sys/types.h> |
|
23 #include <sys/stat.h> |
|
24 |
|
25 #include "stringutils.h" |
|
26 #include "symbiantypes.h" |
|
27 #include "logger.h" |
|
28 #include "is_utils.h" |
|
29 |
|
30 const std::wstring KAdornedWildCharString = L"{????????}"; |
|
31 const int KFileNameUnadornedPartLength = 10; |
|
32 |
|
33 |
|
34 void GetUnadornedFileName(const std::wstring& aAdornedFilename, std::wstring& aUnadornedFilename) |
|
35 { |
|
36 aUnadornedFilename = aAdornedFilename; |
|
37 int length = aAdornedFilename.length(); |
|
38 |
|
39 // check to see if the name is adorned. If so, remove the version number |
|
40 int startVersion = aAdornedFilename.find('{'); |
|
41 if (startVersion != 0) |
|
42 { |
|
43 int endVersion = aAdornedFilename.find('}'); |
|
44 if ((endVersion != 0) && (endVersion - startVersion == (KFileNameUnadornedPartLength - 1))) |
|
45 { |
|
46 // get unadorned version of the file |
|
47 aUnadornedFilename = aAdornedFilename.substr(0,startVersion); |
|
48 |
|
49 // for names ending with } i.e: DummyFile{12345678} nothing is to be appended to |
|
50 // aUnadornedFilename in such a case aAdornedFilename.Mid(endVersion+1) would cause a crash |
|
51 if (endVersion < (length - 1)) |
|
52 { |
|
53 aUnadornedFilename.append(aAdornedFilename.substr(endVersion + 1,length)); |
|
54 } |
|
55 } |
|
56 } |
|
57 } |
|
58 |
|
59 bool IsAdornedVariationOf(const std::wstring& aFileName1, const std::wstring& aFileName2) |
|
60 { |
|
61 std::wstring unadornedFileName1; |
|
62 GetUnadornedFileName(aFileName1,unadornedFileName1); |
|
63 |
|
64 std::wstring unadornedFileName2; |
|
65 GetUnadornedFileName(aFileName2,unadornedFileName2); |
|
66 |
|
67 // Check whether filename2 is a variant of filename1 |
|
68 // e.g: d:\sys\bin\DummyDll{000A0001}.dll is considered a variant of c:\sys\bin\DummyDll.dll |
|
69 // because they both break down to \sys\bin\DummyDll.dll |
|
70 std::wstring fileName1Path(StringUtils::Path(unadornedFileName1)); |
|
71 std::wstring fileName1NameAndExt(StringUtils::NameAndExt(unadornedFileName1)); |
|
72 |
|
73 std::wstring fileName2Path(StringUtils::Path(unadornedFileName2)); |
|
74 std::wstring fileName2NameAndExt(StringUtils::NameAndExt(unadornedFileName2)); |
|
75 |
|
76 return ((fileName1Path == fileName2Path) && (fileName1NameAndExt == fileName2NameAndExt)); |
|
77 } |
|
78 |
|
79 void FindAllAdornedVariants(const std::wstring& aSearchNameWild, const std::wstring& aSearchPath, std::list<std::wstring>& aAdornedFileNamesFound, const DrivesMap& aDriveMap) |
|
80 { |
|
81 DrivesMap::const_iterator it = aDriveMap.begin(); |
|
82 DrivesMap::const_iterator end = aDriveMap.end(); |
|
83 |
|
84 for ( ; it != end ; ++it) |
|
85 { |
|
86 // drive to search on |
|
87 int disk = tolower(it->first); |
|
88 std::wstring drive = L"$:"; |
|
89 drive[0] = disk; |
|
90 |
|
91 std::wstring searchPath(aSearchPath); |
|
92 |
|
93 // actual readable directory |
|
94 std::wstring localDir = it->second->iDir; |
|
95 |
|
96 // using ROM/ROFS logs for the z drive, searching for adorned variants is handled later. |
|
97 if (disk == 'z' && localDir.empty()) |
|
98 continue; |
|
99 |
|
100 // convert to the local path and see if the file exists on the drive |
|
101 ConvertToLocalPath( searchPath, localDir ); |
|
102 |
|
103 // search this directory |
|
104 std::list<std::wstring> dirContents; |
|
105 GetDirContents(searchPath, dirContents); |
|
106 |
|
107 std::list<std::wstring>::iterator curr = dirContents.begin(); |
|
108 std::list<std::wstring>::iterator end = dirContents.end(); |
|
109 while (curr != end) |
|
110 { |
|
111 std::wstring dirFile(*curr); |
|
112 |
|
113 if (StringUtils::WildcardCompare(aSearchNameWild,dirFile)) |
|
114 { |
|
115 // found an adorned file, add to the list of adorned names found |
|
116 std::wstringstream foundFile; |
|
117 foundFile << drive << aSearchPath << dirFile; |
|
118 aAdornedFileNamesFound.push_back(foundFile.str()); |
|
119 } |
|
120 |
|
121 ++curr; |
|
122 } |
|
123 } |
|
124 } |
|
125 |
|
126 void GenerateSearchNameWild(const std::wstring& aFileName, std::wstring& aSearchNameWild) |
|
127 { |
|
128 std::wstring unadornedFileName; |
|
129 GetUnadornedFileName(aFileName, unadornedFileName); |
|
130 |
|
131 aSearchNameWild = StringUtils::Name(unadornedFileName); |
|
132 aSearchNameWild.append(KAdornedWildCharString); |
|
133 aSearchNameWild.append(StringUtils::Ext(unadornedFileName)); |
|
134 } |