()
| 37 | |
| 38 | |
| 39 | def build_application_index(): |
| 40 | apps = {} |
| 41 | for root in safe_search_dirs(): |
| 42 | try: |
| 43 | candidates = list(root.rglob("*.lnk")) |
| 44 | if root.name.lower() in {"program files", "program files (x86)", "programs"}: |
| 45 | candidates.extend(root.glob("*/*.exe")) |
| 46 | candidates.extend(root.glob("*.exe")) |
| 47 | except OSError: |
| 48 | continue |
| 49 | for path in candidates: |
| 50 | if not is_safe_app_path(path): |
| 51 | continue |
| 52 | name = app_name_from_path(path) |
| 53 | key = normalize_text(name) |
| 54 | apps.setdefault(key, {"name": name, "path": str(path)}) |
| 55 | sorted_apps = sorted(apps.values(), key=lambda item: item["name"].lower()) |
| 56 | APP_INDEX_FILE.write_text(json.dumps(sorted_apps, ensure_ascii=False, indent=2), encoding="utf-8") |
| 57 | return sorted_apps |
| 58 | |
| 59 | |
| 60 | def load_application_index(refresh=False): |
no test coverage detected