mirror of
https://github.com/rizonesoft/Notepad3.git
synced 2026-06-28 21:02:59 +08:00
some more LongPath handling
This commit is contained in:
parent
1e3d76ab1f
commit
fdd7c4170d
135
src/Dialogs.c
135
src/Dialogs.c
@ -1440,6 +1440,9 @@ CASE_WM_CTLCOLOR_SET:
|
||||
Path_RemoveFileSpec(pthDirectory);
|
||||
}
|
||||
|
||||
Path_ToShortPathName(hfile_pth);
|
||||
Path_ToShortPathName(pthDirectory);
|
||||
|
||||
SHELLEXECUTEINFO sei = { sizeof(SHELLEXECUTEINFO) };
|
||||
sei.fMask = SEE_MASK_DEFAULT;
|
||||
sei.hwnd = hwnd;
|
||||
@ -1452,11 +1455,11 @@ CASE_WM_CTLCOLOR_SET:
|
||||
if (bQuickExit) {
|
||||
sei.fMask |= SEE_MASK_NOZONECHECKS;
|
||||
EndDialog(hwnd, IDOK);
|
||||
ShellExecuteEx(&sei);
|
||||
ShellExecuteExW(&sei);
|
||||
}
|
||||
|
||||
else {
|
||||
if (ShellExecuteEx(&sei)) {
|
||||
if (ShellExecuteExW(&sei)) {
|
||||
EndDialog(hwnd, IDOK);
|
||||
}
|
||||
|
||||
@ -1688,47 +1691,67 @@ CASE_WM_CTLCOLOR_SET:
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// OpenWithDlg() TODO: §§§ MAX_PATH limit §§§ @@@!
|
||||
// OpenWithDlg()
|
||||
//
|
||||
bool OpenWithDlg(HWND hwnd,LPCWSTR lpstrFile)
|
||||
bool OpenWithDlg(HWND hwnd, LPCWSTR lpstrFile)
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
DLITEM dliOpenWith = { 0 };
|
||||
dliOpenWith.mask = DLI_FILENAME;
|
||||
|
||||
HPATHL hpthFileName = Path_Allocate(NULL);
|
||||
dliOpenWith.pthFileName = Path_WriteAccessBuf(hpthFileName, PATHLONG_MAX_CCH);
|
||||
|
||||
HSTRINGW hstrDisplayName = StrgCreate(NULL);
|
||||
dliOpenWith.strDisplayName = StrgWriteAccessBuf(hstrDisplayName, INTERNET_MAX_URL_LENGTH);
|
||||
|
||||
if (IDOK == ThemedDialogBoxParam(Globals.hLngResContainer,MAKEINTRESOURCE(IDD_MUI_OPENWITH),
|
||||
hwnd,OpenWithDlgProc,(LPARAM)&dliOpenWith)) {
|
||||
WCHAR szParam[MAX_PATH] = { L'\0' };
|
||||
|
||||
HPATHL pthDirectory = NULL;
|
||||
StrgSanitize(hstrDisplayName);
|
||||
Path_Sanitize(hpthFileName);
|
||||
|
||||
HPATHL hpthParams = Path_Allocate(NULL);
|
||||
wchar_t* const params_buf = Path_WriteAccessBuf(hpthParams, PATHLONG_MAX_CCH);
|
||||
|
||||
HPATHL hpthDirectory = NULL;
|
||||
if (Path_IsNotEmpty(Paths.CurrentFile)) {
|
||||
pthDirectory = Path_Copy(Paths.CurrentFile);
|
||||
Path_RemoveFileSpec(pthDirectory);
|
||||
hpthDirectory = Path_Copy(Paths.CurrentFile);
|
||||
Path_RemoveFileSpec(hpthDirectory);
|
||||
}
|
||||
|
||||
SHELLEXECUTEINFO sei = { sizeof(SHELLEXECUTEINFO) };
|
||||
sei.fMask = SEE_MASK_DEFAULT;
|
||||
sei.hwnd = hwnd;
|
||||
sei.lpVerb = NULL;
|
||||
sei.lpFile = dliOpenWith.szFileName;
|
||||
sei.lpParameters = szParam;
|
||||
sei.lpDirectory = Path_Get(pthDirectory);
|
||||
sei.nShow = SW_SHOWNORMAL;
|
||||
//else {
|
||||
// pthDirectory = Path_Allocate(NULL);
|
||||
//}
|
||||
|
||||
// resolve links and get short path name
|
||||
if (!(PathIsLnkFile(lpstrFile) && PathGetLnkPath(lpstrFile, szParam, COUNTOF(szParam)))) {
|
||||
StringCchCopy(szParam, COUNTOF(szParam), lpstrFile);
|
||||
if (!(PathIsLnkFile(lpstrFile) && PathGetLnkPath(lpstrFile, params_buf, (int)Path_GetBufCount(hpthParams)))) {
|
||||
StringCchCopy(params_buf, Path_GetBufCount(hpthParams), lpstrFile);
|
||||
}
|
||||
//GetShortPathName(szParam,szParam,sizeof(WCHAR)*COUNTOF(szParam));
|
||||
PathQuoteSpaces(szParam);
|
||||
result = ShellExecuteEx(&sei);
|
||||
Path_Sanitize(hpthParams);
|
||||
Path_ToShortPathName(hpthParams);
|
||||
Path_QuoteSpaces(hpthParams, true);
|
||||
|
||||
Path_Release(pthDirectory);
|
||||
}
|
||||
Path_ToShortPathName(hpthFileName);
|
||||
Path_ToShortPathName(hpthDirectory);
|
||||
|
||||
return result;
|
||||
SHELLEXECUTEINFO sei = { sizeof(SHELLEXECUTEINFO) };
|
||||
sei.fMask = SEE_MASK_DEFAULT;
|
||||
sei.hwnd = hwnd;
|
||||
sei.lpVerb = NULL;
|
||||
sei.lpFile = Path_Get(hpthFileName);
|
||||
sei.lpParameters = Path_Get(hpthParams);
|
||||
sei.lpDirectory = Path_Get(hpthDirectory);
|
||||
sei.nShow = SW_SHOWNORMAL;
|
||||
result = ShellExecuteExW(&sei);
|
||||
|
||||
Path_Release(hpthDirectory);
|
||||
Path_Release(hpthParams);
|
||||
}
|
||||
|
||||
StrgDestroy(hstrDisplayName);
|
||||
Path_Release(hpthFileName);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@ -1925,20 +1948,29 @@ CASE_WM_CTLCOLOR_SET:
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// FavoritesDlg()
|
||||
// FavoritesDlg() MAX_PATH
|
||||
//
|
||||
bool FavoritesDlg(HWND hwnd,LPWSTR lpstrFile)
|
||||
bool FavoritesDlg(HWND hwnd, LPWSTR lpstrFile, size_t cch)
|
||||
{
|
||||
|
||||
DLITEM dliFavorite = { 0 };
|
||||
dliFavorite.mask = DLI_FILENAME;
|
||||
|
||||
HPATHL hpthFileName = Path_Allocate(NULL);
|
||||
dliFavorite.pthFileName = Path_WriteAccessBuf(hpthFileName, PATHLONG_MAX_CCH);
|
||||
|
||||
HSTRINGW hstrDisplayName = StrgCreate(NULL);
|
||||
dliFavorite.strDisplayName = StrgWriteAccessBuf(hstrDisplayName, INTERNET_MAX_URL_LENGTH);
|
||||
|
||||
bool res = false;
|
||||
if (IDOK == ThemedDialogBoxParam(Globals.hLngResContainer,MAKEINTRESOURCE(IDD_MUI_FAVORITES),
|
||||
hwnd,FavoritesDlgProc,(LPARAM)&dliFavorite)) {
|
||||
StringCchCopyN(lpstrFile,MAX_PATH,dliFavorite.szFileName,MAX_PATH);
|
||||
return TRUE;
|
||||
StringCchCopyW(lpstrFile, cch, dliFavorite.pthFileName);
|
||||
res = true;
|
||||
}
|
||||
return FALSE;
|
||||
|
||||
StrgDestroy(hstrDisplayName);
|
||||
Path_Release(hpthFileName);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
@ -4521,22 +4553,29 @@ void DialogNewWindow(HWND hwnd, bool bSaveOnRunTools, const HPATHL hFilePath, WI
|
||||
|
||||
if (Path_IsNotEmpty(hFilePath)) {
|
||||
HPATHL hfile_pth = Path_Copy(hFilePath);
|
||||
Path_ToShortPathName(hfile_pth);
|
||||
Path_QuoteSpaces(hfile_pth, true);
|
||||
StrgCat(hparam_str, Path_Get(hfile_pth));
|
||||
Path_Release(hfile_pth);
|
||||
}
|
||||
|
||||
HPATHL hwrkd_pth = Path_Copy(Paths.WorkingDirectory);
|
||||
Path_ToShortPathName(hwrkd_pth);
|
||||
Path_ToShortPathName(hmod_pth);
|
||||
|
||||
SHELLEXECUTEINFO sei = { sizeof(SHELLEXECUTEINFO) };
|
||||
sei.fMask = SEE_MASK_NOASYNC | SEE_MASK_NOZONECHECKS;
|
||||
sei.hwnd = hwnd;
|
||||
sei.lpVerb = NULL;
|
||||
sei.lpFile = Path_Get(hmod_pth);
|
||||
sei.lpParameters = StrgGet(hparam_str);
|
||||
sei.lpDirectory = Path_Get(Paths.WorkingDirectory);
|
||||
sei.lpDirectory = Path_Get(hwrkd_pth);
|
||||
sei.nShow = SW_SHOWNORMAL;
|
||||
ShellExecuteEx(&sei);
|
||||
ShellExecuteExW(&sei);
|
||||
|
||||
Path_Release(hwrkd_pth);
|
||||
StrgDestroy(hparam_str);
|
||||
Path_Release(hmod_pth);
|
||||
}
|
||||
|
||||
|
||||
@ -4582,17 +4621,16 @@ void DialogFileBrowse(HWND hwnd)
|
||||
Path_Release(hTemp);
|
||||
}
|
||||
|
||||
if (StrIsNotEmpty(param_buf) && Path_IsNotEmpty(Paths.CurrentFile)) {
|
||||
StringCchCat(param_buf, PATHLONG_MAX_CCH, L" ");
|
||||
}
|
||||
|
||||
if (Path_IsNotEmpty(Paths.CurrentFile)) {
|
||||
HPATHL pthTmp = Path_Copy(Paths.CurrentFile);
|
||||
Path_ToShortPathName(pthTmp);
|
||||
Path_QuoteSpaces(pthTmp, true);
|
||||
StringCchCat(param_buf, PATHLONG_MAX_CCH, Path_Get(pthTmp));
|
||||
Path_Release(pthTmp);
|
||||
}
|
||||
|
||||
Path_ToShortPathName(hExeFile);
|
||||
|
||||
SHELLEXECUTEINFO sei = { sizeof(SHELLEXECUTEINFO) };
|
||||
sei.fMask = SEE_MASK_FLAG_NO_UI | SEE_MASK_NOZONECHECKS;
|
||||
sei.hwnd = hwnd;
|
||||
@ -4601,7 +4639,7 @@ void DialogFileBrowse(HWND hwnd)
|
||||
sei.lpParameters = param_buf;
|
||||
sei.lpDirectory = NULL;
|
||||
sei.nShow = SW_SHOWNORMAL;
|
||||
ShellExecuteEx(&sei);
|
||||
ShellExecuteExW(&sei);
|
||||
|
||||
if ((INT_PTR)sei.hInstApp < 32) {
|
||||
InfoBoxLng(MB_ICONWARNING, NULL, IDS_MUI_ERR_BROWSE);
|
||||
@ -4784,6 +4822,7 @@ void DialogGrepWin(HWND hwnd, LPCWSTR searchPattern)
|
||||
if (Path_RelativePathTo(hTemp, hGrepWinDir, FILE_ATTRIBUTE_DIRECTORY, hGrepWinIniPath, FILE_ATTRIBUTE_NORMAL)) {
|
||||
Path_Swap(hGrepWinIniPath, hTemp);
|
||||
}
|
||||
Path_ToShortPathName(hGrepWinIniPath);
|
||||
StrgFormat(hstrParams, L"/portable /content %s /inipath:\"%s\"", StrgGet(hstrOptions), Path_Get(hGrepWinIniPath));
|
||||
} else {
|
||||
StrgFormat(hstrParams, L"/portable /content %s", StrgGet(hstrOptions));
|
||||
@ -4793,6 +4832,9 @@ void DialogGrepWin(HWND hwnd, LPCWSTR searchPattern)
|
||||
//}
|
||||
StrgDestroy(hstrOptions);
|
||||
|
||||
Path_ToShortPathName(hExeFilePath);
|
||||
Path_ToShortPathName(hGrepWinDir);
|
||||
|
||||
SHELLEXECUTEINFO sei = { sizeof(SHELLEXECUTEINFO) };
|
||||
sei.fMask = SEE_MASK_FLAG_NO_UI | SEE_MASK_NOZONECHECKS;
|
||||
sei.hwnd = hwnd;
|
||||
@ -4801,7 +4843,7 @@ void DialogGrepWin(HWND hwnd, LPCWSTR searchPattern)
|
||||
sei.lpParameters = StrgGet(hstrParams);
|
||||
sei.lpDirectory = Path_Get(hGrepWinDir);
|
||||
sei.nShow = SW_SHOWNORMAL;
|
||||
ShellExecuteEx(&sei);
|
||||
ShellExecuteExW(&sei);
|
||||
|
||||
if ((INT_PTR)sei.hInstApp < 32) {
|
||||
InfoBoxLng(MB_ICONWARNING, NULL, IDS_MUI_ERR_GREPWIN);
|
||||
@ -4836,28 +4878,35 @@ void DialogAdminExe(HWND hwnd, bool bExecInstaller)
|
||||
}
|
||||
Path_Sanitize(hexe_pth);
|
||||
|
||||
|
||||
HPATHL hwrkd_pth = Path_Copy(Paths.WorkingDirectory);
|
||||
Path_ToShortPathName(hwrkd_pth);
|
||||
Path_ToShortPathName(hexe_pth);
|
||||
|
||||
SHELLEXECUTEINFO sei = { sizeof(SHELLEXECUTEINFO) };
|
||||
sei.fMask = SEE_MASK_FLAG_NO_UI | SEE_MASK_NOZONECHECKS;
|
||||
sei.hwnd = hwnd;
|
||||
sei.lpVerb = NULL;
|
||||
sei.lpFile = Path_Get(hexe_pth);
|
||||
sei.lpParameters = NULL; // tchParam;
|
||||
sei.lpDirectory = Path_Get(Paths.WorkingDirectory);
|
||||
sei.lpDirectory = Path_Get(hwrkd_pth);
|
||||
sei.nShow = SW_SHOWNORMAL;
|
||||
|
||||
if (bExecInstaller) {
|
||||
ShellExecuteEx(&sei);
|
||||
ShellExecuteExW(&sei);
|
||||
if ((INT_PTR)sei.hInstApp < 32) {
|
||||
WORD const answer = INFOBOX_ANSW(InfoBoxLng(MB_OKCANCEL, L"NoAdminTool", IDS_MUI_ERR_ADMINEXE));
|
||||
if ((IDOK == answer) || (IDYES == answer)) {
|
||||
sei.lpFile = VERSION_UPDATE_CHECK;
|
||||
ShellExecuteEx(&sei);
|
||||
ShellExecuteExW(&sei);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sei.lpFile = VERSION_UPDATE_CHECK;
|
||||
ShellExecuteEx(&sei);
|
||||
ShellExecuteExW(&sei);
|
||||
}
|
||||
|
||||
Path_Release(hwrkd_pth);
|
||||
Path_Release(hexe_pth);
|
||||
}
|
||||
|
||||
|
||||
@ -45,7 +45,7 @@ INT_PTR DisplayCmdLineHelp(HWND hwnd);
|
||||
INT_PTR CALLBACK AboutDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam);
|
||||
INT_PTR RunDlg(HWND hwnd,LPCWSTR lpstrDefault);
|
||||
bool OpenWithDlg(HWND hwnd,LPCWSTR lpstrFile);
|
||||
bool FavoritesDlg(HWND hwnd,LPWSTR lpstrFile);
|
||||
bool FavoritesDlg(HWND hwnd,LPWSTR lpstrFile, size_t cch);
|
||||
bool AddToFavDlg(HWND hwnd,LPCWSTR lpszName,LPCWSTR lpszTarget);
|
||||
bool FileMRUDlg(HWND hwnd,LPWSTR lpstrFile);
|
||||
bool ChangeNotifyDlg(HWND hwnd);
|
||||
|
||||
34
src/Dlapi.c
34
src/Dlapi.c
@ -21,6 +21,7 @@
|
||||
#include <shlwapi.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "PathLib.h"
|
||||
#include "Dlapi.h"
|
||||
|
||||
|
||||
@ -603,13 +604,13 @@ int DirList_GetItem(HWND hwnd,int iItem,LPDLITEM lpdli)
|
||||
if (lpdli->mask & DLI_FILENAME)
|
||||
|
||||
IL_GetDisplayName(lplvid->lpsf,lplvid->pidl,SHGDN_FORPARSING,
|
||||
lpdli->szFileName,MAX_PATH);
|
||||
lpdli->pthFileName, PATHLONG_MAX_CCH);
|
||||
|
||||
// Displayname
|
||||
if (lpdli->mask & DLI_DISPNAME)
|
||||
|
||||
IL_GetDisplayName(lplvid->lpsf,lplvid->pidl,SHGDN_INFOLDER,
|
||||
lpdli->szDisplayName,MAX_PATH);
|
||||
lpdli->strDisplayName, INTERNET_MAX_URL_LENGTH);
|
||||
|
||||
// Type (File / Directory)
|
||||
if (lpdli->mask & DLI_TYPE) {
|
||||
@ -795,14 +796,14 @@ bool DirList_SelectItem(HWND hwnd,LPCWSTR lpszDisplayName,LPCWSTR lpszFullPath)
|
||||
return false;
|
||||
}
|
||||
|
||||
WCHAR szShortPath[MAX_PATH] = { L'\0' };
|
||||
GetShortPathName(lpszFullPath, szShortPath, MAX_PATH);
|
||||
HPATHL hshort_pth = Path_Allocate(lpszFullPath);
|
||||
Path_ToShortPathName(hshort_pth);
|
||||
|
||||
SHFILEINFO shfi = { 0 };
|
||||
if (StrIsEmpty(lpszDisplayName)) {
|
||||
SHGetFileInfo(lpszFullPath, 0, &shfi, sizeof(SHFILEINFO), SHGFI_DISPLAYNAME);
|
||||
SHGetFileInfoW(lpszFullPath, 0, &shfi, sizeof(SHFILEINFO), SHGFI_DISPLAYNAME);
|
||||
} else {
|
||||
StringCchCopyN(shfi.szDisplayName, COUNTOF(shfi.szDisplayName), lpszDisplayName, MAX_PATH);
|
||||
StringCchCopy(shfi.szDisplayName, COUNTOF(shfi.szDisplayName), lpszDisplayName);
|
||||
}
|
||||
LV_FINDINFO lvfi = { 0 };
|
||||
lvfi.flags = LVFI_STRING;
|
||||
@ -811,23 +812,32 @@ bool DirList_SelectItem(HWND hwnd,LPCWSTR lpszDisplayName,LPCWSTR lpszFullPath)
|
||||
DLITEM dli = { 0 };
|
||||
dli.mask = DLI_ALL;
|
||||
|
||||
HPATHL hpthFileName = Path_Allocate(NULL);
|
||||
dli.pthFileName = Path_WriteAccessBuf(hpthFileName, PATHLONG_MAX_CCH);
|
||||
|
||||
HSTRINGW hstrDisplayName = StrgCreate(NULL);
|
||||
dli.strDisplayName = StrgWriteAccessBuf(hstrDisplayName, INTERNET_MAX_URL_LENGTH);
|
||||
|
||||
int i = -1;
|
||||
bool res = false;
|
||||
while ((i = ListView_FindItem(hwnd, i, &lvfi)) != -1) {
|
||||
|
||||
DirList_GetItem(hwnd,i,&dli);
|
||||
GetShortPathName(dli.szFileName,dli.szFileName,MAX_PATH);
|
||||
GetShortPathNameW(dli.pthFileName, dli.pthFileName, (DWORD)Path_GetBufCount(hpthFileName));
|
||||
|
||||
if (!StringCchCompareNI(dli.szFileName,COUNTOF(dli.szFileName),szShortPath,COUNTOF(szShortPath))) {
|
||||
if (StringCchCompareXI(dli.pthFileName, Path_Get(hshort_pth)) == 0) {
|
||||
ListView_SetItemState(hwnd,i,LVIS_FLAGS,LVIS_FLAGS);
|
||||
ListView_EnsureVisible(hwnd,i,false);
|
||||
|
||||
return true;
|
||||
res = true;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
StrgDestroy(hstrDisplayName);
|
||||
Path_Release(hpthFileName);
|
||||
Path_Release(hshort_pth);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -98,8 +98,8 @@ bool DirList_Sort(HWND hwnd,int lFlags,bool);
|
||||
typedef struct tagDLITEM { // dli
|
||||
|
||||
UINT mask;
|
||||
WCHAR szFileName[MAX_PATH];
|
||||
WCHAR szDisplayName[MAX_PATH];
|
||||
wchar_t* pthFileName;
|
||||
wchar_t* strDisplayName;
|
||||
int ntype;
|
||||
|
||||
} DLITEM, *LPDLITEM;
|
||||
|
||||
136
src/Notepad3.c
136
src/Notepad3.c
@ -4349,20 +4349,25 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
|
||||
break;
|
||||
}
|
||||
|
||||
HPATHL hfile = Path_Copy(Paths.CurrentFile);
|
||||
Path_ToShortPathName(hfile);
|
||||
|
||||
HPATHL hdir = Path_Copy(Paths.CurrentFile);
|
||||
Path_RemoveFileSpec(hdir);
|
||||
Path_ToShortPathName(hdir);
|
||||
|
||||
SHELLEXECUTEINFO sei = { sizeof(SHELLEXECUTEINFO) };
|
||||
sei.fMask = SEE_MASK_DEFAULT;
|
||||
sei.hwnd = hwnd;
|
||||
sei.lpVerb = NULL;
|
||||
sei.lpFile = Path_Get(Paths.CurrentFile);
|
||||
sei.lpFile = Path_Get(hfile);
|
||||
sei.lpParameters = NULL;
|
||||
sei.lpDirectory = Path_Get(hdir);
|
||||
sei.nShow = SW_SHOWNORMAL;
|
||||
ShellExecuteEx(&sei);
|
||||
ShellExecuteExW(&sei);
|
||||
|
||||
Path_Release(hdir);
|
||||
Path_Release(hfile);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -4449,13 +4454,20 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
|
||||
break;
|
||||
}
|
||||
|
||||
HPATHL hfile = Path_Copy(Paths.CurrentFile);
|
||||
Path_ToShortPathName(hfile);
|
||||
|
||||
SHELLEXECUTEINFO sei = { sizeof(SHELLEXECUTEINFO) };
|
||||
sei.fMask = SEE_MASK_INVOKEIDLIST;
|
||||
sei.hwnd = hwnd;
|
||||
sei.lpVerb = L"properties";
|
||||
sei.lpFile = Path_Get(Paths.CurrentFile); // TODO: §§§ MAX_PATH limit §§§ @@@!
|
||||
sei.lpFile = Path_Get(hfile);
|
||||
sei.lpParameters = NULL;
|
||||
sei.lpDirectory = NULL;
|
||||
sei.nShow = SW_SHOWNORMAL;
|
||||
ShellExecuteEx(&sei);
|
||||
ShellExecuteExW(&sei);
|
||||
|
||||
Path_Release(hfile);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -4476,8 +4488,8 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
|
||||
case IDM_FILE_OPENFAV:
|
||||
if (FileSave(false, true, false, false, Flags.bPreserveFileModTime)) {
|
||||
HPATHL hfile_pth = Path_Allocate(NULL);
|
||||
wchar_t* const file_buf = Path_WriteAccessBuf(hfile_pth, MAX_PATH); // TODO: §§§ @@@ MAX_PATH
|
||||
if (FavoritesDlg(hwnd, file_buf)) {
|
||||
wchar_t* const file_buf = Path_WriteAccessBuf(hfile_pth, PATHLONG_MAX_CCH);
|
||||
if (FavoritesDlg(hwnd, file_buf, Path_GetBufCount(hfile_pth))) {
|
||||
if (Path_IsLnkToDirectory(hfile_pth, NULL)) {
|
||||
Path_GetLnkPath(hfile_pth, hfile_pth);
|
||||
}
|
||||
@ -4504,16 +4516,22 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
|
||||
|
||||
|
||||
case IDM_FILE_MANAGEFAV: {
|
||||
|
||||
HPATHL hfile = Path_Copy(Settings.FavoritesDir);
|
||||
Path_ToShortPathName(hfile);
|
||||
|
||||
SHELLEXECUTEINFO sei = { sizeof(SHELLEXECUTEINFO) };
|
||||
sei.fMask = SEE_MASK_DEFAULT;
|
||||
sei.hwnd = hwnd;
|
||||
sei.lpVerb = NULL;
|
||||
sei.lpFile = Path_Get(Settings.FavoritesDir);
|
||||
sei.lpFile = Path_Get(hfile);
|
||||
sei.lpParameters = NULL;
|
||||
sei.lpDirectory = NULL;
|
||||
sei.nShow = SW_SHOWNORMAL;
|
||||
// Run favorites directory
|
||||
ShellExecuteEx(&sei);
|
||||
ShellExecuteExW(&sei);
|
||||
|
||||
Path_Release(hfile);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -6489,22 +6507,28 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
|
||||
StrgFormat(hstr_hyplnk, wchWebTemplate, wszSelection);
|
||||
ExpandEnvironmentStrgs(hstr_hyplnk);
|
||||
|
||||
Path_ToShortPathName(hdir);
|
||||
|
||||
if (StrgIsNotEmpty(Settings2.HyperlinkShellExURLWithApp))
|
||||
{
|
||||
HSTRINGW hstr_params = StrgCopy(Settings2.HyperlinkShellExURLCmdLnArgs);
|
||||
StrgReplace(hstr_params, URLPLACEHLDR, StrgGet(hstr_hyplnk));
|
||||
|
||||
HPATHL hfile = Path_Allocate(StrgGet(Settings2.HyperlinkShellExURLWithApp));
|
||||
Path_ToShortPathName(hfile);
|
||||
|
||||
SHELLEXECUTEINFO sei = { sizeof(SHELLEXECUTEINFO) };
|
||||
sei.fMask = SEE_MASK_DEFAULT;
|
||||
sei.hwnd = NULL;
|
||||
sei.lpVerb = NULL;
|
||||
sei.lpFile = StrgGet(Settings2.HyperlinkShellExURLWithApp);
|
||||
sei.lpFile = Path_Get(hfile);
|
||||
sei.lpParameters = StrgGet(hstr_params);
|
||||
sei.lpDirectory = Path_Get(hdir);
|
||||
sei.nShow = SW_SHOWNORMAL;
|
||||
ShellExecuteEx(&sei);
|
||||
ShellExecuteExW(&sei);
|
||||
|
||||
StrgDestroy(hstr_params);
|
||||
Path_Release(hfile);
|
||||
}
|
||||
else {
|
||||
SHELLEXECUTEINFO sei = { sizeof(SHELLEXECUTEINFO) };
|
||||
@ -6515,7 +6539,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
|
||||
sei.lpParameters = NULL;
|
||||
sei.lpDirectory = Path_Get(hdir);
|
||||
sei.nShow = SW_SHOWNORMAL;
|
||||
ShellExecuteEx(&sei);
|
||||
ShellExecuteExW(&sei);
|
||||
}
|
||||
StrgDestroy(hstr_hyplnk);
|
||||
Path_Release(hdir);
|
||||
@ -7556,7 +7580,7 @@ bool HandleHotSpotURLClicked(const DocPos position, const HYPERLINK_OPS operatio
|
||||
HPATHL hDirectory = Path_Allocate(NULL);
|
||||
|
||||
if (UrlIsFileUrl(szTextW)) {
|
||||
// ShellExecuteEx() will handle file-system path correctly for "file://" protocol
|
||||
// ShellExecuteExW() will handle file-system path correctly for "file://" protocol
|
||||
StringCchCopy(szUnEscW, COUNTOF(szUnEscW), chkPreFix);
|
||||
dCch -= (DWORD)lenPfx;
|
||||
PathCreateFromUrl(szTextW, &szUnEscW[lenPfx], &dCch, 0);
|
||||
@ -7570,22 +7594,28 @@ bool HandleHotSpotURLClicked(const DocPos position, const HYPERLINK_OPS operatio
|
||||
Path_RemoveFileSpec(hDirectory);
|
||||
}
|
||||
|
||||
Path_ToShortPathName(hDirectory);
|
||||
|
||||
if (StrgIsNotEmpty(Settings2.HyperlinkShellExURLWithApp)) {
|
||||
|
||||
HSTRINGW hstr_params = StrgCopy(Settings2.HyperlinkShellExURLCmdLnArgs);
|
||||
StrgReplace(hstr_params, URLPLACEHLDR, szUnEscW);
|
||||
|
||||
HPATHL hfile = Path_Allocate(StrgGet(Settings2.HyperlinkShellExURLWithApp));
|
||||
Path_ToShortPathName(hfile);
|
||||
|
||||
SHELLEXECUTEINFO sei = { sizeof(SHELLEXECUTEINFO) };
|
||||
sei.fMask = SEE_MASK_DEFAULT;
|
||||
sei.hwnd = NULL;
|
||||
sei.lpVerb = NULL;
|
||||
sei.lpFile = StrgGet(Settings2.HyperlinkShellExURLWithApp);
|
||||
sei.lpFile = Path_Get(hfile);
|
||||
sei.lpParameters = StrgIsNotEmpty(hstr_params) ? StrgGet(hstr_params) : szUnEscW;
|
||||
sei.lpDirectory = Path_Get(hDirectory);
|
||||
sei.nShow = SW_SHOWNORMAL;
|
||||
bHandled = ShellExecuteEx(&sei);
|
||||
bHandled = ShellExecuteExW(&sei);
|
||||
|
||||
StrgDestroy(hstr_params);
|
||||
Path_Release(hfile);
|
||||
|
||||
} else {
|
||||
|
||||
@ -7599,7 +7629,7 @@ bool HandleHotSpotURLClicked(const DocPos position, const HYPERLINK_OPS operatio
|
||||
sei.lpParameters = NULL;
|
||||
sei.lpDirectory = Path_Get(hDirectory);
|
||||
sei.nShow = SW_SHOWNORMAL;
|
||||
bHandled = ShellExecuteEx(&sei);
|
||||
bHandled = ShellExecuteExW(&sei);
|
||||
}
|
||||
|
||||
Path_Release(hDirectory);
|
||||
@ -11491,50 +11521,68 @@ bool RelaunchElevated(LPCWSTR lpNewCmdLnArgs)
|
||||
return false; // reject initial RelaunchElevated() try
|
||||
}
|
||||
|
||||
STARTUPINFO si = { sizeof(STARTUPINFO) };
|
||||
GetStartupInfo(&si);
|
||||
LPCWSTR lpCmdLine = GetCommandLine();
|
||||
size_t const wlen = StringCchLenW(lpCmdLine, 0) + 2ULL;
|
||||
|
||||
// TODO: §§§ @@@ MAX_PATH and args limit
|
||||
HPATHL hfile = Path_Allocate(NULL);
|
||||
wchar_t* const fbuf = Path_WriteAccessBuf(hfile, PATHLONG_MAX_CCH);
|
||||
|
||||
WCHAR lpExe[MAX_PATH] = { L'\0' };
|
||||
WCHAR szOrigArgs[4096] = { L'\0' };
|
||||
HSTRINGW hstrOrigArgs = StrgCreate(NULL);
|
||||
wchar_t* const arg_buf = StrgWriteAccessBuf(hstrOrigArgs, CMDLN_LENGTH_LIMIT);
|
||||
|
||||
LPWSTR lpCmdLine = GetCommandLine();
|
||||
size_t wlen = StringCchLenW(lpCmdLine, 0) + 2UL;
|
||||
ExtractFirstArgument(lpCmdLine, lpExe, szOrigArgs, (int)wlen);
|
||||
// override
|
||||
GetModuleFileName(NULL, lpExe, COUNTOF(lpExe)); // full path
|
||||
PathCanonicalizeEx(lpExe, COUNTOF(lpExe));
|
||||
if (lpNewCmdLnArgs) {
|
||||
StringCchCopy(szOrigArgs, COUNTOF(szOrigArgs), lpNewCmdLnArgs);
|
||||
ExtractFirstArgument(lpCmdLine, fbuf, arg_buf, min_i((int)wlen, CMDLN_LENGTH_LIMIT));
|
||||
// overrides:
|
||||
Path_GetModuleFilePath(hfile);
|
||||
Path_CanonicalizeEx(hfile);
|
||||
if (StrIsNotEmpty(lpNewCmdLnArgs)) {
|
||||
StringCchCopy(arg_buf, StrgGetAllocLength(hstrOrigArgs), lpNewCmdLnArgs);
|
||||
}
|
||||
size_t const len = StringCchLen(szOrigArgs, 0);
|
||||
szOrigArgs[len] = L' '; // add a space
|
||||
szOrigArgs[len+1] = L'\0'; // ensure termination
|
||||
StrgSanitize(hstrOrigArgs);
|
||||
StrgCat(hstrOrigArgs, L" ");
|
||||
// remove relaunch elevated, we are doing this here already
|
||||
StrCutI(szOrigArgs, L"/u ");
|
||||
StrCutI(szOrigArgs, L"-u ");
|
||||
StrCutIW(arg_buf, L"/u ");
|
||||
StrCutIW(arg_buf, L"-u ");
|
||||
StrgSanitize(hstrOrigArgs);
|
||||
|
||||
WCHAR szArguments[2032] = { L'\0' };
|
||||
if (StrStrI(szOrigArgs, L"/f ") || StrStrI(szOrigArgs, L"-f ") || Path_IsEmpty(Paths.IniFile)) {
|
||||
StringCchCopy(szArguments, COUNTOF(szArguments), szOrigArgs);
|
||||
} else {
|
||||
StringCchPrintf(szArguments, COUNTOF(szArguments), L"/f \"%s\" %s", Path_Get(Paths.IniFile), szOrigArgs);
|
||||
if (!(StrStrIW(arg_buf, L"/f ") || StrStrIW(arg_buf, L"-f ") || Path_IsEmpty(Paths.IniFile))) {
|
||||
|
||||
WCHAR wchIniPath[CMDLN_LENGTH_LIMIT] = { L'\0' };
|
||||
|
||||
HPATHL hini = Path_Copy(Paths.IniFile);
|
||||
Path_ToShortPathName(hini);
|
||||
StringCchPrintf(wchIniPath, COUNTOF(wchIniPath), L"/f \"%s\" ", Path_Get(hini));
|
||||
Path_Release(hini);
|
||||
|
||||
StrgInsert(hstrOrigArgs, 0, wchIniPath);
|
||||
}
|
||||
|
||||
if (StrIsNotEmpty(szArguments)) {
|
||||
bool res = false;
|
||||
if (StrgIsNotEmpty(hstrOrigArgs)) {
|
||||
|
||||
STARTUPINFO si = { sizeof(STARTUPINFO) };
|
||||
GetStartupInfo(&si);
|
||||
|
||||
HPATHL hdir = Path_Copy(Paths.WorkingDirectory);
|
||||
Path_ToShortPathName(hdir);
|
||||
Path_ToShortPathName(hfile);
|
||||
|
||||
SHELLEXECUTEINFO sei = { sizeof(SHELLEXECUTEINFO) };
|
||||
sei.fMask = SEE_MASK_FLAG_NO_UI | SEE_MASK_NOASYNC | SEE_MASK_UNICODE | SEE_MASK_HMONITOR | SEE_MASK_NOZONECHECKS | SEE_MASK_WAITFORINPUTIDLE;
|
||||
sei.hwnd = GetForegroundWindow();
|
||||
sei.hMonitor = MonitorFromWindow(sei.hwnd, MONITOR_DEFAULTTONEAREST);
|
||||
sei.lpVerb = L"runas";
|
||||
sei.lpFile = lpExe;
|
||||
sei.lpParameters = szArguments;
|
||||
sei.lpDirectory = Path_Get(Paths.WorkingDirectory);
|
||||
sei.lpFile = Path_Get(hfile);
|
||||
sei.lpParameters = StrgGet(hstrOrigArgs);
|
||||
sei.lpDirectory = Path_Get(hdir);
|
||||
sei.nShow = si.wShowWindow ? si.wShowWindow : SW_SHOWNORMAL;
|
||||
return ShellExecuteEx(&sei);
|
||||
res = ShellExecuteExW(&sei);
|
||||
|
||||
Path_Release(hdir);
|
||||
}
|
||||
return false;
|
||||
|
||||
StrgDestroy(hstrOrigArgs);
|
||||
Path_Release(hfile);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
100
src/PathLib.c
100
src/PathLib.c
@ -91,6 +91,7 @@
|
||||
// - GetFileAttributesW
|
||||
// - GetFileAttributesExW
|
||||
// - SetFileAttributesW
|
||||
// - GetShortPathNameW
|
||||
// - GetFullPathNameW
|
||||
// - GetLongPathNameW
|
||||
// - MoveFileW
|
||||
@ -104,7 +105,6 @@
|
||||
// - FindNextStreamW
|
||||
// - GetCompressedFileSizeW
|
||||
// - GetFinalPathNameByHandleW
|
||||
//
|
||||
//
|
||||
// Additional helpers (<stdlib.h> oder <wchar.h>)
|
||||
//
|
||||
@ -1237,6 +1237,65 @@ bool PTHAPI Path_GetCurrentDirectory(HPATHL hpth_out)
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
size_t PTHAPI Path_ToShortPathName(HPATHL hpth_in_out)
|
||||
{
|
||||
HSTRINGW hstr_io = ToHStrgW(hpth_in_out);
|
||||
if (!hstr_io)
|
||||
return 0;
|
||||
|
||||
DWORD const _len = GetShortPathNameW(StrgGet(hstr_io), NULL, 0);
|
||||
if (!_len)
|
||||
return false;
|
||||
|
||||
wchar_t* const buf = StrgWriteAccessBuf(hstr_io, _len);
|
||||
|
||||
DWORD const len = GetShortPathNameW(buf, buf, (DWORD)StrgGetAllocLength(hstr_io));
|
||||
StrgSanitize(hstr_io);
|
||||
|
||||
return len;
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
size_t PTHAPI Path_GetLongPathNameEx(HPATHL hpth_in_out)
|
||||
{
|
||||
HSTRINGW hstr_io = ToHStrgW(hpth_in_out);
|
||||
if (!hstr_io)
|
||||
return 0;
|
||||
|
||||
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);
|
||||
|
||||
size_t const res = (size_t)GetLongPathNameW(buf, buf, len);
|
||||
StrgSanitize(hstr_io);
|
||||
|
||||
if (res > 2ULL) {
|
||||
wchar_t* const pos = wcschr(buf, L':');
|
||||
if (pos && (pos > buf)) {
|
||||
CharUpperBuffW(pos - 1, 1);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
#if 0
|
||||
size_t PTHAPI GetLongPathNameEx(LPWSTR lpszPath, const size_t cchBuffer)
|
||||
{
|
||||
HPATHL hpth = Path_Allocate(lpszPath);
|
||||
size_t const res = Path_GetLongPathNameEx(hpth);
|
||||
if (res) {
|
||||
StringCchCopyW(lpszPath, cchBuffer, PathGet(hpth));
|
||||
}
|
||||
Path_Release(hpth);
|
||||
return res;
|
||||
}
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
// ============================================================================
|
||||
// Old Stuff in INTERMEDIATE DEV state
|
||||
// ============================================================================
|
||||
@ -1479,45 +1538,6 @@ bool PTHAPI Path_RelativePathTo(HPATHL hrecv, const HPATHL hfrom, DWORD attr_fro
|
||||
}
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// GetLongPathNameEx()
|
||||
//
|
||||
size_t PTHAPI Path_GetLongPathNameEx(HPATHL hpth_in_out)
|
||||
{
|
||||
HSTRINGW hstr_io = ToHStrgW(hpth_in_out);
|
||||
if (!hstr_io)
|
||||
return 0UL;
|
||||
|
||||
PrependLongPathPrefix(hpth_in_out, false); // TODO: check or true ?
|
||||
|
||||
DWORD const len = (size_t)GetLongPathNameW(StrgGet(hstr_io), NULL, 0);
|
||||
wchar_t* const buf = StrgWriteAccessBuf(hstr_io, (size_t)len);
|
||||
|
||||
size_t const res = (size_t)GetLongPathNameW(buf, buf, len);
|
||||
StrgSanitize(hstr_io);
|
||||
|
||||
if (res > 2ULL) {
|
||||
wchar_t* const pos = wcschr(buf, L':');
|
||||
if (pos && (pos > buf)) {
|
||||
CharUpperBuffW(pos - 1, 1);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
size_t PTHAPI GetLongPathNameEx(LPWSTR lpszPath, const size_t cchBuffer)
|
||||
{
|
||||
HPATHL hpth = Path_Allocate(lpszPath);
|
||||
size_t const res = Path_GetLongPathNameEx(hpth);
|
||||
if (res) {
|
||||
StringCchCopyW(lpszPath, cchBuffer, PathGet(hpth));
|
||||
}
|
||||
Path_Release(hpth);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// GetKnownFolderPath()
|
||||
|
||||
@ -83,6 +83,8 @@ wchar_t PTHAPI Path_GetDriveLetterByNumber(const int number);
|
||||
DWORD PTHAPI Path_GetFileAttributes(const HPATHL hpth);
|
||||
bool PTHAPI Path_SetFileAttributes(HPATHL hpth, DWORD dwAttributes);
|
||||
bool PTHAPI Path_GetCurrentDirectory(HPATHL hpth_out);
|
||||
size_t PTHAPI Path_ToShortPathName(HPATHL hpth_in_out);
|
||||
size_t PTHAPI Path_GetLongPathNameEx(HPATHL hpth_in_out);
|
||||
|
||||
// -------------------------------------------------------
|
||||
// get wchar buffer with at least MAX_PATH size
|
||||
@ -111,9 +113,6 @@ void PTHAPI Path_ExpandEnvironmentStrings(HPATHL hpth_in_out);
|
||||
|
||||
bool PTHAPI Path_RelativePathTo(HPATHL hrecv, const HPATHL hfrom, DWORD attr_from, const HPATHL hto, DWORD attr_to);
|
||||
|
||||
size_t PTHAPI Path_GetLongPathNameEx(HPATHL hpth_in_out);
|
||||
size_t PTHAPI GetLongPathNameEx(LPWSTR lpszPath, const size_t cchBuffer);
|
||||
|
||||
bool PTHAPI Path_GetKnownFolder(REFKNOWNFOLDERID rfid, HPATHL hpth_out);
|
||||
bool PTHAPI PathGetKnownFolder(REFKNOWNFOLDERID, LPWSTR lpOutPath, size_t cchOut);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user