mirror of
https://github.com/Open-Shell/Open-Shell-Menu.git
synced 2026-04-13 20:28:31 +10:00
Added option to open folders to their true path
Adds a new function called GetFakeFolder which attempts to find and get the target.lnk file from a fake folder (what Open-Shell uses to pin folders). If detected, InvokeCommand is swapped for a ShellExecute call to the target shortcut. Fixes #555, #653, and by extension, #691.
This commit is contained in:
committed by
Ibuprophen
parent
bb26cec0ec
commit
27e5c2bc74
@@ -60,3 +60,17 @@ bool IsFakeFolder( const wchar_t *fname )
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool GetFakeFolder( wchar_t *dst, int len, const wchar_t *src )
|
||||||
|
{
|
||||||
|
Sprintf(dst,len,L"%s\\target.lnk",src);
|
||||||
|
if (GetFileAttributes(dst)!=INVALID_FILE_ATTRIBUTES)
|
||||||
|
{
|
||||||
|
wchar_t path[_MAX_PATH];
|
||||||
|
Sprintf(path,_countof(path),L"%s\\desktop.ini",src);
|
||||||
|
DWORD attrib=GetFileAttributes(path);
|
||||||
|
if (attrib!=INVALID_FILE_ATTRIBUTES && (attrib&FILE_ATTRIBUTE_SYSTEM))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,3 +7,4 @@
|
|||||||
bool CreateFakeFolder( const wchar_t *source, const wchar_t *fname );
|
bool CreateFakeFolder( const wchar_t *source, const wchar_t *fname );
|
||||||
void DeleteFakeFolder( const wchar_t *fname );
|
void DeleteFakeFolder( const wchar_t *fname );
|
||||||
bool IsFakeFolder( const wchar_t *fname );
|
bool IsFakeFolder( const wchar_t *fname );
|
||||||
|
bool GetFakeFolder( wchar_t *dst, int len, const wchar_t *src );
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
#include "SettingsUI.h"
|
#include "SettingsUI.h"
|
||||||
#include "SettingsUIHelper.h"
|
#include "SettingsUIHelper.h"
|
||||||
|
#include "FileHelper.h"
|
||||||
#include "Translations.h"
|
#include "Translations.h"
|
||||||
#include "LogManager.h"
|
#include "LogManager.h"
|
||||||
#include "FNVHash.h"
|
#include "FNVHash.h"
|
||||||
@@ -2782,12 +2783,19 @@ void CMenuContainer::ActivateItem( int index, TActivateType type, const POINT *p
|
|||||||
info.lpVerb=MAKEINTRESOURCEA(res-verbOffset);
|
info.lpVerb=MAKEINTRESOURCEA(res-verbOffset);
|
||||||
info.lpVerbW=MAKEINTRESOURCEW(res-verbOffset);
|
info.lpVerbW=MAKEINTRESOURCEW(res-verbOffset);
|
||||||
info.nShow=SW_SHOWNORMAL;
|
info.nShow=SW_SHOWNORMAL;
|
||||||
|
bool bOpenTruePath=false;
|
||||||
|
wchar_t targetlnkPath[_MAX_PATH]; // path to target.lnk in a fake folder
|
||||||
wchar_t dir[_MAX_PATH];
|
wchar_t dir[_MAX_PATH];
|
||||||
if (SHGetPathFromIDList(pItemPidl1,dir))
|
if (SHGetPathFromIDList(pItemPidl1,dir))
|
||||||
{
|
{
|
||||||
PathRemoveFileSpec(dir);
|
if (_stricmp(command,"open")==0 && GetSettingBool(L"OpenTruePath") && GetFakeFolder(targetlnkPath,_countof(targetlnkPath),dir))
|
||||||
if (GetFileAttributes(dir)!=INVALID_FILE_ATTRIBUTES)
|
bOpenTruePath=true;
|
||||||
info.lpDirectoryW=dir;
|
else
|
||||||
|
{
|
||||||
|
PathRemoveFileSpec(dir);
|
||||||
|
if (GetFileAttributes(dir)!=INVALID_FILE_ATTRIBUTES)
|
||||||
|
info.lpDirectoryW=dir;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (pPt)
|
if (pPt)
|
||||||
{
|
{
|
||||||
@@ -2818,9 +2826,20 @@ void CMenuContainer::ActivateItem( int index, TActivateType type, const POINT *p
|
|||||||
::SetForegroundWindow(g_OwnerWindow);
|
::SetForegroundWindow(g_OwnerWindow);
|
||||||
::SetWindowPos(g_OwnerWindow,HWND_TOPMOST,rc.left,rc.top,rc.right-rc.left,rc.bottom-rc.top,0);
|
::SetWindowPos(g_OwnerWindow,HWND_TOPMOST,rc.left,rc.top,rc.right-rc.left,rc.bottom-rc.top,0);
|
||||||
LOG_MENU(LOG_EXECUTE,L"Invoke command, ptr=%p, command='%S'",this,command);
|
LOG_MENU(LOG_EXECUTE,L"Invoke command, ptr=%p, command='%S'",this,command);
|
||||||
HRESULT hr=pInvokeMenu->InvokeCommand((LPCMINVOKECOMMANDINFO)&info);
|
bool executeSuccess;
|
||||||
LOG_MENU(LOG_EXECUTE,L"Invoke command, ptr=%p, res=%d",this,hr);
|
if (bOpenTruePath) // we are trying to open a fake folder, directly open target.lnk instead
|
||||||
if (type==ACTIVATE_EXECUTE && SUCCEEDED(hr))
|
{
|
||||||
|
HINSTANCE hinst=ShellExecute(NULL,NULL,targetlnkPath,NULL,NULL,SW_SHOWNORMAL);
|
||||||
|
LOG_MENU(LOG_EXECUTE,L"Invoke command, ptr=%p, res=%d",this,hinst);
|
||||||
|
executeSuccess=static_cast<int>(reinterpret_cast<uintptr_t>(hinst))>=32;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
HRESULT hr=pInvokeMenu->InvokeCommand((LPCMINVOKECOMMANDINFO)&info);
|
||||||
|
LOG_MENU(LOG_EXECUTE,L"Invoke command, ptr=%p, res=%d",this,hr);
|
||||||
|
executeSuccess=SUCCEEDED(hr);
|
||||||
|
}
|
||||||
|
if (type==ACTIVATE_EXECUTE && executeSuccess)
|
||||||
{
|
{
|
||||||
if (bTrackRecent)
|
if (bTrackRecent)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4349,6 +4349,7 @@ CSetting g_Settings[]={
|
|||||||
{L"SearchFilesCommand",CSetting::TYPE_STRING,IDS_SEARCH_COMMAND,IDS_SEARCH_COMMAND_TIP,L"search-ms:",CSetting::FLAG_MENU_CLASSIC_BOTH},
|
{L"SearchFilesCommand",CSetting::TYPE_STRING,IDS_SEARCH_COMMAND,IDS_SEARCH_COMMAND_TIP,L"search-ms:",CSetting::FLAG_MENU_CLASSIC_BOTH},
|
||||||
{L"ExpandFolderLinks",CSetting::TYPE_BOOL,IDS_EXPAND_LINKS,IDS_EXPAND_LINKS_TIP,1},
|
{L"ExpandFolderLinks",CSetting::TYPE_BOOL,IDS_EXPAND_LINKS,IDS_EXPAND_LINKS_TIP,1},
|
||||||
{L"SingleClickFolders",CSetting::TYPE_BOOL,IDS_NO_DBLCLICK,IDS_NO_DBLCLICK_TIP,0},
|
{L"SingleClickFolders",CSetting::TYPE_BOOL,IDS_NO_DBLCLICK,IDS_NO_DBLCLICK_TIP,0},
|
||||||
|
{L"OpenTruePath",CSetting::TYPE_BOOL,IDS_OPEN_TRUE_PATH,IDS_OPEN_TRUE_PATH_TIP,1},
|
||||||
{L"EnableTouch",CSetting::TYPE_BOOL,IDS_ENABLE_TOUCH,IDS_ENABLE_TOUCH_TIP,1},
|
{L"EnableTouch",CSetting::TYPE_BOOL,IDS_ENABLE_TOUCH,IDS_ENABLE_TOUCH_TIP,1},
|
||||||
{L"EnableAccessibility",CSetting::TYPE_BOOL,IDS_ACCESSIBILITY,IDS_ACCESSIBILITY_TIP,1},
|
{L"EnableAccessibility",CSetting::TYPE_BOOL,IDS_ACCESSIBILITY,IDS_ACCESSIBILITY_TIP,1},
|
||||||
{L"ShowNextToTaskbar",CSetting::TYPE_BOOL,IDS_NEXTTASKBAR,IDS_NEXTTASKBAR_TIP,0},
|
{L"ShowNextToTaskbar",CSetting::TYPE_BOOL,IDS_NEXTTASKBAR,IDS_NEXTTASKBAR_TIP,0},
|
||||||
|
|||||||
@@ -1315,6 +1315,12 @@ BEGIN
|
|||||||
IDS_ITEM_LINKS_TIP "This item will appear as a sub-menu showing only its top-level contents"
|
IDS_ITEM_LINKS_TIP "This item will appear as a sub-menu showing only its top-level contents"
|
||||||
END
|
END
|
||||||
|
|
||||||
|
STRINGTABLE
|
||||||
|
BEGIN
|
||||||
|
IDS_OPEN_TRUE_PATH "Open pinned folders to their true path"
|
||||||
|
IDS_OPEN_TRUE_PATH_TIP "When this is checked, pinned folders will open to their true path instead of the path to their shortcut in the Pinned Programs folder"
|
||||||
|
END
|
||||||
|
|
||||||
#endif // English (U.S.) resources
|
#endif // English (U.S.) resources
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|||||||
@@ -776,6 +776,8 @@
|
|||||||
#define IDS_OPEN_CMD_TEXT_TIP 3679
|
#define IDS_OPEN_CMD_TEXT_TIP 3679
|
||||||
#define IDS_ITEM_LINKS 3680
|
#define IDS_ITEM_LINKS 3680
|
||||||
#define IDS_ITEM_LINKS_TIP 3681
|
#define IDS_ITEM_LINKS_TIP 3681
|
||||||
|
#define IDS_OPEN_TRUE_PATH 3682
|
||||||
|
#define IDS_OPEN_TRUE_PATH_TIP 3683
|
||||||
#define IDS_STRING7001 7001
|
#define IDS_STRING7001 7001
|
||||||
#define IDS_STRING7002 7002
|
#define IDS_STRING7002 7002
|
||||||
#define IDS_STRING7003 7003
|
#define IDS_STRING7003 7003
|
||||||
|
|||||||
Reference in New Issue
Block a user