mirror of
https://github.com/RubyMetric/chsrc
synced 2025-06-09 20:34:08 +08:00
parent
6006b42d60
commit
419168fcf7
@ -322,13 +322,24 @@ auto_select_ (SourceInfo *sources, size_t size, const char *target)
|
|||||||
(NULL!=(input)) ? find_mirror(s, input) : auto_select(s)
|
(NULL!=(input)) ? find_mirror(s, input) : auto_select(s)
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
is_url (const char *str)
|
||||||
|
{
|
||||||
|
return (xy_str_start_with (str, "http://") || xy_str_start_with (str, "https://"));
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
is_upstream (SourceInfo *source)
|
source_is_upstream (SourceInfo *source)
|
||||||
{
|
{
|
||||||
return xy_streql (source->mirror->code, "upstream");
|
return xy_streql (source->mirror->code, "upstream");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
source_is_userdefine (SourceInfo *source)
|
||||||
|
{
|
||||||
|
return xy_streql (source->mirror->code, "user");
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
source_has_empty_url (SourceInfo *source)
|
source_has_empty_url (SourceInfo *source)
|
||||||
{
|
{
|
||||||
@ -336,6 +347,8 @@ source_has_empty_url (SourceInfo *source)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define split_between_source_changing_process puts ("--------------------------------")
|
#define split_between_source_changing_process puts ("--------------------------------")
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -351,7 +364,7 @@ chsrc_confirm_selection (SourceInfo *source)
|
|||||||
// chsrc 已经规避用户使用未实现的 `chsrc reset`
|
// chsrc 已经规避用户使用未实现的 `chsrc reset`
|
||||||
// 但是某些用户可能摸索着强行使用 chsrc set target upstream,从而执行起该禁用的功能,
|
// 但是某些用户可能摸索着强行使用 chsrc set target upstream,从而执行起该禁用的功能,
|
||||||
// 之所以禁用,是因为有的 reset 我们并没有实现,我们在这里阻止这些邪恶的用户
|
// 之所以禁用,是因为有的 reset 我们并没有实现,我们在这里阻止这些邪恶的用户
|
||||||
if (is_upstream (source) && source_has_empty_url (source))
|
if (source_is_upstream (source) && source_has_empty_url (source))
|
||||||
{
|
{
|
||||||
chsrc_error ("暂未对该软件实现重置");
|
chsrc_error ("暂未对该软件实现重置");
|
||||||
exit (2);
|
exit (2);
|
||||||
@ -388,9 +401,16 @@ chsrc_say_lastly (SourceInfo *source, const char *last_word)
|
|||||||
if (xy_streql (ChsrcTypeAuto, last_word))
|
if (xy_streql (ChsrcTypeAuto, last_word))
|
||||||
{
|
{
|
||||||
if (source)
|
if (source)
|
||||||
|
{
|
||||||
|
if (source_is_userdefine (source))
|
||||||
|
{
|
||||||
|
chsrc_log ("全自动换源完成; 邀您参与贡献,帮助其他人使用该URL换源: chsrc issue");
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
chsrc_log (xy_2strjoin ("全自动换源完成,感谢镜像提供方: ", xy_str_to_purple (source->mirror->name)));
|
chsrc_log (xy_2strjoin ("全自动换源完成,感谢镜像提供方: ", xy_str_to_purple (source->mirror->name)));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
chsrc_log ("全自动换源完成");
|
chsrc_log ("全自动换源完成");
|
||||||
@ -398,15 +418,22 @@ chsrc_say_lastly (SourceInfo *source, const char *last_word)
|
|||||||
}
|
}
|
||||||
else if (xy_streql (ChsrcTypeReset, last_word))
|
else if (xy_streql (ChsrcTypeReset, last_word))
|
||||||
{
|
{
|
||||||
// is_upstream (source)
|
// source_is_upstream (source)
|
||||||
chsrc_log (xy_str_to_purple ("已重置为上游默认源"));
|
chsrc_log (xy_str_to_purple ("已重置为上游默认源"));
|
||||||
}
|
}
|
||||||
else if (xy_streql (ChsrcTypeSemiAuto, last_word))
|
else if (xy_streql (ChsrcTypeSemiAuto, last_word))
|
||||||
{
|
{
|
||||||
if (source)
|
if (source)
|
||||||
|
{
|
||||||
|
if (source_is_userdefine (source))
|
||||||
|
{
|
||||||
|
chsrc_log ("半自动换源完成,仍需按上述提示手工操作; 邀您参与贡献,帮助其他人使用该URL换源: chsrc issue");
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
chsrc_log (xy_2strjoin ("半自动换源完成,仍需按上述提示手工操作,感谢镜像提供方: ", xy_str_to_purple (source->mirror->name)));
|
chsrc_log (xy_2strjoin ("半自动换源完成,仍需按上述提示手工操作,感谢镜像提供方: ", xy_str_to_purple (source->mirror->name)));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
chsrc_log ("半自动换源完成,仍需按上述提示手工操作");
|
chsrc_log ("半自动换源完成,仍需按上述提示手工操作");
|
||||||
@ -416,9 +443,16 @@ chsrc_say_lastly (SourceInfo *source, const char *last_word)
|
|||||||
else if (xy_streql (ChsrcTypeManual, last_word))
|
else if (xy_streql (ChsrcTypeManual, last_word))
|
||||||
{
|
{
|
||||||
if (source)
|
if (source)
|
||||||
|
{
|
||||||
|
if (source_is_userdefine (source))
|
||||||
|
{
|
||||||
|
chsrc_log ("因实现约束需按上述提示手工操作; 邀您参与贡献,帮助其他人使用该URL换源: chsrc issue");
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
chsrc_log (xy_2strjoin ("因实现约束需按上述提示手工操作,感谢镜像提供方: ", xy_str_to_purple (source->mirror->name)));
|
chsrc_log (xy_2strjoin ("因实现约束需按上述提示手工操作,感谢镜像提供方: ", xy_str_to_purple (source->mirror->name)));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
chsrc_log ("因实现约束需按上述提示手工操作");
|
chsrc_log ("因实现约束需按上述提示手工操作");
|
||||||
@ -428,9 +462,16 @@ chsrc_say_lastly (SourceInfo *source, const char *last_word)
|
|||||||
else if (xy_streql (ChsrcTypeUntested, last_word))
|
else if (xy_streql (ChsrcTypeUntested, last_word))
|
||||||
{
|
{
|
||||||
if (source)
|
if (source)
|
||||||
|
{
|
||||||
|
if (source_is_userdefine (source))
|
||||||
|
{
|
||||||
|
chsrc_log ("邀您参与贡献,帮助其他人使用该URL换源: chsrc issue");
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
chsrc_log (xy_2strjoin ("感谢镜像提供方: ", xy_str_to_purple (source->mirror->name)));
|
chsrc_log (xy_2strjoin ("感谢镜像提供方: ", xy_str_to_purple (source->mirror->name)));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
chsrc_log ("自动换源完成");
|
chsrc_log ("自动换源完成");
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
* Authors : Aoran Zeng <ccmywish@qq.com>
|
* Authors : Aoran Zeng <ccmywish@qq.com>
|
||||||
* | Heng Guo <2085471348@qq.com>
|
* | Heng Guo <2085471348@qq.com>
|
||||||
* Created on : <2023-08-29>
|
* Created on : <2023-08-29>
|
||||||
* Last modified : <2024-06-12>
|
* Last modified : <2024-06-13>
|
||||||
*
|
*
|
||||||
* 镜像站与换源信息
|
* 镜像站与换源信息
|
||||||
* ------------------------------------------------------------*/
|
* ------------------------------------------------------------*/
|
||||||
@ -125,6 +125,9 @@ MirrorSite
|
|||||||
|
|
||||||
MirrorSite
|
MirrorSite
|
||||||
Upstream = {"upstream", "Upstream", "上游默认源", NULL, NULL};
|
Upstream = {"upstream", "Upstream", "上游默认源", NULL, NULL};
|
||||||
|
MirrorSite
|
||||||
|
UserDefine = {"user", "用户自定义", "用户自定义", NULL, NULL};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
MirrorSite*
|
MirrorSite*
|
||||||
@ -134,7 +137,7 @@ available_mirrors[] = {
|
|||||||
&RubyChina, &EmacsChina, &NpmMirror, &GoProxyCN, &GoProxyIO,
|
&RubyChina, &EmacsChina, &NpmMirror, &GoProxyCN, &GoProxyIO,
|
||||||
// 暂不支持 &NugetOrg
|
// 暂不支持 &NugetOrg
|
||||||
|
|
||||||
// 不要列出 &Upstream
|
// 不要列出 &Upstream 和 &UserDdefine
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
26
src/chsrc.c
26
src/chsrc.c
@ -40,8 +40,6 @@ pl_ruby_remove_gem_source (const char *source)
|
|||||||
void
|
void
|
||||||
pl_ruby_setsrc (char *option)
|
pl_ruby_setsrc (char *option)
|
||||||
{
|
{
|
||||||
int index = 0;
|
|
||||||
|
|
||||||
char *chsrc_type = xy_streql (option, ChsrcTypeReset) ? ChsrcTypeReset : ChsrcTypeAuto;
|
char *chsrc_type = xy_streql (option, ChsrcTypeReset) ? ChsrcTypeReset : ChsrcTypeAuto;
|
||||||
|
|
||||||
char *check_cmd = xy_str_to_quietcmd ("gem -v");
|
char *check_cmd = xy_str_to_quietcmd ("gem -v");
|
||||||
@ -52,9 +50,19 @@ pl_ruby_setsrc (char *option)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
index = use_specific_mirror_or_auto_select (option, pl_ruby);
|
SourceInfo source;
|
||||||
|
|
||||||
|
if (is_url (option))
|
||||||
|
{
|
||||||
|
SourceInfo tmp = { &UserDefine, option };
|
||||||
|
source = tmp;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int index = use_specific_mirror_or_auto_select (option, pl_ruby);
|
||||||
|
source = pl_ruby_sources[index];
|
||||||
|
}
|
||||||
|
|
||||||
SourceInfo source = pl_ruby_sources[index];
|
|
||||||
chsrc_confirm_selection (&source);
|
chsrc_confirm_selection (&source);
|
||||||
|
|
||||||
char *cmd = NULL;
|
char *cmd = NULL;
|
||||||
@ -2429,7 +2437,7 @@ print_available_mirrors ()
|
|||||||
{
|
{
|
||||||
chsrc_info ("支持以下镜像站");
|
chsrc_info ("支持以下镜像站");
|
||||||
puts (xy_str_to_yellow ("下方 code 列,可用于指定使用某镜像站,请使用 chsrc set <target> <code>"));
|
puts (xy_str_to_yellow ("下方 code 列,可用于指定使用某镜像站,请使用 chsrc set <target> <code>"));
|
||||||
printf ("%-14s%-30s%-41s ", "code", "服务商缩写", "服务商URL"); puts("服务商名称");
|
printf ("%-14s%-30s%-41s ", "code", "服务商简写", "服务商URL"); puts("服务商名称");
|
||||||
puts ("-------------------------------------------------------------------------------------------------");
|
puts ("-------------------------------------------------------------------------------------------------");
|
||||||
for (int i=0; i<xy_arylen(available_mirrors); i++)
|
for (int i=0; i<xy_arylen(available_mirrors); i++)
|
||||||
{
|
{
|
||||||
@ -2652,7 +2660,7 @@ get_target (const char *input, TargetOp code, char *option)
|
|||||||
{
|
{
|
||||||
chsrc_info (xy_strjoin (3, "对 ", input ," 支持以下镜像站"));
|
chsrc_info (xy_strjoin (3, "对 ", input ," 支持以下镜像站"));
|
||||||
puts (xy_str_to_yellow (xy_strjoin (3, "下方 code 列,可用于指定使用某源,请使用 chsrc set ", input, " <code>")));
|
puts (xy_str_to_yellow (xy_strjoin (3, "下方 code 列,可用于指定使用某源,请使用 chsrc set ", input, " <code>")));
|
||||||
printf ("%-14s%-35s%-45s ", "code", "服务商缩写", "服务源URL"); puts("服务商名称");
|
printf ("%-14s%-35s%-45s ", "code", "服务商简写", "服务源URL"); puts("服务商名称");
|
||||||
puts ("--------------------------------------------------------------------------------------------------------");
|
puts ("--------------------------------------------------------------------------------------------------------");
|
||||||
print_supported_sources_for_target (target->sources, target->sources_n);
|
print_supported_sources_for_target (target->sources, target->sources_n);
|
||||||
}
|
}
|
||||||
@ -2824,12 +2832,12 @@ main (int argc, char const *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
target = argv[cli_arg_Target_pos];
|
target = argv[cli_arg_Target_pos];
|
||||||
char *mirror = NULL;
|
char *mirrorCode_or_url = NULL;
|
||||||
if (argc >= cli_arg_Mirror_pos) {
|
if (argc >= cli_arg_Mirror_pos) {
|
||||||
mirror = xy_strdup (argv[cli_arg_Mirror_pos]);
|
mirrorCode_or_url = xy_strdup (argv[cli_arg_Mirror_pos]);
|
||||||
}
|
}
|
||||||
|
|
||||||
matched = get_target (target, TargetOp_Set_Source, mirror);
|
matched = get_target (target, TargetOp_Set_Source, mirrorCode_or_url);
|
||||||
if (!matched) goto not_matched;
|
if (!matched) goto not_matched;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user