From 2745ad40e573a41f513c3d889e5b29b97ca3d3f6 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Mon, 1 Nov 2010 16:08:43 +0000 Subject: [PATCH] [NEW_FEATURE] Add the capacity to open x64 system files. git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@692 f5eea248-9336-0410-98b8-ebc06183d4e3 --- .../src/MISC/Common/precompiledHeaders.h | 2 + PowerEditor/src/Notepad_plus.cpp | 1 + PowerEditor/src/NppIO.cpp | 41 ++++++++++++------ PowerEditor/src/Parameters.cpp | 25 +++++++++++ PowerEditor/src/Parameters.h | 1 + PowerEditor/src/ScitillaComponent/Buffer.cpp | 42 ++++++++++++------- 6 files changed, 86 insertions(+), 26 deletions(-) diff --git a/PowerEditor/src/MISC/Common/precompiledHeaders.h b/PowerEditor/src/MISC/Common/precompiledHeaders.h index 6fe155c6a..037e656bd 100644 --- a/PowerEditor/src/MISC/Common/precompiledHeaders.h +++ b/PowerEditor/src/MISC/Common/precompiledHeaders.h @@ -20,6 +20,8 @@ // w/o precompiled headers file : 1 minute 55 sec +#define _WIN32_WINNT 0x0501 + // C RunTime Header Files #include #include diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index c3fdb698f..715646759 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -142,6 +142,7 @@ Notepad_plus::~Notepad_plus() delete _pTrayIco; } + LRESULT Notepad_plus::init(HWND hwnd) { NppParameters *pNppParam = NppParameters::getInstance(); diff --git a/PowerEditor/src/NppIO.cpp b/PowerEditor/src/NppIO.cpp index 8c07d1971..c86bab545 100644 --- a/PowerEditor/src/NppIO.cpp +++ b/PowerEditor/src/NppIO.cpp @@ -20,8 +20,10 @@ #include "FileDialog.h" + BufferID Notepad_plus::doOpen(const TCHAR *fileName, bool isReadOnly, int encoding) { + NppParameters *pNppParam = NppParameters::getInstance(); TCHAR longFileName[MAX_PATH]; ::GetFullPathName(fileName, MAX_PATH, longFileName, NULL); @@ -66,35 +68,45 @@ BufferID Notepad_plus::doOpen(const TCHAR *fileName, bool isReadOnly, int encodi return BUFFER_INVALID; } + bool isWow64Off = false; + if (!PathFileExists(longFileName)) + { + pNppParam->safeWow64EnableWow64FsRedirection(FALSE); + isWow64Off = true; + } - if (!PathFileExists(longFileName)) { TCHAR str2display[MAX_PATH*2]; generic_string longFileDir(longFileName); PathRemoveFileSpec(longFileDir); + bool isCreateFileSuccessful = false; if (PathFileExists(longFileDir.c_str())) { wsprintf(str2display, TEXT("%s doesn't exist. Create it?"), longFileName); - if (::MessageBox(_pPublicInterface->getHSelf(), str2display, TEXT("Create new file"), MB_YESNO) == IDYES) { bool res = MainFileManager->createEmptyFile(longFileName); - if (!res) + if (res) + { + isCreateFileSuccessful = true; + } + else { wsprintf(str2display, TEXT("Cannot create the file \"%s\""), longFileName); ::MessageBox(_pPublicInterface->getHSelf(), str2display, TEXT("Create new file"), MB_OK); - return BUFFER_INVALID; } } - else - { - return BUFFER_INVALID; - } } - else + + if (!isCreateFileSuccessful) { + if (isWow64Off) + { + pNppParam->safeWow64EnableWow64FsRedirection(TRUE); + isWow64Off = false; + } return BUFFER_INVALID; } } @@ -113,6 +125,7 @@ BufferID Notepad_plus::doOpen(const TCHAR *fileName, bool isReadOnly, int encodi } BufferID buffer = MainFileManager->loadFile(longFileName, NULL, encoding); + if (buffer != BUFFER_INVALID) { _isFileOpening = true; @@ -149,8 +162,6 @@ BufferID Notepad_plus::doOpen(const TCHAR *fileName, bool isReadOnly, int encodi // Notify plugins that current file is just opened scnN.nmhdr.code = NPPN_FILEOPENED; _pluginsManager.notify(&scnN); - - return buffer; } else { @@ -181,8 +192,14 @@ BufferID Notepad_plus::doOpen(const TCHAR *fileName, bool isReadOnly, int encodi scnN.nmhdr.code = NPPN_FILELOADFAILED; _pluginsManager.notify(&scnN); } - return BUFFER_INVALID; } + + if (isWow64Off) + { + pNppParam->safeWow64EnableWow64FsRedirection(TRUE); + isWow64Off = false; + } + return buffer;; } bool Notepad_plus::doReload(BufferID id, bool alert) diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index c83382a60..e3939f0bd 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -5167,3 +5167,28 @@ void NppParameters::addScintillaModifiedIndex(int index) } } +void NppParameters::safeWow64EnableWow64FsRedirection(BOOL Wow64FsEnableRedirection) +{ + HMODULE kernel = GetModuleHandle(TEXT("kernel32")); + if (kernel) + { + BOOL isWow64 = FALSE; + typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL); + LPFN_ISWOW64PROCESS IsWow64ProcessFunc = (LPFN_ISWOW64PROCESS) GetProcAddress(kernel,"IsWow64Process"); + + if (IsWow64ProcessFunc) + { + IsWow64ProcessFunc(GetCurrentProcess(),&isWow64); + + if (isWow64) + { + typedef BOOL (WINAPI *LPFN_WOW64ENABLEWOW64FSREDIRECTION)(BOOL); + LPFN_WOW64ENABLEWOW64FSREDIRECTION Wow64EnableWow64FsRedirectionFunc = (LPFN_WOW64ENABLEWOW64FSREDIRECTION)GetProcAddress(kernel, "Wow64EnableWow64FsRedirection"); + if (Wow64EnableWow64FsRedirectionFunc) + { + Wow64EnableWow64FsRedirectionFunc(Wow64FsEnableRedirection); + } + } + } + } +} diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index 0146b1dd8..8c4384250 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -1403,6 +1403,7 @@ public: winVer getWinVersion() { return _winVersion;}; FindHistory & getFindHistory() {return _findHistory;}; bool _isFindReplacing; // an on the fly variable for find/replace functions + void safeWow64EnableWow64FsRedirection(BOOL Wow64FsEnableRedirection); #ifdef UNICODE LocalizationSwitcher & getLocalizationSwitcher() { diff --git a/PowerEditor/src/ScitillaComponent/Buffer.cpp b/PowerEditor/src/ScitillaComponent/Buffer.cpp index 936ce1a62..7ac6eb703 100644 --- a/PowerEditor/src/ScitillaComponent/Buffer.cpp +++ b/PowerEditor/src/ScitillaComponent/Buffer.cpp @@ -143,6 +143,15 @@ bool Buffer::checkFileState() { //returns true if the status has been changed (i if (_currentStatus == DOC_UNNAMED) //unsaved document cannot change by environment return false; + bool isWow64Off = false; + NppParameters *pNppParam = NppParameters::getInstance(); + if (!PathFileExists(_fullPathName.c_str())) + { + pNppParam->safeWow64EnableWow64FsRedirection(FALSE); + isWow64Off = true; + } + + bool isOK = false; if (_currentStatus != DOC_DELETED && !PathFileExists(_fullPathName.c_str())) //document has been deleted { _currentStatus = DOC_DELETED; @@ -150,12 +159,10 @@ bool Buffer::checkFileState() { //returns true if the status has been changed (i _isDirty = true; //dirty sicne no match with filesystem _timeStamp = 0; doNotify(BufferChangeStatus | BufferChangeReadonly | BufferChangeTimestamp); - return true; + isOK = true; } - - if (_currentStatus == DOC_DELETED && PathFileExists(_fullPathName.c_str())) + else if (_currentStatus == DOC_DELETED && PathFileExists(_fullPathName.c_str())) { //document has returned from its grave - if (!generic_stat(_fullPathName.c_str(), &buf)) { _isFileReadOnly = (bool)(!(buf.st_mode & _S_IWRITE)); @@ -163,33 +170,40 @@ bool Buffer::checkFileState() { //returns true if the status has been changed (i _currentStatus = DOC_MODIFIED; _timeStamp = buf.st_mtime; doNotify(BufferChangeStatus | BufferChangeReadonly | BufferChangeTimestamp); - return true; + isOK = true; } } - - if (!generic_stat(_fullPathName.c_str(), &buf)) + else if (!generic_stat(_fullPathName.c_str(), &buf)) { int mask = 0; //status always 'changes', even if from modified to modified bool isFileReadOnly = (bool)(!(buf.st_mode & _S_IWRITE)); - if (isFileReadOnly != _isFileReadOnly) { + if (isFileReadOnly != _isFileReadOnly) + { _isFileReadOnly = isFileReadOnly; mask |= BufferChangeReadonly; } - - if (_timeStamp != buf.st_mtime) { + if (_timeStamp != buf.st_mtime) + { _timeStamp = buf.st_mtime; mask |= BufferChangeTimestamp; _currentStatus = DOC_MODIFIED; mask |= BufferChangeStatus; //status always 'changes', even if from modified to modified } - if (mask != 0) { + if (mask != 0) + { doNotify(mask); - return true; + isOK = true; } - return false; + isOK = false; } - return false; + + if (isWow64Off) + { + pNppParam->safeWow64EnableWow64FsRedirection(TRUE); + isWow64Off = false; + } + return isOK; } int Buffer::getFileLength()