Suggestion for notepad-plus-plus

Questions about WAPT Packaging / Requests and help regarding Wapt packages.
Forum Rules
Community Forum Rules
* English support on www.reddit.com/r/wapt
* French community support is available on this forum
* Please prefix the topic title with [RESOLVED] if it is resolved.
* Please do not edit a topic that is tagged [RESOLVED]. Open a new topic referencing the old one.
* Specify the installed WAPT version, full version, and build number (2.2.1.11957 / 2.2.2.12337 / etc.) as well as the Enterprise/Discovery edition.
* Versions 1.8.2 and earlier are no longer supported. The only questions accepted regarding version 1.8.2 are related to upgrading to a supported version (2.1, 2.2, etc.).
* Specify the server OS (Linux/Windows) and version (Debian Buster/Bullseye - CentOS 7 - Windows Server 2012/2016/2019).
* Specify the OS of the administration/package creation machine and the machine with the problematic agent, if applicable (Windows 7/10/11/Debian 11/etc.).
* Avoid asking multiple questions when opening a topic, otherwise it may be ignored. If there are multiple topics, open separate topics, preferably one after the other and not all at the same time (i.e., do not spam the forum).
* Include code snippets, screenshots, and other images directly in the post. Links to Pastebin, Bitly, and other third-party sites will be systematically removed.
* As with any community forum, support is provided voluntarily by members. If you require commercial support, you can contact Tranquil IT's sales department at 02.40.97.57.55
Locked
elelay
Messages: 27
Registration: Oct 20, 2020 - 12:39

July 8, 2021 - 10:55 PM

Good morning,

I would like to propose an addition to the notepad-plus-plus package, specifically to the update_package function.
Looking at the Notepad github, I noticed that they were providing the file hashes.
Why not do this additional check?

To achieve this, I propose two fairly simple pieces of code:

Code: Select all

import hashlib

# Obtention du hash du fichier fournit sur le Github
github_url = 'https://github.com/notepad-plus-plus/notepad-plus-plus/releases'
github_page = wgets(github_url)
checksum_regex = re.compile(r'([a-f0-9]{64})  ' + filenamex64)
checksum = checksum_regex.findall(github_page)[0]

# Obtention du hash calculé du fichier téléchargé
sha256_hash = hashlib.sha256()
    with open(filenamex64, 'rb') as f:  
        for byte_block in iter(lambda: f.read(4096),b''):
            sha256_hash.update(byte_block)
        print(sha256_hash.hexdigest())
    if sha256_hash != checksum:
        print(f'Integrity check failed. The file may have been corrupted or an error occured while downloading.')
I would also like to suggest using the pkg_resources library for version checking, as I noticed that only filenames were being compared.

Example using notepadplus:

Code: Select all

from pkg_resources import parse_version

url = 'https://api.github.com/repos/notepad-plus-plus/notepad-plus-plus/releases/latest'
    data = json.loads(wgets(url, proxies=proxies))
    assets = data['assets']
    filenamex64, url64 = [(str(p['name']), str(p['browser_download_url'])) for p in assets if 'Installer.x64.exe' in p['name']][0]

package_version = control.get_software_version()
latest_version = filenamex64.split('npp.',)[1].split('.Installer.x64.exe')[0]

for fileexe in glob.glob('npp.*.Installer.x64.exe'):
	if parse_version(package_version) < parse_version(latest_version)
	print('Delete ' + 
	remove_file(fileexe)
[...]
Far from being a Python expert, I thank you for the quality of the packages provided; they really allow me to improve :D

Sincerely,

Étienne
WAPT Server version: 2.0 Enterprise
Console installed on a Windows Server 2019
Debian 10 Buster server
Locked