Skip to content

Commit

Permalink
Fix issue #1: add File.Start PowerShell... ctrl+p is the shortcut.
Browse files Browse the repository at this point in the history
NOTE: I'll fix the szParams buffer length issue when I fix the cmd.exe one.
  • Loading branch information
craigwi committed Apr 9, 2018
1 parent f24f776 commit c6e9029
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Winfile.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>.;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>DBG;_X86_;_M_IX86;WIN32;_WIN32;_WINDOWS;LFN;STRICT;FASTMOVE;LFNCLIPBOARD;W3;UNICODE;_UNICODE;USELASTDOT;MEMDOUBLE;WINVER=0x0501;_WIN32_WINNT=0x501;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>DBG;_X86_;_M_IX86;WIN32;_WIN32;_WINDOWS;LFN;STRICT;FASTMOVE;LFNCLIPBOARD;W3;UNICODE;_UNICODE;USELASTDOT;MEMDOUBLE;WINVER=0x0601;_WIN32_WINNT=0x601;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
Expand All @@ -105,7 +105,7 @@
<CallingConvention>StdCall</CallingConvention>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>_X86_;_M_IX86;WIN32;_WIN32;_DEBUG;_WINDOWS;LFN;STRICT;FASTMOVE;LFNCLIPBOARD;W3;UNICODE;_UNICODE;USELASTDOT;MEMDOUBLE;WINVER=0x0501;_WIN32_WINNT=0x501;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_X86_;_M_IX86;WIN32;_WIN32;_DEBUG;_WINDOWS;LFN;STRICT;FASTMOVE;LFNCLIPBOARD;W3;UNICODE;_UNICODE;USELASTDOT;MEMDOUBLE;WINVER=0x0601;_WIN32_WINNT=0x601;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>.;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<ResourceOutputFileName>
</ResourceOutputFileName>
Expand All @@ -123,7 +123,7 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<AdditionalIncludeDirectories>.;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_X86_;_M_IX86;WIN32;_WIN32;_WINDOWS;LFN;STRICT;FASTMOVE;LFNCLIPBOARD;W3;UNICODE;_UNICODE;USELASTDOT;MEMDOUBLE;WINVER=0x0501;_WIN32_WINNT=0x501;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_X86_;_M_IX86;WIN32;_WIN32;_WINDOWS;LFN;STRICT;FASTMOVE;LFNCLIPBOARD;W3;UNICODE;_UNICODE;USELASTDOT;MEMDOUBLE;WINVER=0x0601;_WIN32_WINNT=0x601;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
Expand All @@ -132,7 +132,7 @@
<CallingConvention>StdCall</CallingConvention>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>_X86_;_M_IX86;WIN32;_WIN32;_DEBUG;_WINDOWS;LFN;STRICT;FASTMOVE;LFNCLIPBOARD;W3;UNICODE;_UNICODE;USELASTDOT;MEMDOUBLE;WINVER=0x0400;_WIN32_WINNT=0x501;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_X86_;_M_IX86;WIN32;_WIN32;_DEBUG;_WINDOWS;LFN;STRICT;FASTMOVE;LFNCLIPBOARD;W3;UNICODE;_UNICODE;USELASTDOT;MEMDOUBLE;WINVER=0x0400;_WIN32_WINNT=0x601;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>.;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
<Link>
Expand All @@ -154,7 +154,7 @@
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>.;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_X64_;_M_IX64;WIN64;_WIN64;_WINDOWS;LFN;STRICT;FASTMOVE;LFNCLIPBOARD;W3;UNICODE;_UNICODE;USELASTDOT;MEMDOUBLE;WINVER=0x0501;_WIN32_WINNT=0x501;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_X64_;_M_IX64;WIN64;_WIN64;_WINDOWS;LFN;STRICT;FASTMOVE;LFNCLIPBOARD;W3;UNICODE;_UNICODE;USELASTDOT;MEMDOUBLE;WINVER=0x0601;_WIN32_WINNT=0x601;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
Expand All @@ -165,7 +165,7 @@
<CallingConvention>StdCall</CallingConvention>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>_X64_;_M_IX64;WIN64;_WIN64;_DEBUG;_WINDOWS;LFN;STRICT;FASTMOVE;LFNCLIPBOARD;W3;UNICODE;_UNICODE;USELASTDOT;MEMDOUBLE;WINVER=0x0501;_WIN32_WINNT=0x0501;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_X64_;_M_IX64;WIN64;_WIN64;_DEBUG;_WINDOWS;LFN;STRICT;FASTMOVE;LFNCLIPBOARD;W3;UNICODE;_UNICODE;USELASTDOT;MEMDOUBLE;WINVER=0x0601;_WIN32_WINNT=0x0601;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>.;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<ResourceOutputFileName>
</ResourceOutputFileName>
Expand Down
2 changes: 2 additions & 0 deletions src/res.rc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ BEGIN
"^c", IDM_COPYTOCLIPBOARD, NOINVERT
"^v", IDM_PASTE, NOINVERT
"^k", IDM_STARTCMDSHELL, NOINVERT
"^p", IDM_STARTPOWERSHELL, NOINVERT
"^g", IDM_GOTODIR, NOINVERT
"^f", IDM_SEARCH, NOINVERT
VK_LEFT, IDM_HISTORYBACK, NOINVERT, VIRTKEY, ALT
Expand Down Expand Up @@ -93,6 +94,7 @@ BEGIN
MENUITEM "Searc&h...\tCtrl+F", IDM_SEARCH
MENUITEM "Select &Files...", IDM_SELECT
MENUITEM "Start Cmd Shel&l...", IDM_STARTCMDSHELL
MENUITEM "Start Po&werShell...", IDM_STARTPOWERSHELL
MENUITEM "&Goto Directory...\tCtrl+G", IDM_GOTODIR
MENUITEM SEPARATOR
MENUITEM "E&xit", IDM_EXIT
Expand Down
85 changes: 85 additions & 0 deletions src/wfcomman.c
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,66 @@ FmifsLoaded()
return TRUE;
}

BOOL
GetPowershellExePath(LPTSTR szPSPath)
{
HKEY hkey;
if (ERROR_SUCCESS != RegOpenKey(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Microsoft\\PowerShell"), &hkey))
{
return FALSE;
}

szPSPath[0] = TEXT('\0');

for (int ikey = 0; ikey < 5; ikey++)
{
TCHAR szSub[10]; // just the "1" or "3"

DWORD dwError = RegEnumKey(hkey, ikey, szSub, COUNTOF(szSub));

if (dwError == ERROR_SUCCESS)
{
// if installed, get powershell exe
DWORD dwInstall;
DWORD dwType;
DWORD cbValue = sizeof(dwInstall);
dwError = RegGetValue(hkey, szSub, TEXT("Install"), RRF_RT_DWORD, &dwType, (PVOID)&dwInstall, &cbValue);

if (dwError == ERROR_SUCCESS && dwInstall == 1)
{
// this install of powershell is active; get path

HKEY hkeySub;
dwError = RegOpenKey(hkey, szSub, &hkeySub);

if (dwError == ERROR_SUCCESS)
{
LPTSTR szPSExe = TEXT("\\Powershell.exe");

cbValue = (MAXPATHLEN - lstrlen(szPSExe)) * sizeof(TCHAR);
dwError = RegGetValue(hkeySub, TEXT("PowerShellEngine"), TEXT("ApplicationBase"), RRF_RT_REG_SZ | RRF_RT_REG_EXPAND_SZ, &dwType, (PVOID)szPSPath, &cbValue);

if (dwError == ERROR_SUCCESS)
{
lstrcat(szPSPath, szPSExe);
}
else
{
// reset to empty string if not successful
szPSPath[0] = TEXT('\0');
}

RegCloseKey(hkeySub);
}
}
}
}

RegCloseKey(hkey);

// return true if we got a valid path
return szPSPath[0] != TEXT('\0');
}

/*--------------------------------------------------------------------------*/
/* */
Expand Down Expand Up @@ -977,6 +1037,31 @@ AppCommandProc(register DWORD id)
}
break;

case IDM_STARTPOWERSHELL:
{
BOOL bRunAs;
BOOL bDir;
TCHAR szToRun[MAXPATHLEN];
LPTSTR szDir;
TCHAR szParams[MAXPATHLEN + 20];

szDir = GetSelection(1 | 4 | 16, &bDir);
if (!bDir)
StripFilespec(szDir);

bRunAs = GetKeyState(VK_SHIFT) < 0;

if (GetPowershellExePath(szToRun))
{
wsprintf(szParams, TEXT(" -noexit -command \"cd \\\"%s\\\"\""), szDir);

ret = ExecProgram(szToRun, szParams, szDir, FALSE, bRunAs);
}

LocalFree(szDir);
}
break;

case IDM_SELECT:

// push the focus to the dir half so when they are done
Expand Down
1 change: 1 addition & 0 deletions src/winfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,7 @@ BOOL RectTreeItem(HWND hwndLB, register INT iItem, BOOL bFocusOn);
#define IDM_GOTODIR 125
#define IDM_HISTORYBACK 126
#define IDM_HISTORYFWD 127
#define IDM_STARTPOWERSHELL 128

// This IDM_ is reserved for IDH_GROUP_ATTRIBS
#define IDM_GROUP_ATTRIBS 199
Expand Down

0 comments on commit c6e9029

Please sign in to comment.