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