Select upstream source depending on global var

This commit is contained in:
Aoran Zeng 2024-11-22 07:51:55 +08:00
parent 7eb120befa
commit 6a59ec51e1
No known key found for this signature in database
GPG Key ID: 8F8BA8488E10ED98
3 changed files with 32 additions and 19 deletions

View File

@ -325,28 +325,46 @@ chsrc_check_file (char *path)
/** /**
* _setsrc codetarget可用源中 * _setsrc codetarget可用源中
* *
* @note Source必定来自于一个Provider query_provider_exist
*
* @param target * @param target
* @param input default def * @param input default def
*/ */
#define find_mirror(s, input) query_mirror_exist(s##_sources, s##_sources_n, (char*)#s+3, input) #define find_mirror(s, input) query_provider_exist(s##_sources, s##_sources_n, (char*)#s+3, input)
int int
query_mirror_exist (Source_t *sources, size_t size, char *target, char *input) query_provider_exist (Source_t *sources, size_t size, char *target, char *input)
{ {
if (is_url (input)) if (is_url (input))
{ {
char *msg = CliOpt_InEnglish ? "Using user-defined sources for this software is not supported at this time, please contact the developer to ask why or request support" : "暂不支持对该软件使用用户自定义源,请联系开发者询问原因或请求支持"; char *msg = CliOpt_InEnglish ? "Using user-defined sources for this software is not supported at this time, please contact the developers to ask why or request support" : "暂不支持对该软件使用用户自定义源,请联系开发者询问原因或请求支持";
chsrc_error (msg); chsrc_error (msg);
exit (Exit_Unsupported); exit (Exit_Unsupported);
} }
if (0==size || 1==size) if (0==size)
{ {
char *msg1 = CliOpt_InEnglish ? "Currently " : "当前 "; char *msg1 = CliOpt_InEnglish ? "Currently " : "当前 ";
char *msg2 = CliOpt_InEnglish ? " doesn't have any source available, please contact the maintainer" : " 无任何可用源,请联系维护者"; char *msg2 = CliOpt_InEnglish ? " doesn't have any source available. Please contact the maintainers" : " 无任何可用源,请联系维护者";
chsrc_error (xy_strjoin (3, msg1, target, msg2)); chsrc_error (xy_strjoin (3, msg1, target, msg2));
exit (Exit_MaintainerCause); exit (Exit_MaintainerCause);
} }
if (1==size)
{
char *msg1 = CliOpt_InEnglish ? "Currently " : "当前 ";
char *msg2 = CliOpt_InEnglish ? " only the upstream source exists. Please contact the maintainers" : " 仅存在上游默认源,请联系维护者";
chsrc_error (xy_strjoin (3, msg1, target, msg2));
exit (Exit_MaintainerCause);
}
/* if (xy_streql ("reset", input)) 不再使用这种方式 */
if (ProgMode_CMD_Reset)
{
char *msg = CliOpt_InEnglish ? "Will reset to the upstream's default source" : "将重置为上游默认源";
say (msg);
return 0; /* 返回第1个因为第1个是上游默认源 */
}
if (2==size) if (2==size)
{ {
char *msg1 = CliOpt_InEnglish ? " is " : ""; char *msg1 = CliOpt_InEnglish ? " is " : "";
@ -357,18 +375,11 @@ query_mirror_exist (Source_t *sources, size_t size, char *target, char *input)
chsrc_succ (xy_strjoin (4, name, msg1, target, msg2)); chsrc_succ (xy_strjoin (4, name, msg1, target, msg2));
} }
if (xy_streql ("reset", input))
{
char *msg = CliOpt_InEnglish ? "Will reset to the upstream's default source" : "将重置为上游默认源";
say (msg);
return 0; // 返回第1个因为第1个是上游默认源
}
if (xy_streql ("first", input)) if (xy_streql ("first", input))
{ {
char *msg = CliOpt_InEnglish ? "Will use the first speedy source measured by maintainers" : "将使用维护团队测速第一的源"; char *msg = CliOpt_InEnglish ? "Will use the first speedy source measured by maintainers" : "将使用维护团队测速第一的源";
say (msg); say (msg);
return 1; // 返回第2个因为第1个是上游默认源 return 1; /* 返回第2个因为第1个是上游默认源 */
} }
int idx = 0; int idx = 0;
@ -755,7 +766,7 @@ source_has_empty_url (Source_t *source)
/** /**
* **5 Source_t * **5 Source_t
* option: * option:
* 1. MirrorCode * 1. Mirror Code
* 2. NULL: () * 2. NULL: ()
* 3. URL * 3. URL
* 4. SetsrcType_Reset * 4. SetsrcType_Reset

View File

@ -79,11 +79,13 @@ pl_go_setsrc (char *option)
chsrc_conclude (&source, SetsrcType_Auto); chsrc_conclude (&source, SetsrcType_Auto);
} }
/**
* chsrc reset go
*/
void void
pl_go_resetsrc (char *option) pl_go_resetsrc (char *option)
{ {
pl_go_setsrc (SetsrcType_Reset); pl_go_setsrc (option);
} }

View File

@ -5,7 +5,7 @@
* File Authors : Aoran Zeng <ccmywish@qq.com> * File Authors : Aoran Zeng <ccmywish@qq.com>
* Contributors : Nil Null <nil@null.org> * Contributors : Nil Null <nil@null.org>
* Created On : <2024-08-09> * Created On : <2024-08-09>
* Last Modified : <2024-11-08> * Last Modified : <2024-11-22>
* ------------------------------------------------------------- * -------------------------------------------------------------
* *
* *
@ -95,8 +95,8 @@ void
void void
<category>_<target>_resetsrc (char *option) <category>_<target>_resetsrc (char *option)
{ {
// 往往通过下述方式统一在 setsrc() 中实现 /* 往往统一在 _setsrc() 中实现,直接调用即可 */
// <category>_<target>_setsrc (SetsrcType_Reset); // <category>_<target>_setsrc (option);
} }