Auto-detect Bandizip install dir via registry
- find_bandizip_dir(): checks HKLM\SOFTWARE\Bandizip\ProgramFolder, uninstall info, and common paths - Support BANDIZIP_DIR env var override - Remove hardcoded path D:\Apps\Bandizip
This commit is contained in:
+50
-7
@@ -27,13 +27,53 @@ import shutil
|
||||
import winreg
|
||||
|
||||
# ============ 配置 ============
|
||||
BANDIZIP_DIR = r'D:\Apps\Bandizip'
|
||||
EXE_PATH = os.path.join(BANDIZIP_DIR, 'Bandizip.exe')
|
||||
BACKUP_PATH = EXE_PATH + '.bak'
|
||||
REG_KEY = r'SOFTWARE\Bandizip'
|
||||
REG_VALUE = 'Edition'
|
||||
REG_DATA = 'PRO'
|
||||
|
||||
|
||||
def find_bandizip_dir():
|
||||
"""自动查找 Bandizip 安装目录"""
|
||||
# 方法1: 注册表 HKLM\SOFTWARE\Bandizip\ProgramFolder
|
||||
try:
|
||||
with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, REG_KEY) as key:
|
||||
path, _ = winreg.QueryValueEx(key, 'ProgramFolder')
|
||||
if path and os.path.exists(os.path.join(path, 'Bandizip.exe')):
|
||||
return path.rstrip('\\')
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 方法2: 注册表卸载信息
|
||||
for subkey in [r'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Bandizip',
|
||||
r'SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Bandizip']:
|
||||
try:
|
||||
with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, subkey) as key:
|
||||
loc, _ = winreg.QueryValueEx(key, 'InstallLocation')
|
||||
if loc and os.path.exists(os.path.join(loc, 'Bandizip.exe')):
|
||||
return loc.rstrip('\\')
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 方法3: 常见安装路径
|
||||
common_paths = [
|
||||
os.path.join(os.environ.get('ProgramFiles', r'C:\Program Files'), 'Bandizip'),
|
||||
os.path.join(os.environ.get('ProgramFiles(x86)', r'C:\Program Files (x86)'), 'Bandizip'),
|
||||
os.path.join(os.environ.get('LOCALAPPDATA', ''), 'Programs', 'Bandizip'),
|
||||
r'D:\Apps\Bandizip',
|
||||
r'D:\Program Files\Bandizip',
|
||||
]
|
||||
for p in common_paths:
|
||||
if os.path.exists(os.path.join(p, 'Bandizip.exe')):
|
||||
return p
|
||||
|
||||
return None
|
||||
|
||||
|
||||
# 启动时自动检测(可通过环境变量 BANDIZIP_DIR 手动覆盖)
|
||||
BANDIZIP_DIR = os.environ.get('BANDIZIP_DIR') or find_bandizip_dir()
|
||||
EXE_PATH = os.path.join(BANDIZIP_DIR, 'Bandizip.exe') if BANDIZIP_DIR else None
|
||||
BACKUP_PATH = (EXE_PATH + '.bak') if EXE_PATH else None
|
||||
|
||||
# Patch 定义: (文件偏移, 原始字节, 补丁字节, 描述)
|
||||
PATCHES = [
|
||||
(0xD0CF0, b'\x48\x89\x5C\x24\x08\x55', b'\xB0\x01\xC3',
|
||||
@@ -176,10 +216,13 @@ def check_status():
|
||||
print('=' * 50)
|
||||
|
||||
# 文件存在
|
||||
if os.path.exists(EXE_PATH):
|
||||
if EXE_PATH and os.path.exists(EXE_PATH):
|
||||
print(' [OK] Bandizip.exe found: ' + EXE_PATH)
|
||||
else:
|
||||
print(' [!] Bandizip.exe not found: ' + EXE_PATH)
|
||||
print(' [!] Bandizip.exe not found!')
|
||||
print(' [!] Tried registry, uninstall info, and common paths.')
|
||||
print(' [!] Please pass install dir manually:')
|
||||
print(' [!] set BANDIZIP_DIR=C:\\path\\to\\Bandizip')
|
||||
return
|
||||
|
||||
# 备份状态
|
||||
@@ -231,8 +274,8 @@ def do_patch():
|
||||
print(' Bandizip Patcher - Apply')
|
||||
print('=' * 50)
|
||||
|
||||
if not os.path.exists(EXE_PATH):
|
||||
print(' [!] Bandizip.exe not found: ' + EXE_PATH)
|
||||
if not EXE_PATH or not os.path.exists(EXE_PATH):
|
||||
print(' [!] Bandizip.exe not found!')
|
||||
return False
|
||||
|
||||
if is_bandizip_running():
|
||||
|
||||
Reference in New Issue
Block a user