使用 xy.

This commit is contained in:
Aoran Zeng
2025-08-27 11:58:43 +08:00
parent 28d913c58b
commit 55865d6a7b
11 changed files with 41 additions and 47 deletions

View File

@@ -381,7 +381,7 @@ query_program_exist (char *check_cmd, char *prog_name, int mode)
static char *
cmd_to_check_program (char *prog_name)
{
char *check_tool = xy_on_windows ? "where " : "command -v ";
char *check_tool = xy.on_windows ? "where " : "command -v ";
char *quiet_cmd = xy_str_to_quietcmd (xy_2strcat (check_tool, prog_name));
@@ -906,7 +906,7 @@ auto_select_mirror (Source_t *sources, size_t size, const char *target_name)
exit (Exit_UserCause);
}
if (xy_on_windows)
if (xy.on_windows)
{
char *curl_version = xy_run ("curl --version", 1);
/**
@@ -1399,7 +1399,7 @@ chsrc_make_tmpfile (char *filename, char *postfix, bool loud, char **tmpfilename
* 这样的话,其实是是无法删除该文件的,但是生成在 /tmp 目录下我们恰好可以不用清理
* 但是在 Windows 上,就没有办法了,所以我们禁止在 Windows 上不指定返回出的临时文件名
*/
if (xy_on_windows && !tmpfilename)
if (xy.on_windows && !tmpfilename)
{
chsrc_error2 ("在 Windows 上,创建临时文件时必须指定返回的临时文件名");
xy_unreached();
@@ -1562,7 +1562,7 @@ chsrc_view_file (const char *path)
{
char *cmd = NULL;
path = xy_normalize_path (path);
if (xy_on_windows)
if (xy.on_windows)
{
cmd = xy_2strcat ("type ", path);
}
@@ -1586,7 +1586,7 @@ chsrc_ensure_dir (const char *dir)
// 不存在就生成
char *mkdir_cmd = NULL;
if (xy_on_windows)
if (xy.on_windows)
{
mkdir_cmd = "md "; // 已存在时返回 errorlevel = 1
}
@@ -1644,7 +1644,7 @@ log_anyway:
/*
char *cmd = NULL;
if (xy_on_windows)
if (xy.on_windows)
{
cmd = xy_strcat (4, "echo ", str, " >> ", file);
}
@@ -1669,7 +1669,7 @@ chsrc_prepend_to_file (const char *str, const char *filename)
chsrc_ensure_dir (dir);
char *cmd = NULL;
if (xy_on_windows)
if (xy.on_windows)
{
xy_unimplemented();
}
@@ -1697,7 +1697,7 @@ chsrc_overwrite_file (const char *str, const char *filename)
chsrc_ensure_dir (dir);
char *cmd = NULL;
if (xy_on_windows)
if (xy.on_windows)
{
cmd = xy_strcat (4, "echo ", str, " > ", file);
}
@@ -1730,12 +1730,12 @@ chsrc_backup (const char *path)
return;
}
if (xy_on_bsd || xy_on_macos)
if (xy.on_bsd || xy.on_macos)
{
/* BSD 和 macOS 的 cp 不支持 --backup 选项 */
cmd = xy_strcat (5, "cp -f ", path, " ", path, ".bak");
}
else if (xy_on_windows)
else if (xy.on_windows)
{
/**
* @note /Y 表示覆盖

View File

@@ -55,7 +55,7 @@ pl_dart_flutter_setsrc (char *option)
char *w = NULL;
char *cmd = NULL;
if (xy_on_windows)
if (xy.on_windows)
{
cmd = xy_strcat (3, "setx FLUTTER_STORAGE_BASE_URL \"", source.url, "\"");
chsrc_run (cmd, RunOpt_No_Last_New_Line);

View File

@@ -51,7 +51,7 @@ pl_dart_setsrc (char *option)
char *w = NULL;
char *cmd = NULL;
if (xy_on_windows)
if (xy.on_windows)
{
cmd = xy_strcat (3, "setx PUB_HOSTED_URL \"", source.url, "\"");
chsrc_run (cmd, RunOpt_No_Last_New_Line);

View File

@@ -44,7 +44,7 @@ pl_haskell_setsrc (char *option)
char *content = xy_str_gsub (RAWSTR_pl_haskell_cabal_config, "@url@", source.url);
char *config = NULL;
if (xy_on_windows)
if (xy.on_windows)
{
config = xy_normalize_path ("~/AppData/Roaming/cabal/config");
}

View File

@@ -49,7 +49,7 @@ pl_python_find_uv_config (bool mkdir)
}
else
{
if (xy_on_windows)
if (xy.on_windows)
{
/* config path on Windows */
char *appdata = getenv ("APPDATA");

View File

@@ -46,7 +46,7 @@ pl_r_getsrc (char *option)
* options()$repos
* options()$BioC_mirror
*/
if (xy_on_windows)
if (xy.on_windows)
{
chsrc_view_file (PL_R_Config_Windows);
}
@@ -74,7 +74,7 @@ pl_r_setsrc (char *option)
// 或者我们调用 r.exe --slave -e 上面的内容
char *config = xy_on_windows ? PL_R_Config_Windows : PL_R_Config_POSIX;
char *config = xy.on_windows ? PL_R_Config_Windows : PL_R_Config_POSIX;
chsrc_append_to_file (w, config);

View File

@@ -59,7 +59,7 @@ wr_anaconda_setsrc (char *option)
/* Windows 也是在这里 */
char *configfile = xy_2strcat (xy_os_home, "/.condarc");
if (xy_on_windows)
if (xy.on_windows)
{
if (xy_file_exist (configfile))
{

View File

@@ -50,7 +50,7 @@ wr_docker_prelude ()
void
wr_docker_getsrc (char *option)
{
if (xy_on_linux || xy_on_bsd)
if (xy.on_linux || xy.on_bsd)
{
chsrc_view_file (WR_Docker_ConfigFile);
}
@@ -73,7 +73,7 @@ wr_docker_setsrc (char *option)
chsrc_use_this_source (wr_docker);
if (xy_on_linux || xy_on_bsd)
if (xy.on_linux || xy.on_bsd)
{
char *to_add = xy_str_gsub (RAWSTR_wr_docker_insert_content, "@1@", source.url);
@@ -119,7 +119,7 @@ wr_docker_setsrc (char *option)
chsrc_append_to_file (to_add, WR_Docker_ConfigFile);
}
if (xy_on_linux)
if (xy.on_linux)
{
/* 由于 systemctl restart docker 会导致所有容器停止,所以不自动重启 */
chsrc_alert2 ("请自行运行: sudo systemctl restart docker");