fix: handle FileNotFoundError when accessing Windows registry keys

This commit is contained in:
2026-07-05 18:15:19 +08:00
parent 11f5f1dd64
commit 0590eebd44
+14 -3
View File
@@ -5,11 +5,11 @@ import typing as t
import winreg
from dataclasses import dataclass
from module.device.platform.emulator_base import EmulatorBase, EmulatorInstanceBase, EmulatorManagerBase
# module/device/platform/emulator_base.py
# module/device/platform/emulator_windows.py
# Will be used in Alas Easy Install, they shouldn't import any Alas modules.
from module.device.platform.utils import cached_property, iter_folder
from module.device.platform.emulator_base import EmulatorBase, EmulatorInstanceBase, EmulatorManagerBase
@dataclass
@@ -330,8 +330,12 @@ class EmulatorManager(EmulatorManagerBase):
path = r'Software\Microsoft\Windows\CurrentVersion\Explorer\UserAssist'
# {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}\xxx.exe
regex_hash = re.compile(r'{.*}')
try:
with winreg.OpenKey(winreg.HKEY_CURRENT_USER, path) as reg:
folders = list_key(reg)
except FileNotFoundError:
return
for folder in folders:
try:
with winreg.OpenKey(winreg.HKEY_CURRENT_USER, f'{path}\\{folder}\\Count') as reg:
@@ -358,8 +362,11 @@ class EmulatorManager(EmulatorManagerBase):
str: Path to emulator executable, may contains duplicate values
"""
path = r'Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache'
try:
with winreg.OpenKey(winreg.HKEY_CURRENT_USER, path) as reg:
rows = list_reg(reg)
except FileNotFoundError:
return
regex = re.compile(r'(^.*\.exe)\.')
for row in rows:
@@ -425,12 +432,16 @@ class EmulatorManager(EmulatorManagerBase):
'MEmu',
]
for path in known_uninstall_registry_path:
try:
with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, path) as reg:
for software in list_key(reg):
software_list = list_key(reg)
except FileNotFoundError:
continue
for software in software_list:
if software not in known_emulator_registry_name:
continue
with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, f'{path}\\{software}') as software_reg:
try:
with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, f'{path}\\{software}') as software_reg:
uninstall = winreg.QueryValueEx(software_reg, 'UninstallString')[0]
except FileNotFoundError:
continue