# WinStd: include/WinStd/Shell.h Source File

Loading...
Searching...
No Matches
Shell.h
/*
SPDX-License-Identifier: MIT
Copyright © 1991-2024 Amebis
Copyright © 2016 GÉANT
*/
#pragma once
#include "Common.h"
#include <Shlwapi.h>
#include <string>
template<class _Traits, class _Ax>
static BOOL PathCanonicalizeA(_Inout_ std::basic_string<char, _Traits, _Ax> &sValue, _In_ LPCSTR pszPath)
{
char szBuffer[MAX_PATH + 1];
BOOL bResult = ::PathCanonicalizeA(szBuffer, pszPath);
sValue.assign(szBuffer, bResult ? MAX_PATH : 0);
return bResult;
}
template<class _Traits, class _Ax>
static BOOL PathCanonicalizeW(_Inout_ std::basic_string<wchar_t, _Traits, _Ax> &sValue, _In_ LPCWSTR pszPath)
{
wchar_t szBuffer[MAX_PATH + 1];
BOOL bResult = ::PathCanonicalizeW(szBuffer, pszPath);
sValue.assign(szBuffer, bResult ? MAX_PATH : 0);
return bResult;
}
template<class _Traits, class _Ax>
static void PathRemoveBackslashA(_Inout_ std::basic_string<char, _Traits, _Ax>& sValue)
{
char szBuffer[MAX_PATH + 1];
size_t len = sValue.length();
if (len < _countof(szBuffer)) {
memcpy(szBuffer, sValue.c_str(), len);
szBuffer[len] = 0;
PathRemoveBackslashA(szBuffer);
sValue.assign(szBuffer);
}
else {
std::unique_ptr<char[]> buf(new char[len + 1]);
memcpy(buf.get(), sValue.c_str(), len);
buf[len] = 0;
PathRemoveBackslashA(buf.get());
sValue.assign(buf.get());
}
}
template<class _Traits, class _Ax>
static void PathRemoveBackslashW(_Inout_ std::basic_string<wchar_t, _Traits, _Ax>& sValue)
{
wchar_t szBuffer[MAX_PATH + 1];
size_t len = sValue.length();
if (len < _countof(szBuffer)) {
wmemcpy(szBuffer, sValue.c_str(), len);
szBuffer[len] = 0;
PathRemoveBackslashW(szBuffer);
sValue.assign(szBuffer);
}
else {
std::unique_ptr<wchar_t[]> buf(new wchar_t[len + 1]);
wmemcpy(buf.get(), sValue.c_str(), len);
buf[len] = 0;
PathRemoveBackslashW(buf.get());
sValue.assign(buf.get());
}
}
PathCanonicalizeW
static BOOL PathCanonicalizeW(std::basic_string< wchar_t, _Traits, _Ax > &sValue, LPCWSTR pszPath)
Simplifies a path by removing navigation elements such as "." and ".." to produce a direct,...
Definition Shell.h:34
PathRemoveBackslashW
static void PathRemoveBackslashW(std::basic_string< wchar_t, _Traits, _Ax > &sValue)
Removes the trailing backslash from a given path.
Definition Shell.h:69
PathRemoveBackslashA
static void PathRemoveBackslashA(std::basic_string< char, _Traits, _Ax > &sValue)
Removes the trailing backslash from a given path.
Definition Shell.h:44
PathCanonicalizeA
static BOOL PathCanonicalizeA(std::basic_string< char, _Traits, _Ax > &sValue, LPCSTR pszPath)
Simplifies a path by removing navigation elements such as "." and ".." to produce a direct,...
Definition Shell.h:20