Skip to content

Commit 27e5c2b

Browse files
thisismy-githubIbuprophen
authored andcommitted
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.
1 parent bb26cec commit 27e5c2b

File tree

6 files changed

+49
-6
lines changed

6 files changed

+49
-6
lines changed

Src/Lib/FileHelper.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,17 @@ bool IsFakeFolder( const wchar_t *fname )
6060
}
6161
return false;
6262
}
63+
64+
bool GetFakeFolder( wchar_t *dst, int len, const wchar_t *src )
65+
{
66+
Sprintf(dst,len,L"%s\\target.lnk",src);
67+
if (GetFileAttributes(dst)!=INVALID_FILE_ATTRIBUTES)
68+
{
69+
wchar_t path[_MAX_PATH];
70+
Sprintf(path,_countof(path),L"%s\\desktop.ini",src);
71+
DWORD attrib=GetFileAttributes(path);
72+
if (attrib!=INVALID_FILE_ATTRIBUTES && (attrib&FILE_ATTRIBUTE_SYSTEM))
73+
return true;
74+
}
75+
return false;
76+
}

Src/Lib/FileHelper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
bool CreateFakeFolder( const wchar_t *source, const wchar_t *fname );
88
void DeleteFakeFolder( const wchar_t *fname );
99
bool IsFakeFolder( const wchar_t *fname );
10+
bool GetFakeFolder( wchar_t *dst, int len, const wchar_t *src );

Src/StartMenu/StartMenuDLL/MenuCommands.cpp

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "Settings.h"
1212
#include "SettingsUI.h"
1313
#include "SettingsUIHelper.h"
14+
#include "FileHelper.h"
1415
#include "Translations.h"
1516
#include "LogManager.h"
1617
#include "FNVHash.h"
@@ -2782,12 +2783,19 @@ void CMenuContainer::ActivateItem( int index, TActivateType type, const POINT *p
27822783
info.lpVerb=MAKEINTRESOURCEA(res-verbOffset);
27832784
info.lpVerbW=MAKEINTRESOURCEW(res-verbOffset);
27842785
info.nShow=SW_SHOWNORMAL;
2786+
bool bOpenTruePath=false;
2787+
wchar_t targetlnkPath[_MAX_PATH]; // path to target.lnk in a fake folder
27852788
wchar_t dir[_MAX_PATH];
27862789
if (SHGetPathFromIDList(pItemPidl1,dir))
27872790
{
2788-
PathRemoveFileSpec(dir);
2789-
if (GetFileAttributes(dir)!=INVALID_FILE_ATTRIBUTES)
2790-
info.lpDirectoryW=dir;
2791+
if (_stricmp(command,"open")==0 && GetSettingBool(L"OpenTruePath") && GetFakeFolder(targetlnkPath,_countof(targetlnkPath),dir))
2792+
bOpenTruePath=true;
2793+
else
2794+
{
2795+
PathRemoveFileSpec(dir);
2796+
if (GetFileAttributes(dir)!=INVALID_FILE_ATTRIBUTES)
2797+
info.lpDirectoryW=dir;
2798+
}
27912799
}
27922800
if (pPt)
27932801
{
@@ -2818,9 +2826,20 @@ void CMenuContainer::ActivateItem( int index, TActivateType type, const POINT *p
28182826
::SetForegroundWindow(g_OwnerWindow);
28192827
::SetWindowPos(g_OwnerWindow,HWND_TOPMOST,rc.left,rc.top,rc.right-rc.left,rc.bottom-rc.top,0);
28202828
LOG_MENU(LOG_EXECUTE,L"Invoke command, ptr=%p, command='%S'",this,command);
2821-
HRESULT hr=pInvokeMenu->InvokeCommand((LPCMINVOKECOMMANDINFO)&info);
2822-
LOG_MENU(LOG_EXECUTE,L"Invoke command, ptr=%p, res=%d",this,hr);
2823-
if (type==ACTIVATE_EXECUTE && SUCCEEDED(hr))
2829+
bool executeSuccess;
2830+
if (bOpenTruePath) // we are trying to open a fake folder, directly open target.lnk instead
2831+
{
2832+
HINSTANCE hinst=ShellExecute(NULL,NULL,targetlnkPath,NULL,NULL,SW_SHOWNORMAL);
2833+
LOG_MENU(LOG_EXECUTE,L"Invoke command, ptr=%p, res=%d",this,hinst);
2834+
executeSuccess=static_cast<int>(reinterpret_cast<uintptr_t>(hinst))>=32;
2835+
}
2836+
else
2837+
{
2838+
HRESULT hr=pInvokeMenu->InvokeCommand((LPCMINVOKECOMMANDINFO)&info);
2839+
LOG_MENU(LOG_EXECUTE,L"Invoke command, ptr=%p, res=%d",this,hr);
2840+
executeSuccess=SUCCEEDED(hr);
2841+
}
2842+
if (type==ACTIVATE_EXECUTE && executeSuccess)
28242843
{
28252844
if (bTrackRecent)
28262845
{

Src/StartMenu/StartMenuDLL/SettingsUI.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4349,6 +4349,7 @@ CSetting g_Settings[]={
43494349
{L"SearchFilesCommand",CSetting::TYPE_STRING,IDS_SEARCH_COMMAND,IDS_SEARCH_COMMAND_TIP,L"search-ms:",CSetting::FLAG_MENU_CLASSIC_BOTH},
43504350
{L"ExpandFolderLinks",CSetting::TYPE_BOOL,IDS_EXPAND_LINKS,IDS_EXPAND_LINKS_TIP,1},
43514351
{L"SingleClickFolders",CSetting::TYPE_BOOL,IDS_NO_DBLCLICK,IDS_NO_DBLCLICK_TIP,0},
4352+
{L"OpenTruePath",CSetting::TYPE_BOOL,IDS_OPEN_TRUE_PATH,IDS_OPEN_TRUE_PATH_TIP,1},
43524353
{L"EnableTouch",CSetting::TYPE_BOOL,IDS_ENABLE_TOUCH,IDS_ENABLE_TOUCH_TIP,1},
43534354
{L"EnableAccessibility",CSetting::TYPE_BOOL,IDS_ACCESSIBILITY,IDS_ACCESSIBILITY_TIP,1},
43544355
{L"ShowNextToTaskbar",CSetting::TYPE_BOOL,IDS_NEXTTASKBAR,IDS_NEXTTASKBAR_TIP,0},

Src/StartMenu/StartMenuDLL/StartMenuDLL.rc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,6 +1315,12 @@ BEGIN
13151315
IDS_ITEM_LINKS_TIP "This item will appear as a sub-menu showing only its top-level contents"
13161316
END
13171317

1318+
STRINGTABLE
1319+
BEGIN
1320+
IDS_OPEN_TRUE_PATH "Open pinned folders to their true path"
1321+
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"
1322+
END
1323+
13181324
#endif // English (U.S.) resources
13191325
/////////////////////////////////////////////////////////////////////////////
13201326

Src/StartMenu/StartMenuDLL/resource.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,8 @@
776776
#define IDS_OPEN_CMD_TEXT_TIP 3679
777777
#define IDS_ITEM_LINKS 3680
778778
#define IDS_ITEM_LINKS_TIP 3681
779+
#define IDS_OPEN_TRUE_PATH 3682
780+
#define IDS_OPEN_TRUE_PATH_TIP 3683
779781
#define IDS_STRING7001 7001
780782
#define IDS_STRING7002 7002
781783
#define IDS_STRING7003 7003

0 commit comments

Comments
 (0)