| 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 #include "bin/utils.h" | 10 #include "bin/utils.h" |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 GetLastError() == ERROR_ALREADY_EXISTS && | 376 GetLastError() == ERROR_ALREADY_EXISTS && |
| 377 ExistsHelper(system_name) == EXISTS) { | 377 ExistsHelper(system_name) == EXISTS) { |
| 378 free(const_cast<wchar_t*>(system_name)); | 378 free(const_cast<wchar_t*>(system_name)); |
| 379 return true; | 379 return true; |
| 380 } | 380 } |
| 381 free(const_cast<wchar_t*>(system_name)); | 381 free(const_cast<wchar_t*>(system_name)); |
| 382 return (create_status != 0); | 382 return (create_status != 0); |
| 383 } | 383 } |
| 384 | 384 |
| 385 | 385 |
| 386 char* Directory::CreateTemp(const char* const_template) { | 386 char* Directory::CreateTemp(const char* const_template, bool system) { |
| 387 // Returns a new, unused directory name, modifying the contents of | 387 // Returns a new, unused directory name, modifying the contents of |
| 388 // dir_template. Creates this directory, with a default security | 388 // dir_template. Creates this directory, with a default security |
| 389 // descriptor inherited from its parent directory. | 389 // descriptor inherited from its parent directory. |
| 390 // The return value must be freed by the caller. | 390 // The return value must be freed by the caller. |
| 391 PathBuffer path; | 391 PathBuffer path; |
| 392 if (0 == strncmp(const_template, "", 1)) { | 392 if (system) { |
| 393 path.Reset(GetTempPathW(MAX_PATH, path.AsStringW())); | 393 path.Reset(GetTempPathW(MAX_PATH, path.AsStringW())); |
| 394 if (path.length() == 0) { | 394 if (path.length() == 0) { |
| 395 return NULL; | 395 return NULL; |
| 396 } | 396 } |
| 397 } else { | |
| 398 const wchar_t* system_template = StringUtils::Utf8ToWide(const_template); | |
| 399 path.AddW(system_template); | |
| 400 free(const_cast<wchar_t*>(system_template)); | |
| 401 } | 397 } |
| 402 // Length of tempdir-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx is 44. | 398 const wchar_t* system_template = StringUtils::Utf8ToWide(const_template); |
| 403 if (path.length() > MAX_PATH - 44) { | 399 path.AddW(system_template); |
| 400 free(const_cast<wchar_t*>(system_template)); |
| 401 |
| 402 // Length of xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx is 36. |
| 403 if (path.length() > MAX_PATH - 36) { |
| 404 return NULL; | 404 return NULL; |
| 405 } | 405 } |
| 406 if ((path.AsStringW())[path.length() - 1] == L'\\') { | |
| 407 // No base name for the directory - use "tempdir". | |
| 408 path.AddW(L"tempdir"); | |
| 409 } | |
| 410 | 406 |
| 411 UUID uuid; | 407 UUID uuid; |
| 412 RPC_STATUS status = UuidCreateSequential(&uuid); | 408 RPC_STATUS status = UuidCreateSequential(&uuid); |
| 413 if (status != RPC_S_OK && status != RPC_S_UUID_LOCAL_ONLY) { | 409 if (status != RPC_S_OK && status != RPC_S_UUID_LOCAL_ONLY) { |
| 414 return NULL; | 410 return NULL; |
| 415 } | 411 } |
| 416 RPC_WSTR uuid_string; | 412 RPC_WSTR uuid_string; |
| 417 status = UuidToStringW(&uuid, &uuid_string); | 413 status = UuidToStringW(&uuid, &uuid_string); |
| 418 if (status != RPC_S_OK) { | 414 if (status != RPC_S_OK) { |
| 419 return NULL; | 415 return NULL; |
| 420 } | 416 } |
| 421 | 417 |
| 422 path.AddW(L"-"); | |
| 423 // RPC_WSTR is an unsigned short*, so we cast to wchar_t*. | 418 // RPC_WSTR is an unsigned short*, so we cast to wchar_t*. |
| 424 path.AddW(reinterpret_cast<wchar_t*>(uuid_string)); | 419 path.AddW(reinterpret_cast<wchar_t*>(uuid_string)); |
| 425 RpcStringFreeW(&uuid_string); | 420 RpcStringFreeW(&uuid_string); |
| 426 if (!CreateDirectoryW(path.AsStringW(), NULL)) { | 421 if (!CreateDirectoryW(path.AsStringW(), NULL)) { |
| 427 return NULL; | 422 return NULL; |
| 428 } | 423 } |
| 429 char* result = path.AsString(); | 424 char* result = path.AsString(); |
| 430 return result; | 425 return result; |
| 431 } | 426 } |
| 432 | 427 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 MoveFileExW(system_path, system_new_path, flags); | 464 MoveFileExW(system_path, system_new_path, flags); |
| 470 free(const_cast<wchar_t*>(system_path)); | 465 free(const_cast<wchar_t*>(system_path)); |
| 471 free(const_cast<wchar_t*>(system_new_path)); | 466 free(const_cast<wchar_t*>(system_new_path)); |
| 472 return (move_status != 0); | 467 return (move_status != 0); |
| 473 } | 468 } |
| 474 | 469 |
| 475 } // namespace bin | 470 } // namespace bin |
| 476 } // namespace dart | 471 } // namespace dart |
| 477 | 472 |
| 478 #endif // defined(TARGET_OS_WINDOWS) | 473 #endif // defined(TARGET_OS_WINDOWS) |
| OLD | NEW |