Last active
February 20, 2024 12:32
-
-
Save 123DMWM/0852dca55be0ce863d9736a3016d6d50 to your computer and use it in GitHub Desktop.
Python script to automatically update the Steam version of ClassiCube to the latest dev build once opened.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
import os | |
import re | |
import requests | |
import subprocess | |
import sys | |
import urllib.request | |
from dateutil.parser import parse as parsedate | |
# Get the command-line arguments | |
args = sys.argv[1:] | |
# Define variables | |
pattern_URL = r"[Mm][Cc]://((?:\d{1,3}\.){3}\d{1,3}):(\d{1,5})/([A-Za-z0-9.]{2,16})/([a-f0-9]{32})/?" | |
pattern_Username = r"[A-Za-z0-9._]{2,16}" | |
pattern_MPPass = r"[a-f0-9]{32}" | |
pattern_IP = r"(?:\d{1,3}\.){3}\d{1,3}" | |
pattern_Port = r"\d{1,5}" | |
url = "https://cdn.classicube.net/client/latest/cc-w64-d3d11.exe" | |
dstFile = "C:\\Program Files (x86)\\Steam\\steamapps\\common\\ClassiCube\\ClassiCube.exe" | |
# Request file headers for datetime checking | |
r = requests.head(url, allow_redirects=True) | |
url_date = parsedate(r.headers['Last-Modified']).astimezone() | |
file_time = datetime.datetime.fromtimestamp(os.path.getmtime(dstFile)).astimezone() | |
# Download new file if there is an update | |
if url_date > file_time: | |
print("Updating ClassiCube...") | |
urllib.request.urlretrieve(url, dstFile) | |
os.utime(dstFile, (int(url_date.timestamp()), int(url_date.timestamp()))) | |
print("Update complete! Starting ClassiCube...") | |
# Check the number of arguments | |
if len(args) == 1: # 1 Argument, most likely an mc:// URL | |
match_URL = re.match(pattern_URL, args[0]) | |
if match_URL: | |
IP_Address, Port, Username, MPPass = match_URL.groups() | |
elif len(args) == 4: # 4 Arguments, most likely default run arguments | |
match_Username = re.search(pattern_Username, args[0]) | |
match_MPPass = re.search(pattern_MPPass, args[1]) | |
match_IP = re.search(pattern_IP, args[2]) | |
match_Port = re.search(pattern_Port, args[3]) | |
if match_Username and match_MPPass and match_IP and match_Port: | |
Username = match_Username.group() | |
MPPass = match_MPPass.group() | |
IP_Address = match_IP.group() | |
Port = match_Port.group() | |
# Run ClassiCube | |
try: | |
subprocess.Popen([r'C:\Program Files (x86)\Steam\steam.exe', '-applaunch', '1065710', Username, MPPass, IP_Address, Port]) | |
except NameError: | |
subprocess.Popen([r'C:\Program Files (x86)\Steam\steam.exe', '-applaunch', '1065710']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment