@@ -59,7 +59,9 @@ def download_file(self, url, file_path, progress_signal: pyqtBoundSignal):
59
59
60
60
def extract_zip (self , zip_file_path , extract_to ):
61
61
try :
62
- with zipfile .ZipFile (zip_file_path , "r" , metadata_encoding = 'utf-8' ) as zip_ref :
62
+ with zipfile .ZipFile (
63
+ zip_file_path , "r" , metadata_encoding = "utf-8"
64
+ ) as zip_ref :
63
65
all_members = zip_ref .namelist ()
64
66
actual_main_folder = all_members [0 ].split ("/" )[0 ]
65
67
zip_ref .extractall (extract_to )
@@ -345,7 +347,7 @@ def mirror_check(
345
347
Returns:
346
348
Dict: 资源信息
347
349
"""
348
- if maa_config_data .interface_config .get ("mirrorchyan_multiplatform" ,False ):
350
+ if maa_config_data .interface_config .get ("mirrorchyan_multiplatform" , False ):
349
351
version_file_path = os .path .join (os .getcwd (), "config" , "version.txt" )
350
352
logger .info (f"正在读取版本文件: { version_file_path } " )
351
353
with open (version_file_path , "r" , encoding = "utf-8" ) as f :
@@ -608,6 +610,8 @@ def github_download(self, update_dict: Dict):
608
610
logger .info (f"正在读取版本文件: { version_file_path } " )
609
611
with open (version_file_path , "r" ) as version_file :
610
612
version = version_file .read ().split ()[2 ][1 :]
613
+ os_type = version_file .read ().split ()[0 ]
614
+ arch = version_file .read ().split ()[1 ]
611
615
logger .debug (f"当前版本: { version } " )
612
616
except FileNotFoundError :
613
617
logger .exception ("版本文件未找到" )
@@ -625,7 +629,22 @@ def github_download(self, update_dict: Dict):
625
629
self .stop_flag = False
626
630
try :
627
631
# 下载过程
628
- download_url = update_dict ["zipball_url" ]
632
+ if maa_config_data .interface_config .get ("agent" , False ):
633
+ for release in update_dict ["assets" ]:
634
+ if os_type in release ["name" ] and arch in release ["name" ]:
635
+ download_url = release ["browser_download_url" ]
636
+ break
637
+ else :
638
+ logger .warning ("未找到匹配的资源" )
639
+ signalBus .update_download_finished .emit (
640
+ {
641
+ "status" : "failed" ,
642
+ "msg" : self .tr ("No matching resource found" ),
643
+ }
644
+ )
645
+
646
+ else :
647
+ download_url = update_dict ["zipball_url" ]
629
648
logger .info (f"开始下载更新包: { download_url } " )
630
649
631
650
hotfix_directory = os .path .join (os .getcwd (), "hotfix" )
@@ -658,11 +677,29 @@ def github_download(self, update_dict: Dict):
658
677
{"status" : "failed" , "msg" : self .tr ("Extraction failed" )}
659
678
)
660
679
return
680
+ if maa_config_data .interface_config .get ("agent" , False ):
681
+ main_folder = os .path .join (os .getcwd (), "hotfix" , main_folder )
682
+ files_to_keep = [
683
+ "python" ,
684
+ "resource" ,
685
+ "interface.json" ,
686
+ "custom" ,
687
+ "agent" ,
688
+ ]
689
+
690
+ for item in os .listdir (main_folder ):
691
+ if item not in files_to_keep :
692
+ item_path = os .path .join (main_folder , item )
693
+ if os .path .isdir (item_path ):
694
+ shutil .rmtree (item_path )
695
+ else :
696
+ os .remove (item_path )
661
697
662
- folder_to_extract = os .path .join (
663
- os .getcwd (), "hotfix" , main_folder , "assets"
664
- )
665
- logger .debug (f"资源解压路径: { folder_to_extract } " )
698
+ else :
699
+ folder_to_extract = os .path .join (
700
+ os .getcwd (), "hotfix" , main_folder , "assets"
701
+ )
702
+ logger .debug (f"资源解压路径: { folder_to_extract } " )
666
703
667
704
# 版本兼容性检查
668
705
interface_file = os .path .join (folder_to_extract , "interface.json" )
@@ -689,15 +726,24 @@ def github_download(self, update_dict: Dict):
689
726
if os .path .exists (target_path ):
690
727
logger .info ("开始清理旧资源" )
691
728
try :
729
+ if os .path .exists (os .path .join (target_path , "python" )):
730
+ shutil .rmtree (os .path .join (target_path , "python" ))
731
+ logger .debug ("成功删除 python 目录" )
732
+
733
+ if os .path .exists (os .path .join (target_path , "custom" )):
734
+ shutil .rmtree (os .path .join (target_path , "custom" ))
735
+ logger .debug ("成功删除 custom 目录" )
736
+
737
+ if os .path .exists (os .path .join (target_path , "agent" )):
738
+ shutil .rmtree (os .path .join (target_path , "agent" ))
739
+ logger .debug ("成功删除 agent 目录" )
740
+
692
741
shutil .rmtree (os .path .join (target_path , "resource" ))
693
742
logger .debug ("成功删除 resource 目录" )
694
743
695
744
os .remove (os .path .join (target_path , "interface.json" ))
696
745
logger .debug ("成功删除 interface.json" )
697
746
698
- if os .path .exists (os .path .join (target_path , "custom" )):
699
- shutil .rmtree (os .path .join (target_path , "custom" ))
700
- logger .debug ("成功删除 custom 目录" )
701
747
except Exception as e :
702
748
logger .error (f"清理旧资源失败: { str (e )} " )
703
749
signalBus .update_download_finished .emit (
@@ -743,7 +789,7 @@ def github_download(self, update_dict: Dict):
743
789
except requests .exceptions .HTTPError as e :
744
790
logger .exception (f"HTTP错误: { str (e )} " )
745
791
signalBus .update_download_finished .emit (
746
- {"status" : "failed" , "msg" : self .tr ("HTTP error" )+ str (e )}
792
+ {"status" : "failed" , "msg" : self .tr ("HTTP error" ) + str (e )}
747
793
)
748
794
except KeyError as e :
749
795
logger .exception (f"关键数据缺失: { str (e )} " )
0 commit comments