Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
IncognitoMode

GZDoom auto updater?

Recommended Posts

Sorry if this has been posted before, is there an auto updater for GZDOOM? it gets annoying having to reinstall it every time it gets an update like every week

Share this post


Link to post
On 5/18/2018 at 1:14 AM, IncognitoMode said:

... every time it gets an update like every week

 

You mean every month? The zdoom.org news page lists four releases this year: 3.2.5, 3.3.0, 3.3.1 and 3.3.2.

 

Share this post


Link to post
3 hours ago, Jerry.C said:

 

You mean every month? The zdoom.org news page lists four releases this year: 3.2.5, 3.3.0, 3.3.1 and 3.3.2.

 

Obviously @IncognitoMode means the dev builds.

 

I wrote a small Python script that reads the HTML of the site, downloads and unpacks the latest version of GZDoom. Requires the Python 3, and the HTMLParser and requests modules, and 7zip.


 

from html.parser import HTMLParser
import os.path
import requests
import subprocess


platform = 'x64' # or x32 for the 32-bit version
gzdoom_dir = 'c:/games/doom/ports/gzdoom/'
download_dir = gzdoom_dir
sevenzip_exe = 'c:/Program Files/7-Zip/7z.exe'

class DevBuildsParser(HTMLParser):
    def download_file(self, url, out_file):
        print('Downloading', url, 'to', out_file)
        
        r = requests.get(url, stream=True)
        
        if r.status_code != 200:
            return False, r.status_code
        
        with open(out_file, 'wb') as file:
            for chunk in r:
                file.write(chunk)
        
        return True, 0
        
        
    def handle_starttag(self, tag, attrs):
        # There's no nice way to stop the HTMLParser, so just don't do anything
        # for the rest of the HTML when we're already finished
        if self.finished:
            return

        # A td tag with the class x-filename is the introduction to the URL,
        # followed by an a tag that includes the path to the file
        if tag == 'td' and len([ True for x in attrs if x[0] == 'class' and x[1] == 'x-filename' ]) == 1:
            self.found_filename = True
        elif tag == 'a' and self.found_filename:
            file_path = [ x[1] for x in attrs if x[0] == 'href' ][0]
            if platform in file_path:
                self.finished = True
                out_file = download_dir + file_path.split('/')[-1]
                url = 'https://devbuilds.drdteam.org' + file_path

                # Check if we previously downloaded the latest version, and
                # stop processing if so
                if os.path.isfile('updater.version'):
                    with open('updater.version', 'r') as file:
                        version = file.read().strip()
                        if version == file_path.split('/')[-1]:
                            print('Already got the latest version, no need to do anything')
                            input('\nPress enter to exit')
                            return

                success, error_code = self.download_file(url, out_file)
                
                if not success:
                    print('Error downloading file. HTTP error code:', error_code)
                    input('\nPress enter to exit')
                    return
                
                print('Unpacking...')
                
                try:
                    subprocess.check_output([sevenzip_exe, 'x', out_file, '-aoa', '-o' + gzdoom_dir], stderr=subprocess.STDOUT)
                    print('Removing', out_file)
                    os.remove(out_file)
                    
                    # Write version file
                    print('Updating version file')
                    with open('updater.version', 'w') as file:
                        file.write(file_path.split('/')[-1])
                        
                    print('Update finished')
                    input('\nPress enter to exit')
                except subprocess.CalledProcessError as e:
                    print('Error unpacking:')
                    print('Return code:', e.returncode)
                    print('Output:', output.decode('utf-8'))
                
        else:
            # Sanity check. Make sure that a td with class=x-filename has to
            # come before the a tag, so that we don't download who-knows-what
            # when the HTML changes
            self.found_filename = False

    def __init__(self):
        HTMLParser.__init__(self)
        self.found_filename = False
        self.finished = False

r = requests.get('https://devbuilds.drdteam.org/gzdoom/')

if r.status_code != 200:
    print('HTTP error:', r.status_code)
    exit(1)

parser = DevBuildsParser()
parser.feed(r.text)

Script is also attached. Note that it does some big assumptions about the HTML layout and file names, so it might break in the future. Make sure to change the paths at the top to your environment.

updater.7z

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×