mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-25 18:22:59 +02:00
initial import
This commit is contained in:
135
Foundation/src/Path_WIN32U.cpp
Normal file
135
Foundation/src/Path_WIN32U.cpp
Normal file
@@ -0,0 +1,135 @@
|
||||
//
|
||||
// Path_WIN32U.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Foundation/src/Path_WIN32U.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Filesystem
|
||||
// Module: Path
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Foundation/Path_WIN32U.h"
|
||||
#include "Foundation/Environment_WIN32.h"
|
||||
#include "Foundation/UnicodeConverter.h"
|
||||
#include "Foundation/Buffer.h"
|
||||
#include "Foundation/Exception.h"
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
Foundation_BEGIN
|
||||
|
||||
|
||||
std::string PathImpl::currentImpl()
|
||||
{
|
||||
std::string result;
|
||||
DWORD len = GetCurrentDirectoryW(0, NULL);
|
||||
if (len > 0)
|
||||
{
|
||||
Buffer<wchar_t> buffer(len);
|
||||
DWORD n = GetCurrentDirectoryW(len, buffer.begin());
|
||||
if (n > 0 && n <= len)
|
||||
{
|
||||
UnicodeConverter::toUTF8(buffer.begin(), result);
|
||||
if (result[n - 1] != '\\')
|
||||
result.append("\\");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
throw SystemException("Cannot get current directory");
|
||||
}
|
||||
|
||||
|
||||
std::string PathImpl::homeImpl()
|
||||
{
|
||||
std::string result = EnvironmentImpl::getImpl("HOMEDRIVE");
|
||||
result.append(EnvironmentImpl::getImpl("HOMEPATH"));
|
||||
std::string::size_type n = result.size();
|
||||
if (n > 0 && result[n - 1] != '\\')
|
||||
result.append("\\");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
std::string PathImpl::tempImpl()
|
||||
{
|
||||
Buffer<wchar_t> buffer(MAX_PATH_LEN);
|
||||
DWORD n = GetTempPathW(buffer.size(), buffer.begin());
|
||||
if (n > 0)
|
||||
{
|
||||
std::string result;
|
||||
UnicodeConverter::toUTF8(buffer.begin(), result);
|
||||
if (result[n - 1] != '\\')
|
||||
result.append("\\");
|
||||
return result;
|
||||
}
|
||||
throw SystemException("Cannot get current directory");
|
||||
}
|
||||
|
||||
|
||||
std::string PathImpl::nullImpl()
|
||||
{
|
||||
return "NUL:";
|
||||
}
|
||||
|
||||
|
||||
std::string PathImpl::expandImpl(const std::string& path)
|
||||
{
|
||||
std::wstring upath;
|
||||
UnicodeConverter::toUTF16(path, upath);
|
||||
Buffer<wchar_t> buffer(MAX_PATH_LEN);
|
||||
DWORD n = ExpandEnvironmentStringsW(upath.c_str(), buffer.begin(), buffer.size());
|
||||
if (n > 0 && n < buffer.size() - 1)
|
||||
{
|
||||
buffer[n + 1] = 0;
|
||||
std::string result;
|
||||
UnicodeConverter::toUTF8(buffer.begin(), result);
|
||||
return result;
|
||||
}
|
||||
else return path;
|
||||
}
|
||||
|
||||
|
||||
void PathImpl::listRootsImpl(std::vector<std::string>& roots)
|
||||
{
|
||||
roots.clear();
|
||||
char buffer[128];
|
||||
DWORD n = GetLogicalDriveStrings(sizeof(buffer) - 1, buffer);
|
||||
char* it = buffer;
|
||||
char* end = buffer + (n > sizeof(buffer) ? sizeof(buffer) : n);
|
||||
while (it < end)
|
||||
{
|
||||
std::string dev;
|
||||
while (it < end && *it) dev += *it++;
|
||||
roots.push_back(dev);
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Foundation_END
|
||||
Reference in New Issue
Block a user