OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 } | 209 } |
210 | 210 |
211 bool Win32Filesystem::GetAppPathname(Pathname* path) { | 211 bool Win32Filesystem::GetAppPathname(Pathname* path) { |
212 TCHAR buffer[MAX_PATH + 1]; | 212 TCHAR buffer[MAX_PATH + 1]; |
213 if (0 == ::GetModuleFileName(NULL, buffer, arraysize(buffer))) | 213 if (0 == ::GetModuleFileName(NULL, buffer, arraysize(buffer))) |
214 return false; | 214 return false; |
215 path->SetPathname(ToUtf8(buffer)); | 215 path->SetPathname(ToUtf8(buffer)); |
216 return true; | 216 return true; |
217 } | 217 } |
218 | 218 |
219 bool Win32Filesystem::GetAppDataFolder(Pathname* path, bool per_user) { | |
220 RTC_DCHECK(!organization_name_.empty()); | |
221 RTC_DCHECK(!application_name_.empty()); | |
222 TCHAR buffer[MAX_PATH + 1]; | |
223 int csidl = per_user ? CSIDL_LOCAL_APPDATA : CSIDL_COMMON_APPDATA; | |
224 if (!::SHGetSpecialFolderPath(NULL, buffer, csidl, TRUE)) | |
225 return false; | |
226 if (!IsCurrentProcessLowIntegrity() && | |
227 !::GetLongPathName(buffer, buffer, arraysize(buffer))) | |
228 return false; | |
229 size_t len = strcatn(buffer, arraysize(buffer), __T("\\")); | |
230 len += strcpyn(buffer + len, arraysize(buffer) - len, | |
231 ToUtf16(organization_name_).c_str()); | |
232 if ((len > 0) && (buffer[len-1] != __T('\\'))) { | |
233 len += strcpyn(buffer + len, arraysize(buffer) - len, __T("\\")); | |
234 } | |
235 len += strcpyn(buffer + len, arraysize(buffer) - len, | |
236 ToUtf16(application_name_).c_str()); | |
237 if ((len > 0) && (buffer[len-1] != __T('\\'))) { | |
238 len += strcpyn(buffer + len, arraysize(buffer) - len, __T("\\")); | |
239 } | |
240 if (len >= arraysize(buffer) - 1) | |
241 return false; | |
242 path->clear(); | |
243 path->SetFolder(ToUtf8(buffer)); | |
244 return CreateFolder(*path); | |
245 } | |
246 | |
247 bool Win32Filesystem::GetAppTempFolder(Pathname* path) { | 219 bool Win32Filesystem::GetAppTempFolder(Pathname* path) { |
248 if (!GetAppPathname(path)) | 220 if (!GetAppPathname(path)) |
249 return false; | 221 return false; |
250 std::string filename(path->filename()); | 222 std::string filename(path->filename()); |
251 return GetTemporaryFolder(*path, true, &filename); | 223 return GetTemporaryFolder(*path, true, &filename); |
252 } | 224 } |
253 | 225 |
254 bool Win32Filesystem::GetDiskFreeSpace(const Pathname& path, | |
255 int64_t* free_bytes) { | |
256 if (!free_bytes) { | |
257 return false; | |
258 } | |
259 char drive[4]; | |
260 std::wstring drive16; | |
261 const wchar_t* target_drive = NULL; | |
262 if (path.GetDrive(drive, sizeof(drive))) { | |
263 drive16 = ToUtf16(drive); | |
264 target_drive = drive16.c_str(); | |
265 } else if (path.folder().substr(0, 2) == "\\\\") { | |
266 // UNC path, fail. | |
267 // TODO: Handle UNC paths. | |
268 return false; | |
269 } else { | |
270 // The path is probably relative. GetDriveType and GetDiskFreeSpaceEx | |
271 // use the current drive if NULL is passed as the drive name. | |
272 // TODO: Add method to Pathname to determine if the path is relative. | |
273 // TODO: Add method to Pathname to convert a path to absolute. | |
274 } | |
275 UINT drive_type = ::GetDriveType(target_drive); | |
276 if ((drive_type == DRIVE_REMOTE) || (drive_type == DRIVE_UNKNOWN)) { | |
277 LOG(LS_VERBOSE) << "Remote or unknown drive: " << drive; | |
278 return false; | |
279 } | |
280 | |
281 int64_t total_number_of_bytes; // receives the number of bytes on disk | |
282 int64_t total_number_of_free_bytes; // receives the free bytes on disk | |
283 // make sure things won't change in 64 bit machine | |
284 // TODO replace with compile time assert | |
285 RTC_DCHECK(sizeof(ULARGE_INTEGER) == sizeof(uint64_t)); // NOLINT | |
286 if (::GetDiskFreeSpaceEx(target_drive, | |
287 (PULARGE_INTEGER)free_bytes, | |
288 (PULARGE_INTEGER)&total_number_of_bytes, | |
289 (PULARGE_INTEGER)&total_number_of_free_bytes)) { | |
290 return true; | |
291 } else { | |
292 LOG(LS_VERBOSE) << "GetDiskFreeSpaceEx returns error."; | |
293 return false; | |
294 } | |
295 } | |
296 | |
297 } // namespace rtc | 226 } // namespace rtc |
OLD | NEW |