Path_WIN32U.cpp
Go to the documentation of this file.
00001 //
00002 // Path_WIN32U.cpp
00003 //
00004 // $Id: //poco/1.3/Foundation/src/Path_WIN32U.cpp#3 $
00005 //
00006 // Library: Foundation
00007 // Package: Filesystem
00008 // Module:  Path
00009 //
00010 // Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
00011 // and Contributors.
00012 //
00013 // Permission is hereby granted, free of charge, to any person or organization
00014 // obtaining a copy of the software and accompanying documentation covered by
00015 // this license (the "Software") to use, reproduce, display, distribute,
00016 // execute, and transmit the Software, and to prepare derivative works of the
00017 // Software, and to permit third-parties to whom the Software is furnished to
00018 // do so, all subject to the following:
00019 // 
00020 // The copyright notices in the Software and this entire statement, including
00021 // the above license grant, this restriction and the following disclaimer,
00022 // must be included in all copies of the Software, in whole or in part, and
00023 // all derivative works of the Software, unless such copies or derivative
00024 // works are solely in the form of machine-executable object code generated by
00025 // a source language processor.
00026 // 
00027 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00028 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00029 // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
00030 // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
00031 // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
00032 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00033 // DEALINGS IN THE SOFTWARE.
00034 //
00035 
00036 
00037 #include "Poco/Path_WIN32U.h"
00038 #include "Poco/Environment_WIN32.h"
00039 #include "Poco/UnicodeConverter.h"
00040 #include "Poco/Buffer.h"
00041 #include "Poco/Exception.h"
00042 #include "Poco/UnWindows.h"
00043 
00044 
00045 namespace Poco {
00046 
00047 
00048 std::string PathImpl::currentImpl()
00049 {
00050         std::string result;
00051         DWORD len = GetCurrentDirectoryW(0, NULL);
00052         if (len > 0)
00053         {
00054                 Buffer<wchar_t> buffer(len);
00055                 DWORD n = GetCurrentDirectoryW(len, buffer.begin());
00056                 if (n > 0 && n <= len)
00057                 {
00058                         UnicodeConverter::toUTF8(buffer.begin(), result);
00059                         if (result[n - 1] != '\\')
00060                                 result.append("\\");
00061                         return result;
00062                 }
00063         }
00064         throw SystemException("Cannot get current directory");
00065 }
00066 
00067 
00068 std::string PathImpl::homeImpl()
00069 {
00070         std::string result = EnvironmentImpl::getImpl("HOMEDRIVE");
00071         result.append(EnvironmentImpl::getImpl("HOMEPATH"));
00072         std::string::size_type n = result.size();
00073         if (n > 0 && result[n - 1] != '\\')
00074                 result.append("\\");
00075         return result;
00076 }
00077 
00078 
00079 std::string PathImpl::tempImpl()
00080 {
00081         Buffer<wchar_t> buffer(MAX_PATH_LEN);
00082         DWORD n = GetTempPathW(static_cast<DWORD>(buffer.size()), buffer.begin());
00083         if (n > 0)
00084         {
00085                 std::string result;
00086                 UnicodeConverter::toUTF8(buffer.begin(), result);
00087                 if (result[n - 1] != '\\')
00088                         result.append("\\");
00089                 return result;
00090         }
00091         throw SystemException("Cannot get current directory");
00092 }
00093 
00094 
00095 std::string PathImpl::nullImpl()
00096 {
00097         return "NUL:";
00098 }
00099 
00100 
00101 std::string PathImpl::expandImpl(const std::string& path)
00102 {
00103         std::wstring upath;
00104         UnicodeConverter::toUTF16(path, upath);
00105         Buffer<wchar_t> buffer(MAX_PATH_LEN);
00106         DWORD n = ExpandEnvironmentStringsW(upath.c_str(), buffer.begin(), static_cast<DWORD>(buffer.size()));
00107         if (n > 0 && n < buffer.size() - 1)
00108         {
00109                 buffer[n + 1] = 0;
00110                 std::string result;
00111                 UnicodeConverter::toUTF8(buffer.begin(), result);
00112                 return result;
00113         }
00114         else return path;
00115 }
00116 
00117 
00118 void PathImpl::listRootsImpl(std::vector<std::string>& roots)
00119 {
00120         roots.clear();
00121         wchar_t buffer[128];
00122         DWORD n = GetLogicalDriveStringsW(sizeof(buffer)/sizeof(wchar_t) - 1, buffer);
00123         wchar_t* it  = buffer;
00124         wchar_t* end = buffer + (n > sizeof(buffer) ? sizeof(buffer) : n);
00125         while (it < end)
00126         {
00127                 std::wstring udev;
00128                 while (it < end && *it) udev += *it++;
00129                 std::string dev;
00130                 UnicodeConverter::toUTF8(udev, dev);
00131                 roots.push_back(dev);
00132                 ++it;
00133         }
00134 }
00135 
00136 
00137 } // namespace Poco


pluginlib
Author(s): Tully Foote and Eitan Marder-Eppstein
autogenerated on Sat Dec 28 2013 17:20:19