[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:
parent
df0f0b3a30
commit
2745ad40e5
@ -20,6 +20,8 @@
|
||||
|
||||
// w/o precompiled headers file : 1 minute 55 sec
|
||||
|
||||
#define _WIN32_WINNT 0x0501
|
||||
|
||||
// C RunTime Header Files
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -142,6 +142,7 @@ Notepad_plus::~Notepad_plus()
|
||||
delete _pTrayIco;
|
||||
}
|
||||
|
||||
|
||||
LRESULT Notepad_plus::init(HWND hwnd)
|
||||
{
|
||||
NppParameters *pNppParam = NppParameters::getInstance();
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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() {
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user