@@ -19,17 +19,14 @@ const DEFAULT_PORT: u16 = 13000;
1919const PORT_RANGE_END : u16 = 14000 ;
2020
2121fn should_show_terminal_qrcode ( exe_dir : & Path , args : & [ String ] ) -> bool {
22- // 非 Windows 平台始终显示终端二维码
2322 if cfg ! ( not( target_os = "windows" ) ) {
2423 return true ;
2524 }
2625
27- // 检查命令行参数
2826 if args. iter ( ) . any ( |a| a == "--headless" ) {
2927 return true ;
3028 }
3129
32- // 检查配置文件
3330 let config_path = exe_dir. join ( "bin/pmhq/pmhq_config.json" ) ;
3431 if let Ok ( content) = fs:: read_to_string ( & config_path) {
3532 if let Ok ( json) = serde_json:: from_str :: < serde_json:: Value > ( & content) {
@@ -39,38 +36,48 @@ fn should_show_terminal_qrcode(exe_dir: &Path, args: &[String]) -> bool {
3936 false
4037}
4138
39+ fn get_exe_name ( base : & str ) -> String {
40+ if cfg ! ( target_os = "windows" ) {
41+ format ! ( "{}.exe" , base)
42+ } else {
43+ base. to_string ( )
44+ }
45+ }
46+
4247fn main ( ) {
4348 let exe_dir = env:: current_exe ( )
4449 . ok ( )
4550 . and_then ( |p| p. parent ( ) . map ( |p| p. to_path_buf ( ) ) )
4651 . unwrap_or_else ( || PathBuf :: from ( "." ) ) ;
4752
4853 let args: Vec < String > = env:: args ( ) . skip ( 1 ) . collect ( ) ;
49- let pmhq_exe = exe_dir. join ( "bin/pmhq/pmhq.exe" ) ;
54+ let pmhq_exe = exe_dir. join ( format ! ( "bin/pmhq/{}" , get_exe_name ( " pmhq" ) ) ) ;
5055
5156 // --help 或 --version 直接转发给 pmhq
5257 if args. iter ( ) . any ( |a| a == "--help" || a == "-h" || a == "--version" ) {
5358 if pmhq_exe. exists ( ) {
5459 let status = Command :: new ( & pmhq_exe) . args ( & args) . status ( ) ;
5560 std:: process:: exit ( status. map ( |s| s. code ( ) . unwrap_or ( 0 ) ) . unwrap_or ( 1 ) ) ;
5661 } else {
57- eprintln ! ( "错误: 未找到 pmhq.exe : {}" , pmhq_exe. display( ) ) ;
62+ eprintln ! ( "错误: 未找到 pmhq: {}" , pmhq_exe. display( ) ) ;
5863 std:: process:: exit ( 1 ) ;
5964 }
6065 }
6166
6267 migrate_old_files ( & exe_dir) ;
6368
6469 let llbot_dir = exe_dir. join ( "bin/llbot" ) ;
70+ let node_exe = get_exe_name ( "node" ) ;
6571
6672 if !pmhq_exe. exists ( ) {
67- eprintln ! ( "错误: 未找到 pmhq.exe : {}" , pmhq_exe. display( ) ) ;
73+ eprintln ! ( "错误: 未找到 pmhq: {}" , pmhq_exe. display( ) ) ;
6874 wait_exit ( 1 ) ;
6975 }
70- if !llbot_dir. join ( "node.exe" ) . exists ( ) {
76+ if !llbot_dir. join ( & node_exe ) . exists ( ) {
7177 eprintln ! (
72- "错误: 未找到 node.exe: {}" ,
73- llbot_dir. join( "node.exe" ) . display( )
78+ "错误: 未找到 {}: {}" ,
79+ node_exe,
80+ llbot_dir. join( & node_exe) . display( )
7481 ) ;
7582 wait_exit ( 1 ) ;
7683 }
@@ -102,7 +109,7 @@ fn main() {
102109 cmd. arg ( "--sub-cmd-workdir" )
103110 . arg ( & llbot_dir)
104111 . arg ( "--sub-cmd" )
105- . arg ( "node.exe" )
112+ . arg ( & node_exe )
106113 . arg ( "--enable-source-maps" )
107114 . arg ( "llbot.js" )
108115 . arg ( "--" )
0 commit comments