Enhance network connectivity tests with comprehensive checks for ping, DNS resolution, and HTTP connection; update validation button text in multiple languages to "OK".
This commit is contained in:
@@ -1,11 +1,19 @@
|
|||||||
import pygame # type: ignore
|
import pygame # type: ignore
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
import logging
|
import logging
|
||||||
|
import platform
|
||||||
|
from rgsx_settings import load_rgsx_settings, save_rgsx_settings, migrate_old_settings
|
||||||
|
|
||||||
# Version actuelle de l'application
|
# Version actuelle de l'application
|
||||||
app_version = "1.9.9.0"
|
app_version = "1.9.9.0"
|
||||||
|
|
||||||
|
def get_operating_system():
|
||||||
|
"""Renvoie le nom du système d'exploitation."""
|
||||||
|
return platform.system()
|
||||||
|
#log dans la console le système d'exploitation
|
||||||
|
print(f"Système d'exploitation : {get_operating_system()}")
|
||||||
|
|
||||||
|
|
||||||
def get_application_root():
|
def get_application_root():
|
||||||
"""Détermine le dossier de l'application de manière portable."""
|
"""Détermine le dossier de l'application de manière portable."""
|
||||||
try:
|
try:
|
||||||
@@ -13,38 +21,47 @@ def get_application_root():
|
|||||||
current_file = os.path.abspath(__file__)
|
current_file = os.path.abspath(__file__)
|
||||||
# Remonter au dossier parent de config.py (par exemple, dossier de l'application)
|
# Remonter au dossier parent de config.py (par exemple, dossier de l'application)
|
||||||
app_root = os.path.dirname(os.path.dirname(current_file))
|
app_root = os.path.dirname(os.path.dirname(current_file))
|
||||||
|
print(f"Dossier de l'application : {app_root}")
|
||||||
return app_root
|
return app_root
|
||||||
|
|
||||||
except NameError:
|
except NameError:
|
||||||
# Si __file__ n'est pas défini (par exemple, exécution dans un REPL)
|
# Si __file__ n'est pas défini (par exemple, exécution dans un REPL)
|
||||||
return os.path.abspath(os.getcwd())
|
return os.path.abspath(os.getcwd())
|
||||||
|
|
||||||
def get_system_root():
|
def get_system_root():
|
||||||
|
OPERATING_SYSTEM = get_operating_system()
|
||||||
"""Détermine le dossier racine du système de fichiers (par exemple, /userdata ou C:\\)."""
|
"""Détermine le dossier racine du système de fichiers (par exemple, /userdata ou C:\\)."""
|
||||||
try:
|
try:
|
||||||
if sys.platform.startswith("win"):
|
if OPERATING_SYSTEM == "Windows":
|
||||||
# Sur Windows, extraire la lettre de disque
|
# Sur Windows, extraire la lettre de disque
|
||||||
current_path = os.path.abspath(__file__)
|
current_path = os.path.abspath(__file__)
|
||||||
drive, _ = os.path.splitdrive(current_path)
|
drive, _ = os.path.splitdrive(current_path)
|
||||||
system_root = drive + os.sep
|
system_root = drive + os.sep
|
||||||
|
print(f"Dossier racine du système : {system_root}")
|
||||||
return system_root
|
return system_root
|
||||||
else:
|
elif OPERATING_SYSTEM == "Linux":
|
||||||
# Sur Linux/Batocera, remonter jusqu'à atteindre /userdata ou /
|
# tester si c'est batocera :
|
||||||
current_path = os.path.abspath(__file__)
|
if os.path.exists("/usr/share/batocera"):
|
||||||
current_dir = current_path
|
OPERATING_SYSTEM = "Batocera"
|
||||||
while current_dir != os.path.dirname(current_dir): # Tant qu'on peut remonter
|
#remonter jusqu'à atteindre /userdata
|
||||||
parent_dir = os.path.dirname(current_dir)
|
current_path = os.path.abspath(__file__)
|
||||||
if os.path.basename(parent_dir) == "userdata": # Vérifier si le parent est userdata
|
current_dir = current_path
|
||||||
system_root = parent_dir
|
while current_dir != os.path.dirname(current_dir): # Tant qu'on peut remonter
|
||||||
return system_root
|
parent_dir = os.path.dirname(current_dir)
|
||||||
current_dir = parent_dir
|
if os.path.basename(parent_dir) == "userdata": # Vérifier si le parent est userdata
|
||||||
# Si userdata n'est pas trouvé, retourner /
|
system_root = parent_dir
|
||||||
return "/"
|
print(f"Dossier racine du système : {system_root}")
|
||||||
|
return system_root
|
||||||
|
current_dir = parent_dir
|
||||||
|
# Si userdata n'est pas trouvé, retourner /
|
||||||
|
return "/"
|
||||||
|
else:
|
||||||
|
return "/"
|
||||||
except NameError:
|
except NameError:
|
||||||
# Si __file__ n'est pas défini, utiliser le répertoire de travail actuel
|
|
||||||
return "/" if not sys.platform.startswith("win") else os.path.splitdrive(os.getcwd())[0] + os.sep
|
return "/" if not OPERATING_SYSTEM == "Windows" else os.path.splitdrive(os.getcwd())[0] + os.sep
|
||||||
|
|
||||||
# Chemins de base
|
# Chemins de base
|
||||||
|
|
||||||
SYSTEM_FOLDER = get_system_root()
|
SYSTEM_FOLDER = get_system_root()
|
||||||
APP_FOLDER = os.path.join(get_application_root(), "RGSX")
|
APP_FOLDER = os.path.join(get_application_root(), "RGSX")
|
||||||
ROMS_FOLDER = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(APP_FOLDER))), "roms")
|
ROMS_FOLDER = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(APP_FOLDER))), "roms")
|
||||||
@@ -86,8 +103,7 @@ XDVDFS_LINUX = os.path.join(APP_FOLDER,"assets", "xdvdfs")
|
|||||||
unrar_download_exe = os.path.join(OTA_SERVER_URL, "unrar.exe")
|
unrar_download_exe = os.path.join(OTA_SERVER_URL, "unrar.exe")
|
||||||
xdvdfs_download_exe = os.path.join(OTA_SERVER_URL, "xdvdfs.exe")
|
xdvdfs_download_exe = os.path.join(OTA_SERVER_URL, "xdvdfs.exe")
|
||||||
|
|
||||||
# Import des fonctions de gestion des paramètres RGSX
|
|
||||||
from rgsx_settings import load_rgsx_settings, save_rgsx_settings, migrate_old_settings
|
|
||||||
xdvdfs_download_linux = os.path.join(OTA_SERVER_URL, "xdvdfs")
|
xdvdfs_download_linux = os.path.join(OTA_SERVER_URL, "xdvdfs")
|
||||||
|
|
||||||
# Constantes pour la répétition automatique dans pause_menu
|
# Constantes pour la répétition automatique dans pause_menu
|
||||||
|
|||||||
@@ -88,7 +88,7 @@
|
|||||||
|
|
||||||
"button_yes": "Ja",
|
"button_yes": "Ja",
|
||||||
"button_no": "Nein",
|
"button_no": "Nein",
|
||||||
"button_validate": "Bestätigen",
|
"button_validate": "OK",
|
||||||
|
|
||||||
"controls_hold_message": "3 Sekunden halten für: '{0}'",
|
"controls_hold_message": "3 Sekunden halten für: '{0}'",
|
||||||
"controls_skip_message": "Drücke Esc, um zu überspringen (nur PC)",
|
"controls_skip_message": "Drücke Esc, um zu überspringen (nur PC)",
|
||||||
|
|||||||
@@ -88,7 +88,7 @@
|
|||||||
|
|
||||||
"button_yes": "Yes",
|
"button_yes": "Yes",
|
||||||
"button_no": "No",
|
"button_no": "No",
|
||||||
"button_validate": "Validate",
|
"button_validate": "OK",
|
||||||
|
|
||||||
"controls_hold_message": "Hold for 3s for: '{0}'",
|
"controls_hold_message": "Hold for 3s for: '{0}'",
|
||||||
"controls_skip_message": "Press Esc to skip (PC only)",
|
"controls_skip_message": "Press Esc to skip (PC only)",
|
||||||
|
|||||||
@@ -89,7 +89,7 @@
|
|||||||
|
|
||||||
"button_yes": "Sí",
|
"button_yes": "Sí",
|
||||||
"button_no": "No",
|
"button_no": "No",
|
||||||
"button_validate": "Validar",
|
"button_validate": "OK",
|
||||||
|
|
||||||
"controls_hold_message": "Mantén presionado durante 3s para: '{0}'",
|
"controls_hold_message": "Mantén presionado durante 3s para: '{0}'",
|
||||||
"controls_skip_message": "Presiona Esc para omitir (solo PC)",
|
"controls_skip_message": "Presiona Esc para omitir (solo PC)",
|
||||||
|
|||||||
@@ -85,7 +85,7 @@
|
|||||||
|
|
||||||
"button_yes": "Oui",
|
"button_yes": "Oui",
|
||||||
"button_no": "Non",
|
"button_no": "Non",
|
||||||
"button_validate": "Valider",
|
"button_validate": "OK",
|
||||||
|
|
||||||
"controls_hold_message": "Maintenez pendant 3s pour : '{0}'",
|
"controls_hold_message": "Maintenez pendant 3s pour : '{0}'",
|
||||||
"controls_skip_message": "Appuyez sur Échap pour passer(Pc only)",
|
"controls_skip_message": "Appuyez sur Échap pour passer(Pc only)",
|
||||||
|
|||||||
@@ -25,29 +25,102 @@ cache = {}
|
|||||||
CACHE_TTL = 3600 # 1 heure
|
CACHE_TTL = 3600 # 1 heure
|
||||||
|
|
||||||
def test_internet():
|
def test_internet():
|
||||||
"""Teste la connexion Internet de manière portable pour Windows et Linux/Batocera."""
|
"""Teste la connexion Internet de manière complète et portable pour Windows et Linux/Batocera."""
|
||||||
logger.debug("Test de connexion Internet")
|
logger.debug("=== Début test de connexion Internet complet ===")
|
||||||
|
|
||||||
# Choisir l'option ping en fonction de la plateforme
|
# Test 1: Ping vers serveurs DNS publics
|
||||||
ping_option = '-n' if sys.platform.startswith("win") else '-c'
|
ping_option = '-n' if sys.platform.startswith("win") else '-c'
|
||||||
logger.debug(f"Utilisation de ping avec option {ping_option}")
|
dns_servers = ['8.8.8.8', '1.1.1.1', '208.67.222.222'] # Google, Cloudflare, OpenDNS
|
||||||
|
|
||||||
|
ping_success = False
|
||||||
|
for dns_server in dns_servers:
|
||||||
|
logger.debug(f"Test ping vers {dns_server} avec option {ping_option}")
|
||||||
|
try:
|
||||||
|
result = subprocess.run(
|
||||||
|
['ping', ping_option, '2', dns_server],
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
timeout=8
|
||||||
|
)
|
||||||
|
if result.returncode == 0:
|
||||||
|
logger.debug(f"[OK] Ping vers {dns_server} réussi")
|
||||||
|
ping_success = True
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
logger.debug(f"[FAIL] Ping vers {dns_server} échoué (code: {result.returncode})")
|
||||||
|
if result.stderr:
|
||||||
|
logger.debug(f"Erreur ping: {result.stderr.strip()}")
|
||||||
|
except subprocess.TimeoutExpired:
|
||||||
|
logger.debug(f"[FAIL] Timeout ping vers {dns_server}")
|
||||||
|
except Exception as e:
|
||||||
|
logger.debug(f"[FAIL] Exception ping vers {dns_server}: {str(e)}")
|
||||||
|
|
||||||
|
# Test 2: Tentative de résolution DNS
|
||||||
|
dns_success = False
|
||||||
try:
|
try:
|
||||||
result = subprocess.run(
|
import socket
|
||||||
['ping', ping_option, '4', '8.8.8.8'],
|
logger.debug("Test de résolution DNS pour google.com")
|
||||||
capture_output=True,
|
socket.gethostbyname('google.com')
|
||||||
text=True,
|
logger.debug("[OK] Résolution DNS réussie")
|
||||||
timeout=5
|
dns_success = True
|
||||||
)
|
except socket.gaierror as e:
|
||||||
if result.returncode == 0:
|
logger.debug(f"[FAIL] Erreur résolution DNS: {str(e)}")
|
||||||
logger.debug("Connexion Internet OK (ping)")
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
logger.debug(f"Échec ping 8.8.8.8, code retour: {result.returncode}")
|
|
||||||
return False
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.debug(f"Erreur test Internet (ping): {str(e)}")
|
logger.debug(f"[FAIL] Exception résolution DNS: {str(e)}")
|
||||||
|
|
||||||
|
# Test 3: Tentative de connexion HTTP
|
||||||
|
http_success = False
|
||||||
|
test_urls = [
|
||||||
|
'http://www.google.com',
|
||||||
|
'http://www.cloudflare.com',
|
||||||
|
'https://httpbin.org/get'
|
||||||
|
]
|
||||||
|
|
||||||
|
for test_url in test_urls:
|
||||||
|
logger.debug(f"Test connexion HTTP vers {test_url}")
|
||||||
|
try:
|
||||||
|
response = requests.get(test_url, timeout=5, allow_redirects=True)
|
||||||
|
if response.status_code == 200:
|
||||||
|
logger.debug(f"[OK] Connexion HTTP vers {test_url} réussie (code: {response.status_code})")
|
||||||
|
http_success = True
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
logger.debug(f"[FAIL] Connexion HTTP vers {test_url} échouée (code: {response.status_code})")
|
||||||
|
except requests.exceptions.Timeout:
|
||||||
|
logger.debug(f"[FAIL] Timeout connexion HTTP vers {test_url}")
|
||||||
|
except requests.exceptions.ConnectionError as e:
|
||||||
|
logger.debug(f"[FAIL] Erreur connexion HTTP vers {test_url}: {str(e)}")
|
||||||
|
except Exception as e:
|
||||||
|
logger.debug(f"[FAIL] Exception connexion HTTP vers {test_url}: {str(e)}")
|
||||||
|
|
||||||
|
# Analyse des résultats
|
||||||
|
total_tests = 3
|
||||||
|
passed_tests = sum([ping_success, dns_success, http_success])
|
||||||
|
|
||||||
|
logger.debug(f"=== Résultats test Internet: {passed_tests}/{total_tests} tests réussis ===")
|
||||||
|
logger.debug(f"Ping: {'[OK]' if ping_success else '[FAIL]'}")
|
||||||
|
logger.debug(f"DNS: {'[OK]' if dns_success else '[FAIL]'}")
|
||||||
|
logger.debug(f"HTTP: {'[OK]' if http_success else '[FAIL]'}")
|
||||||
|
|
||||||
|
# Diagnostic et conseils
|
||||||
|
if passed_tests == 0:
|
||||||
|
logger.error("Aucune connexion Internet détectée. Vérifiez:")
|
||||||
|
logger.error("- Câble réseau ou WiFi connecté")
|
||||||
|
logger.error("- Configuration proxy/firewall")
|
||||||
|
logger.error("- Paramètres réseau système")
|
||||||
return False
|
return False
|
||||||
|
elif passed_tests < total_tests:
|
||||||
|
logger.warning(f"Connexion Internet partielle ({passed_tests}/{total_tests})")
|
||||||
|
if not ping_success:
|
||||||
|
logger.warning("- Ping échoué: possible blocage ICMP par firewall")
|
||||||
|
if not dns_success:
|
||||||
|
logger.warning("- DNS échoué: problème serveurs DNS")
|
||||||
|
if not http_success:
|
||||||
|
logger.warning("- HTTP échoué: possible blocage proxy/firewall")
|
||||||
|
return True # Connexion partielle acceptable
|
||||||
|
else:
|
||||||
|
logger.debug("[OK] Connexion Internet complète et fonctionnelle")
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def check_for_updates():
|
async def check_for_updates():
|
||||||
|
|||||||
Reference in New Issue
Block a user