Community
    • Login

    Script to auto-update portable Notepad++ version

    Scheduled Pinned Locked Moved General Discussion
    15 Posts 6 Posters 924 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.
    • PeterJonesP
      PeterJones @Laur Florin
      last edited by

      @Laur-Florin ,

      I am glad you found a sequence that works for you, and a way to automate it.

      However, to caution other users who might be considering whether or not to use the shared script: it uses a “destructive” upgrade: if you are using any of the themes, rather than the default stylers.xml normal-theme, and if you’ve have added any “user defined keywords” to any language in that theme, or any “user defined extensions” to any languages in that theme, or changed any colors in that theme, then the batch script provided will overwrite your modified theme, and you will lose your customization(s). Fortunately, if you use the normal stylers.xml for your theme, it will not be overwritten – however, that means that as Notepad++ improves its language syntax highlighting, this script will not help get you the new styles that didn’t exist when you first launched your portable N versions ago.

      (@Laur-Florin , I am not chastising you, or denegrading your script; that was kind of you to share your script, in the hopes that it would help someone else. However, since you did admit that people shouldn’t run the script if they didn’t understand all the implications, I just thought I would point out at least one implication that some people might not have thought of.)

      patrickdrdP Laur FlorinL xomxX 3 Replies Last reply Reply Quote 3
      • patrickdrdP
        patrickdrd @PeterJones
        last edited by

        I agree, the OP needs to exclude some, if not all, xml files, such as config.xml etc

        1 Reply Last reply Reply Quote 0
        • Laur FlorinL
          Laur Florin @PeterJones
          last edited by Laur Florin

          @PeterJones hahaha don’t worry about it, I know I am a coding noob and script kiddie 😂 . I am just trying different things out, breaking things, learning from it.

          I appreciate actually that you answered and explained some things that I was not aware of. Clearly I have more work ahead, that’s what I was actually looking for, some feedback, maybe I can even improve the script for myself later down the road for my needs.

          What you said about the settings is valid, I didn’t think of that, maybe if you can share anything you can think of about the script that may be doing some things wrong, I can try to take that in consideration and improve it for myself.

          Thank you for taking the time to tell me, and please, anyone, any ideas or feedback you may have, keep it coming !!🙏🙏😁

          Alan KilbornA 1 Reply Last reply Reply Quote 2
          • Alan KilbornA
            Alan Kilborn @Laur Florin
            last edited by

            @Laur-Florin said:

            or feedback you may have

            I think this is positive feedback: While I won’t use your script in its entirety, I think I’ll adapt parts of it to automate grabbing a new version of N++ portable; mainly to save the drudge work of click…click…click…

            1 Reply Last reply Reply Quote 1
            • xomxX
              xomx @PeterJones
              last edited by

              @PeterJones said in Script to auto-update portable Notepad++ version:

              a “destructive” upgrade

              There already is the @mpheath handy PythonScript sln, IIRC it does not overwrite that xmls:
              https://community.notepad-plus-plus.org/post/95098

              patrickdrdP 1 Reply Last reply Reply Quote 2
              • patrickdrdP
                patrickdrd @xomx
                last edited by

                @xomx good, thanks, but isn’t a batch file more convenient? can the OP include the code in his own script?

                Laur FlorinL 1 Reply Last reply Reply Quote 0
                • Laur FlorinL
                  Laur Florin @patrickdrd
                  last edited by Laur Florin

                  @patrickdrd I tried to come with an updated version that can (hopefully) backup the configs before in a temporary folder, perform the upgrade, then restore back the config files.

                  As always , I recommend caution and extensive testing first in a virtual environment, if someone ever want to use it.

                  @echo off
                  setlocal enabledelayedexpansion
                  
                  :: Define variables
                  set "json_url=https://api.github.com/repos/notepad-plus-plus/notepad-plus-plus/releases/latest"
                  set "download_path=%~dp0npp_latest.zip"
                  set "extract_temp=%~dp0npp_temp"
                  set "install_path=%~dp0"
                  set "exe_path=%install_path%notepad++.exe"
                  set "backup_path=%install_path%config_backup"
                  set "installed_version="
                  set "latest_version="
                  
                  :: Get installed Notepad++ version
                  for /f "tokens=*" %%i in ('powershell -Command "(Get-Item '%exe_path%').VersionInfo.ProductVersion"') do (
                      set "installed_version=%%i"
                  )
                  
                  :: Get latest release version from GitHub
                  for /f "tokens=*" %%i in ('powershell -Command "$json = Invoke-WebRequest -Uri '%json_url%' -UseBasicParsing | ConvertFrom-Json; $json.tag_name -replace 'v',''"') do (
                      set "latest_version=%%i"
                  )
                  
                  :: Check if both versions were retrieved
                  if "%installed_version%"=="" (
                      echo Error: Could not determine installed Notepad++ version.
                      pause
                      exit /b
                  )
                  
                  if "%latest_version%"=="" (
                      echo Error: Could not retrieve latest Notepad++ version from GitHub.
                      pause
                      exit /b
                  )
                  
                  :: Display versions
                  echo Installed Version  : %installed_version%
                  echo Latest Version     : %latest_version%
                  
                  :: Compare versions
                  if "%installed_version%"=="%latest_version%" (
                      echo Notepad++ is up to date. No update needed.
                      pause
                      exit /b
                  )
                  
                  echo A new version is available! Updating...
                  
                  :: Get latest release download URL
                  for /f "tokens=*" %%i in ('powershell -Command "$json = Invoke-WebRequest -Uri '%json_url%' -UseBasicParsing | ConvertFrom-Json; $json.assets | Where-Object { $_.name -like 'npp.*.portable.x64.zip' } | Select-Object -ExpandProperty browser_download_url"') do (
                      set "download_url=%%i"
                  )
                  
                  if "%download_url%"=="" (
                      echo Failed to retrieve the latest Notepad++ Portable download URL.
                      pause
                      exit /b
                  )
                  
                  :: Backup important config files
                  echo Backing up user configurations...
                  mkdir "%backup_path%" 2>nul
                  for %%f in (config.xml stylers.xml langs.xml shortcuts.xml contextMenu.xml userDefineLang.xml) do (
                      if exist "%install_path%\%%f" copy /Y "%install_path%\%%f" "%backup_path%"
                  )
                  
                  :: Download the latest version
                  echo Downloading latest Notepad++ Portable...
                  powershell -Command "(New-Object System.Net.WebClient).DownloadFile('%download_url%', '%download_path%')"
                  
                  :: Extract to a temporary folder
                  echo Extracting update...
                  rmdir /s /q "%extract_temp%" 2>nul
                  mkdir "%extract_temp%"
                  powershell -Command "Expand-Archive -Force '%download_path%' '%extract_temp%'"
                  
                  :: Move extracted files to install directory FIRST
                  echo Updating Notepad++...
                  xcopy /E /Y "%extract_temp%\*" "%install_path%\" >nul
                  
                  :: Restore user configurations AFTER updating
                  echo Restoring user configurations...
                  for %%f in (config.xml stylers.xml langs.xml shortcuts.xml contextMenu.xml userDefineLang.xml) do (
                      if exist "%backup_path%\%%f" copy /Y "%backup_path%\%%f" "%install_path%\%%f"
                  )
                  
                  :: Cleanup
                  echo Cleaning up...
                  del "%download_path%"
                  rmdir /s /q "%extract_temp%"
                  rmdir /s /q "%backup_path%"
                  
                  echo Update completed! Notepad++ is now updated to version %latest_version%.
                  pause
                  
                  

                  Mainly added the lines to preserve the configs, maybe this will be better a bit. If i missed any files to backup and restore from config, as I don’t know them all exactly, I can try to update this further by excluding the necessary files from updating or overwriting

                  patrickdrdP 1 Reply Last reply Reply Quote 0
                  • patrickdrdP
                    patrickdrd @Laur Florin
                    last edited by

                    @Laur-Florin hmm, I would prefer to skip them like the other script, actually I think they’re only two: config xml and shortcuts.xml,
                    also an option to skip localisation files (and do copy only English ones) would be great,
                    thanks!

                    Laur FlorinL deleeleeD 2 Replies Last reply Reply Quote 0
                    • Laur FlorinL
                      Laur Florin @patrickdrd
                      last edited by

                      @patrickdrd sure! I’ll keep tinkering with it, and if I manage to accomplish this, I’ll post an update

                      Laur FlorinL 1 Reply Last reply Reply Quote 1
                      • Laur FlorinL
                        Laur Florin @Laur Florin
                        last edited by Laur Florin

                        Hi there. I tried to make some further changes to it. Hopefully it will work alright . However it still needs further work for sure.

                        @echo off
                        setlocal enabledelayedexpansion
                        
                        :: Define variables
                        set "json_url=https://api.github.com/repos/notepad-plus-plus/notepad-plus-plus/releases/latest"
                        set "download_path=%~dp0npp_latest.zip"
                        set "extract_temp=%~dp0npp_temp"
                        set "install_path=%~dp0"
                        set "exe_path=%install_path%notepad++.exe"
                        set "backup_path=%install_path%config_backup"
                        set "installed_version="
                        set "latest_version="
                        
                        :: Get installed Notepad++ version
                        for /f "tokens=*" %%i in ('powershell -Command "(Get-Item '%exe_path%').VersionInfo.ProductVersion"') do (
                            set "installed_version=%%i"
                        )
                        
                        :: Get latest release version from GitHub
                        for /f "tokens=*" %%i in ('powershell -Command "$json = Invoke-WebRequest -Uri '%json_url%' -UseBasicParsing | ConvertFrom-Json; $json.tag_name -replace 'v',''"') do (
                            set "latest_version=%%i"
                        )
                        
                        :: Check if both versions were retrieved
                        if "%installed_version%"=="" (
                            echo Error: Could not determine installed Notepad++ version.
                            pause
                            exit /b
                        )
                        
                        if "%latest_version%"=="" (
                            echo Error: Could not retrieve latest Notepad++ version from GitHub.
                            pause
                            exit /b
                        )
                        
                        :: Display versions
                        echo Installed Version  : %installed_version%
                        echo Latest Version     : %latest_version%
                        
                        :: Compare versions
                        if "%installed_version%"=="%latest_version%" (
                            echo Notepad++ is up to date. No update needed.
                            pause
                            exit /b
                        )
                        
                        echo A new version is available! Updating...
                        
                        :: Get latest release download URL
                        for /f "tokens=*" %%i in ('powershell -Command "$json = Invoke-WebRequest -Uri '%json_url%' -UseBasicParsing | ConvertFrom-Json; $json.assets | Where-Object { $_.name -like 'npp.*.portable.x64.zip' } | Select-Object -ExpandProperty browser_download_url"') do (
                            set "download_url=%%i"
                        )
                        
                        if "%download_url%"=="" (
                            echo Failed to retrieve the latest Notepad++ Portable download URL.
                            pause
                            exit /b
                        )
                        
                        :: Backup important config files (except config.xml and shortcuts.xml)
                        echo Backing up user configurations...
                        mkdir "%backup_path%" 2>nul
                        for %%f in (stylers.xml langs.xml contextMenu.xml userDefineLang.xml) do (
                            if exist "%install_path%\%%f" copy /Y "%install_path%\%%f" "%backup_path%"
                        )
                        
                        :: Download the latest version
                        echo Downloading latest Notepad++ Portable...
                        powershell -Command "(New-Object System.Net.WebClient).DownloadFile('%download_url%', '%download_path%')"
                        
                        :: Extract to a temporary folder
                        echo Extracting update...
                        rmdir /s /q "%extract_temp%" 2>nul
                        mkdir "%extract_temp%"
                        powershell -Command "Expand-Archive -Force '%download_path%' '%extract_temp%'"
                        
                        :: Move extracted files to install directory while EXCLUDING config.xml and shortcuts.xml
                        echo Updating Notepad++...
                        robocopy "%extract_temp%" "%install_path%" /E /NFL /NDL /NJH /NJS /R:3 /W:2 /XF config.xml shortcuts.xml >nul
                        
                        :: Restore user configurations (EXCEPT config.xml and shortcuts.xml)
                        echo Restoring user configurations...
                        for %%f in (stylers.xml langs.xml contextMenu.xml userDefineLang.xml) do (
                            if exist "%backup_path%\%%f" copy /Y "%backup_path%\%%f" "%install_path%\%%f"
                        )
                        
                        :: Remove all localization files except English
                        echo Removing unnecessary localization files...
                        for %%f in ("%install_path%\localization\*") do (
                            if NOT "%%~nxf"=="english.xml" if NOT "%%~nxf"=="nativeLang.xml" del "%%f"
                        )
                        
                        :: Cleanup
                        echo Cleaning up...
                        del "%download_path%"
                        rmdir /s /q "%extract_temp%"
                        rmdir /s /q "%backup_path%"
                        
                        echo Update completed! Notepad++ is now updated to version %latest_version%.
                        pause
                        
                        

                        Hopefully this later iteration can sort all the issues so far. Tried to include an approach to skip the important settings, hotkeys, localizations as well. // edit: after some tests it still has unexpected errors, do not use. Work will still be in progress , hopefully i will find a breakthrough with enough testing in my spare time

                        patrickdrdP Alan KilbornA 2 Replies Last reply Reply Quote 1
                        • patrickdrdP
                          patrickdrd @Laur Florin
                          last edited by

                          @Laur-Florin said in Script to auto-update portable Notepad++ version:

                          robocopy “%extract_temp%” “%install_path%” /E /NFL /NDL /NJH /NJS /R:3 /W:2 /XF config.xml shortcuts.xml >nul

                          I like this exclusion command, I think there’s no need for backup folder,
                          also you could copy from extract_temp/localization only english.xml and skip the rest, so it should be somehow simpler

                          patrickdrdP 1 Reply Last reply Reply Quote 0
                          • patrickdrdP
                            patrickdrd @patrickdrd
                            last edited by patrickdrd

                            here’s my version, I tested and it works,
                            I’m excluding themes too and I changed working folder(s) to d:\downloads

                            @echo off
                            setlocal enabledelayedexpansion
                            
                            :: Define variables
                            set "json_url=https://api.github.com/repos/notepad-plus-plus/notepad-plus-plus/releases/latest "
                            set "download_path=d:\downloads\npp_latest.zip"
                            set "extract_temp=d:\downloads\npp"
                            set "install_path=.\"
                            set "exe_path=%install_path%notepad++.exe"
                            
                            REM set "download_path=%~dp0npp_latest.zip"
                            REM set "extract_temp=%~dp0npp_temp"
                            REM set "install_path=%~dp0"
                            REM set "exe_path=%install_path%notepad++.exe"
                            REM set "backup_path=%install_path%config_backup"
                            set "installed_version="
                            set "latest_version="
                            
                            :: Get installed Notepad++ version
                            for /f "tokens=*" %%i in ('powershell -Command "(Get-Item '%exe_path%').VersionInfo.ProductVersion"') do (
                                set "installed_version=%%i"
                            )
                            
                            :: Get latest release version from GitHub
                            for /f "tokens=*" %%i in ('powershell -Command "$json = Invoke-WebRequest -Uri '%json_url%' -UseBasicParsing | ConvertFrom-Json; $json.tag_name -replace 'v',''"') do (
                                set "latest_version=%%i"
                            )
                            
                            :: Check if both versions were retrieved
                            if "%installed_version%"=="" (
                                echo Error: Could not determine installed Notepad++ version.
                                pause
                                exit /b
                            )
                            
                            if "%latest_version%"=="" (
                                echo Error: Could not retrieve latest Notepad++ version from GitHub.
                                pause
                                exit /b
                            )
                            
                            :: Display versions
                            echo Installed Version  : %installed_version%
                            echo Latest Version     : %latest_version%
                            
                            :: Compare versions
                            if "%installed_version%"=="%latest_version%" (
                                echo Notepad++ is up to date. No update needed.
                                pause
                                exit /b
                            )
                            
                            echo A new version is available! Updating...
                            
                            :: Get latest release download URL
                            for /f "tokens=*" %%i in ('powershell -Command "$json = Invoke-WebRequest -Uri '%json_url%' -UseBasicParsing | ConvertFrom-Json; $json.assets | Where-Object { $_.name -like 'npp.*.portable.x64.zip' } | Select-Object -ExpandProperty browser_download_url"') do (
                                set "download_url=%%i"
                            )
                            
                            if "%download_url%"=="" (
                                echo Failed to retrieve the latest Notepad++ Portable download URL.
                                pause
                                exit /b
                            )
                            
                            REM :: Backup important config files (except config.xml and shortcuts.xml)
                            REM echo Backing up user configurations...
                            REM mkdir "%backup_path%" 2>nul
                            REM for %%f in (stylers.xml langs.xml contextMenu.xml userDefineLang.xml) do (
                                REM if exist "%install_path%\%%f" copy /Y "%install_path%\%%f" "%backup_path%"
                            REM )
                            
                            :: Download the latest version
                            echo Downloading latest Notepad++ Portable...
                            powershell -Command "(New-Object System.Net.WebClient).DownloadFile('%download_url%', '%download_path%')"
                            
                            :: Extract to a temporary folder
                            echo Extracting update...
                            rmdir /s /q "%extract_temp%" 2>nul
                            mkdir "%extract_temp%"
                            powershell -Command "Expand-Archive -Force '%download_path%' '%extract_temp%'"
                            
                            :: Move extracted files to install directory while EXCLUDING config.xml and shortcuts.xml
                            echo Updating Notepad++...
                            robocopy "%extract_temp%" . /e /copy:DAT /dcopy:T /r:0 /xf config.xml shortcuts.xml /XD localization themes /IS /IT
                            REM xcopy . "D:\downloads\npp2" /c /q /h /r /k /y /e /exclude:"D:\Utilities\PortableApps\Notepad++\xcopy_excludes.txt"
                            REM robocopy "%extract_temp%" "%install_path%" /E /NFL /NDL /NJH /NJS /R:3 /W:2 /XF config.xml shortcuts.xml /XD localization themes >nul
                            REM pause
                            
                            REM :: Restore user configurations (EXCEPT config.xml and shortcuts.xml)
                            REM echo Restoring user configurations...
                            REM for %%f in (stylers.xml langs.xml contextMenu.xml userDefineLang.xml) do (
                                REM if exist "%backup_path%\%%f" copy /Y "%backup_path%\%%f" "%install_path%\%%f"
                            REM )
                            
                            REM :: Remove all localization files except English
                            REM echo Removing unnecessary localization files...
                            REM for %%f in ("%install_path%\localization\*") do (
                                REM if NOT "%%~nxf"=="english.xml" if NOT "%%~nxf"=="nativeLang.xml" del "%%f"
                            REM )
                            
                            
                            copy /y "%extract_temp%\localization\english*.xml" ".\localization"
                            REM pause
                            
                            :: Cleanup
                            echo Cleaning up...
                            del "%download_path%"
                            rmdir /s /q "%extract_temp%"
                            REM rmdir /s /q "%backup_path%"
                            REM pause
                            
                            
                            echo Update completed! Notepad++ is now updated to version %latest_version%.
                            pause
                            
                            
                            
                            1 Reply Last reply Reply Quote 1
                            • Alan KilbornA
                              Alan Kilborn @Laur Florin
                              last edited by

                              @Laur-Florin

                              Just curious… The batch file makes use of a lot of powershell. Why did you decide to make it a hybrid batch/powershell script instead of going 100% powershell?

                              1 Reply Last reply Reply Quote 0
                              • deleeleeD
                                deleelee @patrickdrd
                                last edited by deleelee

                                actually I think they’re only two: config xml and shortcuts.xml,

                                If used, there is also toolbarIcons.xml and overrideMap.xml

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