diff --git a/include/chsrc.h b/include/chsrc.h index 7131ea1..391bb46 100644 --- a/include/chsrc.h +++ b/include/chsrc.h @@ -322,13 +322,24 @@ auto_select_ (SourceInfo *sources, size_t size, const char *target) (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 -is_upstream (SourceInfo *source) +source_is_upstream (SourceInfo *source) { return xy_streql (source->mirror->code, "upstream"); } +bool +source_is_userdefine (SourceInfo *source) +{ + return xy_streql (source->mirror->code, "user"); +} + bool source_has_empty_url (SourceInfo *source) { @@ -336,6 +347,8 @@ source_has_empty_url (SourceInfo *source) } + + #define split_between_source_changing_process puts ("--------------------------------") /** @@ -351,7 +364,7 @@ chsrc_confirm_selection (SourceInfo *source) // chsrc 已经规避用户使用未实现的 `chsrc reset` // 但是某些用户可能摸索着强行使用 chsrc set target upstream,从而执行起该禁用的功能, // 之所以禁用,是因为有的 reset 我们并没有实现,我们在这里阻止这些邪恶的用户 - if (is_upstream (source) && source_has_empty_url (source)) + if (source_is_upstream (source) && source_has_empty_url (source)) { chsrc_error ("暂未对该软件实现重置"); exit (2); @@ -389,7 +402,14 @@ chsrc_say_lastly (SourceInfo *source, const char *last_word) { if (source) { - chsrc_log (xy_2strjoin ("全自动换源完成,感谢镜像提供方: ", xy_str_to_purple (source->mirror->name))); + if (source_is_userdefine (source)) + { + chsrc_log ("全自动换源完成; 邀您参与贡献,帮助其他人使用该URL换源: chsrc issue"); + } + else + { + chsrc_log (xy_2strjoin ("全自动换源完成,感谢镜像提供方: ", xy_str_to_purple (source->mirror->name))); + } } else { @@ -398,14 +418,21 @@ chsrc_say_lastly (SourceInfo *source, const char *last_word) } else if (xy_streql (ChsrcTypeReset, last_word)) { - // is_upstream (source) + // source_is_upstream (source) chsrc_log (xy_str_to_purple ("已重置为上游默认源")); } else if (xy_streql (ChsrcTypeSemiAuto, last_word)) { if (source) { - chsrc_log (xy_2strjoin ("半自动换源完成,仍需按上述提示手工操作,感谢镜像提供方: ", xy_str_to_purple (source->mirror->name))); + if (source_is_userdefine (source)) + { + chsrc_log ("半自动换源完成,仍需按上述提示手工操作; 邀您参与贡献,帮助其他人使用该URL换源: chsrc issue"); + } + else + { + chsrc_log (xy_2strjoin ("半自动换源完成,仍需按上述提示手工操作,感谢镜像提供方: ", xy_str_to_purple (source->mirror->name))); + } } else { @@ -417,7 +444,14 @@ chsrc_say_lastly (SourceInfo *source, const char *last_word) { if (source) { - chsrc_log (xy_2strjoin ("因实现约束需按上述提示手工操作,感谢镜像提供方: ", xy_str_to_purple (source->mirror->name))); + if (source_is_userdefine (source)) + { + chsrc_log ("因实现约束需按上述提示手工操作; 邀您参与贡献,帮助其他人使用该URL换源: chsrc issue"); + } + else + { + chsrc_log (xy_2strjoin ("因实现约束需按上述提示手工操作,感谢镜像提供方: ", xy_str_to_purple (source->mirror->name))); + } } else { @@ -429,7 +463,14 @@ chsrc_say_lastly (SourceInfo *source, const char *last_word) { if (source) { - chsrc_log (xy_2strjoin ("感谢镜像提供方: ", xy_str_to_purple (source->mirror->name))); + if (source_is_userdefine (source)) + { + chsrc_log ("邀您参与贡献,帮助其他人使用该URL换源: chsrc issue"); + } + else + { + chsrc_log (xy_2strjoin ("感谢镜像提供方: ", xy_str_to_purple (source->mirror->name))); + } } else { diff --git a/include/source.h b/include/source.h index 1ca8455..5e3adb7 100644 --- a/include/source.h +++ b/include/source.h @@ -5,7 +5,7 @@ * Authors : Aoran Zeng * | Heng Guo <2085471348@qq.com> * Created on : <2023-08-29> - * Last modified : <2024-06-12> + * Last modified : <2024-06-13> * * 镜像站与换源信息 * ------------------------------------------------------------*/ @@ -124,7 +124,10 @@ MirrorSite MirrorSite - Upstream = {"upstream", "Upstream", "上游默认源", NULL, NULL}; + Upstream = {"upstream", "Upstream", "上游默认源", NULL, NULL}; +MirrorSite + UserDefine = {"user", "用户自定义", "用户自定义", NULL, NULL}; + MirrorSite* @@ -134,7 +137,7 @@ available_mirrors[] = { &RubyChina, &EmacsChina, &NpmMirror, &GoProxyCN, &GoProxyIO, // 暂不支持 &NugetOrg - // 不要列出 &Upstream + // 不要列出 &Upstream 和 &UserDdefine }; diff --git a/src/chsrc.c b/src/chsrc.c index ca7c75e..1937e6e 100644 --- a/src/chsrc.c +++ b/src/chsrc.c @@ -40,8 +40,6 @@ pl_ruby_remove_gem_source (const char *source) void pl_ruby_setsrc (char *option) { - int index = 0; - char *chsrc_type = xy_streql (option, ChsrcTypeReset) ? ChsrcTypeReset : ChsrcTypeAuto; char *check_cmd = xy_str_to_quietcmd ("gem -v"); @@ -52,9 +50,19 @@ pl_ruby_setsrc (char *option) 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); char *cmd = NULL; @@ -671,7 +679,7 @@ pl_dart_setsrc (char *option) void -pl_haskell_setsrc(char *option) +pl_haskell_setsrc (char *option) { int index = use_specific_mirror_or_auto_select (option, pl_haskell); @@ -2429,7 +2437,7 @@ print_available_mirrors () { chsrc_info ("支持以下镜像站"); puts (xy_str_to_yellow ("下方 code 列,可用于指定使用某镜像站,请使用 chsrc set ")); - printf ("%-14s%-30s%-41s ", "code", "服务商缩写", "服务商URL"); puts("服务商名称"); + printf ("%-14s%-30s%-41s ", "code", "服务商简写", "服务商URL"); puts("服务商名称"); puts ("-------------------------------------------------------------------------------------------------"); for (int i=0; i"))); - printf ("%-14s%-35s%-45s ", "code", "服务商缩写", "服务源URL"); puts("服务商名称"); + printf ("%-14s%-35s%-45s ", "code", "服务商简写", "服务源URL"); puts("服务商名称"); puts ("--------------------------------------------------------------------------------------------------------"); 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]; - char *mirror = NULL; + char *mirrorCode_or_url = NULL; 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; return 0; }