Skip to content

Commit

Permalink
Avoid system wide searching file.
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed Jan 14, 2019
1 parent e8d674c commit cac743c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
20 changes: 10 additions & 10 deletions metapath/src/Helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1220,26 +1220,26 @@ void PathCanonicalizeEx(LPWSTR lpSrc) {
extern WCHAR tchFavoritesDir[MAX_PATH];
extern WCHAR szCurDir[MAX_PATH + 40];

DWORD SearchPathEx(LPCWSTR lpPath, LPCWSTR lpFileName, LPCWSTR lpExtension, DWORD nBufferLength, LPWSTR lpBuffer, LPWSTR *lpFilePart) {
BOOL SearchPathEx(LPCWSTR lpFileName, DWORD nBufferLength, LPWSTR lpBuffer) {
DWORD dwRetVal = 0;

if (StrEqual(lpFileName, L"..") || StrEqual(lpFileName, L".")) {
if (StrEqual(lpFileName, L"..") && PathIsRoot(szCurDir)) {
lstrcpyn(lpBuffer, L"*.*", nBufferLength);
dwRetVal = 1;
} else {
dwRetVal = SearchPath(szCurDir, lpFileName, lpExtension, nBufferLength, lpBuffer, lpFilePart);
}
} else {
dwRetVal = SearchPath(lpPath, lpFileName, lpExtension, nBufferLength, lpBuffer, lpFilePart);
}

// Search L"Favorites" if no result
if (!dwRetVal) {
dwRetVal = SearchPath(tchFavoritesDir, lpFileName, lpExtension, nBufferLength, lpBuffer, lpFilePart);
}
if (!dwRetVal) {
dwRetVal = SearchPath(szCurDir, lpFileName, NULL, nBufferLength, lpBuffer, NULL);
}

// Search Favorites if no result
if (!dwRetVal) {
dwRetVal = SearchPath(tchFavoritesDir, lpFileName, NULL, nBufferLength, lpBuffer, NULL);
}

return dwRetVal;
return dwRetVal != 0;
}

//=============================================================================
Expand Down
3 changes: 1 addition & 2 deletions metapath/src/Helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,7 @@ void StrTab2Space(LPWSTR lpsz);
void PathFixBackslashes(LPWSTR lpsz);
void ExpandEnvironmentStringsEx(LPWSTR lpSrc, DWORD dwSrc);
void PathCanonicalizeEx(LPWSTR lpSrc);
DWORD SearchPathEx(LPCWSTR lpPath, LPCWSTR lpFileName, LPCWSTR lpExtension,
DWORD nBufferLength, LPWSTR lpBuffer, LPWSTR *lpFilePart);
BOOL SearchPathEx(LPCWSTR lpFileName, DWORD nBufferLength, LPWSTR lpBuffer);
void FormatNumberStr(LPWSTR lpNumberStr);

void GetDefaultFavoritesDir(LPWSTR lpFavDir, int cchFavDir);
Expand Down
4 changes: 2 additions & 2 deletions metapath/src/metapath.c
Original file line number Diff line number Diff line change
Expand Up @@ -3041,7 +3041,7 @@ BOOL DisplayPath(LPCWSTR lpPath, UINT uIdError) {
ExpandEnvironmentStringsEx(szTmp, COUNTOF(szTmp));

WCHAR szPath[MAX_PATH];
if (!SearchPathEx(NULL, szTmp, NULL, COUNTOF(szPath), szPath, NULL)) {
if (!SearchPathEx(szTmp, COUNTOF(szPath), szPath)) {
lstrcpy(szPath, szTmp);
}

Expand Down Expand Up @@ -3120,7 +3120,7 @@ BOOL DisplayLnkFile(LPCWSTR pszLnkFile) {
ExpandEnvironmentStringsEx(szTmp, COUNTOF(szTmp));

WCHAR szPath[MAX_PATH];
if (!SearchPathEx(NULL, szTmp, NULL, COUNTOF(szPath), szPath, NULL)) {
if (!SearchPathEx(szTmp, COUNTOF(szPath), szPath)) {
lstrcpy(szPath, szTmp);
}

Expand Down

0 comments on commit cac743c

Please sign in to comment.