1 | // |
---|
2 | // Path_WIN32.cpp |
---|
3 | // |
---|
4 | // $Id: //poco/1.3/Foundation/src/Path_WIN32.cpp#3 $ |
---|
5 | // |
---|
6 | // Library: Foundation |
---|
7 | // Package: Filesystem |
---|
8 | // Module: Path |
---|
9 | // |
---|
10 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. |
---|
11 | // and Contributors. |
---|
12 | // |
---|
13 | // Permission is hereby granted, free of charge, to any person or organization |
---|
14 | // obtaining a copy of the software and accompanying documentation covered by |
---|
15 | // this license (the "Software") to use, reproduce, display, distribute, |
---|
16 | // execute, and transmit the Software, and to prepare derivative works of the |
---|
17 | // Software, and to permit third-parties to whom the Software is furnished to |
---|
18 | // do so, all subject to the following: |
---|
19 | // |
---|
20 | // The copyright notices in the Software and this entire statement, including |
---|
21 | // the above license grant, this restriction and the following disclaimer, |
---|
22 | // must be included in all copies of the Software, in whole or in part, and |
---|
23 | // all derivative works of the Software, unless such copies or derivative |
---|
24 | // works are solely in the form of machine-executable object code generated by |
---|
25 | // a source language processor. |
---|
26 | // |
---|
27 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
28 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
29 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT |
---|
30 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE |
---|
31 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, |
---|
32 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
---|
33 | // DEALINGS IN THE SOFTWARE. |
---|
34 | // |
---|
35 | |
---|
36 | |
---|
37 | #include <Poco/Path_WIN32.h> |
---|
38 | #include <Poco/Environment_WIN32.h> |
---|
39 | #include <Poco/UnWindows.h> |
---|
40 | |
---|
41 | |
---|
42 | namespace Poco { |
---|
43 | |
---|
44 | |
---|
45 | std::string PathImpl::currentImpl() |
---|
46 | { |
---|
47 | char buffer[_MAX_PATH]; |
---|
48 | DWORD n = GetCurrentDirectoryA(sizeof(buffer), buffer); |
---|
49 | if (n > 0 && n < sizeof(buffer)) |
---|
50 | { |
---|
51 | std::string result(buffer, n); |
---|
52 | if (result[n - 1] != '\\') |
---|
53 | result.append("\\"); |
---|
54 | return result; |
---|
55 | } |
---|
56 | else throw SystemException("Cannot get current directory"); |
---|
57 | } |
---|
58 | |
---|
59 | |
---|
60 | std::string PathImpl::homeImpl() |
---|
61 | { |
---|
62 | std::string result = EnvironmentImpl::getImpl("HOMEDRIVE"); |
---|
63 | result.append(EnvironmentImpl::getImpl("HOMEPATH")); |
---|
64 | std::string::size_type n = result.size(); |
---|
65 | if (n > 0 && result[n - 1] != '\\') |
---|
66 | result.append("\\"); |
---|
67 | return result; |
---|
68 | } |
---|
69 | |
---|
70 | |
---|
71 | std::string PathImpl::tempImpl() |
---|
72 | { |
---|
73 | char buffer[_MAX_PATH]; |
---|
74 | DWORD n = GetTempPathA(sizeof(buffer), buffer); |
---|
75 | if (n > 0 && n < sizeof(buffer)) |
---|
76 | { |
---|
77 | std::string result(buffer, n); |
---|
78 | if (result[n - 1] != '\\') |
---|
79 | result.append("\\"); |
---|
80 | return result; |
---|
81 | } |
---|
82 | else throw SystemException("Cannot get current directory"); |
---|
83 | } |
---|
84 | |
---|
85 | |
---|
86 | std::string PathImpl::nullImpl() |
---|
87 | { |
---|
88 | return "NUL:"; |
---|
89 | } |
---|
90 | |
---|
91 | |
---|
92 | std::string PathImpl::expandImpl(const std::string& path) |
---|
93 | { |
---|
94 | char buffer[_MAX_PATH]; |
---|
95 | DWORD n = ExpandEnvironmentStringsA(path.c_str(), buffer, sizeof(buffer)); |
---|
96 | if (n > 0 && n < sizeof(buffer)) |
---|
97 | return std::string(buffer, n - 1); |
---|
98 | else |
---|
99 | return path; |
---|
100 | } |
---|
101 | |
---|
102 | |
---|
103 | void PathImpl::listRootsImpl(std::vector<std::string>& roots) |
---|
104 | { |
---|
105 | roots.clear(); |
---|
106 | char buffer[128]; |
---|
107 | DWORD n = GetLogicalDriveStrings(sizeof(buffer) - 1, buffer); |
---|
108 | char* it = buffer; |
---|
109 | char* end = buffer + (n > sizeof(buffer) ? sizeof(buffer) : n); |
---|
110 | while (it < end) |
---|
111 | { |
---|
112 | std::string dev; |
---|
113 | while (it < end && *it) dev += *it++; |
---|
114 | roots.push_back(dev); |
---|
115 | ++it; |
---|
116 | } |
---|
117 | } |
---|
118 | |
---|
119 | |
---|
120 | } // namespace Poco |
---|