From a8323322668cf344285bebf3a74e2e385491d8eb Mon Sep 17 00:00:00 2001 From: actboy168 Date: Wed, 22 Jan 2014 22:49:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9GetTempPathW=E7=9A=84?= =?UTF-8?q?=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Core/YDWEBase/base/path/detail/get_path.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Development/Editor/Core/YDWEBase/base/path/detail/get_path.cpp b/Development/Editor/Core/YDWEBase/base/path/detail/get_path.cpp index 5ec98f1f8..fcb45edd4 100644 --- a/Development/Editor/Core/YDWEBase/base/path/detail/get_path.cpp +++ b/Development/Editor/Core/YDWEBase/base/path/detail/get_path.cpp @@ -53,14 +53,18 @@ namespace base { namespace path { namespace detail { return std::move(boost::filesystem::path(result.get())); } - wchar_t buffer[MAX_PATH + 1]; - DWORD path_len = ::GetTempPathW(MAX_PATH, buffer); - if (path_len >= MAX_PATH || path_len <= 0) + std::dynarray buffer(::GetTempPathW(0, nullptr)); + if (buffer.empty() || ::GetTempPathW(buffer.size(), &buffer[0]) == 0) { - throw windows_exception("::GetTempPathW(MAX_PATH, buffer) failed."); + throw windows_exception("::GetTempPathW failed."); } - return std::move(boost::filesystem::path(buffer)); + boost::filesystem::path p(buffer.begin(), buffer.begin() + buffer.size() - 1); + if (!boost::filesystem::is_directory(p)) + { + throw windows_exception("::GetTempPathW failed."); + } + return std::move(p); } boost::filesystem::path windows_path()