• Login
Community
  • Login

Script to auto-update portable Notepad++ version

Scheduled Pinned Locked Moved General Discussion
15 Posts 6 Posters 2.4k 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.
  • X
    xomx @PeterJones
    last edited by Mar 17, 2025, 12:42 PM

    @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

    P 1 Reply Last reply Mar 17, 2025, 1:31 PM Reply Quote 2
    • P
      patrickdrd @xomx
      last edited by Mar 17, 2025, 1:31 PM

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

      L 1 Reply Last reply Mar 17, 2025, 1:59 PM Reply Quote 0
      • L
        Laur Florin @patrickdrd
        last edited by Laur Florin Mar 17, 2025, 5:07 PM Mar 17, 2025, 1:59 PM

        @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

        P 1 Reply Last reply Mar 17, 2025, 6:52 PM Reply Quote 0
        • P
          patrickdrd @Laur Florin
          last edited by Mar 17, 2025, 6:52 PM

          @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!

          L D 2 Replies Last reply Mar 17, 2025, 6:54 PM Reply Quote 0
          • L
            Laur Florin @patrickdrd
            last edited by Mar 17, 2025, 6:54 PM

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

            L 1 Reply Last reply Mar 17, 2025, 8:28 PM Reply Quote 1
            • L
              Laur Florin @Laur Florin
              last edited by Laur Florin Mar 17, 2025, 8:47 PM Mar 17, 2025, 8:28 PM

              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

              P Alan KilbornA 2 Replies Last reply Mar 20, 2025, 2:22 PM Reply Quote 1
              • P
                patrickdrd @Laur Florin
                last edited by Mar 20, 2025, 2:22 PM

                @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

                P 1 Reply Last reply Mar 21, 2025, 7:37 AM Reply Quote 0
                • P
                  patrickdrd @patrickdrd
                  last edited by patrickdrd Mar 21, 2025, 7:44 AM Mar 21, 2025, 7:37 AM

                  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 Mar 23, 2025, 12:00 PM

                    @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
                    • D
                      deleelee @patrickdrd
                      last edited by deleelee Mar 31, 2025, 6:46 AM Mar 31, 2025, 6:46 AM

                      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