Community
    • Login

    File Content Vanishing?

    Scheduled Pinned Locked Moved General Discussion
    18 Posts 5 Posters 2.7k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Steve ValliereS
      Steve Valliere @Steve Valliere
      last edited by Steve Valliere

      I just thought of one more thing that may or may not be of interest/use:

      My program has a thread that watches specific files for changes using FindFirstChangeNotification()/FindNextChangeNotification(). If a change to one of the files is detected, the thread posts a message to the main loop and the main loop re-reads the file when it receives the message. This keeps all of the actual file reading (and writing, if the users uses the config dialog) in the same thread.

      1 Reply Last reply Reply Quote 1
      • pnedevP
        pnedev
        last edited by

        @Steve-Valliere ,

        About your older thread, that from August:

        What might be happening is that when Notepad++ is saving the file it first opens it with fopen() which erases the file.
        This is perhaps immediately detected by your program that ‘locks’ the file to re-read it and during that time Notepad++ tries to write the changed contents. This fails as your program has locked the file. Notepad++ fails writing the file and exits leaving the file empty.

        This is just a guess of course but if this is the case then the fix I made should prevent this from happening.
        But as @dinkumoil mentioned my fix is still not accepted and merged into Notepad++ so currently your issue will still be there.

        BR

        Steve ValliereS 2 Replies Last reply Reply Quote 2
        • Steve ValliereS
          Steve Valliere @pnedev
          last edited by

          @pnedev That is a very believable scenario. I wonder if adding a short delay before I notify my main loop of the file change would help at all. Looking forward to your fix being incorporated. Thanks!

          pnedevP 1 Reply Last reply Reply Quote 2
          • pnedevP
            pnedev @Steve Valliere
            last edited by

            @Steve-Valliere ,

            I wonder if adding a short delay before I notify my main loop …

            It is worth trying.
            Please write back if that helps (if you test it).

            BR

            Steve ValliereS 1 Reply Last reply Reply Quote 1
            • Steve ValliereS
              Steve Valliere @pnedev
              last edited by

              @pnedev I added a 5 second delay between detecting the file change and notifying the main loop. If the file is detected again during the delay, the delay is reset to the full 5 seconds. There is probably still a timing window when the file is being saved just as the notification is sent to/processed by the main loop, but it seems small and this has been working for the short while that I have been testing it. I’m not thrilled about the lag between saving a change and seeing that my program is using the new setting, but I will need to live with it for now. At least my time delay is a setting itself, so I can easily turn it off later, when it is time to see of NPP is fixed. (smile) Thanks again for your thoughts and, hopefully, thanks for your fix – whenever it makes it in!

              1 Reply Last reply Reply Quote 3
              • Steve ValliereS
                Steve Valliere @pnedev
                last edited by

                @pnedev I have noticed that I get TWO apparently identical notifications about the file change event when Notepad++ saves the file, but things like the original Notepad and KeditW32 save the same file to the same folder, my program receives only ONE event notification about the file change.
                (Strangely, VS2019 generated 11 events, 3 of which referenced the file I changed and the others all appear to be random temp file/dir names.)
                I have tried this using the FindFirstChangeNotification / FindNextChangeNotification functions and re-implemented this morning to try using ReadDirectoryChangesW instead. Both generate the same number of events when Notepad++ saves a file, but the read version lets me know for certain that the events are specifically about the file and not the directory itself or a different file.
                I don’t know if this helps or is of any use. If you (or anyone, really) wants to create a test app that uses the monitor functions and then reads an ini file, I can provide my monitoring module (it will need some clean up to eliminate calls to the remainder of the application, but I think it is mostly self-contained.) Just tell me where/how to post it.
                Unless I find something truly new and amazing about this, I won’t pester the community about it any more. Thanks for all of your assistance and information, it really helped!

                pnedevP 1 Reply Last reply Reply Quote 2
                • pnedevP
                  pnedev @Steve Valliere
                  last edited by

                  @Steve-Valliere ,

                  If you’d like you can try my AppVeyor PR Notepad++ exe build from here:
                  https://ci.appveyor.com/project/pnedev/notepad-plus-plus/builds/27654824

                  This is version 7.7.1 + my fix so you’ll need Notepad++ 7.7.1 (either install it or use the portable) but replace the exe with the one from the link (just get the correct build - x64 or x32).

                  You can then check how many notifications you are getting with it and also try removing your delay and see how it behaves.

                  BR

                  Steve ValliereS 1 Reply Last reply Reply Quote 1
                  • Steve ValliereS
                    Steve Valliere @pnedev
                    last edited by

                    @pnedev With your 32 bit version I am still seeing two events when NPP saves the file and when I switched to a zero delay before reloading the content [via GetPrivateProfileString()], it only took a couple of tries before I started to see this message box from NPP when I clicked save:

                    Save failed
                    The file cannot be saved and it may be protected.
                    Do you want to launch Notepad++ in Administrator mode?
                    Yes No

                    When that message box is visible, my program has loaded all default settings (used when an empty or missing INI file is detected). I was able to click NO and then ask NPP to save again, which has worked – so far. This does not happen every time, but it did happen a few times in only a couple minutes testing.

                    (Also, just FYI: the tab title when I downloaded your file says notepad-plus-plus 7.6.35 - AppVeyor, by the way, even though the About shows 7.7.1)

                    pnedevP 1 Reply Last reply Reply Quote 2
                    • pnedevP
                      pnedev @Steve Valliere
                      last edited by

                      @Steve-Valliere ,

                      Thanks for trying.
                      Are you sure it was written notepad-plus-plus 7.6.35 - AppVeyor and not notepad-plus-plus 7.6.53 - AppVeyor?
                      This is AppVeyor build number it is not related to Notepad++ version.

                      And what would happen if you say Yes to switching to Admin mode? (If you try it please backup your files so you can recover if those get zeroed.)

                      Steve ValliereS 1 Reply Last reply Reply Quote 1
                      • Steve ValliereS
                        Steve Valliere @pnedev
                        last edited by

                        @pnedev I’m sure the .35 is a typo, sorry. It was close enough to NPP’s version that I thought it might have been overlooked when the NPP version changed. Sorry.

                        When I click YES for Admin mode, I ended up with an Admin NPP running and showing an EMPTY file. Behind the Admin copy, the original was still running, too, and it was now showing this new message box:

                        Reload
                        “C:\pics64\config\ev11\ev11.ini”
                        This file has been modified by another program.
                        Do you want to reload it and lose the changes made in Notepad++?
                        Yes No

                        When I clicked Yes on this message, that NPP also showed a completely empty copy of the INI file.

                        So, I am not sure why NPP needs to modify the file (or file’s metadata?) twice, but with no delay after the OS tells it about the change, my program is able to start reading before the second modify and getting an empty file – and often causing NPP to leave the empty file behind.

                        This is probably no help at all, but here is the sequence of events my program logs when VS2019 saves the file using a very safe method:

                          ADDED       :  cetwiqja.43f~
                          MODIFIED    :  cetwiqja.43f~
                          MODIFIED    :  cetwiqja.43f~
                          ADDED       :  ev11.ini~RFd859b.TMP
                          REMOVED     :  ev11.ini~RFd859b.TMP
                          RENAMED(old):  ev11.ini
                          RENAMED(new):  ev11.ini~RFd859b.TMP
                          RENAMED(old):  cetwiqja.43f~
                          RENAMED(new):  ev11.ini
                          MODIFIED    :  ev11.ini
                          REMOVED     :  ev11.ini~RFd859b.TMP
                        

                        While there are many more events, there is only one MODIFY of the INI file and that is due to a rename, so the file is neither open nor locked when the system notifies other programs.

                        Let me know if there are any more tests I can perform for you. I am happy to help. Thanks for your interest in this, too!

                        pnedevP 1 Reply Last reply Reply Quote 2
                        • pnedevP
                          pnedev @Steve Valliere
                          last edited by pnedev

                          @Steve-Valliere said in File Content Vanishing?:

                          I’m sure the .35 is a typo

                          If the string was notepad-plus-plus 7.6.53 - AppVeyor then I suspect you have gotten my Notepad++ exe build without the fix.
                          Are you sure you have downloaded this 32-bit exe:
                          https://ci.appveyor.com/api/buildjobs/g720d29abjg08fnx/artifacts/Notepad%2B%2B.Win32.Unicode Release.exe ?

                          So just to clarify:
                          You are getting the same behavior as with the original Notepad++ 7.7.1 exe?

                          And when you say Yes to Admin mode is the file with zero size on the disk as well?

                          Thank you for testing once again.

                          Steve ValliereS 1 Reply Last reply Reply Quote 2
                          • Steve ValliereS
                            Steve Valliere @pnedev
                            last edited by

                            @pnedev sorry about the mix-up, I had difficulty finding the correct file from the link you provided. The file name was the same, but the direct-linked file I just downloaded was slightly larger and only generates ONE modify event when the file is saved.

                            I have tried the steps that were reliably generating a problem quite a few times using the new file and I have not encountered the problem again. So now that I actually have your fix, I think it works.

                            (And yes, in the other build when I said Yes to Admin mode, the file was zero length according to File Explorer.)

                            Thanks again and I hope the “NPP powers that be” accept your change for inclusion in the main project soon!

                            donhoD 1 Reply Last reply Reply Quote 4
                            • donhoD
                              donho @Steve Valliere
                              last edited by

                              @Steve-Valliere
                              Were you using “SaveAsAdmin” plugin?

                              1 Reply Last reply Reply Quote 0
                              • First post
                                Last post
                              The Community of users of the Notepad++ text editor.
                              Powered by NodeBB | Contributors