Reviewed-on: #51 Reviewed-by: Corentin <solois.corentin@gmail.com> Co-authored-by: Tipragot <contact@tipragot.fr> Co-committed-by: Tipragot <contact@tipragot.fr>
46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
from pathlib import Path
|
|
import subprocess as sp
|
|
from zipfile import ZipFile
|
|
import requests as rq
|
|
import os, sys, shutil
|
|
|
|
|
|
project_folder = Path.home() / ".ponguito"
|
|
project_folder.mkdir(exist_ok=True, parents=True)
|
|
os.chdir(project_folder)
|
|
|
|
# Récupération de la version locale
|
|
try:
|
|
with open("version.txt", "r") as f:
|
|
version = f.read()
|
|
except:
|
|
version = "0.0.0"
|
|
|
|
# Récupération de la version du serveur
|
|
try:
|
|
response = rq.get(
|
|
"https://git.tipragot.fr/raphael/ponguito/raw/branch/main/version.txt"
|
|
)
|
|
server_version = response.text
|
|
except:
|
|
print("Impossible de se connecter au serveur")
|
|
server_version = version
|
|
|
|
# Mise à jour de la version locale
|
|
if server_version != version:
|
|
response = rq.get("https://git.tipragot.fr/raphael/ponguito/archive/main.zip")
|
|
if response.status_code == 200:
|
|
with open("main.zip", "wb") as f:
|
|
f.write(response.content)
|
|
ZipFile("main.zip").extractall()
|
|
os.remove("main.zip")
|
|
if os.path.isdir("game"):
|
|
shutil.rmtree("game")
|
|
os.rename("ponguito", "game")
|
|
os.remove(__file__)
|
|
os.rename("game/launch.py", __file__)
|
|
|
|
# Lancement du jeu
|
|
os.chdir(project_folder / "game")
|
|
sp.call([sys.executable, f"src/main.py"])
|