Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore XP compatibility #59

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 47 additions & 7 deletions src/lfn.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,35 @@

BOOL IsFATName(LPTSTR pName);

typedef BOOL (WINAPI *tW64P)(HANDLE, PBOOL);
typedef BOOL (WINAPI *tFSDisable)(PVOID*);
typedef BOOL (WINAPI *tFSRevert)(PVOID);

HMODULE hKernel = NULL;
BOOL bIsWow64 = FALSE;
BOOL bWow64FuncsSearched = FALSE;

tFSDisable pDisableFunc = NULL;
tFSRevert pRevertFunc = NULL;
tW64P pIsWow64Func = NULL;

void _InitWow64Funcs() {
if(!bWow64FuncsSearched) {
hKernel = GetModuleHandle(L"Kernel32");
pIsWow64Func = (tW64P) GetProcAddress(hKernel, "IsWow64Process");

if (pIsWow64Func)
{
pIsWow64Func(GetCurrentProcess(), &bIsWow64);
if (bIsWow64)
{
pDisableFunc = (tFSDisable) GetProcAddress(hKernel, "Wow64DisableWow64FsRedirection");
pRevertFunc = (tFSRevert) GetProcAddress(hKernel, "Wow64RevertWow64FsRedirection");
}
}
bWow64FuncsSearched = TRUE;
}
}

/* WFFindFirst -
*
Expand All @@ -43,8 +72,12 @@ WFFindFirst(
// and ORDINARY files too.
//

PVOID oldValue;
Wow64DisableWow64FsRedirection(&oldValue);
PVOID oldValue;

_InitWow64Funcs();

if ((pDisableFunc) && (pRevertFunc))
pDisableFunc(&oldValue);

if ((dwAttrFilter & ~(ATTR_DIR | ATTR_HS)) == 0)
{
Expand All @@ -63,7 +96,8 @@ WFFindFirst(

lpFind->fd.dwFileAttributes &= ATTR_USED;

Wow64RevertWow64FsRedirection(oldValue);
if ((pDisableFunc) && (pRevertFunc))
pRevertFunc(oldValue);

//
// Keep track of length
Expand Down Expand Up @@ -110,8 +144,12 @@ BOOL
WFFindNext(LPLFNDTA lpFind)
{
PVOID oldValue;
Wow64DisableWow64FsRedirection(&oldValue);


_InitWow64Funcs();

if ((pDisableFunc) && (pRevertFunc))
pDisableFunc(&oldValue);

while (FindNextFile(lpFind->hFindFile, &lpFind->fd)) {

lpFind->fd.dwFileAttributes &= ATTR_USED;
Expand Down Expand Up @@ -139,12 +177,14 @@ WFFindNext(LPLFNDTA lpFind)
lstrcpy(lpFind->fd.cFileName, lpFind->fd.cAlternateFileName);
}

Wow64RevertWow64FsRedirection(oldValue);
if ((pDisableFunc) && (pRevertFunc))
pRevertFunc(oldValue);

return TRUE;
}

Wow64RevertWow64FsRedirection(oldValue);
if ((pDisableFunc) && (pRevertFunc))
pRevertFunc(oldValue);

lpFind->err = GetLastError();
return(FALSE);
Expand Down
10 changes: 5 additions & 5 deletions src/treectl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1976,6 +1976,11 @@ TreeControlWndProc(

WCHAR szPath[MAXPATHLEN*3];

PDNODE pParentNode;

RECT rc;


hwndLB = GetDlgItem(hwnd, IDCW_TREELISTBOX);
hwndParent = GetParent(hwnd);

Expand All @@ -1985,7 +1990,6 @@ TreeControlWndProc(

case TC_COLLAPSELEVEL:
{
PDNODE pParentNode;

//
// Don't do anything while the tree is being built.
Expand Down Expand Up @@ -2088,7 +2092,6 @@ TreeControlWndProc(
//
// set the selection in the tree to that for a given path
//
INT i;

if (FindItemFromPath(hwndLB, (LPTSTR)lParam, wParam != 0, &i, NULL))
{
Expand Down Expand Up @@ -2117,9 +2120,6 @@ TreeControlWndProc(
if (GetWindowLongPtr(hwnd, GWL_READLEVEL))
break;

RECT rc;
INT i;
PDNODE pNode;

// do the same as TC_SETDIRECTORY above for the simple case
if (FindItemFromPath(hwndLB, (LPTSTR)lParam, 0, &i, &pNode))
Expand Down
111 changes: 96 additions & 15 deletions src/wfcomman.c
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,8 @@ CreateDirWindow(
{
register HWND hwndT;
INT dxSplit;
DRIVE drive;
INT i;

if (hwndActive == hwndSearch) {
bReplaceOpen = FALSE;
Expand All @@ -532,8 +534,8 @@ CreateDirWindow(
if (bReplaceOpen) {
CharUpperBuff(szPath, 1); // make sure

DRIVE drive = DRIVEID(szPath);
for (INT i = 0; i<cDrives; i++)
drive = DRIVEID(szPath);
for (i = 0; i<cDrives; i++)
{
if (drive == rgiDrive[i])
{
Expand Down Expand Up @@ -791,44 +793,123 @@ FmifsLoaded()
return TRUE;
}

#ifndef UNICODE
LSTATUS MyRegGetValue (HKEY hkey, LPCSTR lpSubKey, LPCSTR lpValue, DWORD dwFlags, LPDWORD pdwType, PVOID pvData, LPDWORD pcbData)
{
typedef LSTATUS (WINAPI *REGGETVALUEA)(HKEY hkey, LPCSTR lpSubKey, LPCSTR lpValue, DWORD dwFlags, LPDWORD pdwType, PVOID pvData, LPDWORD pcbData);
REGGETVALUEA LoadLibAddy;
DWORD type;
LoadLibAddy = (REGGETVALUEA)GetProcAddress(GetModuleHandle(L"advapi32.dll"), "RegGetValueA");


if (LoadLibAddy)
{
return LoadLibAddy(hkey, lpSubKey, lpValue, dwFlags, pdwType, pvData, pcbData);
}
else
{
if (dwFlags == RRF_RT_REG_SZ)
{
type = REG_SZ;
}
else if (dwFlags == RRF_RT_REG_DWORD)
{
type = REG_DWORD;
}
if (pszSubKey && pszSubKey[0])
{
RegOpenKeyExA(hkey,pszSubKey,0,KEY_READ,&hksub);
dwStatus = RegQueryValueExA(hksub, pszValue, NULL, &type, (LPBYTE)pvData, pcbData);
RegCloseKey(hksub);
}
else
{
dwStatus = RegQueryValueExA(hkey, pszValue, NULL, &type, (LPBYTE)pvData, pcbData);
}
}
}
#else /* UNICODE version belows */
LSTATUS MyRegGetValue (HKEY hkey, LPCWSTR pszSubKey, LPCWSTR pszValue, DWORD dwFlags, LPDWORD pdwType, PVOID pvData, LPDWORD pcbData)
{
typedef LSTATUS (WINAPI *REGGETVALUEW)(HKEY hkey, LPCWSTR pszSubKey, LPCWSTR pszValue, DWORD dwFlags, LPDWORD pdwType, PVOID pvData, LPDWORD pcbData);
REGGETVALUEW LoadLibAddy;
DWORD type;
HKEY hksub;
LSTATUS dwStatus;

LoadLibAddy = (REGGETVALUEW)GetProcAddress(GetModuleHandle(L"advapi32.dll"), "RegGetValueW");

if (LoadLibAddy)
{
return LoadLibAddy(hkey, pszSubKey, pszValue, dwFlags, pdwType, pvData, pcbData);
}
else
{
if (dwFlags == RRF_RT_REG_SZ)
{
type = REG_SZ;
}
else if (dwFlags == RRF_RT_REG_DWORD || dwFlags == RRF_RT_DWORD)
{
type = REG_DWORD;
}
if (pszSubKey && pszSubKey[0])
{
RegOpenKeyExW(hkey,pszSubKey,0,KEY_READ,&hksub);
dwStatus = RegQueryValueExW(hksub, pszValue, NULL, &type, (LPBYTE)pvData, pcbData);
RegCloseKey(hksub);
}
else
{
dwStatus = RegQueryValueExW(hkey, pszValue, NULL, &type, (LPBYTE)pvData, pcbData);
}
return dwStatus;
}
}
#endif /* !UNICODE */


BOOL
GetPowershellExePath(LPTSTR szPSPath)
{
HKEY hkey;
if (ERROR_SUCCESS != RegOpenKey(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Microsoft\\PowerShell"), &hkey))
{
return FALSE;
}
HKEY hkey;
TCHAR szSub[10]; // just the "1" or "3"
DWORD dwError;
HKEY hkeySub;
LPTSTR szPSExe;
int ikey;

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++)
for (ikey = 0; ikey < 5; ikey++)
{
TCHAR szSub[10]; // just the "1" or "3"

DWORD dwError = RegEnumKey(hkey, ikey, szSub, COUNTOF(szSub));
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);
dwError = MyRegGetValue(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");
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);
dwError = MyRegGetValue(hkeySub, TEXT("PowerShellEngine"), TEXT("ApplicationBase"), RRF_RT_REG_SZ | RRF_RT_REG_EXPAND_SZ, &dwType, (PVOID)szPSPath, &cbValue);

if (dwError == ERROR_SUCCESS)
{
Expand Down
14 changes: 9 additions & 5 deletions src/wfgoto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,10 @@ vector<wstring> SplitIntoWords(LPTSTR szText)
void FreeDirectoryBagOValues(BagOValues<PDNODE> *pbov, vector<PDNODE> *pNodes)
{
// free all PDNODE in BagOValues
for (PDNODE p : *pNodes)
for (int i = 0; i < pNodes->size(); i++)
{
LocalFree(p);
PDNODE child = pNodes->at(i);
LocalFree(child);
}

// free that vector and the BagOValues itself
Expand Down Expand Up @@ -375,8 +376,9 @@ BOOL BuildDirectoryBagOValues(BagOValues<PDNODE> *pbov, vector<PDNODE> *pNodes,
// if spaces, each word individually (and not whole thing)
vector<wstring> words = SplitIntoWords(lfndta.fd.cFileName);

for (auto word : words)
for (int i = 0; i < words.size(); i++)
{
wstring word = words.at(i);
// TODO: how to mark which word is primary to avoid double free?
pbov->Add(word, pNodeChild);
}
Expand Down Expand Up @@ -418,8 +420,9 @@ vector<PDNODE> *GetDirectoryOptionsFromText(LPTSTR szText, BOOL *pbLimited)

vector<vector<PDNODE> *> options_per_word;

for (auto word : words)
for (int i = 0; i < words.size(); i++)
{
wstring word = words.at(i);
vector<PDNODE> *options;
size_t pos = word.find_first_of(L'\\');
if (pos == word.size() - 1)
Expand Down Expand Up @@ -465,8 +468,9 @@ vector<PDNODE> *GetDirectoryOptionsFromText(LPTSTR szText, BOOL *pbLimited)

vector<PDNODE> *final_options = TreeIntersection(options_per_word);

for (auto option : options_per_word)
for (int i = 0; i < options_per_word.size(); i++)
{
vector<PDNODE> *option = options_per_word.at(i);
// if we didn't return one of the options as is
if (option != final_options)
delete option;
Expand Down
3 changes: 2 additions & 1 deletion src/wfsearch.c
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ SearchWndProc(
WCHAR szPath[MAXPATHLEN];
WCHAR szTitle[128];
WCHAR szMessage[MAXMESSAGELEN];
int msg;

hwndLB = GetDlgItem(hwnd, IDCW_LISTBOX);

Expand Down Expand Up @@ -750,7 +751,7 @@ SearchWndProc(
if (wParam == CD_SEARCHUPDATE) {
LoadString(hAppInstance, IDS_SEARCHTITLE, szTitle, COUNTOF(szTitle));
LoadString(hAppInstance, IDS_SEARCHREFRESH, szMessage, COUNTOF(szMessage));
int msg = MessageBox(hwnd, szMessage, szTitle, MB_ABORTRETRYIGNORE | MB_ICONQUESTION);
msg = MessageBox(hwnd, szMessage, szTitle, MB_ABORTRETRYIGNORE | MB_ICONQUESTION);

if (msg == IDABORT)
{
Expand Down
3 changes: 2 additions & 1 deletion src/wfutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ HistoryDir rghistoryDir[MAXHISTORY];
VOID
SaveHistoryDir(HWND hwnd, LPWSTR szDir)
{
DWORD historyT;
if (rghistoryDir[historyCur].hwnd == hwnd && lstrcmpi(rghistoryDir[historyCur].szDir, szDir) == 0)
return;

Expand All @@ -37,7 +38,7 @@ SaveHistoryDir(HWND hwnd, LPWSTR szDir)
lstrcpy(rghistoryDir[historyCur].szDir, szDir);

// always leave one NULL entry after current
DWORD historyT = (historyCur + 1) % MAXHISTORY;
historyT = (historyCur + 1) % MAXHISTORY;
rghistoryDir[historyT].hwnd = NULL;
rghistoryDir[historyT].szDir[0] = '\0';
}
Expand Down