mirror of
https://github.com/rizonesoft/Notepad3.git
synced 2026-06-14 21:09:05 +08:00
some more LongPath handling
This commit is contained in:
parent
b8558bbfd4
commit
447f66bf01
@ -905,10 +905,10 @@ static bool _CheckAndSetIniFile(HPATHL hpth_in_out)
|
||||
Path_Reset(hPathEx, Path_IsNotEmpty(hpth_in_out) ? Path_FindFileName(hpth_in_out) : SAPPNAME L".ini");
|
||||
Path_ExpandEnvStrings(hPathEx);
|
||||
HPATHL hsearchpth = Path_Allocate(NULL);
|
||||
wchar_t* const buf = Path_WriteAccessBuf(hsearchpth, PATHLONG_MAX_CCH);
|
||||
LPWSTR const buf = Path_WriteAccessBuf(hsearchpth, PATHLONG_MAX_CCH);
|
||||
if (SearchPathW(NULL, Path_Get(hPathEx), L".ini", PATHLONG_MAX_CCH, buf, NULL)) {
|
||||
Path_Sanitize(hsearchpth);
|
||||
Path_FreeExtra(hsearchpth, MAX_PATH);
|
||||
Path_FreeExtra(hsearchpth, MAX_PATH_EXPLICIT);
|
||||
Path_Swap(hPathEx, hsearchpth);
|
||||
result = true;
|
||||
}
|
||||
@ -931,7 +931,7 @@ static bool _HandleIniFileRedirect(LPCWSTR lpszSecName, LPCWSTR lpszKeyName, HPA
|
||||
bool result = false;
|
||||
if (Path_IsExistingFile(hpth_in_out)) {
|
||||
HPATHL hredirect = Path_Allocate(NULL);
|
||||
wchar_t* const buf = Path_WriteAccessBuf(hredirect, PATHLONG_MAX_CCH);
|
||||
LPWSTR const buf = Path_WriteAccessBuf(hredirect, PATHLONG_MAX_CCH);
|
||||
if (IniFileGetString(Path_Get(hpth_in_out), lpszSecName, lpszKeyName, L"", buf, PATHLONG_MAX_CCH)) {
|
||||
Path_Sanitize(hredirect);
|
||||
Path_FreeExtra(hredirect, 0);
|
||||
@ -1409,7 +1409,7 @@ void LoadSettings()
|
||||
Settings.EFR_Data.fuFlags = (UINT)IniSectionGetInt(IniSecSettings, L"efrData_fuFlags", (int)Defaults.EFR_Data.fuFlags);
|
||||
|
||||
Path_GetKnownFolder(FOLDERID_Desktop, Defaults.OpenWithDir);
|
||||
wchar_t* const wchOpenWithDir = Path_WriteAccessBuf(Settings.OpenWithDir, PATHLONG_MAX_CCH);
|
||||
LPWSTR const wchOpenWithDir = Path_WriteAccessBuf(Settings.OpenWithDir, PATHLONG_MAX_CCH);
|
||||
if (IniSectionGetStringNoQuotes(IniSecSettings, L"OpenWithDir", Path_Get(Defaults.OpenWithDir), wchOpenWithDir, PATHLONG_MAX_CCH)) {
|
||||
Path_Sanitize(Settings.OpenWithDir);
|
||||
Path_FreeExtra(Settings.OpenWithDir, 0);
|
||||
@ -1418,7 +1418,7 @@ void LoadSettings()
|
||||
//~Path_FreeExtra(Settings.OpenWithDir, 0); ~ already done
|
||||
|
||||
Path_GetKnownFolder(FOLDERID_Favorites, Defaults.FavoritesDir);
|
||||
wchar_t* const wchFavoritesDir = Path_WriteAccessBuf(Settings.FavoritesDir, PATHLONG_MAX_CCH);
|
||||
LPWSTR const wchFavoritesDir = Path_WriteAccessBuf(Settings.FavoritesDir, PATHLONG_MAX_CCH);
|
||||
if (IniSectionGetStringNoQuotes(IniSecSettings, L"Favorites", Path_Get(Defaults.FavoritesDir), wchFavoritesDir, PATHLONG_MAX_CCH)) {
|
||||
Path_Sanitize(Settings.FavoritesDir);
|
||||
Path_FreeExtra(Settings.FavoritesDir, 0);
|
||||
|
||||
@ -1339,15 +1339,15 @@ CASE_WM_CTLCOLOR_SET:
|
||||
case IDC_SEARCHEXE: {
|
||||
|
||||
HPATHL hfile_pth = Path_Allocate(NULL);
|
||||
wchar_t* const file_buf = Path_WriteAccessBuf(hfile_pth, CMDLN_LENGTH_LIMIT);
|
||||
LPWSTR const file_buf = Path_WriteAccessBuf(hfile_pth, CMDLN_LENGTH_LIMIT);
|
||||
|
||||
HSTRINGW hargs_str = StrgCreate(NULL);
|
||||
wchar_t* const args_buf = StrgWriteAccessBuf(hargs_str, CMDLN_LENGTH_LIMIT);
|
||||
LPWSTR const args_buf = StrgWriteAccessBuf(hargs_str, CMDLN_LENGTH_LIMIT);
|
||||
HSTRINGW hargs2_str = StrgCreate(NULL);
|
||||
wchar_t* const args2_buf = StrgWriteAccessBuf(hargs2_str, StrgGetAllocLength(hargs_str));
|
||||
LPWSTR const args2_buf = StrgWriteAccessBuf(hargs2_str, StrgGetAllocLength(hargs_str));
|
||||
|
||||
HSTRINGW hflt_str = StrgCreate(NULL);
|
||||
wchar_t* const flt_buf = StrgWriteAccessBuf(hflt_str, EXTENTIONS_FILTER_BUFFER);
|
||||
LPWSTR const flt_buf = StrgWriteAccessBuf(hflt_str, EXTENTIONS_FILTER_BUFFER);
|
||||
|
||||
GetDlgItemText(hwnd, IDC_COMMANDLINE, args_buf, (int)StrgGetAllocLength(hargs_str));
|
||||
StrgSanitize(hargs_str);
|
||||
|
||||
21
src/Dlapi.c
21
src/Dlapi.c
@ -186,7 +186,7 @@ int DirList_Fill(HWND hwnd,LPCWSTR lpszDir,DWORD grfFlags,LPCWSTR lpszFileSpec,
|
||||
lvi.iItem = 0;
|
||||
lvi.iSubItem = 0;
|
||||
lvi.pszText = LPSTR_TEXTCALLBACK;
|
||||
lvi.cchTextMax = MAX_PATH;
|
||||
lvi.cchTextMax = MAX_PATH_EXPLICIT;
|
||||
lvi.iImage = I_IMAGECALLBACK;
|
||||
|
||||
// Convert Directory to a UNICODE string
|
||||
@ -195,7 +195,7 @@ int DirList_Fill(HWND hwnd,LPCWSTR lpszDir,DWORD grfFlags,LPCWSTR lpszFileSpec,
|
||||
lpszDir,
|
||||
-1,
|
||||
wszDir,
|
||||
MAX_PATH);*/
|
||||
MAX_PATH_EXPLICIT);*/
|
||||
LPWSTR const wchDir = Path_WriteAccessBuf(lpdl->hDirectoryPath, 0);
|
||||
|
||||
// Get Desktop Folder
|
||||
@ -752,13 +752,18 @@ bool DirList_PropertyDlg(HWND hwnd,int iItem)
|
||||
//
|
||||
bool DirList_GetLongPathName(HWND hwnd,LPWSTR lpszLongPath,int length)
|
||||
{
|
||||
WCHAR tch[MAX_PATH] = { L'\0' };
|
||||
HPATHL hpth = Path_Allocate(NULL);
|
||||
LPWSTR const pth_buf = Path_WriteAccessBuf(hpth, PATHLONG_MAX_CCH);
|
||||
|
||||
LPDLDATA lpdl = (LPVOID)GetProp(hwnd,pDirListProp);
|
||||
if (SHGetPathFromIDList(lpdl->pidl,tch)) {
|
||||
StringCchCopy(lpszLongPath,length,tch);
|
||||
return true;
|
||||
bool res = false;
|
||||
if (SHGetPathFromIDListW(lpdl->pidl, pth_buf)) {
|
||||
Path_Sanitize(hpth);
|
||||
StringCchCopyW(lpszLongPath, length, pth_buf);
|
||||
res = true;
|
||||
}
|
||||
return false;
|
||||
Path_Release(hpth);
|
||||
return res;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -967,7 +972,7 @@ int DriveBox_Fill(HWND hwnd)
|
||||
COMBOBOXEXITEM cbei = { 0 };
|
||||
cbei.mask = CBEIF_TEXT | CBEIF_IMAGE | CBEIF_SELECTEDIMAGE | CBEIF_LPARAM;
|
||||
cbei.pszText = LPSTR_TEXTCALLBACK;
|
||||
cbei.cchTextMax = MAX_PATH;
|
||||
cbei.cchTextMax = MAX_PATH_EXPLICIT;
|
||||
cbei.iImage = I_IMAGECALLBACK;
|
||||
cbei.iSelectedImage = I_IMAGECALLBACK;
|
||||
|
||||
|
||||
@ -35,7 +35,7 @@
|
||||
|
||||
typedef struct tagSTRINGW
|
||||
{
|
||||
wchar_t* data;
|
||||
LPWSTR data;
|
||||
size_t data_length;
|
||||
size_t alloc_length;
|
||||
|
||||
@ -125,7 +125,7 @@ inline static void * ReAllocBuffer(void* pdata, const size_t len, bool bZeroMem,
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
inline static void FreeBuffer(wchar_t * pstr) {
|
||||
inline static void FreeBuffer(LPWSTR pstr) {
|
||||
if (!s_hndlProcessHeap) {
|
||||
s_hndlProcessHeap = GetProcessHeap();
|
||||
}
|
||||
@ -191,7 +191,7 @@ static void AllocCopyW(STRINGW* pstr, STRINGW* pDest, size_t copy_len, size_t co
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
static void SetCopyW(STRINGW* pstr, size_t len, const wchar_t* p)
|
||||
static void SetCopyW(STRINGW* pstr, size_t len, LPCWSTR p)
|
||||
{
|
||||
ReAllocW(pstr, len, false);
|
||||
if (pstr->data) {
|
||||
@ -204,10 +204,10 @@ static void SetCopyW(STRINGW* pstr, size_t len, const wchar_t* p)
|
||||
#if 0
|
||||
//~ replaced by ReAllocW()
|
||||
|
||||
static wchar_t* CopyOldDataW(STRINGW* pstr, size_t* outLen)
|
||||
static LPWSTR CopyOldDataW(STRINGW* pstr, size_t* outLen)
|
||||
{
|
||||
size_t const old_siz = StrlenW(pstr->data) + 1;
|
||||
wchar_t* const ptr = AllocBuffer(old_siz, FALSE);
|
||||
LPWSTR const ptr = AllocBuffer(old_siz, FALSE);
|
||||
if (ptr) {
|
||||
StringCchCopyW(ptr, old_siz, pstr->data ? pstr->data : L"");
|
||||
*outLen = wcslen(ptr);
|
||||
@ -230,7 +230,7 @@ static void FreeUnusedData(STRINGW* pstr, size_t keep_length)
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
static void CopyConcatW(STRINGW *pstr, size_t len1, const wchar_t *p1, size_t len2, const wchar_t *p2)
|
||||
static void CopyConcatW(STRINGW *pstr, size_t len1, LPCWSTR p1, size_t len2, LPCWSTR p2)
|
||||
{
|
||||
size_t const new_len = len1 + len2;
|
||||
if (0 < new_len) {
|
||||
@ -242,7 +242,7 @@ static void CopyConcatW(STRINGW *pstr, size_t len1, const wchar_t *p1, size_t le
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
static void ConcatW(STRINGW* pstr, size_t len, const wchar_t* p)
|
||||
static void ConcatW(STRINGW* pstr, size_t len, LPCWSTR p)
|
||||
{
|
||||
if (len == 0)
|
||||
return;
|
||||
@ -257,12 +257,12 @@ static void ConcatW(STRINGW* pstr, size_t len, const wchar_t* p)
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
static void FormatW(STRINGW* pstr, const wchar_t* fmt, va_list args)
|
||||
static void FormatW(STRINGW* pstr, LPCWSTR fmt, va_list args)
|
||||
{
|
||||
va_list orig_list = args;
|
||||
|
||||
size_t max_len = 0;
|
||||
const wchar_t * p;
|
||||
LPCWSTR p;
|
||||
|
||||
for (p = fmt; *p != L'\0'; p = _wcsinc(p)) {
|
||||
size_t item_len = 0, width = 0, prec = 0, modif = 0;
|
||||
@ -337,7 +337,7 @@ static void FormatW(STRINGW* pstr, const wchar_t* fmt, va_list args)
|
||||
|
||||
case L's':
|
||||
case L'S': {
|
||||
wchar_t* const next_arg = va_arg(args, wchar_t*);
|
||||
LPWSTR const next_arg = va_arg(args, LPWSTR);
|
||||
if (!next_arg)
|
||||
item_len = 6;
|
||||
else {
|
||||
@ -348,7 +348,7 @@ static void FormatW(STRINGW* pstr, const wchar_t* fmt, va_list args)
|
||||
|
||||
case L's' | 0x20000:
|
||||
case L'S' | 0x20000: {
|
||||
wchar_t* const next_arg = va_arg(args, wchar_t*);
|
||||
LPWSTR const next_arg = va_arg(args, LPWSTR);
|
||||
if (!next_arg)
|
||||
item_len = 6;
|
||||
else {
|
||||
@ -421,7 +421,7 @@ static void FormatW(STRINGW* pstr, const wchar_t* fmt, va_list args)
|
||||
/* */
|
||||
/**************************************************/
|
||||
|
||||
HSTRINGW STRAPI StrgCreate(const wchar_t* str)
|
||||
HSTRINGW STRAPI StrgCreate(LPCWSTR str)
|
||||
{
|
||||
STRINGW *pstr = AllocBuffer(sizeof(STRINGW), true);
|
||||
if (!pstr)
|
||||
@ -442,12 +442,12 @@ void STRAPI StrgDestroy(HSTRINGW hstr)
|
||||
if (!pstr)
|
||||
return;
|
||||
FreeBufferW(pstr);
|
||||
FreeBuffer((wchar_t*)pstr);
|
||||
FreeBuffer((LPWSTR)pstr);
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
int STRAPI StrgReset(HSTRINGW hstr, const wchar_t* str)
|
||||
int STRAPI StrgReset(HSTRINGW hstr, LPCWSTR str)
|
||||
{
|
||||
STRINGW* pstr = ToWStrg(hstr);
|
||||
if (!pstr)
|
||||
@ -458,7 +458,7 @@ int STRAPI StrgReset(HSTRINGW hstr, const wchar_t* str)
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
const wchar_t* STRAPI StrgGet(const HSTRINGW hstr)
|
||||
LPCWSTR STRAPI StrgGet(const HSTRINGW hstr)
|
||||
{
|
||||
STRINGW* pstr = ToWStrg(hstr);
|
||||
if (!pstr)
|
||||
@ -588,7 +588,7 @@ void STRAPI StrgSwap(HSTRINGW hstr1, HSTRINGW hstr2)
|
||||
if (!pstr1 || !pstr2)
|
||||
return;
|
||||
|
||||
wchar_t* const ptmp_data = pstr1->data;
|
||||
LPWSTR const ptmp_data = pstr1->data;
|
||||
size_t const tmp_data_len = pstr1->data_length;
|
||||
size_t const tmp_alloc_len = pstr1->alloc_length;
|
||||
|
||||
@ -603,7 +603,7 @@ void STRAPI StrgSwap(HSTRINGW hstr1, HSTRINGW hstr2)
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
void STRAPI StrgCat(HSTRINGW hstr, const wchar_t* str)
|
||||
void STRAPI StrgCat(HSTRINGW hstr, LPCWSTR str)
|
||||
{
|
||||
STRINGW* pstr = ToWStrg(hstr);
|
||||
if (!pstr)
|
||||
@ -613,7 +613,7 @@ void STRAPI StrgCat(HSTRINGW hstr, const wchar_t* str)
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
size_t STRAPI StrgInsert(HSTRINGW hstr, size_t index, const wchar_t* str)
|
||||
size_t STRAPI StrgInsert(HSTRINGW hstr, size_t index, LPCWSTR str)
|
||||
{
|
||||
STRINGW* pstr = ToWStrg(hstr);
|
||||
if (!pstr)
|
||||
@ -664,7 +664,7 @@ size_t STRAPI StrgInsertCh(HSTRINGW hstr, size_t index, const wchar_t c)
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
size_t STRAPI StrgReplace(HSTRINGW hstr, const wchar_t* pOld, const wchar_t* pNew)
|
||||
size_t STRAPI StrgReplace(HSTRINGW hstr, LPCWSTR pOld, LPCWSTR pNew)
|
||||
{
|
||||
STRINGW* pstr = ToWStrg(hstr);
|
||||
if (!pstr)
|
||||
@ -675,9 +675,9 @@ size_t STRAPI StrgReplace(HSTRINGW hstr, const wchar_t* pOld, const wchar_t* pNe
|
||||
return 0;
|
||||
|
||||
size_t const repl_len = StrlenW(pNew);
|
||||
wchar_t * start = pstr->data;
|
||||
wchar_t * end = pstr->data + pstr->data_length;
|
||||
wchar_t * target = NULL;
|
||||
LPWSTR start = pstr->data;
|
||||
LPWSTR end = pstr->data + pstr->data_length;
|
||||
LPWSTR target = NULL;
|
||||
|
||||
size_t count = 0;
|
||||
while (start < end)
|
||||
@ -722,7 +722,7 @@ size_t STRAPI StrgReplace(HSTRINGW hstr, const wchar_t* pOld, const wchar_t* pNe
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
size_t STRAPI StrgRemove(HSTRINGW hstr, const wchar_t *str)
|
||||
size_t STRAPI StrgRemove(HSTRINGW hstr, LPCWSTR str)
|
||||
{
|
||||
return StrgReplace(hstr, str, L"");
|
||||
}
|
||||
@ -738,8 +738,8 @@ size_t STRAPI StrgReplaceCh(HSTRINGW hstr, const wchar_t chOld, const wchar_t ch
|
||||
size_t count = 0;
|
||||
if (chOld != chNew)
|
||||
{
|
||||
wchar_t* p = pstr->data;
|
||||
wchar_t* end = p + pstr->data_length;
|
||||
LPWSTR p = pstr->data;
|
||||
LPWSTR end = p + pstr->data_length;
|
||||
while (p < end)
|
||||
{
|
||||
if (*p == chOld)
|
||||
@ -761,9 +761,9 @@ size_t STRAPI StrgRemoveCh(HSTRINGW hstr, const wchar_t chRemove)
|
||||
if (!pstr)
|
||||
return 0;
|
||||
|
||||
wchar_t * source = pstr->data;
|
||||
wchar_t * dest = pstr->data;
|
||||
wchar_t * end = pstr->data + pstr->data_length;
|
||||
LPWSTR source = pstr->data;
|
||||
LPWSTR dest = pstr->data;
|
||||
LPWSTR end = pstr->data + pstr->data_length;
|
||||
|
||||
size_t count = 0;
|
||||
while (source < end)
|
||||
@ -861,8 +861,8 @@ void STRAPI StrgTrimRight(HSTRINGW hstr, const wchar_t wch)
|
||||
if (!pstr)
|
||||
return;
|
||||
|
||||
wchar_t * start = pstr->data;
|
||||
wchar_t * end = NULL;
|
||||
LPWSTR start = pstr->data;
|
||||
LPWSTR end = NULL;
|
||||
|
||||
while (*start != L'\0')
|
||||
{
|
||||
@ -891,7 +891,7 @@ void STRAPI StrgTrimLeft(HSTRINGW hstr, const wchar_t wch)
|
||||
if (!pstr)
|
||||
return;
|
||||
|
||||
wchar_t * start = pstr->data;
|
||||
LPWSTR start = pstr->data;
|
||||
|
||||
while (isspace(*start) || (wch ? (*start == wch) : 0))
|
||||
start++;
|
||||
@ -914,7 +914,7 @@ void STRAPI StrgTrim(HSTRINGW hstr, const wchar_t wch)
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
size_t STRAPI StrgFind(const HSTRINGW hstr, const wchar_t* sub, const size_t start)
|
||||
size_t STRAPI StrgFind(const HSTRINGW hstr, LPCWSTR sub, const size_t start)
|
||||
{
|
||||
STRINGW* pstr = ToWStrg(hstr);
|
||||
if (!pstr)
|
||||
@ -923,7 +923,7 @@ size_t STRAPI StrgFind(const HSTRINGW hstr, const wchar_t* sub, const size_t sta
|
||||
if (start >= pstr->data_length)
|
||||
return STRINGW_INVALID_IDX;
|
||||
|
||||
wchar_t * str = wcsstr(pstr->data + start, sub);
|
||||
LPWSTR str = wcsstr(pstr->data + start, sub);
|
||||
|
||||
return (str == NULL) ? STRINGW_INVALID_IDX : (size_t)(str - pstr->data);
|
||||
}
|
||||
@ -939,7 +939,7 @@ size_t STRAPI StrgFindCh(const HSTRINGW hstr, const wchar_t ch, const size_t sta
|
||||
if (start >= pstr->data_length)
|
||||
return STRINGW_INVALID_IDX;
|
||||
|
||||
wchar_t * p = wcschr(pstr->data + start, ch);
|
||||
LPWSTR p = wcschr(pstr->data + start, ch);
|
||||
|
||||
return (p == NULL) ? STRINGW_INVALID_IDX : (size_t)(p - pstr->data);
|
||||
}
|
||||
@ -952,20 +952,20 @@ size_t STRAPI StrgReverseFind(const HSTRINGW hstr, wchar_t ch)
|
||||
if (!pstr)
|
||||
return STRINGW_INVALID_IDX;
|
||||
|
||||
wchar_t * p = wcsrchr(pstr->data, ch);
|
||||
LPWSTR p = wcsrchr(pstr->data, ch);
|
||||
|
||||
return (p == NULL) ? STRINGW_INVALID_IDX : (size_t)(p - pstr->data);
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
size_t STRAPI StrgFindOneOf(const HSTRINGW hstr, const wchar_t* char_set)
|
||||
size_t STRAPI StrgFindOneOf(const HSTRINGW hstr, LPCWSTR char_set)
|
||||
{
|
||||
STRINGW* pstr = ToWStrg(hstr);
|
||||
if (!pstr)
|
||||
return STRINGW_INVALID_IDX;
|
||||
|
||||
wchar_t * p = wcspbrk(pstr->data, char_set);
|
||||
LPWSTR p = wcspbrk(pstr->data, char_set);
|
||||
return (p == NULL) ? STRINGW_INVALID_IDX : (size_t)(p - pstr->data);
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -1036,7 +1036,7 @@ HSTRINGW STRAPI StrgRight(HSTRINGW hstr, const size_t count)
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
void STRAPI StrgFormat(HSTRINGW hstr, const wchar_t* fmt, ...)
|
||||
void STRAPI StrgFormat(HSTRINGW hstr, LPCWSTR fmt, ...)
|
||||
{
|
||||
STRINGW* const pstr = ToWStrg(hstr);
|
||||
if (!pstr)
|
||||
@ -1050,7 +1050,7 @@ void STRAPI StrgFormat(HSTRINGW hstr, const wchar_t* fmt, ...)
|
||||
|
||||
// ############################################################################
|
||||
|
||||
wchar_t* STRAPI StrgWriteAccessBuf(HSTRINGW hstr, size_t min_len)
|
||||
LPWSTR STRAPI StrgWriteAccessBuf(HSTRINGW hstr, size_t min_len)
|
||||
{
|
||||
STRINGW* pstr = ToWStrg(hstr);
|
||||
if (!pstr)
|
||||
|
||||
@ -21,6 +21,8 @@
|
||||
|
||||
#define STRAPI __stdcall
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/**************************************************/
|
||||
/* */
|
||||
/* DYNAMIC WIDE CHAR C STRING */
|
||||
@ -30,11 +32,12 @@
|
||||
#define STRINGW_MAX_URL_LENGTH INTERNET_MAX_URL_LENGTH
|
||||
#define STRINGW_INVALID_IDX ((size_t)-1)
|
||||
|
||||
__forceinline size_t StrlenW(const wchar_t* p) { return (!p) ? 0 : wcslen(p); }
|
||||
__forceinline size_t StrlenW(LPCWSTR p) { return (!p) ? 0 : wcslen(p); }
|
||||
|
||||
HSTRINGW STRAPI StrgCreate(const wchar_t* str);
|
||||
HSTRINGW STRAPI StrgCreate(LPCWSTR str);
|
||||
void STRAPI StrgDestroy(HSTRINGW hstr);
|
||||
|
||||
LPCWSTR STRAPI StrgGet(const HSTRINGW hstr);
|
||||
int STRAPI StrgIsEmpty(const HSTRINGW hstr);
|
||||
inline int STRAPI StrgIsNotEmpty(const HSTRINGW hstr) { return !StrgIsEmpty(hstr); };
|
||||
size_t STRAPI StrgGetLength(const HSTRINGW hstr);
|
||||
@ -44,14 +47,13 @@ void STRAPI StrgFree(HSTRINGW hstr); // NULL PTR
|
||||
void STRAPI StrgFreeExtra(HSTRINGW hstr, size_t keep_length); // shrink not below keep_len
|
||||
void STRAPI StrgEmpty(const HSTRINGW hstr, bool truncate); // -> L""
|
||||
|
||||
int STRAPI StrgReset(HSTRINGW hstr, const wchar_t* str);
|
||||
const wchar_t* STRAPI StrgGet(const HSTRINGW hstr);
|
||||
int STRAPI StrgReset(HSTRINGW hstr, LPCWSTR str);
|
||||
void STRAPI StrgSetAt(HSTRINGW hstr, const size_t index, const wchar_t ch);
|
||||
wchar_t STRAPI StrgGetAt(const HSTRINGW hstr, const size_t index);
|
||||
HSTRINGW STRAPI StrgCopy(const HSTRINGW hstr);
|
||||
void STRAPI StrgSwap(HSTRINGW hstr1, HSTRINGW hstr2); // ensure not NULL
|
||||
void STRAPI StrgCat(HSTRINGW hstr, const wchar_t* str); /* concatenate */
|
||||
size_t STRAPI StrgInsert(HSTRINGW hstr, const size_t index, const wchar_t* str);
|
||||
void STRAPI StrgCat(HSTRINGW hstr, LPCWSTR str); /* concatenate */
|
||||
size_t STRAPI StrgInsert(HSTRINGW hstr, const size_t index, LPCWSTR str);
|
||||
size_t STRAPI StrgInsertCh(HSTRINGW hstr, size_t index, const wchar_t c);
|
||||
size_t STRAPI StrgReplace(HSTRINGW hstr, const wchar_t *pOld, const wchar_t *pNew);
|
||||
size_t STRAPI StrgRemove(HSTRINGW hstr, const wchar_t *str);
|
||||
@ -71,18 +73,17 @@ void STRAPI StrgTrimRight(HSTRINGW hstr, const wchar_t wch);
|
||||
void STRAPI StrgTrimLeft(HSTRINGW hstr, const wchar_t wch);
|
||||
void STRAPI StrgTrim(HSTRINGW hstr, const wchar_t wch);
|
||||
|
||||
size_t STRAPI StrgFind(const HSTRINGW hstr, const wchar_t* sub, const size_t start);
|
||||
size_t STRAPI StrgFind(const HSTRINGW hstr, LPCWSTR sub, const size_t start);
|
||||
size_t STRAPI StrgFindCh(const HSTRINGW hstr, const wchar_t wch, const size_t start);
|
||||
size_t STRAPI StrgReverseFind(const HSTRINGW hstr, wchar_t wch);
|
||||
size_t STRAPI StrgFindOneOf(const HSTRINGW hstr, const wchar_t* wchar_t_set);
|
||||
size_t STRAPI StrgFindOneOf(const HSTRINGW hstr, LPCWSTR wchar_t_set);
|
||||
|
||||
HSTRINGW STRAPI StrgMid(HSTRINGW hstr, const size_t start, size_t count);
|
||||
HSTRINGW STRAPI StrgLeft(HSTRINGW hstr, const size_t count);
|
||||
HSTRINGW STRAPI StrgRight(HSTRINGW hstr, const size_t count);
|
||||
|
||||
void STRAPI StrgFormat(HSTRINGW hstr, const wchar_t* fmt, ...);
|
||||
void STRAPI StrgFormat(HSTRINGW hstr, LPCWSTR fmt, ...);
|
||||
|
||||
|
||||
// use together - may consistency issues if not (!)
|
||||
wchar_t* STRAPI StrgWriteAccessBuf(HSTRINGW hstr, size_t min_len); //min_len = 0 for not resizing buffer
|
||||
void STRAPI StrgSanitize(HSTRINGW hstr); // correct string length after buffer access
|
||||
// use together (after external access) - may get consistency issues if not (!)
|
||||
LPWSTR STRAPI StrgWriteAccessBuf(HSTRINGW hstr, size_t min_len); // min_len = 0 for not resizing buffer
|
||||
void STRAPI StrgSanitize(HSTRINGW hstr); // correct string length after buffer access
|
||||
|
||||
@ -5151,14 +5151,14 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
|
||||
case IDM_EDIT_INSERT_GUID: {
|
||||
GUID guid;
|
||||
if (SUCCEEDED(CoCreateGuid(&guid))) {
|
||||
WCHAR wchBuf[256] = { L'\0' };
|
||||
WCHAR wchBuf[128] = { L'\0' };
|
||||
if (StringFromGUID2(&guid, wchBuf, COUNTOF(wchBuf))) {
|
||||
StrTrim(wchBuf, L"{}");
|
||||
//char chMaxPathBuffer[MAX_PATH] = { '\0' };
|
||||
//if (WideCharToMultiByteEx(Encoding_SciCP, 0, tchMaxPathBuffer, -1, chMaxPathBuffer, COUNTOF(chMaxPathBuffer), NULL, NULL)) {
|
||||
// EditReplaceSelection(chMaxPathBuffer, false);
|
||||
//}
|
||||
SetClipboardText(hwnd, wchBuf, StringCchLen(wchBuf, 0));
|
||||
//char chGuidBuffer[128] = { '\0' };
|
||||
//if (WideCharToMultiByte(Encoding_SciCP, 0, wchBuf, -1, chGuidBuffer, (int)COUNTOF(chGuidBuffer), NULL, NULL)) {
|
||||
// EditReplaceSelection(chGuidBuffer, false);
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -7335,7 +7335,7 @@ void HandleDWellStartEnd(const DocPos position, const UINT uid)
|
||||
SplitFilePathLineNum(wchUrl, NULL); // cut off possible linenum spec
|
||||
|
||||
HPATHL hurl_pth = Path_Allocate(NULL);
|
||||
DWORD cchPath = MAX_PATH << 1;
|
||||
DWORD cchPath = INTERNET_MAX_URL_LENGTH;
|
||||
LPWSTR const url_buf = Path_WriteAccessBuf(hurl_pth, cchPath);
|
||||
|
||||
if (FAILED(PathCreateFromUrlW(wchUrl, url_buf, &cchPath, 0))) {
|
||||
@ -7549,8 +7549,8 @@ bool HandleHotSpotURLClicked(const DocPos position, const HYPERLINK_OPS operatio
|
||||
|
||||
bool const bReuseWindow = Flags.bReuseWindow && !(operation & OPEN_NEW_NOTEPAD3);
|
||||
|
||||
PathCreateFromUrl(szTextW, szUnEscW, &dCch, 0);
|
||||
szUnEscW[min_u(MAX_PATH, INTERNET_MAX_URL_LENGTH)] = L'\0'; // limit length
|
||||
PathCreateFromUrlW(szTextW, szUnEscW, &dCch, 0);
|
||||
szUnEscW[INTERNET_MAX_URL_LENGTH] = L'\0'; // limit length
|
||||
StrTrim(szUnEscW, L"/");
|
||||
|
||||
HPATHL hfile_pth = Path_Allocate(szUnEscW);
|
||||
@ -8642,7 +8642,7 @@ void ParseCommandLine()
|
||||
if (*(lp1 + 1) == L'0' || *CharUpper(lp1 + 1) == L'O') {
|
||||
Path_Reset(Paths.IniFile, L"*?");
|
||||
} else if (ExtractFirstArgument(lp2, lp1, lp2, (int)len)) {
|
||||
WCHAR wchPath[MAX_PATH << 2];
|
||||
WCHAR wchPath[INTERNET_MAX_URL_LENGTH];
|
||||
StringCchCopyN(wchPath, COUNTOF(wchPath), lp1, len);
|
||||
Path_Reset(Paths.IniFile, wchPath);
|
||||
Path_NormalizeEx(Paths.IniFile, Paths.ModuleDirectory, true, false);
|
||||
@ -8904,7 +8904,7 @@ void ParseCommandLine()
|
||||
}
|
||||
// pathname
|
||||
else {
|
||||
LPWSTR lpFileBuf = AllocMem(sizeof(WCHAR)*len, HEAP_ZERO_MEMORY);
|
||||
LPWSTR lpFileBuf = AllocMem(sizeof(WCHAR) * len, HEAP_ZERO_MEMORY);
|
||||
if (lpFileBuf) {
|
||||
size_t const fileArgLen = StringCchLenW(lp3, len);
|
||||
s_cchiFileList = (int)(StringCchLenW(lpCmdLine, len - 2) - fileArgLen);
|
||||
@ -8919,7 +8919,7 @@ void ParseCommandLine()
|
||||
Path_Reset(s_pthArgFilePath, lp3);
|
||||
Path_Canonicalize(s_pthArgFilePath);
|
||||
|
||||
// §§§ @@@ TODO: Normalize ???
|
||||
// §§§ @@@ TODO: Normalize MAX_PATH ???
|
||||
//if (!Path_IsRelative(s_pthArgFilePath) && !Path_IsValidUNC(s_pthArgFilePath, NULL) &&
|
||||
// Path_GetDriveNumber(s_pthArgFilePath) == -1 /*&& Path_GetDriveNumber(Paths.WorkingDirectory) != -1*/) {
|
||||
// WCHAR wchPath[MAX_PATH] = { L'\0' };
|
||||
@ -10290,10 +10290,12 @@ bool FileIO(bool fLoad, const HPATHL hfile_pth, EditFileIOStatus* status,
|
||||
{
|
||||
bool fSuccess = false;
|
||||
|
||||
WCHAR tch[MAX_PATH + 40];
|
||||
FormatLngStringW(tch, COUNTOF(tch), (fLoad) ? IDS_MUI_LOADFILE : IDS_MUI_SAVEFILE, Path_FindFileName(hfile_pth));
|
||||
WCHAR wchFName[64];
|
||||
Path_GetDisplayName(wchFName, COUNTOF(wchFName), hfile_pth, L"...");
|
||||
WCHAR wchMsg[128];
|
||||
FormatLngStringW(wchMsg, COUNTOF(wchMsg), (fLoad) ? IDS_MUI_LOADFILE : IDS_MUI_SAVEFILE, wchFName);
|
||||
|
||||
BeginWaitCursor(true, tch);
|
||||
BeginWaitCursor(true, wchMsg);
|
||||
|
||||
if (fLoad) {
|
||||
fSuccess = EditLoadFile(Globals.hwndEdit, hfile_pth, status,
|
||||
@ -10897,16 +10899,16 @@ bool FileSave(bool bSaveAlways, bool bAsk, bool bSaveAs, bool bSaveCopy, bool bP
|
||||
|
||||
if (bAsk) {
|
||||
// File or "Untitled" ...
|
||||
WCHAR tch[MAX_PATH] = { L'\0' };
|
||||
WCHAR wchFileName[128] = { L'\0' };
|
||||
if (Path_IsNotEmpty(Paths.CurrentFile)) {
|
||||
StringCchCopy(tch, COUNTOF(tch), Path_FindFileName(Paths.CurrentFile)); // eq. PathStripPath(tch);
|
||||
Path_GetDisplayName(wchFileName, COUNTOF(wchFileName), Paths.CurrentFile, L"...");
|
||||
} else {
|
||||
GetLngString(IDS_MUI_UNTITLED, tch, COUNTOF(tch));
|
||||
GetLngString(IDS_MUI_UNTITLED, wchFileName, COUNTOF(wchFileName));
|
||||
}
|
||||
|
||||
INT_PTR const answer = (Settings.MuteMessageBeep) ?
|
||||
InfoBoxLng(MB_YESNOCANCEL | MB_ICONWARNING, NULL, IDS_MUI_ASK_SAVE, tch) :
|
||||
MessageBoxLng(MB_YESNOCANCEL | MB_ICONWARNING, IDS_MUI_ASK_SAVE, tch);
|
||||
InfoBoxLng(MB_YESNOCANCEL | MB_ICONWARNING, NULL, IDS_MUI_ASK_SAVE, wchFileName) :
|
||||
MessageBoxLng(MB_YESNOCANCEL | MB_ICONWARNING, IDS_MUI_ASK_SAVE, wchFileName);
|
||||
switch (answer)
|
||||
//switch ()
|
||||
{
|
||||
@ -11158,7 +11160,7 @@ bool OpenFileDlg(HWND hwnd, HPATHL hfile_pth_io, const HPATHL hinidir_pth)
|
||||
Path_Sanitize(hfile_pth_io);
|
||||
|
||||
Path_Release(hpth_dir);
|
||||
Path_FreeExtra(hfile_pth_io, MAX_PATH);
|
||||
Path_FreeExtra(hfile_pth_io, MAX_PATH_EXPLICIT);
|
||||
|
||||
return res;
|
||||
}
|
||||
@ -11202,7 +11204,7 @@ bool SaveFileDlg(HWND hwnd, HPATHL hfile_pth_io, const HPATHL hinidir_pth)
|
||||
Path_Sanitize(hfile_pth_io);
|
||||
|
||||
Path_Release(hpth_dir);
|
||||
Path_FreeExtra(hfile_pth_io, MAX_PATH);
|
||||
Path_FreeExtra(hfile_pth_io, MAX_PATH_EXPLICIT);
|
||||
|
||||
return res;
|
||||
}
|
||||
@ -11253,10 +11255,10 @@ BOOL CALLBACK EnumWndProc2(HWND hwnd,LPARAM lParam)
|
||||
bContinue = FALSE;
|
||||
}
|
||||
|
||||
WCHAR tchFileName[MAX_PATH] = { L'\0' };
|
||||
GetDlgItemText(hwnd, IDC_FILENAME, tchFileName, COUNTOF(tchFileName));
|
||||
WCHAR wchFileName[INTERNET_MAX_URL_LENGTH] = { L'\0' };
|
||||
GetDlgItemText(hwnd, IDC_FILENAME, wchFileName, COUNTOF(wchFileName));
|
||||
|
||||
if (StringCchCompareXI(tchFileName, Path_Get(s_pthArgFilePath)) == 0) {
|
||||
if (StringCchCompareXI(wchFileName, Path_Get(s_pthArgFilePath)) == 0) {
|
||||
*(HWND*)lParam = hwnd;
|
||||
} else {
|
||||
bContinue = TRUE;
|
||||
|
||||
180
src/PathLib.c
180
src/PathLib.c
@ -166,21 +166,21 @@
|
||||
|
||||
// -------------------------------------------------
|
||||
|
||||
const wchar_t* const PATHUNC_PREFIX1 = L"\\\\?\\UNC\\";
|
||||
const wchar_t* const PATHUNC_PREFIX2 = L"\\\\.\\UNC\\";
|
||||
LPCWSTR const PATHUNC_PREFIX1 = L"\\\\?\\UNC\\";
|
||||
LPCWSTR const PATHUNC_PREFIX2 = L"\\\\.\\UNC\\";
|
||||
|
||||
// TODO: ???
|
||||
//const wchar_t* const VOLUME_PREFIX = L"\\\\?\\Volume{";
|
||||
//LPCWSTR const VOLUME_PREFIX = L"\\\\?\\Volume{";
|
||||
|
||||
const wchar_t* const PATHLONG_PREFIX = L"\\\\?\\";
|
||||
LPCWSTR const PATHLONG_PREFIX = L"\\\\?\\";
|
||||
|
||||
const wchar_t* const NETSHARE_PREFIX = L"\\\\";
|
||||
LPCWSTR const NETSHARE_PREFIX = L"\\\\";
|
||||
|
||||
const wchar_t* const PATHPARENT_PREFIX = L"..\\";
|
||||
LPCWSTR const PATHPARENT_PREFIX = L"..\\";
|
||||
|
||||
const wchar_t* const PATHDSPL_INFIX = L" ... ";
|
||||
LPCWSTR const PATHDSPL_INFIX = L" ... ";
|
||||
|
||||
const wchar_t* const PATH_CSIDL_MYDOCUMENTS = L"%CSIDL:MYDOCUMENTS%";
|
||||
LPCWSTR const PATH_CSIDL_MYDOCUMENTS = L"%CSIDL:MYDOCUMENTS%";
|
||||
|
||||
|
||||
// TODO: ...
|
||||
@ -250,20 +250,20 @@ __forceinline size_t max_s(const size_t x, const size_t y) _RETCMPMAX_
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
__forceinline wchar_t _wcsgetprev(const wchar_t* str, const wchar_t* c)
|
||||
__forceinline wchar_t _wcsgetprev(LPCWSTR str, LPCWSTR c)
|
||||
{
|
||||
if (!str)
|
||||
return L'\0';
|
||||
return (c && (c > str)) ? *(c - 1) : L'\0';
|
||||
}
|
||||
__forceinline wchar_t _wcsgetnext(const wchar_t* c)
|
||||
__forceinline wchar_t _wcsgetnext(LPCWSTR c)
|
||||
{
|
||||
return (c && *c) ? *(c + 1) : L'\0';
|
||||
}
|
||||
|
||||
static void _PathFixBackslashes(const wchar_t* pstrg)
|
||||
static void _PathFixBackslashes(LPCWSTR pstrg)
|
||||
{
|
||||
wchar_t* c = wcschr(pstrg, L'/');
|
||||
LPWSTR c = wcschr(pstrg, L'/');
|
||||
while (c) {
|
||||
if ((_wcsgetprev(pstrg, c) == L':') && (_wcsgetnext(c) == L'/')) {
|
||||
c += 2;
|
||||
@ -317,7 +317,7 @@ static void PrependLongPathPrefix(HPATHL hpth_in_out, bool bForce)
|
||||
return;
|
||||
|
||||
if (bForce || !HasOptInToRemoveMaxPathLimit()) {
|
||||
if (bForce || (StrgGetLength(hstr_io) >= MAX_PATH)) {
|
||||
if (bForce || (StrgGetLength(hstr_io) >= MAX_PATH_EXPLICIT)) {
|
||||
if (StrgFind(hstr_io, PATHLONG_PREFIX, 0) != 0) {
|
||||
StrgInsert(hstr_io, 0, PATHLONG_PREFIX);
|
||||
}
|
||||
@ -332,7 +332,7 @@ static void _UnExpandEnvStrgs(HSTRINGW hstr_in_out)
|
||||
if (!hstr_in_out) {
|
||||
return;
|
||||
}
|
||||
const wchar_t* env_var_list[] = {
|
||||
LPCWSTR env_var_list[] = {
|
||||
L"ALLUSERSPROFILE",
|
||||
L"APPDATA",
|
||||
L"LOCALAPPDATA",
|
||||
@ -354,7 +354,7 @@ static void _UnExpandEnvStrgs(HSTRINGW hstr_in_out)
|
||||
|
||||
DWORD const len = GetEnvironmentVariableW(env_var_list[i], NULL, 0);
|
||||
if (len > 0) {
|
||||
wchar_t* buf = StrgWriteAccessBuf(htmp_str, len);
|
||||
LPWSTR buf = StrgWriteAccessBuf(htmp_str, len);
|
||||
if (buf) {
|
||||
GetEnvironmentVariableW(env_var_list[i], buf, len);
|
||||
size_t const hstr_len = StrgGetLength(hstr_in_out);
|
||||
@ -381,7 +381,7 @@ static bool _PathCanonicalize(HSTRINGW hstr_in_out)
|
||||
return false;
|
||||
}
|
||||
|
||||
wchar_t* const path = StrgWriteAccessBuf(hstr_in_out, 0);
|
||||
LPWSTR const path = StrgWriteAccessBuf(hstr_in_out, 0);
|
||||
size_t const cch = StrgGetAllocLength(hstr_in_out);
|
||||
|
||||
// Replace forward slashes with backslashes
|
||||
@ -538,9 +538,9 @@ static bool _PathCanonicalize(HSTRINGW hstr_in_out)
|
||||
// ----------------------------------------------------------
|
||||
//
|
||||
|
||||
static const wchar_t* _Path_SkipLPPrefix(const HPATHL hpth)
|
||||
static LPCWSTR _Path_SkipLPPrefix(const HPATHL hpth)
|
||||
{
|
||||
const wchar_t* start = PathGet(hpth);
|
||||
LPCWSTR start = PathGet(hpth);
|
||||
if (wcsstr(start, PATHLONG_PREFIX) == start) {
|
||||
start += wcslen(PATHLONG_PREFIX) + 1;
|
||||
}
|
||||
@ -548,7 +548,7 @@ static const wchar_t* _Path_SkipLPPrefix(const HPATHL hpth)
|
||||
}
|
||||
|
||||
|
||||
static const wchar_t* _Path_IsValidUNC(const HPATHL hpth, bool* isUNC_out)
|
||||
static LPCWSTR _Path_IsValidUNC(const HPATHL hpth, bool* isUNC_out)
|
||||
{
|
||||
if (!hpth) {
|
||||
return NULL; // false
|
||||
@ -558,8 +558,8 @@ static const wchar_t* _Path_IsValidUNC(const HPATHL hpth, bool* isUNC_out)
|
||||
return PathGet(hpth);
|
||||
}
|
||||
|
||||
const wchar_t* start = PathGet(hpth);
|
||||
const wchar_t* const endz = start + Path_GetLength(hpth); // terminating zero (L'\0')
|
||||
LPCWSTR start = PathGet(hpth);
|
||||
LPCWSTR const endz = start + Path_GetLength(hpth); // terminating zero (L'\0')
|
||||
|
||||
|
||||
bool isUncOrNetShare = false;
|
||||
@ -585,7 +585,7 @@ static const wchar_t* _Path_IsValidUNC(const HPATHL hpth, bool* isUNC_out)
|
||||
if (isUncOrNetShare) {
|
||||
|
||||
// skip <server-name>
|
||||
const wchar_t* nextbs = wcschr(start, L'\\');
|
||||
LPCWSTR nextbs = wcschr(start, L'\\');
|
||||
isUncOrNetShare = (nextbs && (nextbs > start));
|
||||
start = isUncOrNetShare ? (nextbs + 1) : endz;
|
||||
|
||||
@ -604,9 +604,9 @@ static const wchar_t* _Path_IsValidUNC(const HPATHL hpth, bool* isUNC_out)
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#if 0
|
||||
__forceinline const wchar_t* _Path_SkipRoot(const HPATHL hpth)
|
||||
__forceinline LPCWSTR _Path_SkipRoot(const HPATHL hpth)
|
||||
{
|
||||
const wchar_t* path = NULL;
|
||||
LPCWSTR path = NULL;
|
||||
if (SUCCEEDED(PathCchSkipRoot(Path_Get(hpth), &path))) {
|
||||
assert(path != PathGet(hpth));
|
||||
return path; // *root == L'\0' => PathCchIsRoot()==TRUE
|
||||
@ -618,7 +618,7 @@ __forceinline const wchar_t* _Path_SkipRoot(const HPATHL hpth)
|
||||
//
|
||||
// needs converted forward slashes
|
||||
//
|
||||
static const wchar_t* _Path_SkipRoot(const HPATHL hpth)
|
||||
static LPCWSTR _Path_SkipRoot(const HPATHL hpth)
|
||||
{
|
||||
if (!hpth) {
|
||||
assert(hpth);
|
||||
@ -630,8 +630,8 @@ static const wchar_t* _Path_SkipRoot(const HPATHL hpth)
|
||||
}
|
||||
|
||||
bool isUncOrNetShare = false;
|
||||
const wchar_t* start = _Path_IsValidUNC(hpth, &isUncOrNetShare);
|
||||
const wchar_t* const endz = start + Path_GetLength(hpth); // terminating zero (L'\0')
|
||||
LPCWSTR start = _Path_IsValidUNC(hpth, &isUncOrNetShare);
|
||||
LPCWSTR const endz = start + Path_GetLength(hpth); // terminating zero (L'\0')
|
||||
|
||||
if (*start && (*(start + 1) == L':')) { // has drive letter
|
||||
start += 2;
|
||||
@ -658,15 +658,15 @@ static bool _Path_IsRelative(const HPATHL hpth)
|
||||
if (!hstr)
|
||||
return true; // empty is relative
|
||||
|
||||
const wchar_t* const skip = _Path_SkipLPPrefix(hpth);
|
||||
LPCWSTR const skip = _Path_SkipLPPrefix(hpth);
|
||||
|
||||
bool res = false;
|
||||
if (StrgGetLength(hstr) >= MAX_PATH) {
|
||||
// hack for MAX_PATH limit
|
||||
wchar_t const wch = StrgGetAt(hstr, MAX_PATH);
|
||||
StrgSetAt(hstr, MAX_PATH, L'\0');
|
||||
if (StrgGetLength(hstr) >= MAX_PATH_EXPLICIT) {
|
||||
// hack for MAX_PATH_EXPLICIT limit
|
||||
wchar_t const wch = StrgGetAt(hstr, MAX_PATH_EXPLICIT);
|
||||
StrgSetAt(hstr, MAX_PATH_EXPLICIT, L'\0');
|
||||
res = PathIsRelativeW(skip);
|
||||
StrgSetAt(hstr, MAX_PATH, wch);
|
||||
StrgSetAt(hstr, MAX_PATH_EXPLICIT, wch);
|
||||
}
|
||||
else {
|
||||
res = PathIsRelativeW(skip);
|
||||
@ -683,7 +683,7 @@ static bool _Path_IsRelative(const HPATHL hpth)
|
||||
/* */
|
||||
/**************************************************/
|
||||
|
||||
HPATHL PTHAPI Path_Allocate(const wchar_t* path)
|
||||
HPATHL PTHAPI Path_Allocate(LPCWSTR path)
|
||||
{
|
||||
return (HPATHL)StrgCreate(path);
|
||||
}
|
||||
@ -704,7 +704,7 @@ void PTHAPI Path_Empty(HPATHL hpth_in_out, bool truncate)
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
int PTHAPI Path_Reset(HPATHL hpth_in_out, const wchar_t* path)
|
||||
int PTHAPI Path_Reset(HPATHL hpth_in_out, LPCWSTR path)
|
||||
{
|
||||
return (path ? StrgReset(ToHStrgW(hpth_in_out), path) : 0);
|
||||
}
|
||||
@ -725,7 +725,7 @@ HPATHL PTHAPI Path_Copy(const HPATHL hpth)
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
bool PTHAPI Path_Append(HPATHL hpth_in_out, const wchar_t* more)
|
||||
bool PTHAPI Path_Append(HPATHL hpth_in_out, LPCWSTR more)
|
||||
{
|
||||
HSTRINGW hstr_io = ToHStrgW(hpth_in_out);
|
||||
if (!hstr_io)
|
||||
@ -737,7 +737,7 @@ bool PTHAPI Path_Append(HPATHL hpth_in_out, const wchar_t* more)
|
||||
return true;
|
||||
}
|
||||
|
||||
wchar_t* const wbuf = StrgWriteAccessBuf(hstr_io, hstr_len + hmore_len + wcslen(PATHLONG_PREFIX) + 2);
|
||||
LPWSTR const wbuf = StrgWriteAccessBuf(hstr_io, hstr_len + hmore_len + wcslen(PATHLONG_PREFIX) + 2);
|
||||
size_t const cch = StrgGetAllocLength(hstr_io);
|
||||
|
||||
// append directory separator
|
||||
@ -799,7 +799,7 @@ bool PTHAPI Path_Canonicalize(HPATHL hpth_in_out)
|
||||
HPATHL hpth_cpy = Path_Allocate(PathGet(hpth_in_out));
|
||||
HSTRINGW hstr_cpy = ToHStrgW(hpth_cpy);
|
||||
|
||||
wchar_t* const buf = StrgWriteAccessBuf(hstr_cpy, 0);
|
||||
LPWSTR const buf = StrgWriteAccessBuf(hstr_cpy, 0);
|
||||
if (buf) {}
|
||||
|
||||
//~ PathXCchCanonicalizeEx() does not convert forward slashes (/) into back slashes (\).
|
||||
@ -945,7 +945,7 @@ bool PTHAPI Path_RemoveFileSpec(HPATHL hpth_in_out)
|
||||
LPWSTR wbuf = StrgWriteAccessBuf(hstr_io, 0); // no need to ReAlloc
|
||||
//size_t cch = StrgGetAllocLength(hstr_io);
|
||||
|
||||
const wchar_t* pfile = Path_FindFileName(hpth_in_out);
|
||||
LPCWSTR pfile = Path_FindFileName(hpth_in_out);
|
||||
|
||||
if (pfile > wbuf) {
|
||||
StrgDelete(hstr_io, (size_t)(pfile - wbuf), StrgGetLength(hstr_io));
|
||||
@ -963,8 +963,8 @@ bool PTHAPI Path_StripPath(HPATHL hpth) // get filename only
|
||||
if (!hstr)
|
||||
return false;
|
||||
|
||||
const wchar_t* wbuf = StrgWriteAccessBuf(hstr, 0);
|
||||
const wchar_t* pfile = Path_FindFileName(hpth);
|
||||
LPCWSTR wbuf = StrgWriteAccessBuf(hstr, 0);
|
||||
LPCWSTR pfile = Path_FindFileName(hpth);
|
||||
|
||||
size_t const idx = (size_t)(wbuf - pfile);
|
||||
if (idx != 0) {
|
||||
@ -976,7 +976,7 @@ bool PTHAPI Path_StripPath(HPATHL hpth) // get filename only
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
bool PTHAPI Path_RenameExtension(HPATHL hpth_in_out, const wchar_t* ext)
|
||||
bool PTHAPI Path_RenameExtension(HPATHL hpth_in_out, LPCWSTR ext)
|
||||
{
|
||||
HSTRINGW hstr_io = ToHStrgW(hpth_in_out);
|
||||
if (!hstr_io)
|
||||
@ -994,7 +994,7 @@ bool PTHAPI Path_RenameExtension(HPATHL hpth_in_out, const wchar_t* ext)
|
||||
size_t cch = StrgGetAllocLength(hstr_io);
|
||||
|
||||
///bool const bOK = SUCCEEDED(PathXCchRenameExtension(wbuf, cch, (ext ? ext : L"")));
|
||||
wchar_t* const pdot = (wchar_t*)Path_FindExtension(hpth_in_out);
|
||||
LPWSTR const pdot = (LPWSTR)Path_FindExtension(hpth_in_out);
|
||||
if (pdot) {
|
||||
*pdot = L'\0';
|
||||
}
|
||||
@ -1054,7 +1054,7 @@ void PTHAPI Path_GetModuleFilePath(HPATHL hpth_out)
|
||||
|
||||
if (!mod_path) {
|
||||
mod_path = Path_Allocate(NULL);
|
||||
wchar_t* const buf = Path_WriteAccessBuf(mod_path, PATHLONG_MAX_CCH);
|
||||
LPWSTR const buf = Path_WriteAccessBuf(mod_path, PATHLONG_MAX_CCH);
|
||||
GetModuleFileNameW(NULL, buf, PATHLONG_MAX_CCH);
|
||||
Path_Sanitize(mod_path);
|
||||
Path_CanonicalizeEx(mod_path);
|
||||
@ -1131,10 +1131,10 @@ size_t PTHAPI Path_CommonPrefix(const HPATHL hpth1, const HPATHL hpth2, HPATHL h
|
||||
|
||||
HSTRINGW hout_str = ToHStrgW(hpfx_out);
|
||||
bool const cpy_out = (hout_str != NULL);
|
||||
wchar_t* const out_buf = cpy_out ? StrgWriteAccessBuf(hout_str, ovl_cnt + 1) : NULL;
|
||||
LPWSTR const out_buf = cpy_out ? StrgWriteAccessBuf(hout_str, ovl_cnt + 1) : NULL;
|
||||
|
||||
const wchar_t* p1 = StrgGet(hpth1_str);
|
||||
const wchar_t* p2 = StrgGet(hpth2_str);
|
||||
LPCWSTR p1 = StrgGet(hpth1_str);
|
||||
LPCWSTR p2 = StrgGet(hpth2_str);
|
||||
|
||||
size_t cnt = 0;
|
||||
while (p1 && p2 && (*p1 == *p2) && (cnt < ovl_cnt)) {
|
||||
@ -1160,7 +1160,7 @@ size_t PTHAPI Path_CommonPrefix(const HPATHL hpth1, const HPATHL hpth2, HPATHL h
|
||||
// precedes the extension within pszPath.
|
||||
// If no extension is found, it points to the string's terminating null character.
|
||||
//
|
||||
const wchar_t* PTHAPI Path_FindExtension(const HPATHL hpth)
|
||||
LPCWSTR PTHAPI Path_FindExtension(const HPATHL hpth)
|
||||
{
|
||||
HSTRINGW hstr = ToHStrgW(hpth);
|
||||
if (!hstr)
|
||||
@ -1170,8 +1170,8 @@ const wchar_t* PTHAPI Path_FindExtension(const HPATHL hpth)
|
||||
//size_t const cch = StrgGetAllocLength(hstr);
|
||||
|
||||
///PathXCchFindExtension(StrgGet(hstr), StrgGetAllocLength(hstr), &pext);
|
||||
const wchar_t* pfile = Path_FindFileName(hpth);
|
||||
wchar_t* const pdot = pfile ? wcschr(pfile, L'.') : NULL;
|
||||
LPCWSTR pfile = Path_FindFileName(hpth);
|
||||
LPWSTR const pdot = pfile ? wcschr(pfile, L'.') : NULL;
|
||||
|
||||
StrgSanitize(hstr);
|
||||
return pdot ? pdot : &wbuf[StrgGetLength(hstr)];
|
||||
@ -1179,20 +1179,20 @@ const wchar_t* PTHAPI Path_FindExtension(const HPATHL hpth)
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
const wchar_t* PTHAPI Path_FindFileName(const HPATHL hpth)
|
||||
LPCWSTR PTHAPI Path_FindFileName(const HPATHL hpth)
|
||||
{
|
||||
HSTRINGW hstr = ToHStrgW(hpth);
|
||||
if (!hstr)
|
||||
return NULL;
|
||||
|
||||
const wchar_t* pstart = _Path_SkipRoot(hpth);
|
||||
LPCWSTR pstart = _Path_SkipRoot(hpth);
|
||||
if (!pstart || *pstart == L'\0') {
|
||||
return pstart;
|
||||
}
|
||||
|
||||
///bool const res = SUCCEEDED(PathXCchRemoveFileSpec(wbuf, cch));
|
||||
const wchar_t* const plbs = wcsrchr(pstart, L'\\');
|
||||
const wchar_t* const plfs = wcsrchr(pstart, L'/');
|
||||
LPCWSTR const plbs = wcsrchr(pstart, L'\\');
|
||||
LPCWSTR const plfs = wcsrchr(pstart, L'/');
|
||||
if (plbs || plfs) {
|
||||
if (plbs && plfs) {
|
||||
if (plbs >= plfs) {
|
||||
@ -1249,7 +1249,7 @@ int PTHAPI Path_GetDriveNumber(const HPATHL hpth)
|
||||
if (!hstr)
|
||||
return res;
|
||||
|
||||
wchar_t* const colon = wcschr(StrgGet(hstr), L':');
|
||||
LPWSTR const colon = wcschr(StrgGet(hstr), L':');
|
||||
|
||||
if (colon && (colon > StrgGet(hstr))) {
|
||||
res = max_i(-1, ((int)_wcsupr_s((colon - 1), 1) - (int)L'A'));
|
||||
@ -1301,7 +1301,7 @@ bool PTHAPI Path_GetCurrentDirectory(HPATHL hpth_out)
|
||||
if (!wrk_path) {
|
||||
wrk_path = Path_Allocate(NULL);
|
||||
HSTRINGW const hwrk_str = ToHStrgW(wrk_path);
|
||||
wchar_t* const buf = StrgWriteAccessBuf(hwrk_str, PATHLONG_MAX_CCH);
|
||||
LPWSTR const buf = StrgWriteAccessBuf(hwrk_str, PATHLONG_MAX_CCH);
|
||||
GetCurrentDirectoryW(PATHLONG_MAX_CCH, buf);
|
||||
StrgSanitize(hwrk_str);
|
||||
StrgFreeExtra(hwrk_str, 0);
|
||||
@ -1323,7 +1323,7 @@ size_t PTHAPI Path_ToShortPathName(HPATHL hpth_in_out)
|
||||
if (!_len)
|
||||
return false;
|
||||
|
||||
wchar_t* const buf = StrgWriteAccessBuf(hstr_io, _len);
|
||||
LPWSTR const buf = StrgWriteAccessBuf(hstr_io, _len);
|
||||
|
||||
DWORD const len = GetShortPathNameW(buf, buf, (DWORD)StrgGetAllocLength(hstr_io));
|
||||
StrgSanitize(hstr_io);
|
||||
@ -1342,13 +1342,13 @@ size_t PTHAPI Path_GetLongPathNameEx(HPATHL hpth_in_out)
|
||||
PrependLongPathPrefix(hpth_in_out, false); // TODO: check or true ?
|
||||
|
||||
DWORD const len = GetLongPathNameW(StrgGet(hstr_io), NULL, 0);
|
||||
wchar_t* const buf = StrgWriteAccessBuf(hstr_io, len);
|
||||
LPWSTR const buf = StrgWriteAccessBuf(hstr_io, len);
|
||||
|
||||
size_t const res = (size_t)GetLongPathNameW(buf, buf, len);
|
||||
StrgSanitize(hstr_io);
|
||||
|
||||
if (res > 2ULL) {
|
||||
wchar_t* const pos = wcschr(buf, L':');
|
||||
LPWSTR const pos = wcschr(buf, L':');
|
||||
if (pos && (pos > buf)) {
|
||||
CharUpperBuffW(pos - 1, 1);
|
||||
}
|
||||
@ -1434,7 +1434,7 @@ bool PTHAPI Path_GetLnkPath(const HPATHL hLnkFilePth, HPATHL hResPath_out)
|
||||
if (NOERROR == psl->lpVtbl->GetPath(psl, res_buf, (int)Path_GetBufCount(hres_pth), &fd, 0)) {
|
||||
Path_Sanitize(hres_pth);
|
||||
if (hResPath_out) {
|
||||
Path_FreeExtra(hres_pth, MAX_PATH);
|
||||
Path_FreeExtra(hres_pth, MAX_PATH_EXPLICIT);
|
||||
Path_Swap(hResPath_out, hres_pth);
|
||||
}
|
||||
// This additional check seems reasonable
|
||||
@ -1531,7 +1531,7 @@ bool PTHAPI Path_CreateFavLnk(LPCWSTR lpszDisplayName, const HPATHL hTargetPth,
|
||||
IPersistFile* ppf = NULL;
|
||||
if (SUCCEEDED(psl->lpVtbl->QueryInterface(psl, &IID_IPersistFile, (void**)&ppf)))
|
||||
{
|
||||
/*MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,tchLnkFileName,-1,wsz,MAX_PATH);*/
|
||||
/*MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,tchLnkFileName,-1,wsz,MAX_PATH_EXPLICIT);*/
|
||||
|
||||
psl->lpVtbl->SetPath(psl, Path_Get(hTargetPth));
|
||||
|
||||
@ -1588,7 +1588,7 @@ bool PTHAPI Path_CreateDeskLnk(const HPATHL hDocumentPath, LPCWSTR pszDescriptio
|
||||
|
||||
IPersistFile* ppf = NULL;
|
||||
if (SUCCEEDED(psl->lpVtbl->QueryInterface(psl, &IID_IPersistFile, (void**)&ppf))) {
|
||||
/*MultiByteToWideCharEx(CP_ACP,MB_PRECOMPOSED,tchLnkFileName,-1,wsz,MAX_PATH);*/
|
||||
/*MultiByteToWideCharEx(CP_ACP,MB_PRECOMPOSED,tchLnkFileName,-1,wsz,MAX_PATH_EXPLICIT);*/
|
||||
psl->lpVtbl->SetPath(psl, Path_Get(hmod_pth));
|
||||
psl->lpVtbl->SetArguments(psl, StrgGet(hargs_str));
|
||||
psl->lpVtbl->SetDescription(psl, pszDescription);
|
||||
@ -1668,7 +1668,7 @@ bool PTHAPI Path_BrowseDirectory(HWND hwndParent, LPCWSTR lpszTitle, HPATHL hpth
|
||||
LPWSTR const pth_buf = Path_WriteAccessBuf(hpth_in_out, PATHLONG_MAX_CCH);
|
||||
SHGetPathFromIDListW(pidl, pth_buf);
|
||||
Path_Sanitize(hpth_in_out);
|
||||
Path_FreeExtra(hpth_in_out, MAX_PATH);
|
||||
Path_FreeExtra(hpth_in_out, MAX_PATH_EXPLICIT);
|
||||
CoTaskMemFree(pidl);
|
||||
res = true;
|
||||
}
|
||||
@ -1735,7 +1735,7 @@ size_t PTHAPI Path_NormalizeEx(HPATHL hpth_in_out, const HPATHL hpth_wrkdir, boo
|
||||
if (!Path_IsExistingFile(hsrch_pth)) {
|
||||
Path_StripPath(hsrch_pth);
|
||||
HSTRINGW hsrch_str = StrgCreate(NULL);
|
||||
wchar_t* const buf = StrgWriteAccessBuf(hsrch_str, PATHLONG_MAX_CCH);
|
||||
LPWSTR const buf = StrgWriteAccessBuf(hsrch_str, PATHLONG_MAX_CCH);
|
||||
if (SearchPathW(NULL, PathGet(hsrch_pth), NULL, PATHLONG_MAX_CCH, buf, NULL) != 0) {
|
||||
//~StrgSanitize(hsrch_str);
|
||||
Path_Reset(hpth_in_out, buf);
|
||||
@ -1760,7 +1760,7 @@ size_t PTHAPI Path_NormalizeEx(HPATHL hpth_in_out, const HPATHL hpth_wrkdir, boo
|
||||
|
||||
if (bRealPath) {
|
||||
// get real path name (based on version developed by zufuliu)
|
||||
const wchar_t* const path_io = PathGet(hpth_in_out);
|
||||
LPCWSTR const path_io = PathGet(hpth_in_out);
|
||||
HANDLE const hFile = CreateFileW(path_io, // file to open
|
||||
GENERIC_READ, // open for reading
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE, // share anyway
|
||||
@ -1772,13 +1772,13 @@ size_t PTHAPI Path_NormalizeEx(HPATHL hpth_in_out, const HPATHL hpth_wrkdir, boo
|
||||
if (IS_VALID_HANDLE(hFile)) {
|
||||
|
||||
HSTRINGW hstr = StrgCreate(NULL);
|
||||
wchar_t* const buf = StrgWriteAccessBuf(hstr, PATHLONG_MAX_CCH);
|
||||
LPWSTR const buf = StrgWriteAccessBuf(hstr, PATHLONG_MAX_CCH);
|
||||
|
||||
if (GetFinalPathNameByHandleW(hFile, buf, PATHLONG_MAX_CCH, FILE_NAME_OPENED) > 0) {
|
||||
StrgSanitize(hstr);
|
||||
wchar_t* ptr = buf;
|
||||
LPWSTR ptr = buf;
|
||||
// remove prefix
|
||||
if ((wcslen(buf) < MAX_PATH) || HasOptInToRemoveMaxPathLimit()) {
|
||||
if ((wcslen(buf) < MAX_PATH_EXPLICIT) || HasOptInToRemoveMaxPathLimit()) {
|
||||
if ((wcsstr(ptr, PATHUNC_PREFIX1) == ptr) ||
|
||||
(wcsstr(ptr, PATHUNC_PREFIX2) == ptr)) {
|
||||
ptr += (wcslen(PATHUNC_PREFIX1) - 1);
|
||||
@ -1801,8 +1801,7 @@ size_t PTHAPI Path_NormalizeEx(HPATHL hpth_in_out, const HPATHL hpth_wrkdir, boo
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// _Path_RelativePathTo()
|
||||
// TODO: make LongPath version instead of slicing MAX_PATH
|
||||
// Path_RelativePathTo()
|
||||
//
|
||||
static bool _Path_RelativePathTo(HPATHL hrecv, const HPATHL hfrom, DWORD attr_from, const HPATHL hto, DWORD attr_to)
|
||||
{
|
||||
@ -1838,8 +1837,8 @@ static bool _Path_RelativePathTo(HPATHL hrecv, const HPATHL hfrom, DWORD attr_fr
|
||||
Path_Canonicalize(hto_cpy);
|
||||
|
||||
// get first diff
|
||||
const wchar_t* hfrom_buf = PathGet(hfrom_cpy);
|
||||
const wchar_t* hto_buf = PathGet(hto_cpy);
|
||||
LPCWSTR hfrom_buf = PathGet(hfrom_cpy);
|
||||
LPCWSTR hto_buf = PathGet(hto_cpy);
|
||||
size_t const hfrom_len = StrlenW(hfrom_buf);
|
||||
size_t const hto_len = StrlenW(hto_buf);
|
||||
size_t const max_cmp = min_s(hfrom_len, hto_len);
|
||||
@ -1851,9 +1850,9 @@ static bool _Path_RelativePathTo(HPATHL hrecv, const HPATHL hfrom, DWORD attr_fr
|
||||
}
|
||||
|
||||
// check for root prefix
|
||||
const wchar_t* r = _Path_SkipRoot(hfrom_cpy);
|
||||
LPCWSTR r = _Path_SkipRoot(hfrom_cpy);
|
||||
bool const root_f = (r != hfrom_buf);
|
||||
const wchar_t* s = _Path_SkipRoot(hto_cpy);
|
||||
LPCWSTR s = _Path_SkipRoot(hto_cpy);
|
||||
bool const root_t = (s != hto_buf);
|
||||
size_t const lenf = (r - hfrom_buf);
|
||||
size_t const lent = (s - hto_buf);
|
||||
@ -1863,7 +1862,7 @@ static bool _Path_RelativePathTo(HPATHL hrecv, const HPATHL hfrom, DWORD attr_fr
|
||||
if (same_root) {
|
||||
|
||||
// back to prev sync point
|
||||
const wchar_t* p = &hfrom_buf[i];
|
||||
LPCWSTR p = &hfrom_buf[i];
|
||||
while (p > r) {
|
||||
if ((*p == L'\\') || (*p == L':')) {
|
||||
break;
|
||||
@ -1888,7 +1887,7 @@ static bool _Path_RelativePathTo(HPATHL hrecv, const HPATHL hfrom, DWORD attr_fr
|
||||
|
||||
size_t const alloc_add = wcslen(&hto_buf[prefix]) + 1;
|
||||
size_t const len = (wcslen(PATHPARENT_PREFIX) * dir_cnt) + alloc_add;
|
||||
wchar_t* const out_buf = StrgWriteAccessBuf(hrecv_str, len);
|
||||
LPWSTR const out_buf = StrgWriteAccessBuf(hrecv_str, len);
|
||||
for (size_t d = 0; d < dir_cnt; ++d) {
|
||||
StringCchCatW(out_buf, len, PATHPARENT_PREFIX);
|
||||
}
|
||||
@ -2122,35 +2121,6 @@ void PTHAPI PathAbsoluteFromApp(LPWSTR lpszPath, const size_t cchPath, bool bExp
|
||||
Path_Release(hpth_in_out);
|
||||
}
|
||||
|
||||
|
||||
// ============================================================================
|
||||
// try to minimize use of:
|
||||
// ============================================================================
|
||||
|
||||
const wchar_t* PTHAPI Path_Get(HPATHL hpth)
|
||||
{
|
||||
return StrgGet((HSTRINGW)hpth);
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
size_t PTHAPI Path_GetBufCount(HPATHL hpth)
|
||||
{
|
||||
return StrgGetAllocLength((HSTRINGW)hpth);
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// get wchar buffer with at least MAX_PATH size
|
||||
// TODO: get rid of this intermediate state handler
|
||||
wchar_t* PTHAPI Path_WriteAccessBuf(HPATHL hpth, size_t len)
|
||||
{
|
||||
return StrgWriteAccessBuf((HSTRINGW)hpth, max(len, MAX_PATH));
|
||||
}
|
||||
|
||||
void PTHAPI Path_Sanitize(HPATHL hpth)
|
||||
{
|
||||
StrgSanitize((HSTRINGW)hpth);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// ============================================================================
|
||||
|
||||
|
||||
@ -27,9 +27,24 @@
|
||||
// PATHCCH_MAX_CCH: (0x7FFF + 1 for NULL terminator)
|
||||
#define PATHLONG_MAX_CCH 0x8000
|
||||
|
||||
// TODO: §§§ @@@ check for LongPath MAX_PATH §§§ @@@
|
||||
// - explicitly use MAX_PATH vs. PATHLONG_MAX_CCH
|
||||
#define MAX_PATH_EXPLICIT MAX_PATH
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
__forceinline size_t max_sz(const size_t x, const size_t y) { return (x < y) ? y : x; }
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
__forceinline LPCWSTR PTHAPI Path_Get(HPATHL hpth)
|
||||
{
|
||||
return StrgGet((HSTRINGW)hpth);
|
||||
}
|
||||
|
||||
__forceinline size_t PTHAPI Path_GetBufCount(HPATHL hpth)
|
||||
{
|
||||
return StrgGetAllocLength((HSTRINGW)hpth);
|
||||
}
|
||||
|
||||
__forceinline bool IsReadOnly(const DWORD dwFileAttr)
|
||||
{
|
||||
return ((dwFileAttr != INVALID_FILE_ATTRIBUTES) && (dwFileAttr & FILE_ATTRIBUTE_READONLY));
|
||||
@ -45,19 +60,38 @@ __forceinline bool IsExistingDirectory(const DWORD dwFileAttr)
|
||||
return ((dwFileAttr != INVALID_FILE_ATTRIBUTES) && (dwFileAttr & FILE_ATTRIBUTE_DIRECTORY));
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// get wchar buffer with at least MAX_PATH_EXPLICIT size to minimize reallocations
|
||||
// execept for len = 0, where no reallocation (except buffer is NULL) is done
|
||||
__forceinline LPWSTR PTHAPI Path_WriteAccessBuf(HPATHL hpth, size_t len)
|
||||
{
|
||||
return StrgWriteAccessBuf((HSTRINGW)hpth, len ? max_sz(len, MAX_PATH_EXPLICIT) : 0);
|
||||
}
|
||||
|
||||
__forceinline void PTHAPI Path_Sanitize(HPATHL hpth)
|
||||
{
|
||||
StrgSanitize((HSTRINGW)hpth);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
/**************************************************/
|
||||
/* */
|
||||
/* DYNAMIC WIDCHAR LONG PATH */
|
||||
/* */
|
||||
/**************************************************/
|
||||
|
||||
HPATHL PTHAPI Path_Allocate(const wchar_t* path);
|
||||
HPATHL PTHAPI Path_Allocate(LPCWSTR path);
|
||||
void PTHAPI Path_Release(HPATHL hstr);
|
||||
void PTHAPI Path_Empty(HPATHL hpth, bool truncate);
|
||||
int PTHAPI Path_Reset(HPATHL hpth, const wchar_t* path);
|
||||
int PTHAPI Path_Reset(HPATHL hpth, LPCWSTR path);
|
||||
size_t PTHAPI Path_GetLength(HPATHL hpth);
|
||||
HPATHL PTHAPI Path_Copy(const HPATHL hpth);
|
||||
bool PTHAPI Path_Append(HPATHL hpth, const wchar_t* more);
|
||||
bool PTHAPI Path_Append(HPATHL hpth, LPCWSTR more);
|
||||
void PTHAPI Path_Swap(HPATHL hpth1, HPATHL hpth2);
|
||||
void PTHAPI Path_FreeExtra(HPATHL hpth_in_out, size_t keep_length);
|
||||
|
||||
@ -70,7 +104,7 @@ bool PTHAPI Path_IsExistingDirectory(const HPATHL hpth);
|
||||
int PTHAPI Path_StrgComparePath(const HPATHL hpth1, const HPATHL hpth2);
|
||||
bool PTHAPI Path_RemoveBackslash(HPATHL hpth_in_out);
|
||||
bool PTHAPI Path_RemoveFileSpec(HPATHL hpth_in_out);
|
||||
bool PTHAPI Path_RenameExtension(HPATHL hpth, const wchar_t* ext);
|
||||
bool PTHAPI Path_RenameExtension(HPATHL hpth, LPCWSTR ext);
|
||||
void PTHAPI Path_ExpandEnvStrings(HPATHL hpth);
|
||||
void PTHAPI Path_UnExpandEnvStrings(HPATHL hpth);
|
||||
void PTHAPI Path_GetModuleFilePath(HPATHL hpth_out);
|
||||
@ -78,8 +112,8 @@ void PTHAPI Path_GetAppDirectory(HPATHL hpth_out);
|
||||
bool PTHAPI Path_IsRelative(const HPATHL hpath);
|
||||
bool PTHAPI Path_IsPrefix(const HPATHL hprefix, const HPATHL hpth);
|
||||
size_t PTHAPI Path_CommonPrefix(const HPATHL hpth1, const HPATHL hpth2, HPATHL hpfx_out);
|
||||
const wchar_t* PTHAPI Path_FindFileName(const HPATHL hpth);
|
||||
const wchar_t* PTHAPI Path_FindExtension(const HPATHL hpth);
|
||||
LPCWSTR PTHAPI Path_FindFileName(const HPATHL hpth);
|
||||
LPCWSTR PTHAPI Path_FindExtension(const HPATHL hpth);
|
||||
bool PTHAPI Path_QuoteSpaces(HPATHL hpth_in_out, bool bForceQuotes);
|
||||
void PTHAPI Path_UnQuoteSpaces(HPATHL hpth_in_out);
|
||||
int PTHAPI Path_GetDriveNumber(const HPATHL hpth);
|
||||
@ -106,14 +140,6 @@ bool PTHAPI Path_GetKnownFolder(REFKNOWNFOLDERID rfid, HPATHL hpth_ou
|
||||
void PTHAPI ExpandEnvironmentStrgs(HSTRINGW hstr);
|
||||
void PTHAPI Path_ExpandEnvironmentStrings(HPATHL hpth_in_out);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// try to minimize use of:
|
||||
// ----------------------------------------------------------------------------
|
||||
const wchar_t* PTHAPI Path_Get(HPATHL hpth);
|
||||
size_t PTHAPI Path_GetBufCount(HPATHL hpth);
|
||||
wchar_t* PTHAPI Path_WriteAccessBuf(HPATHL hpth, size_t len);
|
||||
void PTHAPI Path_Sanitize(HPATHL hpth);
|
||||
|
||||
|
||||
// ============================================================================
|
||||
// Duplicates for INTERMEDIATE DEV
|
||||
|
||||
Loading…
Reference in New Issue
Block a user