First push
This commit is contained in:
commit
9e59d2a35e
|
@ -0,0 +1,55 @@
|
|||
import os
|
||||
import requests
|
||||
import zipfile
|
||||
from pathlib import Path
|
||||
|
||||
hl_path = Path.home() / ".steam/steam/steamapps/common/Half-Life"
|
||||
spacelife_path = hl_path / "SpaceLife"
|
||||
version_file = hl_path / "SpaceLifeVersion.txt"
|
||||
mod_url = "https://deadzone.tf/SpaceLife.zip"
|
||||
version_url = "https://deadzone.tf/SpaceLifeVersion.txt"
|
||||
mod_zip_file = hl_path / "SpaceLife.zip"
|
||||
|
||||
spacelife_path.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
def download_file(url, dest):
|
||||
response = requests.get(url, stream=True)
|
||||
with open(dest, 'wb') as file:
|
||||
for chunk in response.iter_content(chunk_size=8192):
|
||||
if chunk:
|
||||
file.write(chunk)
|
||||
|
||||
def is_new_version_available(local_version_path, server_version_url):
|
||||
download_file(server_version_url, local_version_path.with_suffix('.tmp'))
|
||||
with open(local_version_path.with_suffix('.tmp'), 'r') as server_version_file:
|
||||
server_version = server_version_file.read().strip()
|
||||
|
||||
if not local_version_path.exists():
|
||||
local_version_path.with_suffix('.tmp').replace(local_version_path)
|
||||
return True
|
||||
|
||||
with open(local_version_path, 'r') as local_version_file:
|
||||
local_version = local_version_file.read().strip()
|
||||
|
||||
if local_version != server_version:
|
||||
local_version_path.with_suffix('.tmp').replace(local_version_path)
|
||||
return True
|
||||
else:
|
||||
local_version_path.with_suffix('.tmp').unlink()
|
||||
return False
|
||||
|
||||
def unzip_file(zip_path, extract_to_path):
|
||||
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
|
||||
zip_ref.extractall(extract_to_path)
|
||||
|
||||
if is_new_version_available(version_file, version_url):
|
||||
print("New version available, downloading...")
|
||||
download_file(mod_url, mod_zip_file)
|
||||
print(f"Unzipping the mod into {spacelife_path}...")
|
||||
unzip_file(mod_zip_file, spacelife_path)
|
||||
print("Update complete!")
|
||||
else:
|
||||
print("No update needed. You have the latest version.")
|
||||
|
||||
if mod_zip_file.exists():
|
||||
mod_zip_file.unlink()
|
Loading…
Reference in New Issue