Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    I lost open tabs and probably, files! HELP!

    Help wanted · · · – – – · · ·
    11
    24
    16158
    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.
    • Vlad Gordiy
      Vlad Gordiy last edited by

      Thanks for your help, really appreciate it! :-)

      Alan Kilborn 1 Reply Last reply Reply Quote 1
      • Alan Kilborn
        Alan Kilborn @Vlad Gordiy last edited by

        Back to the same old way of operating!

        1 Reply Last reply Reply Quote 1
        • kekukui
          kekukui last edited by

          @Meta-Chuh said:

          make sure you don’t shutdown or reboot your pc, while notepad++ is still running.

          And what if the power fails? I always reboot with NPP running and never lost any tabs until version 7.6.3. So I thought it would always recover a session, like Firefox or Microsoft Word… What a surprise when everything disappeared !

          a shutdown will only halt as long as a dialogue window is open.

          …but Windows Notepad halts shutdown even when a dialogue window is NOT open! – NPP should work the same way, as the user expects. (Also, NPP does not implement file locking on the contents of its own temp folder while it is running!?)

          if i understood everything correctly, you have been able to successfully recover your unsaved tabs and files.

          If I understood correctly, it also means that automatic session recovery should be trivial to implement in source with a “clean shutdown” flag and a backup of session.xml


          @Alan-Kilborn said:

          Did you learn any kind of lesson from this experience?

          I think the lesson is for the developers.

          Back to the same old way of operating!

          Which should be supported ! 😁

          Alan Kilborn 1 Reply Last reply Reply Quote 0
          • Alan Kilborn
            Alan Kilborn @kekukui last edited by

            @kekukui said:

            And what if the power fails?

            I think the lesson is for the developers.

            You can’t be serious…If a tornado/hurricane comes to your house and smashes your computer and its hard drive into bits and your data is lost…is that something the developers should protect you from?

            Save (ctrl+s, often)…and backup (independently of Notepad++, move copy offsite, also often).

            1 Reply Last reply Reply Quote 5
            • Douglas Dike
              Douglas Dike last edited by

              What needs to happen to get the old functionality where tabs/files persisted across reboots?

              I’ve been using the notepad++ as a persistent sticky pad for snippets of code, error messages and random state for years. The old behavior was incredibly useful. Do I need to make a fork?

              Meta Chuh 1 Reply Last reply Reply Quote 0
              • PeterJones
                PeterJones last edited by PeterJones

                @Douglas-Dike said:

                The old behavior was incredibly useful

                And the persist-across-exits-or-reboots behavior still exists. It is now, and has always been, a calculated risk on your part to enable it. If you lose data (as the OP of this thread did) because Windows crashed, don’t blame Notepad++; anyone relying on an auto-save to not be corrupted during OS crash is taking the consequences of their own decision: it’s not a danger specific to Notepad++: I’ve lost data because MS Word auto-save feature corrupted both the original file and the periodic auto-backup. I always recommend taking full control of critical data (“save early, save often; commit early, commit often” is my mantra).

                And that behavior is now, and has always been (*) enabled via the Settings > Preferences > Backup > Enable Session Snapshot and periodic backup.

                (*: “always” may be an overstatement. I doubt the feature existed in Notepad++ before Notepad++ existed; I don’t know what version number Notepad++ added the session-snapshot/periodic-backup feature. But as long as I’ve known about that feature, it’s been at that setting.)

                1 Reply Last reply Reply Quote 2
                • Meta Chuh
                  Meta Chuh @Douglas Dike last edited by

                  welcome to the notepad++ community, @Douglas-Dike

                  What needs to happen to get the old functionality where tabs/files persisted across reboots?

                  this code part has not changed.
                  what has changed, is that you are probably on windows 10, or worse: on w10 build 1809, which will currently force kill applications on automatic windows update reboots, with a more limited grace period, for a “better microsoft user experience” due to faster rebooting.

                  Do I need to make a fork?

                  no, you just have to install any of the older versions, which you think worked before, from here:
                  https://notepad-plus-plus.org/download/all-versions.html
                  to personally verify that notepad++ has not changed regarding “tabs/files persisting across reboots”, but your windows platform it is running on.

                  eventually you could also dig out your good old win7 dvd and “repair” win10 with it ;-)

                  1 Reply Last reply Reply Quote 1
                  • vk5880
                    vk5880 last edited by

                    Please update the code for saving current session from time to time to fix the issue with lost sessions on reboot. This is seriously impacting work with NPP as lost sessions/files is very bad experience.
                    Thank you.

                    1 Reply Last reply Reply Quote 0
                    • Felipe G. Nievinski
                      Felipe G. Nievinski last edited by Felipe G. Nievinski

                      the bug seems to have been fixed, thank you.

                      https://github.com/notepad-plus-plus/notepad-plus-plus/commit/62efa463b0a74426af0f3f6ed10382b52a4ac799

                      otherwise, please comment in the bug report:

                      https://github.com/notepad-plus-plus/notepad-plus-plus/issues/10402#

                      1 Reply Last reply Reply Quote 2
                      • sfcfs
                        sfcfs last edited by

                        I have encountered this problem a couple of days ago, my laptop had a BSOD and seems that the session.xml was corrupted or lost.

                        If the “%AppData%\Notepad++\backup” still has the files, you can create a backup in your desktop and use the following c# program to re-create the “session.xml” file.
                        Completely close Notepad++ and execute the following c# script:

                        // Restores session.xml file in %AppData\Roaming\Notepad++ 
                        // from files stored in %AppData\Roaming\Notepad++\backup
                        
                        using System;
                        using System.IO;
                        string app_path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                        string path = app_path + @"\Notepad++\backup\";
                        string fullfile = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?> \n<NotepadPlus> \n<Session activeView=\"0\"> \n<mainView activeIndex=\"2\">";
                        string endtext = "</mainView>\n <subView activeIndex=\"0\" />\n</Session>\n</NotepadPlus>";
                        string entry1 = "<File firstVisibleLine=\"0\" xOffset=\"0\" scrollWidth=\"64\" startPos=\"8\" endPos=\"8\" selMode=\"0\" offset=\"0\" wrapCount=\"1\" lang=\"None (Normal Text)\" encoding=\"-1\" userReadOnly=\"no\" filename=\"";
                        string entry2 = "backupFilePath=\"";
                        string endentry = "originalFileLastModifTimestamp=\"0\" originalFileLastModifTimestampHigh=\"0\" mapFirstVisibleDisplayLine=\"-1\" mapFirstVisibleDocLine=\"-1\" mapLastVisibleDocLine=\"-1\" mapNbLine=\"-1\" mapHigherPos=\"-1\" mapWidth=\"-1\" mapHeight=\"-1\" mapKByteInDoc=\"512\" mapWrapIndentMode=\"-1\" mapIsWrap=\"no\" />";
                        string[] filenames = Directory.GetFiles(path);
                        foreach (string filename in filenames) 
                        {
                            int istart = filename.IndexOf("kup\\")+4;
                            int iend = filename.IndexOf("@");
                            	
                            string entryname = filename.Substring(istart,iend-istart);
                            string fullname = filename.Substring(istart);
                            
                            fullfile = fullfile + entry1 + entryname + "\" " + entry2 + filename + "\" " + endentry + "\n";
                        }
                        fullfile = fullfile + endtext;
                        Console.WriteLine (fullfile);
                        // If you want to test the output, comment the line below or change the path.
                        File.WriteAllText(app_path + @"\session.xml",fullfile);
                        

                        This could be done with Powershell too, may look into it so that it is a bit more accessible.

                        sfcfs PeterJones 2 Replies Last reply Reply Quote 2
                        • sfcfs
                          sfcfs @sfcfs last edited by

                          @sfcfs The last line of the code needs to be changed to

                          File.WriteAllText(app_path + @"\NotePad++\session.xml",fullfile);
                          

                          for it to work seamlessly. If not the user needs to move the session.xml file from the folder %AppData%\Roaming to %AppData%\Roaming\Notepad++

                          After that, just start Notepad++ and your tabs should be back.

                          1 Reply Last reply Reply Quote 2
                          • PeterJones
                            PeterJones @sfcfs last edited by PeterJones

                            Just a clarification:

                            @sfcfs said two posts ago:

                            %AppData%\Notepad++\backup

                            and then one post ago:

                            %AppData%\Roaming to %AppData%\Roaming\Notepad++

                            The first (%AppData%\Notepad++\*) was correct. The second (%AppData%\Roaming\*) is wrong. See the AppData FAQ. Try it yourself: open Windows Explorer, and paste/type %AppData%\Roaming into the title/address bar and see the error message that pops up; then try %AppData%\Notepad++ and see what happens.

                            Other than that mistake (which many people make), that’s a great script, so thanks for sharing.

                            Also, it would be nice, for those who aren’t C# experts, if you showed how an average-Joe Notepad++ user, who might not have ever touched C#, could take that C# code and actually compile/run it (without having to install a huge C# environment) – not all Notepad++ are C# programmers, or programmers at all.

                            ----

                            Addenda: See, for example, this post, where I show errors I get when I tried to compile your script with the .NET framework’s csc.exe using c:\windows\Microsoft.NET\Framework\v4.0.30319\csc.exe recover-lost-session.cs:

                            recover-lost-session.cs(6,1): error CS0116: A namespace cannot directly contain members such as fields or methods
                            recover-lost-session.cs(13,8): error CS1001: Identifier expected
                            recover-lost-session.cs(13,10): error CS1518: Expected class, delegate, enum, interface, or struct
                            
                            PeterJones 1 Reply Last reply Reply Quote 0
                            • PeterJones
                              PeterJones @PeterJones last edited by PeterJones

                              Here is a PythonScript implementation of it.

                              See these instructions for how to run this script in PythonScript

                              The script will pop up a dialog. Respond with:

                              1. click YES to load the recovered session immediately
                              2. click NO to save the recovered session into an XML file that you can later load with File > Load Session…
                              3. click CANCEL to ignore the recovered session

                              This is only effective if Settings > Preferences > Backup > Enable session snapshot… was checkmarked before you lost your session file. This is only effective if nothing happened to erase %AppData%\Notepad++\backup or equiavlent.

                              Script: RecoverLostSession.py

                              # encoding=utf-8
                              """in response to https://community.notepad-plus-plus.org/topic/17344/
                              specifically, translate the ideas behind https://community.notepad-plus-plus.org/post/79695 to PythonScript
                              
                              0. Install Python Script plugin, if not yet installed
                              1. Use Plugins > PythonScript > New Script, give this a name (like `RecoverLostSession.py`)
                              2. Plugins > PythonScript > Scripts > `RecoverLostSession` to recover it
                                  1. click YES to load the recovered session immediately
                                  2. click NO to save the recovered session into an XML file that you can later load with File > Load Session...
                                  3. click CANCEL to ignore the recovered session
                              """
                              from Npp import editor,notepad,console
                              import os
                              import tempfile
                              
                              class SessionRecovery(object):
                                  xml_prefix = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?> \n<NotepadPlus> \n<Session activeView=\"0\"> \n<mainView activeIndex=\"2\">"
                                  xml_suffix = "</mainView>\n <subView activeIndex=\"0\" />\n</Session>\n</NotepadPlus>\n"
                                  xml_entry1 = "<File firstVisibleLine=\"0\" xOffset=\"0\" scrollWidth=\"64\" startPos=\"8\" endPos=\"8\" selMode=\"0\" offset=\"0\" wrapCount=\"1\" lang=\"None (Normal Text)\" encoding=\"-1\" userReadOnly=\"no\" filename=\""
                                  xml_entry2 = "backupFilePath=\""
                                  xml_endentry = "originalFileLastModifTimestamp=\"0\" originalFileLastModifTimestampHigh=\"0\" mapFirstVisibleDisplayLine=\"-1\" mapFirstVisibleDocLine=\"-1\" mapLastVisibleDocLine=\"-1\" mapNbLine=\"-1\" mapHigherPos=\"-1\" mapWidth=\"-1\" mapHeight=\"-1\" mapKByteInDoc=\"512\" mapWrapIndentMode=\"-1\" mapIsWrap=\"no\" />"
                                  xml_full = ""
                              
                                  def go(self):
                                      self.determine_directories()
                                      self.build_xml()
                                      s = notepad.messageBox("YES to load recovered session now\nNO to save as a new session file\nCANCEL to ignore recovered session", "Recovered Session", MESSAGEBOXFLAGS.YESNOCANCEL)
                                      if s == MESSAGEBOXFLAGS.RESULTYES:
                                          self.load_session()
                                      elif s == MESSAGEBOXFLAGS.RESULTNO:
                                          self.saveas_session()
                                      return
                              
                                  def determine_directories(self):
                                      cfg_plg_cfg = notepad.getPluginConfigDir()
                                      (cfg_plg, x) = os.path.split(cfg_plg_cfg)
                                      (self.cfg_dir, x) = os.path.split(cfg_plg)
                                      self.bkup_dir = os.path.join(self.cfg_dir, 'backup')
                                      self.xml_full = self.xml_prefix
                                      self.session_xml_path = os.path.join(self.cfg_dir, 'session.xml')
                                      return
                              
                                  def build_xml(self):
                                      for (root, dirs, files) in os.walk(self.bkup_dir):
                                          for f in files:
                                              filepath = os.path.join(root, f)
                                              posFile = filepath.find(f)
                                              posAt = filepath.find("@")
                                              entry_name = filepath[posFile:posAt]
                                              this_entry = self.xml_entry1 + entry_name + '" ' + self.xml_entry2 + filepath + '" ' + self.xml_endentry + "\n"
                                              self.xml_full += "\n    " + this_entry
                                      self.xml_full += self.xml_suffix
                                      return
                              
                                  def saveas_session(self):
                                      notepad.new()
                                      editor.setText(self.xml_full)
                                      notepad.save()
                                      notepad.close()
                                      return
                              
                                  def load_session(self):
                                      _, fn = tempfile.mkstemp('.xml')
                                      f = open(fn, 'w')
                                      f.write(self.xml_full)
                                      f.close()
                                      notepad.loadSession(f.name)
                                      try:
                                          os.remove(f.name)
                                      except WindowsError as e:
                                          if e.winerror == 32: # cannot delete is fine, just ignore it
                                              pass
                                          else:
                                              raise e
                                      return
                              
                              SessionRecovery().go()
                              
                              1 Reply Last reply Reply Quote 2
                              • Referenced by  PeterJones PeterJones 
                              • Alan Kilborn
                                Alan Kilborn last edited by

                                HERE’s another variation on Python code “solving” the problem.

                                1 Reply Last reply Reply Quote 0
                                • C Raghava
                                  C Raghava last edited by

                                  I am also facing the same issue, I am using Notepad ++ 5. +.+

                                  Terry R 1 Reply Last reply Reply Quote 0
                                  • Terry R
                                    Terry R @C Raghava last edited by

                                    @C-Raghava said in I lost open tabs and probably, files! HELP!:

                                    I am also facing the same issue, I am using Notepad ++ 5. +.+

                                    So if what you typed is correct (5.+.+) you are using a seriously old version. Why haven’t you updated? No-one is going to help you on such an old version. The details listed in this post and several like it all refer to much later versions.

                                    Terry

                                    1 Reply Last reply Reply Quote 0
                                    • First post
                                      Last post
                                    Copyright © 2014 NodeBB Forums | Contributors