Refactor .desktop file deletion logic

This commit is contained in:
Roy
2026-06-10 03:47:48 -07:00
committed by GitHub
parent 5504eda0f6
commit 34e0bf1f87
+39 -17
View File
@@ -6770,30 +6770,52 @@ if removed_apps:
] ]
for game_name in removed_game_names: for game_name in removed_game_names:
base_game_name = game_name.split(' (')[0].strip().lower() base_game_name = game_name.split(' (')[0].strip()
desktop_filename = f"{base_game_name}.desktop" desktop_filename = f"{base_game_name}.desktop"
found_file = False found_file = False
print(f"Looking for .desktop file for: {game_name}") print(f"Looking for .desktop file for: {game_name}")
for directory in directories: for game_name in removed_game_names:
try: base_game_name = game_name.split(' (')[0].strip()
files_in_directory = os.listdir(directory)
except Exception as e:
continue
for f in files_in_directory: found_file = False
if f.lower() == desktop_filename: print(f"Looking for .desktop file for: {game_name}")
full_path = os.path.join(directory, f)
try: for directory in directories:
os.remove(full_path) try:
print(f"Deleted .desktop file for: {game_name} from {directory}") files_in_directory = os.listdir(directory)
except Exception as e: except Exception:
print(f"Failed to delete {full_path} due to: {e}") continue
for f in files_in_directory:
if not f.endswith(".desktop"):
continue continue
found_file = True
full_path = os.path.join(directory, f)
if not found_file: try:
print(f"No .desktop file found for: {game_name}") config = configparser.ConfigParser(interpolation=None)
config.read(full_path)
if "Desktop Entry" not in config:
continue
desktop_name = config["Desktop Entry"].get("Name", "").strip()
if desktop_name == base_game_name:
os.remove(full_path)
print(f"Deleted .desktop file for: {game_name} from {directory}")
found_file = True
break
except Exception as e:
print(f"Failed reading {full_path}: {e}")
continue
if found_file:
break
if not found_file:
print(f"No .desktop file found for: {game_name}")