Prevent file loading
-
Is there an option to prevent file loading? We have some kind of logs that are encrypted by default. When NPP loads these files, it gets stuck for a some time since in encrypted version files consist of non-unicode symbols at all. So before I can press “Decrypt”, I have to wait. Sometimes, to wait a lot.
And I want to make an option to prevent file from loading once I get filename and determine that file is encrypted - so I will create new file manually and fill it with decrypted content. So far, everything works but prevention of opening of original file. -
welcome to the notepad++ community
if i understood your request correctly: yes you can prevent live files from being loaded again if a change has occured since the last opening
to prevent opened files from reloading, go to
settings > misc. > file status autodetection
then uncheck “enable”this way once opened you can decrypt it without the file being reloaded automatically, forcing you to wait again
if you want to reload the file manually, after changing this setting, you can do it manually from the menu:
file > reload from disk -
Well, that’s not what I’m talking about. It’s not about NPP settings, but about plugin messages.
I can catch
case NPPN_FILEBEFOREOPEN:
{
onBeforeOpen(notifyCode->nmhdr.idFrom);
}to run my decoder, smth like
void onBeforeOpen(uptr_t bID)
{
fileName = (wchar_t*)malloc(MAX_PATH);
::SendMessage(nppData._nppHandle, NPPM_GETFULLPATHFROMBUFFERID, bID, (LPARAM)fileName);
wchar_t * pos = wcsstr(fileName, L".encoded");
if (pos) {
encDecrypt(fileName);
}
}
It creates new file with decoded content, but it also still opens original “.encoded” file, that I don’t want to be opened -
Yes, as there is no way to veto on a file load notification
I would give it a try to hook WM_DOOPEN and NPPM_DOOPEN messages.
See NppBigSwitch.cppCheers
Claudia -
Essentially a follow-up to https://community.notepad-plus-plus.org/topic/14841/prevent-file-loading
@Ian-Darken did you get a resolution to your question/project?
I took a look at @Claudia-Frank 's response but I do not see a way to hook into WM_DOOPEN and NPPM_DOOPEN to prevent npp from performing file IO without modifying npp. Are there examples of this? It looks like the plugin system does NOT support callbacks, I can not see a way to indicate to npp that it should not save/load and let the plugin handle that.
I wrote a plugin for SciTE (another Scintilla based editor) that does have clear docs on how to prevent scite from progressing with file load/save. I’d like to do the same for npp
Any pointers would be appreciated!
-
-
@clach04 ,
That was from 7 years ago, and the OP you @-mentioned hasn’t been here since. (And since it’s really the same discussion, I’ll merge the two topics back together…)
It looks like the plugin system does NOT support callbacks,
I’m not sure why you think that. That’s how NPPN_* notification-responses are handled. (You can look at the source code for the PythonScript plugin, which allows you to attach Python functions to be used as callbacks for all the different NPPN notifications)
While Notepad++ doesn’t specifically provide for hooking to the messages like
NPPM_DOOPEN
, I believe you can use normal win32 coding techniques in your plugin to also process those messages.And, if that doesn’t work, you could always hook to
NPPN_FILEOPENED
which triggers after the file is open, and then under your particular circumstances, you could close it again immediately; for most things where you want to prevent it from opening, closing it immediately should be sufficient (except if it’s a huge file).… Speaking of huge file, I think there’s at least one huge-file plugin which chunks the loading of large files, instead of giving Notepad++ the whole file; you might want to dig into their source code, to see if they do something to intercept the normal file-loading process to do their chunking.
-
In response to locked thread https://community.notepad-plus-plus.org/topic/14841/prevent-file-loading
Thanks @PeterJones for the speedy response 🙏.
While Notepad++ doesn’t specifically provide for hooking to the messages like NPPM_DOOPEN, I believe you can use normal win32 coding techniques in your plugin to also process those messages.
I’ll check into that!
And, if that doesn’t work, you could always hook to NPPN_FILEOPENED which triggers after the file is open, and then under your particular circumstances, you could close it again immediately; for most things where you want to prevent it from opening, closing it immediately should be sufficient (except if it’s a huge file).
That’s not really suitable, I do NOT want npp to perform ANY file IO. It’s not a bad workaround BUT it will introduce 2 sets of file IO, one wasted. And for large files it would be an unpleasant experience.
Worse would be write/save where plain text would be exposed on disk which both Ian and I want/need to avoid.
Hopefully, the win32 message approach pans out 🤞
-
-
-
@PeterJones said:
While Notepad++ doesn’t specifically provide for hooking to the messages like NPPM_DOOPEN, I believe you can use normal win32 coding techniques in your plugin to also process those messages.
I don’t believe NPPM_DOOPEN or WM_OPEN do the job, though.
If you want to catch and prevent a file from being opened, a logical test would be to try intercepting those messages when a file opened with File > Open > (pick file) is executed. When I try that, neither NPPM_DOOPEN or WM_DOOPEN happen.
I don’t think it is possible to intercept a file opening by normal Notepad++ means, and then prevent that open from happening. Best that can be achieved is what is already discussed: the open happens and then some code decides to quickly close the file.
In theory, one could write some code that fires up a OpenFileDialog, then looks at the resulting file path the user supplied. Then if that pathname (or extension, or whatever…) isn’t “good”, that code could just not fire off the appropriate commands to allow Notepad++ to open the file. The user would then replace the default Ctrl+o (File > Open) command with that code, providing a level of “protection”. However, this wouldn’t prevent e.g. drag-n-drop loading of the file, or cmd window opening of the file (either to existing instance or not).
-
@clach04 said in Prevent file loading:
In response to locked thread …
Sorry about that; since I had moderator power, I didn’t notice it was locked when I merged the previous copy. I unlocked it in response to this post, and merged it again.
(Old posts don’t get locked automatically, so I don’t expect to find old topics actually locked. But some time ago, a group of old topics did get bulk locked without anyone intending.)
-
@Alan-Kilborn said in Prevent file loading:
I don’t believe NPPM_DOOPEN or WM_OPEN do the job, though.
I doubt that too
@clach04
To “really” not open a file before it is read, Npp must support this internally, which is not yet the case.