From 2d2ba889863b4c3cf8ddee7c55e330b7b2ec1963 Mon Sep 17 00:00:00 2001 From: shenjack-mac <3695888@qq.com> Date: Sun, 23 Apr 2023 00:15:36 +0800 Subject: [PATCH] update crash report --- DR.py | 6 ++++++ Difficult_Rocket/__init__.py | 3 ++- Difficult_Rocket/utils/tools.py | 2 +- docs/src/update_logs.md | 5 ++++- libs/MCDR/version.py | 3 +++ 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/DR.py b/DR.py index 4b255be..f1f1c9f 100644 --- a/DR.py +++ b/DR.py @@ -8,6 +8,8 @@ import time import cProfile import traceback +from io import StringIO + # TODO 默认位置配置文件 # TODO 可自定义工作路径 @@ -89,6 +91,10 @@ def main() -> None: print(error_format['error.unknown']) print(error) crash.create_crash_report(error) + cache_steam = StringIO() + crash.write_info_to_cache(cache_steam) + text = cache_steam.getvalue() + print(text) else: crash.record_thread = False print(crash.all_thread) diff --git a/Difficult_Rocket/__init__.py b/Difficult_Rocket/__init__.py index e6aefba..0a51093 100644 --- a/Difficult_Rocket/__init__.py +++ b/Difficult_Rocket/__init__.py @@ -113,7 +113,7 @@ class _DR_runtime(Options): API_version: Version = Api_version # DR SDK API 版本 DR_long_version: int = long_version # DR SDK 内部协议版本 (不要问我为什么不用 Version,我也在考虑) - DR_Mod_List: List[Tuple[str, Version]] = [] # DR Mod 列表 + DR_Mod_List: List[Tuple[str, Version]] = [] # DR Mod 列表 (name, version) DR_Rust_version: Version = DR_rust_version # 后面要去掉的 DR_rs 版本 DR_Rust_get_version: Optional[Version] = None # 后面也要去掉的 DR_rs 版本 @@ -177,6 +177,7 @@ class _DR_runtime(Options): except ImportError: print(f'ImportError when loading mod {mod_path}') traceback.print_exc() + self.DR_Mod_List = [(mod, Version('0.0.0-unknown')) for mod in mods] return mods diff --git a/Difficult_Rocket/utils/tools.py b/Difficult_Rocket/utils/tools.py index 7d2be64..5609e81 100644 --- a/Difficult_Rocket/utils/tools.py +++ b/Difficult_Rocket/utils/tools.py @@ -40,7 +40,7 @@ file_error = {FileNotFoundError: 'no {filetype} file was founded!:\n file name: def load_file(file_name: str, - stack: Union[str, list, dict] = None, + stack: Union[str, list, dict, None] = None, raise_error: bool = True, encoding: str = 'utf-8') -> Union[dict, ElementTree.ElementTree]: f_type = file_name[file_name.rfind('.') + 1:] # 从最后一个.到末尾 (截取文件格式) diff --git a/docs/src/update_logs.md b/docs/src/update_logs.md index c21c24f..705fbe1 100644 --- a/docs/src/update_logs.md +++ b/docs/src/update_logs.md @@ -49,7 +49,10 @@ - Add `mod_path: str` field - Add `DR_Mod_List: List[Tuple[str, Version]]` field - Add `load_mods() -> None` method - - Add `find_mods -> List[str]` method + - Add `find_mods -> List[str]` method +- 现在游戏崩溃时会自动在 stdio 中输出崩溃日志 内容跟 crash report 中的基本相同 + - Now when the game crashes, it will automatically output the crash log in stdio + - The content of the crash log is basically the same as the crash report ### Mod Loader diff --git a/libs/MCDR/version.py b/libs/MCDR/version.py index 56e1cb9..fa29b02 100644 --- a/libs/MCDR/version.py +++ b/libs/MCDR/version.py @@ -102,6 +102,9 @@ class Version: version_str += '+' + str(self.build) return version_str + def __repr__(self): + return 'Version({})'.format(self.__str__()) + def __getitem__(self, index): if index < len(self.component): return self.component[index]