Correction du launcher retrobat, et ajout de la vitesse de téléchargement

This commit is contained in:
skymike03
2025-07-31 16:19:36 +02:00
parent bd3aa17d3b
commit c16983cc8c
6 changed files with 172 additions and 15 deletions

View File

@@ -779,6 +779,14 @@ async def main():
await asyncio.sleep(0.01)
pygame.mixer.music.stop()
process_name = "emulatorLauncher.exe"
result = os.system(f"taskkill /f /im {process_name}")
if result == 0:
logger.debug(f"Quitté avec succès: {process_name}")
else:
logger.debug("Error en essayant de quitter emulatorlauncher.")
pygame.quit()
logger.debug("Application terminée")

View File

@@ -663,6 +663,25 @@ def draw_history_list(screen):
history = config.history if hasattr(config, 'history') else load_history()
history_count = len(history)
# Cherche une entrée en cours de téléchargement pour afficher la vitesse
speed_str = ""
for entry in history:
if entry.get("status") in ["Téléchargement", "downloading"]:
speed = entry.get("speed", 0.0)
if speed and speed > 0:
speed_str = f" - Téléchargement : {speed:.2f} Mo/s"
break
screen.blit(OVERLAY, (0, 0))
title_text = _("history_title").format(history_count) + speed_str
title_surface = config.title_font.render(title_text, True, THEME_COLORS["text"])
title_rect = title_surface.get_rect(center=(config.screen_width // 2, title_surface.get_height() // 2 + 20))
title_rect_inflated = title_rect.inflate(60, 30)
title_rect_inflated.topleft = ((config.screen_width - title_rect_inflated.width) // 2, 10)
pygame.draw.rect(screen, THEME_COLORS["button_idle"], title_rect_inflated, border_radius=12) # fond opaque
pygame.draw.rect(screen, THEME_COLORS["border"], title_rect_inflated, 2, border_radius=12)
screen.blit(title_surface, title_rect)
# Define column widths as percentages of available space
column_width_percentages = {
"platform": 0.25, # platform column
@@ -682,6 +701,17 @@ def draw_history_list(screen):
extra_margin_bottom = 80
title_height = config.title_font.get_height() + 20
speed = 0.0
if history and history[config.current_history_item].get("status") in ["Téléchargement", "downloading"]:
speed = history[config.current_history_item].get("speed", 0.0)
if speed > 0:
speed_str = f"{speed:.2f} Mo/s"
title_text = _("history_title").format(history_count) + f" - Téléchargement : {speed_str}"
else:
title_text = _("history_title").format(history_count)
title_surface = config.title_font.render(title_text, True, THEME_COLORS["text"])
if not history:
logger.debug("Aucun historique disponible")
message = _("history_empty")
@@ -717,16 +747,6 @@ def draw_history_list(screen):
elif config.current_history_item >= config.history_scroll_offset + items_per_page:
config.history_scroll_offset = config.current_history_item - items_per_page + 1
screen.blit(OVERLAY, (0, 0))
title_text = _("history_title").format(history_count)
title_surface = config.title_font.render(title_text, True, THEME_COLORS["text"])
title_rect = title_surface.get_rect(center=(config.screen_width // 2, title_surface.get_height() // 2 + 20))
title_rect_inflated = title_rect.inflate(60, 30)
title_rect_inflated.topleft = ((config.screen_width - title_rect_inflated.width) // 2, 10)
pygame.draw.rect(screen, THEME_COLORS["button_idle"], title_rect_inflated, border_radius=12)
pygame.draw.rect(screen, THEME_COLORS["border"], title_rect_inflated, 2, border_radius=12)
screen.blit(title_surface, title_rect)
pygame.draw.rect(screen, THEME_COLORS["button_idle"], (rect_x, rect_y, rect_width, rect_height), border_radius=12)
pygame.draw.rect(screen, THEME_COLORS["border"], (rect_x, rect_y, rect_width, rect_height), 2, border_radius=12)

View File

@@ -223,6 +223,7 @@ async def download_rom(url, platform, game_name, is_zip_non_supported=False, tas
downloaded = 0
chunk_size = 4096
last_update_time = time.time()
last_downloaded = 0
update_interval = 0.1 # Mettre à jour toutes les 0,1 secondes
with open(dest_path, 'wb') as f:
for chunk in response.iter_content(chunk_size=chunk_size):
@@ -232,8 +233,13 @@ async def download_rom(url, platform, game_name, is_zip_non_supported=False, tas
downloaded += size_received
current_time = time.time()
if current_time - last_update_time >= update_interval:
progress_queues[task_id].put((task_id, downloaded, total_size))
# Calcul de la vitesse en Mo/s
delta = downloaded - last_downloaded
speed = delta / (current_time - last_update_time) / (1024 * 1024)
last_downloaded = downloaded
last_update_time = current_time
progress_queues[task_id].put((task_id, downloaded, total_size, speed))
os.chmod(dest_path, 0o644)
logger.debug(f"Téléchargement terminé: {dest_path}")
@@ -321,10 +327,14 @@ async def download_rom(url, platform, game_name, is_zip_non_supported=False, tas
logger.debug(f"Final update in history: status={entry['status']}, progress={entry['progress']}%, message={message}, task_id={task_id}")
break
else:
downloaded, total_size = data[1], data[2]
if len(data) >= 4:
downloaded, total_size, speed = data[1], data[2], data[3]
else:
downloaded, total_size = data[1], data[2]
speed = 0.0
progress_percent = int(downloaded / total_size * 100) if total_size > 0 else 0
progress_percent = max(0, min(100, progress_percent))
if isinstance(config.history, list):
for entry in config.history:
if "url" in entry and entry["url"] == url and entry["status"] in ["downloading", "Téléchargement"]:
@@ -332,8 +342,9 @@ async def download_rom(url, platform, game_name, is_zip_non_supported=False, tas
entry["status"] = "Téléchargement"
entry["downloaded_size"] = downloaded
entry["total_size"] = total_size
entry["speed"] = speed # Ajout de la vitesse
config.needs_redraw = True
break
break
await asyncio.sleep(0.1)
except Exception as e:
logger.error(f"Erreur mise à jour progression: {str(e)}")