OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "platform/globals.h" | 5 #include "platform/globals.h" |
6 #if defined(TARGET_OS_WINDOWS) | 6 #if defined(TARGET_OS_WINDOWS) |
7 | 7 |
8 #include "bin/directory.h" | 8 #include "bin/directory.h" |
9 #include "bin/file.h" | 9 #include "bin/file.h" |
10 | 10 |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
418 char* Directory::Current() { | 418 char* Directory::Current() { |
419 int length = GetCurrentDirectoryW(0, NULL); | 419 int length = GetCurrentDirectoryW(0, NULL); |
420 wchar_t* current = new wchar_t[length + 1]; | 420 wchar_t* current = new wchar_t[length + 1]; |
421 GetCurrentDirectoryW(length + 1, current); | 421 GetCurrentDirectoryW(length + 1, current); |
422 char* result = StringUtils::WideToUtf8(current); | 422 char* result = StringUtils::WideToUtf8(current); |
423 delete[] current; | 423 delete[] current; |
424 return result; | 424 return result; |
425 } | 425 } |
426 | 426 |
427 | 427 |
428 bool Directory::SetCurrent(const char* path) { | |
429 const wchar_t* system_path = StringUtils::Utf8ToWide(path); | |
430 return SetCurrentDirectoryW(system_path) == 0; | |
Bill Hesse
2013/04/29 11:01:12
free system_path?
Søren Gjesse
2013/04/29 11:59:15
Absolutely, thanks
| |
431 } | |
432 | |
433 | |
428 bool Directory::Create(const char* dir_name) { | 434 bool Directory::Create(const char* dir_name) { |
429 const wchar_t* system_name = StringUtils::Utf8ToWide(dir_name); | 435 const wchar_t* system_name = StringUtils::Utf8ToWide(dir_name); |
430 int create_status = CreateDirectoryW(system_name, NULL); | 436 int create_status = CreateDirectoryW(system_name, NULL); |
431 // If the directory already existed, treat it as a success. | 437 // If the directory already existed, treat it as a success. |
432 if (create_status == 0 && | 438 if (create_status == 0 && |
433 GetLastError() == ERROR_ALREADY_EXISTS && | 439 GetLastError() == ERROR_ALREADY_EXISTS && |
434 ExistsHelper(system_name) == EXISTS) { | 440 ExistsHelper(system_name) == EXISTS) { |
435 free(const_cast<wchar_t*>(system_name)); | 441 free(const_cast<wchar_t*>(system_name)); |
436 return true; | 442 return true; |
437 } | 443 } |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
526 MoveFileExW(system_path, system_new_path, flags); | 532 MoveFileExW(system_path, system_new_path, flags); |
527 free(const_cast<wchar_t*>(system_path)); | 533 free(const_cast<wchar_t*>(system_path)); |
528 free(const_cast<wchar_t*>(system_new_path)); | 534 free(const_cast<wchar_t*>(system_new_path)); |
529 return (move_status != 0); | 535 return (move_status != 0); |
530 } | 536 } |
531 | 537 |
532 } // namespace bin | 538 } // namespace bin |
533 } // namespace dart | 539 } // namespace dart |
534 | 540 |
535 #endif // defined(TARGET_OS_WINDOWS) | 541 #endif // defined(TARGET_OS_WINDOWS) |
OLD | NEW |