1 /* |
1 /* |
2 * Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * This component and the accompanying materials are made available |
5 * under the terms of the License "Eclipse Public License v1.0" |
5 * under the terms of the License "Eclipse Public License v1.0" |
6 * which accompanies this distribution, and is available |
6 * which accompanies this distribution, and is available |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
20 #include<fstream> |
20 #include<fstream> |
21 #include<iostream> |
21 #include<iostream> |
22 #include<sstream> |
22 #include<sstream> |
23 |
23 |
24 #include"utility_interface.h" |
24 #include"utility_interface.h" |
25 #include"util.h" |
|
26 |
25 |
27 bool FileExists(const std::wstring& aFile) |
26 bool FileExists(const std::wstring& aFile) |
28 { |
27 { |
29 struct stat x; |
28 return true; |
30 int err = GetStat(aFile,&x ); |
|
31 return err == 0; |
|
32 } |
29 } |
33 bool RemoveFile(const std::wstring& aFile) |
30 bool RemoveFile(const std::wstring& aFile) |
34 { |
31 { |
35 return _wunlink(aFile.c_str()) == 0; |
32 return true; |
36 } |
33 } |
37 bool CreateFile(const std::wstring& aFile) |
34 bool CreateFile(const std::wstring& aFile) |
38 { |
35 { |
39 return true; |
36 return true; |
40 } |
37 } |
41 |
38 |
42 int GetStat(const std::wstring& aFile, struct stat* s) |
39 int GetStat(const std::wstring& aFile, struct stat* s) |
43 { |
40 { |
44 std::string str = wstring2string(aFile); |
41 std::string str; |
45 return stat(str.c_str(), s); |
42 return stat(Ucs2ToUtf8(aFile, str).c_str(), s); |
46 } |
43 } |
47 |
44 |
48 void GetDirContents(const std::wstring& path, |
45 void GetDirContents(const std::wstring& path, |
49 std::list<std::wstring>& contents) |
46 std::list<std::wstring>& contents) |
50 { |
47 { |
51 |
48 |
52 std::string utfString = wstring2string(path); |
49 std::string utfString; |
53 DIR* currDir = opendir(utfString.c_str()); |
50 DIR* currDir = opendir(Ucs2ToUtf8(path, utfString).c_str()); |
54 |
51 |
55 while (currDir) |
52 while (currDir) |
56 { |
53 { |
57 dirent* currElem = readdir(currDir); |
54 dirent* currElem = readdir(currDir); |
58 if (currElem == 0) |
55 if (currElem == 0) |
112 { |
109 { |
113 index = 0; |
110 index = 0; |
114 } |
111 } |
115 else |
112 else |
116 {// Skip creation of root directory |
113 {// Skip creation of root directory |
117 #ifndef __TOOLS2_LINUX__ |
|
118 index = aDir.find(L'\\', index); |
114 index = aDir.find(L'\\', index); |
119 #else |
|
120 index = aDir.find(L'/', index); |
|
121 #endif |
|
122 } |
115 } |
123 do |
116 do |
124 { |
117 { |
125 index += 1; |
118 index += 1; |
126 // Try to make each directory in the path. If ERR_ALREADY_EXISTS is returned |
119 // Try to make each directory in the path. If ERR_ALREADY_EXISTS is returned |
127 // then this is okay. Other errors are fatal. |
120 // then this is okay. Other errors are fatal. |
128 #ifndef __TOOLS2_LINUX__ |
|
129 index = aDir.find(L'\\', index); |
121 index = aDir.find(L'\\', index); |
130 #else |
|
131 index = aDir.find(L'/', index); |
|
132 #endif |
|
133 std::wstring dir = aDir.substr( 0, index ); |
122 std::wstring dir = aDir.substr( 0, index ); |
134 if(dir == L".") |
123 if(dir == L".") |
135 { |
124 { |
136 continue; |
125 continue; |
137 } |
126 } |
149 |
138 |
150 |
139 |
151 bool OpenFile(const std::wstring& aFile, std::fstream& aStream, |
140 bool OpenFile(const std::wstring& aFile, std::fstream& aStream, |
152 std::ios_base::open_mode aMode) |
141 std::ios_base::open_mode aMode) |
153 { |
142 { |
154 std::string s = wstring2string(aFile); |
143 std::string s; |
155 aStream.open(s.c_str(), aMode); |
144 aStream.open(Ucs2ToUtf8(aFile, s).c_str(), aMode); |
156 return aStream.good(); |
145 return aStream.good(); |
157 } |
146 } |
158 |
147 |
159 |
148 |
160 int GetAugmentationsNumber(const std::wstring& aFile) |
149 int GetAugmentationsNumber(const std::wstring& aFile) |
185 return IsDirectory(ret); |
174 return IsDirectory(ret); |
186 } |
175 } |
187 |
176 |
188 void RemoveHashForFile(const std::wstring& aFile, const int aDriveLetter, const std::wstring& aPath) |
177 void RemoveHashForFile(const std::wstring& aFile, const int aDriveLetter, const std::wstring& aPath) |
189 { |
178 { |
190 #ifndef __TOOLS2_LINUX__ |
|
191 std::wstring hashdir = L"$:\\sys\\hash\\"; |
179 std::wstring hashdir = L"$:\\sys\\hash\\"; |
192 #else |
|
193 std::wstring hashdir = L"$:/sys/hash/"; |
|
194 #endif |
|
195 std::wstring basename = aFile.substr( aFile.rfind( KDirectorySeparator ) + 1) ; |
180 std::wstring basename = aFile.substr( aFile.rfind( KDirectorySeparator ) + 1) ; |
196 if (basename.size() == 0) |
181 if (basename.size() == 0) |
197 { |
182 { |
198 #ifndef __TOOLS2_LINUX__ |
|
199 basename = aFile.substr(aFile.rfind(L"\\")); |
183 basename = aFile.substr(aFile.rfind(L"\\")); |
200 #else |
|
201 basename = aFile.substr(aFile.rfind(L"/")); |
|
202 #endif |
|
203 } |
184 } |
204 |
185 |
205 hashdir[0] = aDriveLetter; |
186 hashdir[0] = aDriveLetter; |
206 #ifndef __TOOLS2_LINUX__ |
|
207 std::wstring hashFile = aPath + L"\\sys\\hash\\" + basename; |
187 std::wstring hashFile = aPath + L"\\sys\\hash\\" + basename; |
208 #else |
|
209 std::wstring hashFile = aPath + L"/sys/hash/" + basename; |
|
210 #endif |
|
211 if (FileExists(hashFile)) |
188 if (FileExists(hashFile)) |
212 { |
189 { |
213 RemoveFile(hashFile); |
190 RemoveFile(hashFile); |
214 } |
191 } |
215 } |
192 } |