-
-
Notifications
You must be signed in to change notification settings - Fork 269
Restart Notepad2 as Administrator, keeping the changes, when unable to save file #154
Conversation
…e editor from the specified file. This is needed to replace the text buffer from a temp. save file between re-launching as elevated.
…he current buffer, saved to a temp file
There's also #78 which seems less intrusive to be honest. |
I've seen it, but it looks like it's just trying to save a file, and prompts to restart if fails. It doesn't keep the changes as my solution does (and it also seems to be taking a dependency on a guid lib). Is there anything in particular about my solution you find problematic? I'd be happy to rework it! |
This is indeed a much better approach compared to #78 however my question is: dies this introduce a security issue? |
Hmm, I'm honestly not sure, but I don't think this is a security issue. The content from the temp file is merely loaded in the text editor, saving the original file after a reload is still an explicit action by the user. FWIW, this is a similar approach that Notepad++ uses, they keep a copy of the buffer in temp files always, this is how it survives a reload. I'm not 100% sure encoding this information is worth the effort, since if an attacker can modify files (even in the %temp% dir), it's already too late... In any case, I think this is a good suggestion, since I'd like to be 100% transparent about where the actual text is coming from, maybe display it in the title? |
Is there anything else about this PR that doesn't "sit right"? I'd really love for this to be accepted into Notepad2-mod. I use this feature almost every day, having to edit files in Program Files often... |
I love this feature. It's very good. |
@bluenlive I'm using the x64, and so far it worked fine on 2 machines I have, and another user which compiled the PR. |
@hmemcpy
I'm using Windows 10 x64 and it never happens with Notepad2-mod x86. |
@bluenlive can you post a screenshot of the error message? What happens if you initially launch Notepad2-mod elevated, and try to save the hosts file? Also, I want to be absolutely sure, are you using the latest build off my PR sources? |
@hmemcpy (1) Messages are as following... And, it doens't happen in Notepad2-mod x86. (2) When I wrote last comment, I used my own build applying your PR. |
@bluenlive thank you so much! This seems very helpful, I'll try installing a Korean version of Windows in a VM and try it there. Will update! Thanks again! |
@bluenlive ok the good news is that I successfully installed Windows 10 in Korean, and learned that Korean versions of Windows use the The bad news (well, not really bad) is that I am unable to repro the bug so far: I installed Notepad2-mod on the VM, and copied over my build (Release, x64). I was able to relaunch and than save the How are you launching Notepad2? You mentioned Total Commander? Do you press F4 on the file? |
Success! I was able to reproduce this when launching from Total Commander! (pressing F4 to edit a file) |
More interesting reading on the Yen and Won characters for path separators, if you're interested! https://web.archive.org/web/20090305082113/http://blogs.msdn.com/michkap/archive/2005/09/17/469941.aspx |
Finally (sorry for spamming!), the reason for the bug is that the filename was specified twice, for some reason. Here is the command line used to launch Notepad2-mod elevated:
Note that
Anyway, very interesting! |
@hmemcpy Thank you for your effort. Anyway, It's a very good feature! |
@hmemcpy And, in your following code in Notepad2.c, if (szCurFile)
{
if (!StrStr(szArguments, szCurFile)) {
PathQuoteSpaces(szCurFile);
wsprintf(szArguments, L"%s %s", szArguments, szCurFile);
}
} I've changed p.s. WDK failes to compile at following lines in Notepad2.c. they should be fixed like these... |
@bluenlive that's awesome, thanks so much! I'll fix and push the changes soon. |
Ok, I pushed the changes, it seems to work great now! So everything is good to go! 👍 |
It works well! Thank you for your great stuff! |
+ massive code cleanup according to VS2015 Analyze-Mode and Warning Level 4 (partially - not finished yet)
Looking forward to a release with this included. Any reason for the 7 month delay in merging? |
Wow, I just saw that Notepad3 (a more active fork) had cherry picked this PR and merged it! So better try that! |
Fixes #8
This PR adds a much-needed feature to restart Notepad2-mod as an Administrator, when saving a file fails, similarly to how other editors, such as Notepad++ behave.
The main issue was - how to retain the changes between restarts. I solved it by saving a temporary file on disk, and passing it as a new parameter to Notepad2-mod, allowing to load the original file, but replace its text with the contents of the temp file.
The new parameter is called
buffer
, and it will set the text of Notepad2 to the contents of a file passed as parameter, e.g.:notepad2.exe /buffer "C:\temp\N2ffff.tmp" "C:\Program Files (x86)\original.txt"
This allows restarting Notepad2-mod (by leveraging the
RelaunchElevated
function, passing it the additionalbuffer
parameter)