mirror of
https://github.com/RubyMetric/chsrc.git
synced 2025-03-02 08:59:54 +08:00
Add support for ipv6
[Gitee link #I85687]
This commit is contained in:
parent
4936826635
commit
557db108b3
@ -3,7 +3,7 @@
|
|||||||
* License : GPLv3
|
* License : GPLv3
|
||||||
* Authors : Aoran Zeng <ccmywish@qq.com>
|
* Authors : Aoran Zeng <ccmywish@qq.com>
|
||||||
* Created on : <2023-08-29>
|
* Created on : <2023-08-29>
|
||||||
* Last modified : <2024-05-25>
|
* Last modified : <2024-06-05>
|
||||||
*
|
*
|
||||||
* chsrc:
|
* chsrc:
|
||||||
*
|
*
|
||||||
@ -21,17 +21,21 @@
|
|||||||
#define chsrc_error(str) xy_error(xy_2strjoin(App_Prefix, (str)))
|
#define chsrc_error(str) xy_error(xy_2strjoin(App_Prefix, (str)))
|
||||||
|
|
||||||
|
|
||||||
|
int Cli_Option_IPv6 = 0;
|
||||||
|
int Cli_Optiion_Locally = 0;
|
||||||
|
int Cli_Option_InEnglish = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检测二进制程序是否存在
|
* 检测二进制程序是否存在
|
||||||
*
|
*
|
||||||
* @param check_cmd 检测 `progname` 是否存在的一段命令,一般来说,填 `progname` 本身即可,
|
* @param check_cmd 检测 `prog_name` 是否存在的一段命令,一般来说,填 `prog_name` 本身即可,
|
||||||
* 但是某些情况下,需要使用其他命令绕过一些特殊情况,比如 python 这个命令在Windows上
|
* 但是某些情况下,需要使用其他命令绕过一些特殊情况,比如 python 这个命令在Windows上
|
||||||
* 会自动打开 Microsoft Store,需避免
|
* 会自动打开 Microsoft Store,需避免
|
||||||
*
|
*
|
||||||
* @param progname 要检测的二进制程序名
|
* @param prog_name 要检测的二进制程序名
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
query_program_exist (char *check_cmd, char *progname)
|
query_program_exist (char *check_cmd, char *prog_name)
|
||||||
{
|
{
|
||||||
char *which = check_cmd;
|
char *which = check_cmd;
|
||||||
|
|
||||||
@ -39,12 +43,15 @@ query_program_exist (char *check_cmd, char *progname)
|
|||||||
|
|
||||||
// char buf[32] = {0}; sprintf(buf, "错误码: %d", ret);
|
// char buf[32] = {0}; sprintf(buf, "错误码: %d", ret);
|
||||||
|
|
||||||
if (0!=ret) {
|
if (0 != ret)
|
||||||
|
{
|
||||||
// xy_warn (xy_strjoin(4, "× 命令 ", progname, " 不存在,", buf));
|
// xy_warn (xy_strjoin(4, "× 命令 ", progname, " 不存在,", buf));
|
||||||
puts (xy_strjoin (4, xy_str_to_red ("x "), "命令 ", xy_str_to_red (progname), " 不存在"));
|
puts (xy_strjoin (4, xy_str_to_red ("x "), "命令 ", xy_str_to_red (prog_name), " 不存在"));
|
||||||
return false;
|
return false;
|
||||||
} else {
|
}
|
||||||
puts (xy_strjoin (4, xy_str_to_green ("√ "), "命令 ", xy_str_to_green (progname), " 存在"));
|
else
|
||||||
|
{
|
||||||
|
puts (xy_strjoin (4, xy_str_to_green ("√ "), "命令 ", xy_str_to_green (prog_name), " 存在"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -147,13 +154,20 @@ test_speed_url (const char *url)
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
char *ipv6 = ""; // 默认不启用
|
||||||
|
|
||||||
|
if (Cli_Option_IPv6==1) {
|
||||||
|
ipv6 = "--ipv6";
|
||||||
|
}
|
||||||
|
|
||||||
// 我们用 —L,因为Ruby China源会跳转到其他地方
|
// 我们用 —L,因为Ruby China源会跳转到其他地方
|
||||||
// npmmirror 也会跳转
|
// npmmirror 也会跳转
|
||||||
char *curl_cmd = xy_strjoin (6, "curl -qsL -o ", xy_os_devnull,
|
char *curl_cmd = xy_strjoin (7, "curl -qsL ", ipv6,
|
||||||
|
" -o " xy_os_devnull,
|
||||||
" -w \"%{http_code} %{speed_download}\" -m", time_sec ,
|
" -w \"%{http_code} %{speed_download}\" -m", time_sec ,
|
||||||
" -A chsrc/" Chsrc_Version " ", url);
|
" -A chsrc/" Chsrc_Version " ", url);
|
||||||
|
|
||||||
// xy_info (xy_2strjoin("chsrc: 测速 ", url));
|
// xy_info (xy_2strjoin ("chsrc: 测速命令 ", curl_cmd));
|
||||||
|
|
||||||
char *buf = xy_getcmd (curl_cmd, 0, NULL);
|
char *buf = xy_getcmd (curl_cmd, 0, NULL);
|
||||||
// 如果尾部有换行,删除
|
// 如果尾部有换行,删除
|
||||||
|
@ -2311,9 +2311,6 @@ get_target (const char *input, TargetOp code, char *option)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Cli_Option_IPv6 = 0;
|
|
||||||
int Cli_Optiion_Locally = 0;
|
|
||||||
int Cli_Option_InEnglish = 0;
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char const *argv[])
|
main (int argc, char const *argv[])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user