mirror of
https://github.com/TheFunny/ArisuAutoSweeper
synced 2026-10-10 07:02:06 +00:00
fix: handle FileNotFoundError when accessing Windows registry keys
This commit is contained in:
@@ -5,11 +5,11 @@ import typing as t
|
|||||||
import winreg
|
import winreg
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
|
||||||
|
from module.device.platform.emulator_base import EmulatorBase, EmulatorInstanceBase, EmulatorManagerBase
|
||||||
# module/device/platform/emulator_base.py
|
# module/device/platform/emulator_base.py
|
||||||
# module/device/platform/emulator_windows.py
|
# module/device/platform/emulator_windows.py
|
||||||
# Will be used in Alas Easy Install, they shouldn't import any Alas modules.
|
# 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.utils import cached_property, iter_folder
|
||||||
from module.device.platform.emulator_base import EmulatorBase, EmulatorInstanceBase, EmulatorManagerBase
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@@ -330,8 +330,12 @@ class EmulatorManager(EmulatorManagerBase):
|
|||||||
path = r'Software\Microsoft\Windows\CurrentVersion\Explorer\UserAssist'
|
path = r'Software\Microsoft\Windows\CurrentVersion\Explorer\UserAssist'
|
||||||
# {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}\xxx.exe
|
# {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}\xxx.exe
|
||||||
regex_hash = re.compile(r'{.*}')
|
regex_hash = re.compile(r'{.*}')
|
||||||
with winreg.OpenKey(winreg.HKEY_CURRENT_USER, path) as reg:
|
try:
|
||||||
folders = list_key(reg)
|
with winreg.OpenKey(winreg.HKEY_CURRENT_USER, path) as reg:
|
||||||
|
folders = list_key(reg)
|
||||||
|
except FileNotFoundError:
|
||||||
|
return
|
||||||
|
|
||||||
for folder in folders:
|
for folder in folders:
|
||||||
try:
|
try:
|
||||||
with winreg.OpenKey(winreg.HKEY_CURRENT_USER, f'{path}\\{folder}\\Count') as reg:
|
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
|
str: Path to emulator executable, may contains duplicate values
|
||||||
"""
|
"""
|
||||||
path = r'Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache'
|
path = r'Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache'
|
||||||
with winreg.OpenKey(winreg.HKEY_CURRENT_USER, path) as reg:
|
try:
|
||||||
rows = list_reg(reg)
|
with winreg.OpenKey(winreg.HKEY_CURRENT_USER, path) as reg:
|
||||||
|
rows = list_reg(reg)
|
||||||
|
except FileNotFoundError:
|
||||||
|
return
|
||||||
|
|
||||||
regex = re.compile(r'(^.*\.exe)\.')
|
regex = re.compile(r'(^.*\.exe)\.')
|
||||||
for row in rows:
|
for row in rows:
|
||||||
@@ -425,24 +432,28 @@ class EmulatorManager(EmulatorManagerBase):
|
|||||||
'MEmu',
|
'MEmu',
|
||||||
]
|
]
|
||||||
for path in known_uninstall_registry_path:
|
for path in known_uninstall_registry_path:
|
||||||
with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, path) as reg:
|
try:
|
||||||
for software in list_key(reg):
|
with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, path) as reg:
|
||||||
if software not in known_emulator_registry_name:
|
software_list = list_key(reg)
|
||||||
continue
|
except FileNotFoundError:
|
||||||
|
continue
|
||||||
|
for software in software_list:
|
||||||
|
if software not in known_emulator_registry_name:
|
||||||
|
continue
|
||||||
|
try:
|
||||||
with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, f'{path}\\{software}') as software_reg:
|
with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, f'{path}\\{software}') as software_reg:
|
||||||
try:
|
uninstall = winreg.QueryValueEx(software_reg, 'UninstallString')[0]
|
||||||
uninstall = winreg.QueryValueEx(software_reg, 'UninstallString')[0]
|
except FileNotFoundError:
|
||||||
except FileNotFoundError:
|
continue
|
||||||
continue
|
if not uninstall:
|
||||||
if not uninstall:
|
continue
|
||||||
continue
|
# UninstallString is like:
|
||||||
# UninstallString is like:
|
# C:\Program Files\BlueStacks_nxt\BlueStacksUninstaller.exe -tmp
|
||||||
# C:\Program Files\BlueStacks_nxt\BlueStacksUninstaller.exe -tmp
|
# "E:\ProgramFiles\Microvirt\MEmu\uninstall\uninstall.exe" -u
|
||||||
# "E:\ProgramFiles\Microvirt\MEmu\uninstall\uninstall.exe" -u
|
# Extract path in ""
|
||||||
# Extract path in ""
|
res = re.search('"(.*?)"', uninstall)
|
||||||
res = re.search('"(.*?)"', uninstall)
|
uninstall = res.group(1) if res else uninstall
|
||||||
uninstall = res.group(1) if res else uninstall
|
yield uninstall
|
||||||
yield uninstall
|
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def all_emulators(self) -> t.List[Emulator]:
|
def all_emulators(self) -> t.List[Emulator]:
|
||||||
|
|||||||
Reference in New Issue
Block a user