优化Windows下Cloudflare IP优选插件

This commit is contained in:
mayun110 2023-09-19 13:39:41 +08:00
parent bd6805be58
commit 598ab23a2c

View File

@ -274,7 +274,7 @@ class CloudflareSpeedTest(_PluginBase):
if self._re_install:
install_flag = True
if SystemUtils.is_windows():
os.system(f'rd /s /q {self._cf_path}')
os.system(f'rd /s /q \"{self._cf_path}\"')
else:
os.system(f'rm -rf {self._cf_path}')
logger.info(f'删除CloudflareSpeedTest目录 {self._cf_path},开始重新安装')
@ -363,6 +363,7 @@ class CloudflareSpeedTest(_PluginBase):
# 判断是否下载好安装包
if Path(f'{self._cf_path}/{cf_file_name}').exists():
try:
if SystemUtils.is_windows():
with zipfile.ZipFile(f'{self._cf_path}/{cf_file_name}', 'r') as zip_ref:
# 解压ZIP文件中的所有文件到指定目录
@ -372,9 +373,8 @@ class CloudflareSpeedTest(_PluginBase):
return True, release_version
else:
logger.error(f"CloudflareSpeedTest安装失败请检查")
os.removedirs(self._cf_path)
os.system(f'rd /s /q \"{self._cf_path}\"')
return False, None
try:
# 解压
os.system(f'{unzip_command}')
# 删除压缩包
@ -388,11 +388,15 @@ class CloudflareSpeedTest(_PluginBase):
return False, None
except Exception as err:
# 如果升级失败但是有可执行文件CloudflareST则可继续运行反之停止
if Path(f'{self._cf_path}/{self._binary_name}').exists():
if Path(f'{self._cf_path}/{self._binary_name}').exists() or \
Path(f'{self._cf_path}\\CloudflareST.exe').exists():
logger.error(f"CloudflareSpeedTest安装失败{str(err)},继续使用现版本运行")
return True, None
else:
logger.error(f"CloudflareSpeedTest安装失败{str(err)},无可用版本,停止运行")
if SystemUtils.is_windows():
os.system(f'rd /s /q \"{self._cf_path}\"')
else:
os.removedirs(self._cf_path)
return False, None
else:
@ -403,6 +407,9 @@ class CloudflareSpeedTest(_PluginBase):
return True, None
else:
logger.error(f"CloudflareSpeedTest安装失败无可用版本停止运行")
if SystemUtils.is_windows():
os.system(f'rd /s /q \"{self._cf_path}\"')
else:
os.removedirs(self._cf_path)
return False, None