diff --git a/minipath/src/minipath.c b/minipath/src/minipath.c index 123cfb666..a400f3be9 100644 --- a/minipath/src/minipath.c +++ b/minipath/src/minipath.c @@ -304,7 +304,7 @@ int WINAPI wWinMain(HINSTANCE hInstance,HINSTANCE hPrevInst,LPWSTR lpCmdLine,int LoadFlags(); // Try to activate another window - if (ActivatePrevInst()) { return(0); } + if (ActivatePrevInst()) { return 0; } // Init OLE and Common Controls OleInitialize(NULL); diff --git a/src/Dialogs.c b/src/Dialogs.c index 7363e6f33..e33a94ebb 100644 --- a/src/Dialogs.c +++ b/src/Dialogs.c @@ -785,7 +785,7 @@ INT_PTR CALLBACK RunDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam) WCHAR szArgs[MAX_PATH] = { L'\0' }; WCHAR szArg2[MAX_PATH] = { L'\0' }; WCHAR szFile[MAX_PATH * 2] = { L'\0' }; - WCHAR szFilter[256] = { L'\0' }; + WCHAR szFilter[MAX_PATH] = { L'\0' }; OPENFILENAME ofn; ZeroMemory(&ofn,sizeof(OPENFILENAME)); @@ -853,7 +853,7 @@ INT_PTR CALLBACK RunDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam) bQuickExit = true; } - if (StringCchLenW(Globals.CurrentFile, (MAX_PATH+1))) { + if (StringCchLenW(Globals.CurrentFile, MAX_PATH)) { StringCchCopy(wchDirectory,COUNTOF(wchDirectory),Globals.CurrentFile); PathRemoveFileSpec(wchDirectory); } @@ -1080,7 +1080,7 @@ bool OpenWithDlg(HWND hwnd,LPCWSTR lpstrFile) WCHAR szParam[MAX_PATH] = { L'\0' }; WCHAR wchDirectory[MAX_PATH] = { L'\0' }; - if (StringCchLenW(Globals.CurrentFile, (MAX_PATH+1))) { + if (StringCchLenW(Globals.CurrentFile, MAX_PATH)) { StringCchCopy(wchDirectory,COUNTOF(wchDirectory),Globals.CurrentFile); PathRemoveFileSpec(wchDirectory); } @@ -1311,8 +1311,7 @@ INT_PTR CALLBACK AddToFavDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lPa case IDOK: pszName = (LPWSTR)GetWindowLongPtr(hwnd, DWLP_USER); - GetDlgItemText(hwnd, 100, pszName, - MAX_PATH - 1); + GetDlgItemText(hwnd, 100, pszName, MAX_PATH - 1); EndDialog(hwnd, IDOK); break; @@ -2884,7 +2883,7 @@ void DialogNewWindow(HWND hwnd, bool bSaveOnRunTools, bool bSetCurFile) if (bSaveOnRunTools && !FileSave(false, true, false, false)) { return; } GetModuleFileName(NULL, szModuleName, COUNTOF(szModuleName)); - NormalizePathEx(szModuleName, COUNTOF(szModuleName)); + NormalizePathEx(szModuleName, COUNTOF(szModuleName), true, false); StringCchPrintf(tch, COUNTOF(tch), L"\"-appid=%s\"", Settings2.AppUserModelID); StringCchCopy(szParameters, COUNTOF(szParameters), tch); @@ -2918,7 +2917,7 @@ void DialogNewWindow(HWND hwnd, bool bSaveOnRunTools, bool bSetCurFile) StringCchPrintf(tch, COUNTOF(tch), L" -pos %i,%i,%i,%i,%i", wi.x, wi.y, wi.cx, wi.cy, wi.max); StringCchCat(szParameters, COUNTOF(szParameters), tch); - if (bSetCurFile && StringCchLenW(Globals.CurrentFile, (MAX_PATH+1))) + if (bSetCurFile && StringCchLenW(Globals.CurrentFile, MAX_PATH)) { StringCchCopy(szFileName, COUNTOF(szFileName), Globals.CurrentFile); PathQuoteSpaces(szFileName); @@ -2947,9 +2946,9 @@ void DialogNewWindow(HWND hwnd, bool bSaveOnRunTools, bool bSetCurFile) // void DialogFileBrowse(HWND hwnd) { - WCHAR tchParam[MAX_PATH+1] = L""; - WCHAR tchExeFile[MAX_PATH+1] = L""; - WCHAR tchTemp[MAX_PATH+1]; + WCHAR tchParam[MAX_PATH] = L""; + WCHAR tchExeFile[MAX_PATH] = L""; + WCHAR tchTemp[MAX_PATH]; StringCchCopyW(tchTemp, COUNTOF(tchTemp), Settings2.FileBrowserPath); @@ -2971,7 +2970,7 @@ void DialogFileBrowse(HWND hwnd) if (StringCchLenW(tchParam, COUNTOF(tchParam)) && StringCchLenW(Globals.CurrentFile, COUNTOF(tchParam))) { StringCchCat(tchParam, COUNTOF(tchParam), L" "); } - if (StringCchLenW(Globals.CurrentFile, (MAX_PATH+1))) { + if (StringCchLenW(Globals.CurrentFile, MAX_PATH)) { StringCchCopy(tchTemp, COUNTOF(tchTemp), Globals.CurrentFile); PathQuoteSpaces(tchTemp); StringCchCat(tchParam, COUNTOF(tchParam), tchTemp); @@ -3003,12 +3002,12 @@ void DialogFileBrowse(HWND hwnd) void DialogAdminExe(HWND hwnd, bool bExecInstaller) { - WCHAR tchExe[MAX_PATH+2]; + WCHAR tchExe[MAX_PATH]; StringCchCopyW(tchExe, COUNTOF(tchExe), Settings2.AdministrationTool); if (bExecInstaller && !StringCchLenW(tchExe, COUNTOF(tchExe))) { return; } - WCHAR tchExePath[MAX_PATH + 2]; + WCHAR tchExePath[MAX_PATH]; if (!SearchPath(NULL, tchExe, L".exe", COUNTOF(tchExePath), tchExePath, NULL)) { // try Notepad3's dir path GetModuleFileName(NULL, tchExePath, COUNTOF(tchExePath)); @@ -3101,13 +3100,10 @@ bool SetWindowTitle(HWND hwnd, UINT uIDAppName, bool bIsElevated, UINT uIDUntitl { if (iFormat < 2 && !PathIsRoot(lpszFile)) { - if (StringCchCompareN(szCachedFile, COUNTOF(szCachedFile), lpszFile, MAX_PATH) != 0) { - SHFILEINFO shfi; + if (StringCchCompareN(szCachedFile, COUNTOF(szCachedFile), lpszFile, MAX_PATH) != 0) + { StringCchCopy(szCachedFile, COUNTOF(szCachedFile), lpszFile); - if (SHGetFileInfo2(lpszFile, FILE_ATTRIBUTE_NORMAL, &shfi, sizeof(SHFILEINFO), SHGFI_DISPLAYNAME | SHGFI_USEFILEATTRIBUTES)) - StringCchCopy(szCachedDisplayName, COUNTOF(szCachedDisplayName), shfi.szDisplayName); - else - StringCchCopy(szCachedDisplayName, COUNTOF(szCachedDisplayName), PathFindFileName(lpszFile)); + PathGetDisplayName(szCachedDisplayName, COUNTOF(szCachedDisplayName), szCachedFile); } StringCchCat(szTitle, COUNTOF(szTitle), szCachedDisplayName); if (iFormat == 1) { diff --git a/src/Edit.c b/src/Edit.c index fb41ef452..01291cf6f 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -997,19 +997,6 @@ bool EditLoadFile( } } - // display real path name (by zufuliu) - WCHAR realPath[MAX_PATH] = L""; - if (GetFinalPathNameByHandleW(hFile, realPath, MAX_PATH, /*FILE_NAME_OPENED*/0x8) > 0) { - if (StrCmpN(realPath, L"\\\\?\\", 4) == 0) { - WCHAR* p = realPath + 4; - if (StrCmpN(p, L"UNC\\", 4) == 0) { - p += 2; - *p = L'\\'; - } - StringCchCopyW(pszFile, MAX_PATH, p); - } - } - char* lpData = AllocMem(dwBufSize, HEAP_ZERO_MEMORY); Globals.dwLastError = GetLastError(); diff --git a/src/Helpers.c b/src/Helpers.c index 2864a7fa5..7f8af3922 100644 --- a/src/Helpers.c +++ b/src/Helpers.c @@ -1262,10 +1262,9 @@ void PathFixBackslashes(LPWSTR lpsz) // // Adjusted for Windows 95 // -void ExpandEnvironmentStringsEx(LPWSTR lpSrc,DWORD dwSrc) +void ExpandEnvironmentStringsEx(LPWSTR lpSrc, DWORD dwSrc) { - WCHAR szBuf[LARGE_BUFFER]; - + WCHAR szBuf[HUGE_BUFFER]; if (ExpandEnvironmentStrings(lpSrc, szBuf, COUNTOF(szBuf))) { StringCchCopyN(lpSrc, dwSrc, szBuf, COUNTOF(szBuf)); } @@ -1277,11 +1276,12 @@ void ExpandEnvironmentStringsEx(LPWSTR lpSrc,DWORD dwSrc) // PathCanonicalizeEx() // // -void PathCanonicalizeEx(LPWSTR lpszPath,int len) +void PathCanonicalizeEx(LPWSTR lpszPath, DWORD cchBuffer) { - WCHAR szDst[(MAX_PATH+1)] = { L'\0' }; - if (PathCchCanonicalize(szDst,len,lpszPath) == S_OK) - StringCchCopy(lpszPath,len,szDst); + WCHAR szDst[MAX_PATH] = { L'\0' }; + if (PathCchCanonicalize(szDst, MAX_PATH, lpszPath) == S_OK) { + StringCchCopy(lpszPath, cchBuffer, szDst); + } } @@ -1290,42 +1290,29 @@ void PathCanonicalizeEx(LPWSTR lpszPath,int len) // GetLongPathNameEx() // // -DWORD GetLongPathNameEx(LPWSTR lpszPath,DWORD cchBuffer) +DWORD GetLongPathNameEx(LPWSTR lpszPath, DWORD cchBuffer) { - DWORD dwRet = GetLongPathName(lpszPath,lpszPath,cchBuffer); + DWORD const dwRet = GetLongPathName(lpszPath, lpszPath, cchBuffer); if (dwRet) { - if (PathGetDriveNumber(lpszPath) != -1) - CharUpperBuff(lpszPath,1); - return(dwRet); + if (PathGetDriveNumber(lpszPath) != -1) { + CharUpperBuff(lpszPath, 1); + } } - return(0); + return dwRet; } //============================================================================= // -// NormalizePathEx() -// -// -DWORD NormalizePathEx(LPWSTR lpszPath,int len) -{ - PathCanonicalizeEx(lpszPath,len); - return GetLongPathNameEx(lpszPath,(DWORD)len); -} - - - -//============================================================================= -// -// SHGetFileInfo2() +// _SHGetFileInfoEx() // // Return a default name when the file has been removed, and always append // a filename extension // -DWORD_PTR SHGetFileInfo2(LPCWSTR pszPath, DWORD dwFileAttributes, - SHFILEINFO *psfi, UINT cbFileInfo, UINT uFlags) +static DWORD_PTR _SHGetFileInfoEx(LPCWSTR pszPath, DWORD dwFileAttributes, + SHFILEINFO* psfi, UINT cbFileInfo, UINT uFlags) { - if (PathFileExists(pszPath)) + if (PathFileExists(pszPath)) { DWORD_PTR dw = SHGetFileInfo(pszPath, dwFileAttributes, psfi, cbFileInfo, uFlags); if (StringCchLenW(psfi->szDisplayName, COUNTOF(psfi->szDisplayName)) < StringCchLen(PathFindFileName(pszPath), MAX_PATH)) @@ -1341,6 +1328,94 @@ DWORD_PTR SHGetFileInfo2(LPCWSTR pszPath, DWORD dwFileAttributes, } +//============================================================================= +// +// PathResolveDisplayName() +// +void PathGetDisplayName(LPWSTR lpszDestPath, DWORD cchDestBuffer, LPCWSTR lpszSourcePath) +{ + SHFILEINFO shfi; + UINT const shfi_size = (UINT)sizeof(SHFILEINFO); + ZeroMemory(&shfi, shfi_size); + if (_SHGetFileInfoEx(lpszSourcePath, FILE_ATTRIBUTE_NORMAL, &shfi, shfi_size, SHGFI_DISPLAYNAME | SHGFI_USEFILEATTRIBUTES)) { + StringCchCopy(lpszDestPath, cchDestBuffer, shfi.szDisplayName); + } + else { + StringCchCopy(lpszDestPath, cchDestBuffer, PathFindFileName(lpszSourcePath)); + } +} + + +//============================================================================= +// +// NormalizePathEx() +// +DWORD NormalizePathEx(LPWSTR lpszPath, DWORD cchBuffer, bool bRealPath, bool bSearchPathIfRelative) +{ + WCHAR tmpFilePath[MAX_PATH] = { L'\0' }; + + StringCchCopyN(tmpFilePath, COUNTOF(tmpFilePath), lpszPath, cchBuffer); + ExpandEnvironmentStringsEx(tmpFilePath, COUNTOF(tmpFilePath)); + + PathUnquoteSpaces(tmpFilePath); + + if (PathIsRelative(tmpFilePath)) + { + StringCchCopyN(lpszPath, cchBuffer, Globals.WorkingDirectory, COUNTOF(Globals.WorkingDirectory)); + PathCchAppend(lpszPath, cchBuffer, tmpFilePath); + if (bSearchPathIfRelative) { + if (!PathFileExists(lpszPath)) { + PathStripPath(tmpFilePath); + if (SearchPath(NULL, tmpFilePath, NULL, cchBuffer, lpszPath, NULL) == 0) { + StringCchCopy(lpszPath, cchBuffer, tmpFilePath); + } + } + } + } + else { + StringCchCopy(lpszPath, cchBuffer, tmpFilePath); + } + + PathCanonicalizeEx(lpszPath, cchBuffer); + GetLongPathNameEx(lpszPath, cchBuffer); + + if (PathIsLnkFile(lpszPath)) { + PathGetLnkPath(lpszPath, lpszPath, cchBuffer); + } + + if (bRealPath) { + // get real path name (by zufuliu) + HANDLE hFile = CreateFile(lpszPath, // file to open + GENERIC_READ, // open for reading + FILE_SHARE_READ, // share for reading + NULL, // default security + OPEN_EXISTING, // existing file only + FILE_ATTRIBUTE_NORMAL, // normal file + NULL); // no attr. template + + if (hFile != INVALID_HANDLE_VALUE) { + if (GetFinalPathNameByHandleW(hFile, tmpFilePath, + COUNTOF(tmpFilePath), FILE_NAME_OPENED) > 0) + { + if (StrCmpN(tmpFilePath, L"\\\\?\\", 4) == 0) { + WCHAR* p = tmpFilePath + 4; + if (StrCmpN(p, L"UNC\\", 4) == 0) { + p += 2; + *p = L'\\'; + } + StringCchCopyW(lpszPath, MAX_PATH, p); + } + } + } + CloseHandle(hFile); + } + + size_t pathLen = 0; + StringCchLength(lpszPath, cchBuffer, &pathLen); + return (DWORD)pathLen; +} + + //============================================================================= // // FormatNumberStr() diff --git a/src/Helpers.h b/src/Helpers.h index 62a9e66af..40c909dd8 100644 --- a/src/Helpers.h +++ b/src/Helpers.h @@ -314,10 +314,11 @@ void PathFixBackslashes(LPWSTR lpsz); void ExpandEnvironmentStringsEx(LPWSTR lpSrc,DWORD dwSrc); -void PathCanonicalizeEx(LPWSTR lpszPath,int len); -DWORD GetLongPathNameEx(LPWSTR lpszPath,DWORD cchBuffer); -DWORD NormalizePathEx(LPWSTR lpszPath,int len); -DWORD_PTR SHGetFileInfo2(LPCWSTR pszPath,DWORD dwFileAttributes,SHFILEINFO* psfi,UINT cbFileInfo,UINT uFlags); +void PathCanonicalizeEx(LPWSTR lpszPath, DWORD cchBuffer); +DWORD GetLongPathNameEx(LPWSTR lpszPath, DWORD cchBuffer); +void PathGetDisplayName(LPWSTR lpszDestPath, DWORD cchDestBuffer, LPCWSTR lpszSourcePath); +DWORD NormalizePathEx(LPWSTR lpszPath, DWORD cchBuffer, bool bRealPath, bool bSearchPathIfRelative); + size_t FormatNumberStr(LPWSTR lpNumberStr); bool SetDlgItemIntEx(HWND hwnd,int nIdItem,UINT uValue); diff --git a/src/Notepad3.c b/src/Notepad3.c index 7ed0ae575..6184f5243 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -81,8 +81,8 @@ static HWND s_hwndNextCBChain = NULL; static HWND s_hwndToolbar = NULL; static HWND s_hwndReBar = NULL; -static WCHAR s_wchIniFile2[MAX_PATH + 1] = { L'\0' }; -static WCHAR s_wchTmpFilePath[MAX_PATH + 1] = { L'\0' }; +static WCHAR s_wchIniFile2[MAX_PATH] = { L'\0' }; +static WCHAR s_wchTmpFilePath[MAX_PATH] = { L'\0' }; // 'en-US' internal default static WCHAR* const s_tchAvailableLanguages = L"af-ZA be-BY de-DE en-GB es-ES fr-FR hu-HU it-IT ja-JP ko-KR nl-NL pt-BR ru-RU zh-CN"; @@ -99,9 +99,9 @@ static int s_vSBSOrder[STATUS_SECTOR_COUNT] = SBS_INIT_MINUS; static int s_iStatusbarWidthSpec[STATUS_SECTOR_COUNT] = SBS_INIT_ZERO; -static WCHAR s_tchToolbarBitmap[MAX_PATH + 1] = { L'\0' }; -static WCHAR s_tchToolbarBitmapHot[MAX_PATH + 1] = { L'\0' }; -static WCHAR s_tchToolbarBitmapDisabled[MAX_PATH + 1] = { L'\0' }; +static WCHAR s_tchToolbarBitmap[MAX_PATH] = { L'\0' }; +static WCHAR s_tchToolbarBitmapHot[MAX_PATH] = { L'\0' }; +static WCHAR s_tchToolbarBitmapDisabled[MAX_PATH] = { L'\0' }; static WCHAR s_wchPrefixSelection[256] = { L'\0' }; static WCHAR s_wchAppendSelection[256] = { L'\0' }; @@ -125,7 +125,7 @@ static WCHAR* const _s_RecentFiles = L"Recent Files"; static WCHAR* const _s_RecentFind = L"Recent Find"; static WCHAR* const _s_RecentReplace = L"Recent Replace"; -static WCHAR s_tchLastSaveCopyDir[MAX_PATH + 1] = { L'\0' }; +static WCHAR s_tchLastSaveCopyDir[MAX_PATH] = { L'\0' }; static bool s_bExternalBitmap = false; static bool s_bRunningWatch = false; @@ -524,6 +524,11 @@ static void _CleanUpResources(const HWND hwnd, bool bIsInitialized) } OleUninitialize(); + + if (s_lpFileArg) { + FreeMem(s_lpFileArg); + s_lpFileArg = NULL; + } } //============================================================================= @@ -1106,9 +1111,9 @@ HWND InitInstance(HINSTANCE hInstance,LPCWSTR pszCmdLine,int nCmdShow) else StringCchCopy(Globals.CurrentFile,COUNTOF(Globals.CurrentFile),L""); - if (!s_flagLexerSpecified) - Style_SetLexerFromFile(Globals.hwndEdit,Globals.CurrentFile); - + if (!s_flagLexerSpecified) { + Style_SetLexerFromFile(Globals.hwndEdit, Globals.CurrentFile); + } _SetDocumentModified(true); // check for temp file and delete @@ -1267,14 +1272,14 @@ HWND InitInstance(HINSTANCE hInstance,LPCWSTR pszCmdLine,int nCmdShow) // print file immediately and quit if (Flags.PrintFileAndLeave) { - SHFILEINFO shfi; WCHAR *pszTitle; WCHAR tchUntitled[32] = { L'\0' }; WCHAR tchPageFmt[32] = { L'\0' }; + WCHAR szDisplayName[MAX_PATH]; if (StringCchLenW(Globals.CurrentFile,COUNTOF(Globals.CurrentFile))) { - SHGetFileInfo2(Globals.CurrentFile, FILE_ATTRIBUTE_NORMAL, &shfi, sizeof(SHFILEINFO), SHGFI_DISPLAYNAME | SHGFI_USEFILEATTRIBUTES); - pszTitle = shfi.szDisplayName; + PathGetDisplayName(szDisplayName, COUNTOF(szDisplayName), Globals.CurrentFile); + pszTitle = szDisplayName; } else { GetLngString(IDS_MUI_UNTITLED, tchUntitled, COUNTOF(tchUntitled)); @@ -3038,7 +3043,7 @@ LRESULT MsgInitMenu(HWND hwnd, WPARAM wParam, LPARAM lParam) // LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) { - WCHAR tchMaxPathBuffer[MAX_PATH + 1] = { L'\0' }; + WCHAR tchMaxPathBuffer[MAX_PATH] = { L'\0' }; switch(LOWORD(wParam)) { @@ -3185,16 +3190,15 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) case IDM_FILE_PRINT: { - SHFILEINFO shfi; - ZeroMemory(&shfi, sizeof(SHFILEINFO)); - WCHAR *pszTitle; WCHAR tchUntitled[32] = { L'\0' }; WCHAR tchPageFmt[32] = { L'\0' }; + WCHAR szDisplayName[MAX_PATH]; - if (StringCchLenW(Globals.CurrentFile,COUNTOF(Globals.CurrentFile))) { - SHGetFileInfo2(Globals.CurrentFile,FILE_ATTRIBUTE_NORMAL,&shfi,sizeof(SHFILEINFO),SHGFI_DISPLAYNAME | SHGFI_USEFILEATTRIBUTES); - pszTitle = shfi.szDisplayName; + if (StringCchLenW(Globals.CurrentFile,COUNTOF(Globals.CurrentFile))) + { + PathGetDisplayName(szDisplayName, COUNTOF(szDisplayName), Globals.CurrentFile); + pszTitle = szDisplayName; } else { GetLngString(IDS_MUI_UNTITLED, tchUntitled, COUNTOF(tchUntitled)); @@ -3257,11 +3261,10 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) case IDM_FILE_ADDTOFAV: - if (StringCchLenW(Globals.CurrentFile,COUNTOF(Globals.CurrentFile))) { - SHFILEINFO shfi; - SHGetFileInfo2(Globals.CurrentFile,FILE_ATTRIBUTE_NORMAL, - &shfi,sizeof(SHFILEINFO),SHGFI_DISPLAYNAME | SHGFI_USEFILEATTRIBUTES); - AddToFavDlg(hwnd,shfi.szDisplayName,Globals.CurrentFile); + if (StringCchLenW(Globals.CurrentFile, COUNTOF(Globals.CurrentFile))) { + WCHAR szDisplayName[MAX_PATH]; + PathGetDisplayName(szDisplayName, COUNTOF(szDisplayName), Globals.CurrentFile); + AddToFavDlg(hwnd, szDisplayName, Globals.CurrentFile); } break; @@ -4075,25 +4078,24 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) case IDM_EDIT_INSERT_FILENAME: case IDM_EDIT_INSERT_PATHNAME: { - SHFILEINFO shfi; WCHAR *pszInsert; WCHAR tchUntitled[32]; - //int iSelStart; + WCHAR szDisplayName[MAX_PATH]; if (StringCchLenW(Globals.CurrentFile, COUNTOF(Globals.CurrentFile))) { if (LOWORD(wParam) == IDM_EDIT_INSERT_FILENAME) { - SHGetFileInfo2(Globals.CurrentFile, FILE_ATTRIBUTE_NORMAL, &shfi, sizeof(SHFILEINFO), - SHGFI_DISPLAYNAME | SHGFI_USEFILEATTRIBUTES); - pszInsert = shfi.szDisplayName; + PathGetDisplayName(szDisplayName, COUNTOF(szDisplayName), Globals.CurrentFile); + pszInsert = szDisplayName; } - else + else { pszInsert = Globals.CurrentFile; + } } else { GetLngString(IDS_MUI_UNTITLED, tchUntitled, COUNTOF(tchUntitled)); pszInsert = tchUntitled; } - char chPath[MAX_PATH + 1]; + char chPath[MAX_PATH]; WideCharToMultiByte(Encoding_SciCP, 0, pszInsert, -1, chPath, COUNTOF(chPath), NULL, NULL); _BEGIN_UNDO_ACTION_; SendMessage(Globals.hwndEdit, SCI_REPLACESEL, 0, (LPARAM)chPath); @@ -4108,7 +4110,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) if (SUCCEEDED(CoCreateGuid(&guid))) { if (StringFromGUID2(&guid, tchMaxPathBuffer,COUNTOF(tchMaxPathBuffer))) { StrTrimW(tchMaxPathBuffer, L"{}"); - char chMaxPathBuffer[MAX_PATH + 1] = { '\0' }; + char chMaxPathBuffer[MAX_PATH] = { '\0' }; if (WideCharToMultiByte(Encoding_SciCP, 0, tchMaxPathBuffer, -1, chMaxPathBuffer, COUNTOF(chMaxPathBuffer), NULL, NULL)) { _BEGIN_UNDO_ACTION_; SendMessage(Globals.hwndEdit,SCI_REPLACESEL,0,(LPARAM)chMaxPathBuffer); @@ -4965,7 +4967,6 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) IniSetString(L"Settings2", L"SingleFileInstance", NULL); break; - case IDM_VIEW_ALWAYSONTOP: if ((Settings.AlwaysOnTop || s_flagAlwaysOnTop == 2) && s_flagAlwaysOnTop != 1) { Settings.AlwaysOnTop = false; @@ -5958,7 +5959,7 @@ void OpenHotSpotURL(DocPos position, bool bForceBrowser) if (PathIsDirectory(szFileName)) { - WCHAR tchFile[MAX_PATH + 1] = { L'\0' }; + WCHAR tchFile[MAX_PATH] = { L'\0' }; if (OpenFileDlg(Globals.hwndMain, tchFile, COUNTOF(tchFile), szFileName)) FileLoad(false, false, false, Settings.SkipUnicodeDetection, Settings.SkipANSICodePageDetection, tchFile); @@ -5969,7 +5970,7 @@ void OpenHotSpotURL(DocPos position, bool bForceBrowser) } else { // open in web browser - WCHAR wchDirectory[MAX_PATH+1] = { L'\0' }; + WCHAR wchDirectory[MAX_PATH] = { L'\0' }; if (StringCchLenW(Globals.CurrentFile, COUNTOF(Globals.CurrentFile))) { StringCchCopy(wchDirectory, COUNTOF(wchDirectory), Globals.CurrentFile); PathRemoveFileSpec(wchDirectory); @@ -7461,8 +7462,7 @@ void ParseCommandLine() StringCchCopyN(s_wchTmpFilePath, COUNTOF(s_wchTmpFilePath), lp1 + CSTRLEN(L"tmpfbuf="), len - CSTRLEN(L"tmpfbuf=")); TrimStringW(s_wchTmpFilePath); - PathUnquoteSpaces(s_wchTmpFilePath); - NormalizePathEx(s_wchTmpFilePath, COUNTOF(s_wchTmpFilePath)); + NormalizePathEx(s_wchTmpFilePath, COUNTOF(s_wchTmpFilePath), true, false); s_flagBufferFile = 1; } @@ -7492,8 +7492,7 @@ void ParseCommandLine() else if (ExtractFirstArgument(lp2, lp1, lp2, (int)len)) { StringCchCopyN(Globals.IniFile, COUNTOF(Globals.IniFile), lp1, len); TrimStringW(Globals.IniFile); - PathUnquoteSpaces(Globals.IniFile); - NormalizePathEx(Globals.IniFile, COUNTOF(Globals.IniFile)); + NormalizePathEx(Globals.IniFile, COUNTOF(Globals.IniFile), true, false); } break; @@ -7733,18 +7732,18 @@ void ParseCommandLine() //lpFileArg = NULL; } s_lpFileArg = AllocMem(sizeof(WCHAR)*(MAX_PATH+1), HEAP_ZERO_MEMORY); // changed for ActivatePrevInst() needs - StringCchCopy(s_lpFileArg, (MAX_PATH+1), lp3); + StringCchCopy(s_lpFileArg, MAX_PATH, lp3); PathFixBackslashes(s_lpFileArg); if (!PathIsRelative(s_lpFileArg) && !PathIsUNC(s_lpFileArg) && PathGetDriveNumber(s_lpFileArg) == -1 /*&& PathGetDriveNumber(Globals.WorkingDirectory) != -1*/) { - WCHAR wchPath[(MAX_PATH+1)] = { L'\0' }; + WCHAR wchPath[MAX_PATH] = { L'\0' }; StringCchCopy(wchPath, COUNTOF(wchPath), Globals.WorkingDirectory); PathStripToRoot(wchPath); PathCchAppend(wchPath, COUNTOF(wchPath), s_lpFileArg); - StringCchCopy(s_lpFileArg, (MAX_PATH+1), wchPath); + StringCchCopy(s_lpFileArg, MAX_PATH, wchPath); } StrTrim(s_lpFileArg, L" \""); @@ -7972,7 +7971,7 @@ int FindIniFile() { } } - NormalizePathEx(Globals.IniFile,COUNTOF(Globals.IniFile)); + NormalizePathEx(Globals.IniFile,COUNTOF(Globals.IniFile), true, false); return(1); } @@ -8000,7 +7999,7 @@ int TestIniFile() { } } - NormalizePathEx(Globals.IniFile,COUNTOF(Globals.IniFile)); + NormalizePathEx(Globals.IniFile,COUNTOF(Globals.IniFile), true, false); if (!PathFileExists(Globals.IniFile) || PathIsDirectory(Globals.IniFile)) { StringCchCopy(s_wchIniFile2,COUNTOF(s_wchIniFile2),Globals.IniFile); @@ -9264,7 +9263,6 @@ static void _WarnInconsistentIndentation(const EditFileIOStatus* const status) // bool FileLoad(bool bDontSave, bool bNew, bool bReload, bool bSkipUnicodeDetect, bool bSkipANSICPDetection, LPCWSTR lpszFile) { - WCHAR tch[MAX_PATH] = { L'\0' }; WCHAR szFileName[MAX_PATH] = { L'\0' }; bool fSuccess = false; @@ -9322,36 +9320,17 @@ bool FileLoad(bool bDontSave, bool bNew, bool bReload, bool bSkipUnicodeDetect, } if (StrIsEmpty(lpszFile)) { - if (!OpenFileDlg(Globals.hwndMain,tch,COUNTOF(tch),NULL)) + if (!OpenFileDlg(Globals.hwndMain, szFileName,COUNTOF(szFileName),NULL)) return false; } - else - StringCchCopy(tch,COUNTOF(tch),lpszFile); - - ExpandEnvironmentStringsEx(tch,COUNTOF(tch)); - - if (PathIsRelative(tch)) { - StringCchCopyN(szFileName,COUNTOF(szFileName),Globals.WorkingDirectory,COUNTOF(Globals.WorkingDirectory)); - PathCchAppend(szFileName,COUNTOF(szFileName),tch); - //~ don't search in PATH when opening relative paths via command line - //~if (!PathFileExists(szFileName)) { - //~ WCHAR wchFullPath[MAX_PATH] = { L'\0' }; - //~ if (SearchPath(NULL,tch,NULL,COUNTOF(wchFullPath),wchFullPath,NULL)) { - //~ StringCchCopy(szFileName,COUNTOF(szFileName),wchFullPath); - //~ } - //~} - } else { - StringCchCopy(szFileName, COUNTOF(szFileName), tch); + StringCchCopy(szFileName, COUNTOF(szFileName), lpszFile); } - NormalizePathEx(szFileName, COUNTOF(szFileName)); - - if (PathIsLnkFile(szFileName)) - PathGetLnkPath(szFileName,szFileName,COUNTOF(szFileName)); + NormalizePathEx(szFileName, COUNTOF(szFileName), true, false); // change current directory to prevent directory lock on another path - WCHAR szFolder[MAX_PATH+2]; - if (SUCCEEDED(StringCchCopy(szFolder,COUNTOF(szFolder),tch))) { + WCHAR szFolder[MAX_PATH]; + if (SUCCEEDED(StringCchCopy(szFolder,COUNTOF(szFolder), szFileName))) { if (SUCCEEDED(PathCchRemoveFileSpec(szFolder,COUNTOF(szFolder)))) { SetCurrentDirectory(szFolder); } @@ -9920,18 +9899,19 @@ BOOL CALLBACK EnumWndProc2(HWND hwnd,LPARAM lParam) if (StringCchCompareNIW(szClassName,COUNTOF(szClassName),s_wchWndClass,COUNTOF(s_wchWndClass)) == 0) { DWORD dwReuseLock = GetDlgItemInt(hwnd,IDC_REUSELOCK,NULL,false); - if (GetTickCount() - dwReuseLock >= REUSEWINDOWLOCKTIMEOUT) { + if (GetTickCount() - dwReuseLock >= REUSEWINDOWLOCKTIMEOUT) + { + if (IsWindowEnabled(hwnd)) { bContinue = FALSE; } WCHAR tchFileName[MAX_PATH] = { L'\0' }; - - if (IsWindowEnabled(hwnd)) - bContinue = FALSE; - - GetDlgItemText(hwnd,IDC_FILENAME,tchFileName,COUNTOF(tchFileName)); - if (StringCchCompareXI(tchFileName,s_lpFileArg) == 0) + GetDlgItemText(hwnd, IDC_FILENAME, tchFileName, COUNTOF(tchFileName)); + + if (StringCchCompareXI(tchFileName, s_lpFileArg) == 0) { *(HWND*)lParam = hwnd; - else + } + else { bContinue = TRUE; + } } } return bContinue; @@ -9942,22 +9922,14 @@ bool ActivatePrevInst() HWND hwnd = NULL; COPYDATASTRUCT cds; - if ((Flags.fNoReuseWindow && !Flags.fSingleFileInstance) || s_flagStartAsTrayIcon || s_flagNewFromClipboard || s_flagPasteBoard) + if ((Flags.fNoReuseWindow && !Flags.fSingleFileInstance) || s_flagStartAsTrayIcon || s_flagNewFromClipboard || s_flagPasteBoard) { return false; + } if (Flags.fSingleFileInstance && s_lpFileArg) { - ExpandEnvironmentStringsEx(s_lpFileArg,(DWORD)SizeOfMem(s_lpFileArg)/sizeof(WCHAR)); - if (PathIsRelative(s_lpFileArg)) { - WCHAR tchTmp[MAX_PATH] = { L'\0' }; - StringCchCopyN(tchTmp,COUNTOF(tchTmp),Globals.WorkingDirectory,COUNTOF(Globals.WorkingDirectory)); - PathCchAppend(tchTmp,COUNTOF(tchTmp),s_lpFileArg); - StringCchCopy(s_lpFileArg, MAX_PATH, tchTmp); - //~ don't search in PATH when opening relative paths via command line - //~...SearchPath(NULL,lpFileArg,NULL,COUNTOF(tchTmp),tchTmp,NULL)... - } - NormalizePathEx(s_lpFileArg, MAX_PATH); + NormalizePathEx(s_lpFileArg, (DWORD)SizeOfMem(s_lpFileArg) / sizeof(WCHAR), true, false); EnumWindows(EnumWndProc2,(LPARAM)&hwnd); @@ -10048,15 +10020,6 @@ bool ActivatePrevInst() if (s_lpFileArg) { - ExpandEnvironmentStringsEx(s_lpFileArg,(DWORD)SizeOfMem(s_lpFileArg)/sizeof(WCHAR)); - - if (PathIsRelative(s_lpFileArg)) { - WCHAR tchTmp[MAX_PATH] = { L'\0' }; - StringCchCopyN(tchTmp,COUNTOF(tchTmp),Globals.WorkingDirectory,COUNTOF(Globals.WorkingDirectory)); - PathCchAppend(tchTmp,COUNTOF(tchTmp),s_lpFileArg); - StringCchCopy(s_lpFileArg, MAX_PATH, tchTmp); - } - size_t cb = sizeof(np3params); cb += (StringCchLenW(s_lpFileArg,0) + 1) * sizeof(WCHAR); @@ -10188,7 +10151,7 @@ bool RelaunchElevated(LPWSTR lpArgs) { LPWSTR lpCmdLine = GetCommandLine(); size_t wlen = StringCchLenW(lpCmdLine,0) + 2UL; - WCHAR lpExe[MAX_PATH + 2] = { L'\0' }; + WCHAR lpExe[MAX_PATH] = { L'\0' }; WCHAR szArgs[2032] = { L'\0' }; WCHAR szArguments[2032] = { L'\0' }; @@ -10331,10 +10294,9 @@ void SetNotifyIconTitle(HWND hwnd) } else if (StringCchLenW(Globals.CurrentFile,COUNTOF(Globals.CurrentFile))) { - SHFILEINFO shfi; - SHGetFileInfo2(Globals.CurrentFile,FILE_ATTRIBUTE_NORMAL, - &shfi,sizeof(SHFILEINFO),SHGFI_DISPLAYNAME | SHGFI_USEFILEATTRIBUTES); - PathCompactPathEx(tchTitle,shfi.szDisplayName,COUNTOF(tchTitle)-4,0); + WCHAR szDisplayName[MAX_PATH]; + PathGetDisplayName(szDisplayName, COUNTOF(szDisplayName), Globals.CurrentFile); + PathCompactPathEx(tchTitle,szDisplayName,COUNTOF(tchTitle)-4,0); } else { GetLngString(IDS_MUI_UNTITLED, tchTitle, COUNTOF(tchTitle) - 4); diff --git a/src/Styles.c b/src/Styles.c index c49aa8d0a..4cc89ba9e 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -414,8 +414,8 @@ void Style_Save() // bool Style_Import(HWND hwnd) { - WCHAR szFile[MAX_PATH * 2] = { L'\0' }; - WCHAR szFilter[256] = { L'\0' }; + WCHAR szFile[MAX_PATH] = { L'\0' }; + WCHAR szFilter[MAX_PATH] = { L'\0' }; OPENFILENAME ofn; ZeroMemory(&ofn,sizeof(OPENFILENAME)); @@ -465,7 +465,7 @@ bool Style_Import(HWND hwnd) // bool Style_Export(HWND hwnd) { - WCHAR szFile[MAX_PATH * 2] = { L'\0' }; + WCHAR szFile[MAX_PATH] = { L'\0' }; WCHAR szFilter[256] = { L'\0' }; OPENFILENAME ofn; diff --git a/src/TypeDefs.h b/src/TypeDefs.h index d85c33954..4f14ce738 100644 --- a/src/TypeDefs.h +++ b/src/TypeDefs.h @@ -288,9 +288,9 @@ typedef struct _globals_t FR_STATES FindReplaceMatchFoundState; - WCHAR WorkingDirectory[MAX_PATH + 1]; - WCHAR IniFile[MAX_PATH + 1]; - WCHAR CurrentFile[MAX_PATH + 1]; + WCHAR WorkingDirectory[MAX_PATH]; + WCHAR IniFile[MAX_PATH]; + WCHAR CurrentFile[MAX_PATH]; } GLOBALS_T, *PGLOBALS_T; @@ -384,8 +384,8 @@ typedef struct _settings_t RECT PrintMargin; EDITFINDREPLACE EFR_Data; - WCHAR OpenWithDir[MAX_PATH + 1]; - WCHAR FavoritesDir[MAX_PATH + 1]; + WCHAR OpenWithDir[MAX_PATH]; + WCHAR FavoritesDir[MAX_PATH]; WCHAR ToolbarButtons[MIDSZ_BUFFER]; } SETTINGS_T, *PSETTINGS_T; @@ -441,19 +441,19 @@ typedef struct _settings2_t WCHAR PreferredLanguageLocaleName[LOCALE_NAME_MAX_LENGTH+1]; WCHAR DefaultExtension[64]; - WCHAR DefaultDirectory[MAX_PATH + 1]; + WCHAR DefaultDirectory[MAX_PATH]; WCHAR FileDlgFilters[XHUGE_BUFFER]; - WCHAR FileBrowserPath[MAX_PATH + 1]; + WCHAR FileBrowserPath[MAX_PATH]; WCHAR AppUserModelID[32]; WCHAR ExtendedWhiteSpaceChars[ANSI_CHAR_BUFFER + 1]; WCHAR AutoCompleteWordCharSet[ANSI_CHAR_BUFFER + 1]; WCHAR TimeStamp[128]; WCHAR DateTimeShort[128]; WCHAR DateTimeLong[128]; - WCHAR WebTemplate1[MAX_PATH + 1]; - WCHAR WebTemplate2[MAX_PATH + 1]; - WCHAR AdministrationTool[MAX_PATH + 1]; + WCHAR WebTemplate1[MAX_PATH]; + WCHAR WebTemplate2[MAX_PATH]; + WCHAR AdministrationTool[MAX_PATH]; WCHAR DefaultWindowPosition[64]; } SETTINGS2_T, *PSETTINGS2_T;