@@ -612,90 +612,13 @@ init 5 python in maica:
612612
613613 return maica_setting_pane_cache
614614
615- maica_certifi_download_thread_running = False
616-
617615 def maica_set_plain_provider ():
618616 store.persistent.maica_setting_dict[' provider_id' ] = 2
619617 try :
620618 store.maica.maica_instance.provider_id = 2
621619 except Exception as e:
622620 store.mas_submod_utils.submod_log.error(" MAICA: failed to apply fallback provider: {} " .format(e))
623621
624- def maica_download_certifi_files (fix_certifi , basedir , android , android_masbase ):
625- global maica_certifi_download_thread_running
626- try :
627- import requests
628- failed = False
629- if fix_certifi:
630- try :
631- store.mas_submod_utils.submod_log.warning(" Certifi broken, try to fix it" )
632- try :
633- res = requests.get(" https://raw.githubusercontent.com/Monika-After-Story/MonikaModDev/master/Monika%20After%20Story/game/python-packages/certifi/core.py" , verify = False , timeout = 5 )
634- res2 = requests.get(" https://raw.githubusercontent.com/Monika-After-Story/MonikaModDev/master/Monika%20After%20Story/game/python-packages/certifi/__init__.py" , verify = False , timeout = 5 )
635- except :
636- store.mas_submod_utils.submod_log.warning(" Download from github mirror failed, try to download from 0721play" )
637- res = requests.get(" http://sp2.0721play.icu/d/MAS/%E6%89%A9%E5%B1%95%E5%86%85%E5%AE%B9/%E5%AD%90%E6%A8%A1%E7%BB%84/0.12/Github%E5%AD%90%E6%A8%A1%E7%BB%84/MAICA%20%E5%85%89%E8%80%80%E4%B9%8B%E5%9C%B0/core.py" , verify = False , timeout = 5 )
638- res2 = requests.get(" http://sp2.0721play.icu/d/MAS/%E6%89%A9%E5%B1%95%E5%86%85%E5%AE%B9/%E5%AD%90%E6%A8%A1%E7%BB%84/0.12/Github%E5%AD%90%E6%A8%A1%E7%BB%84/MAICA%20%E5%85%89%E8%80%80%E4%B9%8B%E5%9C%B0/__init__.py" , verify = False , timeout = 5 )
639-
640- if res.status_code == 200 and res2.status_code == 200 :
641- with open (os.path.normpath(os.path.join(basedir, " game" , " python-packages" , " certifi" ," core.py" )), " wb" ) as file:
642- file.write(res.content)
643- store.mas_submod_utils.submod_log.info(" MAICA: certifi core.py fixed" )
644-
645- with open (os.path.normpath(os.path.join(basedir, " game" , " python-packages" , " certifi" , " __init__.py" )), " wb" ) as file:
646- file.write(res2.content)
647- store.mas_submod_utils.submod_log.info(" MAICA: certifi __init__.py fixed" )
648- store.maica.maica_instance.disable(
649- store.maica.maica_instance.MaicaAiStatus.CERTIFI_RESTART_REQUIRED,
650- sticky = True ,
651- )
652-
653- else :
654- store.mas_submod_utils.submod_log.error(" MAICA: certifi core.py download failed, HTTP code:core{} init{} " .format(res.status_code, res2.status_code))
655- failed = True
656- except Exception as e:
657- store.mas_submod_utils.submod_log.error(" MAICA: certifi core.py download failed: {} " .format(e))
658- failed = True
659-
660- url = " https://gitee.com/mirrors/python-certifi/raw/master/certifi/cacert.pem"
661- try :
662- response = requests.get(url, verify = False , timeout = 5 )
663- if response.status_code == 200 :
664- path = os.path.join(basedir, " game" , " python-packages" , " certifi" , " cacert.pem" ) if not android else os.path.join(android_masbase, " game" , " python-packages" , " certifi" , " cacert.pem" )
665- with open (path, " wb" ) as file:
666- file.write(response.content)
667- store.mas_submod_utils.submod_log.info(" MAICA: cacert.pem downloaded use gitee mirror" )
668- else :
669- store.mas_submod_utils.submod_log.error(" MAICA: cacert download failed with gitee mirror, HTTP code:{} " .format(response.status_code))
670- failed = True
671- except Exception as e:
672- store.mas_submod_utils.submod_log.error(" MAICA: cacert download failed with gitee mirror: {} " .format(e))
673- failed = True
674-
675- if failed:
676- maica_set_plain_provider()
677- else :
678- check_accessibility()
679- finally :
680- maica_certifi_download_thread_running = False
681-
682- def maica_start_certifi_download_in_background (fix_certifi ):
683- global maica_certifi_download_thread_running
684- if maica_certifi_download_thread_running:
685- store.mas_submod_utils.submod_log.info(" MAICA: certifi download already running" )
686- return
687-
688- maica_certifi_download_thread_running = True
689- basedir = renpy.config.basedir
690- android = renpy.android
691- android_masbase = store.ANDROID_MASBASE if android else None
692- store.mas_submod_utils.submod_log.info(" MAICA: certifi download started in background" )
693- try :
694- renpy.invoke_in_thread(lambda : maica_download_certifi_files(fix_certifi, basedir, android, android_masbase))
695- except Exception as e:
696- maica_certifi_download_thread_running = False
697- store.mas_submod_utils.submod_log.error(" MAICA: certifi background download failed to start: {} " .format(e))
698-
699622 @ store.mas_submod_utils.functionplugin (" ch30_preloop" , priority = - 100 )
700623 def start_maica ():
701624 # 如果从PC迁移到android,切换为plain节点
@@ -716,12 +639,9 @@ init 5 python in maica:
716639 if store.mas_getAPIKey(" Maica_Token" ) != " " :
717640 store.maica.maica_instance.ciphertext = store.mas_getAPIKey(" Maica_Token" )
718641
719- # certifi修复,仅在MAS原生导入失败时启动
720- certifi_broken = not store.mas_can_import.certifi()
721- if certifi_broken:
642+ # CertifiFixer runs during init; retry the MAS import check after it.
643+ if not store.mas_can_import.certifi():
722644 maica_set_plain_provider()
723- if certifi_broken or store.maica_can_update_cacert:
724- maica_start_certifi_download_in_background(certifi_broken)
725645
726646 refresh_setting_pane_cache(force_version = True )
727647
@@ -754,18 +674,6 @@ init 5 python in maica:
754674
755675
756676init - 700 python :
757- maica_can_update_cacert = False
758- try :
759- import os
760- if not os.path.exists(os.path.normpath(os.path.join(renpy.config.basedir, " game" , " python-packages" , " certifi" , " cacert.pem" ))):
761- res = mas_can_import.certifi._update_cert(force = True )
762- if res is None or res < 0 :
763- raise RuntimeError (" MAS native certifi update failed" )
764- except Exception :
765- maica_can_update_cacert = True
766- store.mas_submod_utils.submod_log.warning(" MAS native function update cacert failed" )
767-
768-
769677 import hashlib
770678
771679 def calculate_sha256 (file_path ):
0 commit comments