diff --git a/src/framework/core.c b/src/framework/core.c index a344b47..13b475b 100644 --- a/src/framework/core.c +++ b/src/framework/core.c @@ -2,16 +2,16 @@ * SPDX-License-Identifier: GPL-3.0-or-later * ------------------------------------------------------------- * File Name : core.c - * File Authors : 曾奥然 - * | 郭恒 <2085471348@qq.com> - * Contributors : Peng Gao - * | Happy Game - * | Yangmoooo - * | BingChunMoLi - * | Mikachu2333 + * File Authors : @ccmywish + * | @G_I_Y + * Contributors : @Gn3po4g + * | @happy-game + * | @Yangmoooo + * | @BingChunMoLi + * | @Mikachu2333 * | * Created On : <2023-08-29> - * Last Modified : <2025-10-30> + * Last Modified : <2025-12-29> * * chsrc framework * ------------------------------------------------------------*/ @@ -1557,7 +1557,7 @@ chsrc_run_as_pwsh_file (const char *script_content) FILE *f = chsrc_make_tmpfile ("pwsh_script", ".ps1", false, &tmpfile); fwrite (script_content, strlen (script_content), 1, f); fclose (f); - char *msg = CHINESE ? "即将执行 PowerShell 脚本内容:" : "The PowerShell script content will be executed:"; + char *msg = CHINESE ? "即将执行 PowerShell (v7以上) 脚本内容:" : "The PowerShell script content will be executed:"; chsrc_note2 (msg); println (faint(script_content)); char *cmd = xy_2strcat ("pwsh ", tmpfile); @@ -1567,6 +1567,47 @@ chsrc_run_as_pwsh_file (const char *script_content) } +/** + * 以 powershell file.ps1 的形式运行脚本内容 + */ +void +chsrc_run_as_powershellv5_file (const char *script_content) +{ + char *tmpfile = NULL; + FILE *f = chsrc_make_tmpfile ("psv5_script", ".ps1", false, &tmpfile); + fwrite (script_content, strlen (script_content), 1, f); + fclose (f); + char *msg = CHINESE ? "即将执行 PowerShell v5 脚本内容:" : "The PowerShell v5 script content will be executed:"; + chsrc_note2 (msg); + println (faint(script_content)); + // -ExecutionPolicy Bypass + char *cmd = xy_2strcat ("powershell -File ", tmpfile); + chsrc_run (cmd, RunOpt_Dont_Abort_On_Failure); + remove (tmpfile); + free (tmpfile); +} + + +/** + * 使用 pwsh 或 旧的 powershell (v5) 运行脚本内容,优先使用 pwsh + */ +void +chsrc_run_as_powershell_file (const char *script_content) +{ + // if (chsrc_check_program_quietly_when_exist ("pwsh")) + if (chsrc_check_program_quietly ("pwsh")) + { + chsrc_run_as_pwsh_file (script_content); + } + else + { + chsrc_alert2 (CHINESE ? "未检测到 PowerShell 7 及以上版本,默认使用 PowerShell v5" + : "PowerShell 7 or above not detected, switch to PowerShell v5"); + chsrc_run_as_powershellv5_file (script_content); + } +} + + /** * @param cmdline 需要自己负责转义 * diff --git a/src/recipe/lang/Python/uv.c b/src/recipe/lang/Python/uv.c index f42b047..7f2c6fc 100644 --- a/src/recipe/lang/Python/uv.c +++ b/src/recipe/lang/Python/uv.c @@ -95,7 +95,7 @@ pl_python_uv_getsrc (char *option) { /* 在 Windows 上使用 PowerShell 替代 grep */ char *script = xy_str_gsub (RAWSTR_pl_python_get_uv_config_on_windows, "@f@", uv_config); - chsrc_run_as_pwsh_file (script); + chsrc_run_as_powershell_file (script); } else {