aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/poco/Foundation/src/Path_WINCE.cpp
blob: 750f18dda6ff8c6eb8cbb4ad96d129be71a36b63 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//
// Path_WIN32U.cpp
//
// Library: Foundation
// Package: Filesystem
// Module:  Path
//
// Copyright (c) 2006-2010, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier:	BSL-1.0
//


#include "Poco/Path_WINCE.h"
#include "Poco/Environment_WINCE.h"
#include "Poco/UnicodeConverter.h"
#include "Poco/Buffer.h"
#include "Poco/Environment.h"
#include "Poco/Exception.h"
#include "Poco/UnWindows.h"


namespace Poco {


std::string PathImpl::currentImpl()
{
	return("\\");
}

std::string PathImpl::homeImpl()
{
	return("\\");
}

std::string PathImpl::configHomeImpl()
{
  return homeImpl();
}

std::string PathImpl::dataHomeImpl()
{
  return homeImpl();
}

std::string PathImpl::cacheHomeImpl()
{
  return homeImpl();
}


std::string PathImpl::tempHomeImpl()
{
  return tempImpl();
}


std::string PathImpl::configImpl()
{
  return("\\");
}

std::string PathImpl::systemImpl()
{
	return("\\");
}


std::string PathImpl::nullImpl()
{
	return "NUL:";
}


std::string PathImpl::tempImpl()
{
	return "\\Temp\\";
}


std::string PathImpl::expandImpl(const std::string& path)
{
	std::string result;
	std::string::const_iterator it  = path.begin();
	std::string::const_iterator end = path.end();
	while (it != end)
	{
		if (*it == '%')
		{
			++it;
			if (it != end && *it == '%')
			{
				result += '%';
			}
			else
			{
				std::string var;
				while (it != end && *it != '%') var += *it++;
				if (it != end) ++it;
				result += Environment::get(var, "");
			}
		}
		else result += *it++;
	}
	return result;
}


void PathImpl::listRootsImpl(std::vector<std::string>& roots)
{
	roots.clear();
	roots.push_back("\\");

	WIN32_FIND_DATAW fd;
	HANDLE hFind = FindFirstFileW(L"\\*.*", &fd);
	if (hFind != INVALID_HANDLE_VALUE)
	{
		do
		{
			if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
				(fd.dwFileAttributes & FILE_ATTRIBUTE_TEMPORARY))
			{
				std::wstring name(fd.cFileName);
				name += L"\\Vol:";
				HANDLE h = CreateFileW(name.c_str(), GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
				if (h != INVALID_HANDLE_VALUE)
				{
					// its a device volume
					CloseHandle(h);
					std::string name;
					UnicodeConverter::toUTF8(fd.cFileName, name);
					std::string root = "\\" + name;
					roots.push_back(root);
				}
			}
		} 
		while (FindNextFileW(hFind, &fd));
		FindClose(hFind);
	}
}


} // namespace Poco