[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
This commit is contained in:
Don Ho 2010-11-01 16:08:43 +00:00
parent df0f0b3a30
commit 2745ad40e5
6 changed files with 86 additions and 26 deletions

View File

@ -20,6 +20,8 @@
// w/o precompiled headers file : 1 minute 55 sec // w/o precompiled headers file : 1 minute 55 sec
#define _WIN32_WINNT 0x0501
// C RunTime Header Files // C RunTime Header Files
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>

View File

@ -142,6 +142,7 @@ Notepad_plus::~Notepad_plus()
delete _pTrayIco; delete _pTrayIco;
} }
LRESULT Notepad_plus::init(HWND hwnd) LRESULT Notepad_plus::init(HWND hwnd)
{ {
NppParameters *pNppParam = NppParameters::getInstance(); NppParameters *pNppParam = NppParameters::getInstance();

View File

@ -20,8 +20,10 @@
#include "FileDialog.h" #include "FileDialog.h"
BufferID Notepad_plus::doOpen(const TCHAR *fileName, bool isReadOnly, int encoding) BufferID Notepad_plus::doOpen(const TCHAR *fileName, bool isReadOnly, int encoding)
{ {
NppParameters *pNppParam = NppParameters::getInstance();
TCHAR longFileName[MAX_PATH]; TCHAR longFileName[MAX_PATH];
::GetFullPathName(fileName, MAX_PATH, longFileName, NULL); ::GetFullPathName(fileName, MAX_PATH, longFileName, NULL);
@ -66,35 +68,45 @@ BufferID Notepad_plus::doOpen(const TCHAR *fileName, bool isReadOnly, int encodi
return BUFFER_INVALID; return BUFFER_INVALID;
} }
bool isWow64Off = false;
if (!PathFileExists(longFileName))
{
pNppParam->safeWow64EnableWow64FsRedirection(FALSE);
isWow64Off = true;
}
if (!PathFileExists(longFileName)) if (!PathFileExists(longFileName))
{ {
TCHAR str2display[MAX_PATH*2]; TCHAR str2display[MAX_PATH*2];
generic_string longFileDir(longFileName); generic_string longFileDir(longFileName);
PathRemoveFileSpec(longFileDir); PathRemoveFileSpec(longFileDir);
bool isCreateFileSuccessful = false;
if (PathFileExists(longFileDir.c_str())) if (PathFileExists(longFileDir.c_str()))
{ {
wsprintf(str2display, TEXT("%s doesn't exist. Create it?"), longFileName); wsprintf(str2display, TEXT("%s doesn't exist. Create it?"), longFileName);
if (::MessageBox(_pPublicInterface->getHSelf(), str2display, TEXT("Create new file"), MB_YESNO) == IDYES) if (::MessageBox(_pPublicInterface->getHSelf(), str2display, TEXT("Create new file"), MB_YESNO) == IDYES)
{ {
bool res = MainFileManager->createEmptyFile(longFileName); bool res = MainFileManager->createEmptyFile(longFileName);
if (!res) if (res)
{
isCreateFileSuccessful = true;
}
else
{ {
wsprintf(str2display, TEXT("Cannot create the file \"%s\""), longFileName); wsprintf(str2display, TEXT("Cannot create the file \"%s\""), longFileName);
::MessageBox(_pPublicInterface->getHSelf(), str2display, TEXT("Create new file"), MB_OK); ::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; 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); BufferID buffer = MainFileManager->loadFile(longFileName, NULL, encoding);
if (buffer != BUFFER_INVALID) if (buffer != BUFFER_INVALID)
{ {
_isFileOpening = true; _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 // Notify plugins that current file is just opened
scnN.nmhdr.code = NPPN_FILEOPENED; scnN.nmhdr.code = NPPN_FILEOPENED;
_pluginsManager.notify(&scnN); _pluginsManager.notify(&scnN);
return buffer;
} }
else else
{ {
@ -181,8 +192,14 @@ BufferID Notepad_plus::doOpen(const TCHAR *fileName, bool isReadOnly, int encodi
scnN.nmhdr.code = NPPN_FILELOADFAILED; scnN.nmhdr.code = NPPN_FILELOADFAILED;
_pluginsManager.notify(&scnN); _pluginsManager.notify(&scnN);
} }
return BUFFER_INVALID;
} }
if (isWow64Off)
{
pNppParam->safeWow64EnableWow64FsRedirection(TRUE);
isWow64Off = false;
}
return buffer;;
} }
bool Notepad_plus::doReload(BufferID id, bool alert) bool Notepad_plus::doReload(BufferID id, bool alert)

View File

@ -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);
}
}
}
}
}

View File

@ -1403,6 +1403,7 @@ public:
winVer getWinVersion() { return _winVersion;}; winVer getWinVersion() { return _winVersion;};
FindHistory & getFindHistory() {return _findHistory;}; FindHistory & getFindHistory() {return _findHistory;};
bool _isFindReplacing; // an on the fly variable for find/replace functions bool _isFindReplacing; // an on the fly variable for find/replace functions
void safeWow64EnableWow64FsRedirection(BOOL Wow64FsEnableRedirection);
#ifdef UNICODE #ifdef UNICODE
LocalizationSwitcher & getLocalizationSwitcher() { LocalizationSwitcher & getLocalizationSwitcher() {

View File

@ -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 if (_currentStatus == DOC_UNNAMED) //unsaved document cannot change by environment
return false; 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 if (_currentStatus != DOC_DELETED && !PathFileExists(_fullPathName.c_str())) //document has been deleted
{ {
_currentStatus = DOC_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 _isDirty = true; //dirty sicne no match with filesystem
_timeStamp = 0; _timeStamp = 0;
doNotify(BufferChangeStatus | BufferChangeReadonly | BufferChangeTimestamp); doNotify(BufferChangeStatus | BufferChangeReadonly | BufferChangeTimestamp);
return true; isOK = true;
} }
else if (_currentStatus == DOC_DELETED && PathFileExists(_fullPathName.c_str()))
if (_currentStatus == DOC_DELETED && PathFileExists(_fullPathName.c_str()))
{ //document has returned from its grave { //document has returned from its grave
if (!generic_stat(_fullPathName.c_str(), &buf)) if (!generic_stat(_fullPathName.c_str(), &buf))
{ {
_isFileReadOnly = (bool)(!(buf.st_mode & _S_IWRITE)); _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; _currentStatus = DOC_MODIFIED;
_timeStamp = buf.st_mtime; _timeStamp = buf.st_mtime;
doNotify(BufferChangeStatus | BufferChangeReadonly | BufferChangeTimestamp); doNotify(BufferChangeStatus | BufferChangeReadonly | BufferChangeTimestamp);
return true; isOK = true;
} }
} }
else if (!generic_stat(_fullPathName.c_str(), &buf))
if (!generic_stat(_fullPathName.c_str(), &buf))
{ {
int mask = 0; //status always 'changes', even if from modified to modified int mask = 0; //status always 'changes', even if from modified to modified
bool isFileReadOnly = (bool)(!(buf.st_mode & _S_IWRITE)); bool isFileReadOnly = (bool)(!(buf.st_mode & _S_IWRITE));
if (isFileReadOnly != _isFileReadOnly) { if (isFileReadOnly != _isFileReadOnly)
{
_isFileReadOnly = isFileReadOnly; _isFileReadOnly = isFileReadOnly;
mask |= BufferChangeReadonly; mask |= BufferChangeReadonly;
} }
if (_timeStamp != buf.st_mtime)
if (_timeStamp != buf.st_mtime) { {
_timeStamp = buf.st_mtime; _timeStamp = buf.st_mtime;
mask |= BufferChangeTimestamp; mask |= BufferChangeTimestamp;
_currentStatus = DOC_MODIFIED; _currentStatus = DOC_MODIFIED;
mask |= BufferChangeStatus; //status always 'changes', even if from modified to modified mask |= BufferChangeStatus; //status always 'changes', even if from modified to modified
} }
if (mask != 0) { if (mask != 0)
{
doNotify(mask); doNotify(mask);
return true; isOK = true;
} }
return false; isOK = false;
} }
return false;
if (isWow64Off)
{
pNppParam->safeWow64EnableWow64FsRedirection(TRUE);
isWow64Off = false;
}
return isOK;
} }
int Buffer::getFileLength() int Buffer::getFileLength()