feat: 增加加载器模式

This commit is contained in:
KAAAsS 2024-07-01 03:21:06 +08:00
parent 8447273eb7
commit cc3e6eeb31
Signed by: KAAAsS
GPG Key ID: D22F53AF662411FE
11 changed files with 51 additions and 1 deletions

3
.gitignore vendored
View File

@ -2,7 +2,7 @@
.idea
# Python
*.pyc
__pycache__
# Data
agree-terms
@ -10,3 +10,4 @@ data
language
share.json
config.json
.DS_Store

2
loader/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
logs/
!./binary/*.pyc

BIN
loader/binary/api.pyc Normal file

Binary file not shown.

BIN
loader/binary/globals.pyc Normal file

Binary file not shown.

BIN
loader/binary/i18n.pyc Normal file

Binary file not shown.

BIN
loader/binary/login.pyc Normal file

Binary file not shown.

BIN
loader/binary/main.pyc Normal file

Binary file not shown.

BIN
loader/binary/utility.pyc Normal file

Binary file not shown.

BIN
loader/binary/utils.pyc Normal file

Binary file not shown.

View File

@ -0,0 +1 @@
0.8.7

46
loader/loader.py Normal file
View File

@ -0,0 +1,46 @@
import importlib
import importlib.machinery
import sys
from pathlib import Path
_BINARY_DIR = Path(__file__).parent / 'binary'
_MODULES = [
'utils',
'i18n',
'login',
'globals',
'api',
'main',
]
def load_binary():
sys.path.append(str(_BINARY_DIR))
# 先载入并 patch utils
importlib.import_module('utils')
patch_module()
importlib.import_module('main')
return sys.modules['main']
def patch_module():
def check_policy():
from loguru import logger
logger.info('Bypass check_policy')
sys.modules['utils'].check_policy = check_policy
def run_module(module):
module.main()
def main():
module = load_binary()
run_module(module)
if __name__ == '__main__':
main()