Skip to content

Commit f099a86

Browse files
committed
Use chef_
1 parent 67915c3 commit f099a86

File tree

17 files changed

+84
-89
lines changed

17 files changed

+84
-89
lines changed

doc/11-如何修改URL.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ def_sources_begin()
5252
def_sources_end()
5353
5454
// 把所有上述源的测速 URL 设置为 "换源 URL" + postfix
55-
chsrc_set_sources_speed_measure_url_with_postfix (this, "/dir/BigFile.tar.gz");
55+
chef_set_sources_speed_measure_url_with_postfix (this, "/dir/BigFile.tar.gz");
5656
// 基于 "换源 URL" 做更自定义的操作
57-
chsrc_set_sources_speed_measure_url_with_func (this, func, data);
57+
chef_set_sources_speed_measure_url_with_func (this, func, data);
5858
5959
// 调整某一个镜像站(Provider)的测速 URL
60-
chsrc_set_provider_speed_measure_url (&Tencent, "https://mirrors.cloud.tencent.com/npm/BigFile.tar.gz")
60+
chef_set_provider_speed_measure_url (&Tencent, "https://mirrors.cloud.tencent.com/npm/BigFile.tar.gz")
6161
// 调整某一个镜像站(Provider)的测速精度
62-
chsrc_set_provider_speed_measure_accuracy (&UpstreamProvider, ROUGH);;
62+
chef_set_provider_speed_measure_accuracy (&UpstreamProvider, ROUGH);;
6363
```

src/framework/chef.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,66 @@
1818
#define chef_allow_gs(t) this->getfn = t##_getsrc; this->setfn = t##_setsrc; this->resetfn = NULL;
1919

2020

21+
/**
22+
* @brief 修改 Provider 的测速地址
23+
*/
24+
void
25+
chef_set_provider_speed_measure_url (SourceProvider_t *provider, char *url)
26+
{
27+
provider->psmi.skip = NotSkip;
28+
provider->psmi.url = xy_strdup (url);
29+
chsrc_debug ("m", xy_strjoin (4, "recipe 重新为 ", provider->code, " 设置测速链接: ", url));
30+
}
31+
32+
33+
/**
34+
* @brief 修改 Provider 的测速精度
35+
*/
36+
void
37+
chef_set_provider_speed_measure_accuracy (SourceProvider_t *provider, bool accuracy)
38+
{
39+
provider->psmi.accurate = accuracy;
40+
chsrc_debug ("m", xy_strjoin (4, "recipe 重新为 ", provider->code, " 设置测速精度: ", accuracy ? "精准" : "粗略"));
41+
}
42+
43+
44+
/**
45+
* @brief 提供一个函数,这个函数基于 "换源 URL" 和用户提供的数据来构造和填充精准测速链接
46+
*/
47+
void
48+
chef_set_sources_speed_measure_url_with_func (
49+
Target_t *target,
50+
char *(*func)(const char *url, const char *user_data),
51+
char *user_data)
52+
{
53+
Source_t *sources = target->sources;
54+
int n = target->sources_n;
55+
for (int i=0; i<n; i++)
56+
{
57+
Source_t *src = &sources[i];
58+
ProviderType_t type = src->provider->type;
59+
if (src->url)
60+
{
61+
/* 为空时才修改 或者里面是脏数据 */
62+
if (NULL==src->speed_measure_url || !chef_is_url (src->speed_measure_url))
63+
{
64+
src->speed_measure_url = func (src->url, user_data);
65+
}
66+
}
67+
}
68+
}
69+
70+
71+
/**
72+
* @brief 给 "换源 URL" 增加一个后缀来构造和填充专用测速链接
73+
*/
74+
void
75+
chef_set_sources_speed_measure_url_with_postfix (Target_t *target, char *postfix)
76+
{
77+
chef_set_sources_speed_measure_url_with_func (target, xy_2strjoin, postfix);
78+
}
79+
80+
2181
void
2282
chef_allow_english (Target_t *target)
2383
{

src/framework/core.c

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,6 @@ chsrc_confirm_source (Source_t *source)
10541054
}
10551055

10561056

1057-
10581057
Source_t
10591058
chsrc_yield_source_and_confirm (Target_t *t, char *option)
10601059
{
@@ -1064,70 +1063,6 @@ chsrc_yield_source_and_confirm (Target_t *t, char *option)
10641063
}
10651064

10661065

1067-
/**
1068-
* @brief 修改 Provider 的测速地址
1069-
*/
1070-
void
1071-
chsrc_set_provider_speed_measure_url (SourceProvider_t *provider, char *url)
1072-
{
1073-
provider->psmi.skip = NotSkip;
1074-
provider->psmi.url = xy_strdup (url);
1075-
chsrc_debug ("m", xy_strjoin (4, "recipe 重新为 ", provider->code, " 设置测速链接: ", url));
1076-
}
1077-
1078-
1079-
/**
1080-
* @brief 修改 Provider 的测速精度
1081-
*/
1082-
void
1083-
chsrc_set_provider_speed_measure_accuracy (SourceProvider_t *provider, bool accuracy)
1084-
{
1085-
provider->psmi.accurate = accuracy;
1086-
chsrc_debug ("m", xy_strjoin (4, "recipe 重新为 ", provider->code, " 设置测速精度: ", accuracy ? "精准" : "粗略"));
1087-
}
1088-
1089-
1090-
1091-
/**
1092-
* @brief 提供一个函数,这个函数基于 "换源 URL" 和用户提供的数据来构造和填充精准测速链接
1093-
*/
1094-
static void
1095-
chsrc_set_sources_speed_measure_url_with_func (
1096-
Target_t *target,
1097-
char *(*func)(const char *url, const char *user_data),
1098-
char *user_data)
1099-
{
1100-
Source_t *sources = target->sources;
1101-
int n = target->sources_n;
1102-
for (int i=0; i<n; i++)
1103-
{
1104-
Source_t *src = &sources[i];
1105-
ProviderType_t type = src->provider->type;
1106-
if (src->url)
1107-
{
1108-
/* 为空时才修改 或者里面是脏数据 */
1109-
if (NULL==src->speed_measure_url || !chef_is_url (src->speed_measure_url))
1110-
{
1111-
src->speed_measure_url = func (src->url, user_data);
1112-
}
1113-
}
1114-
}
1115-
}
1116-
1117-
1118-
1119-
/**
1120-
* @brief 给 "换源 URL" 增加一个后缀来构造和填充专用测速链接
1121-
*/
1122-
static void
1123-
chsrc_set_sources_speed_measure_url_with_postfix (Target_t *target, char *postfix)
1124-
{
1125-
chsrc_set_sources_speed_measure_url_with_func (target, xy_2strjoin, postfix);
1126-
}
1127-
1128-
1129-
1130-
11311066
void
11321067
chsrc_determine_chgtype (ChgType_t type)
11331068
{

src/recipe/lang/Dart/Flutter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pl_dart_flutter_prelude (void)
3333
{&Nju, "https://mirror.nju.edu.cn/flutter", FeedByPrelude}
3434
def_sources_end()
3535

36-
chsrc_set_sources_speed_measure_url_with_postfix (this, "/flutter_infra_release/releases/stable/linux/flutter_linux_v1.0.0-stable.tar.xz");
36+
chef_set_sources_speed_measure_url_with_postfix (this, "/flutter_infra_release/releases/stable/linux/flutter_linux_v1.0.0-stable.tar.xz");
3737
}
3838

3939

src/recipe/lang/Dart/Pub.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pl_dart_prelude (void)
3333
{&Nju, "https://mirror.nju.edu.cn/dart-pub", FeedByPrelude}
3434
def_sources_end()
3535

36-
chsrc_set_sources_speed_measure_url_with_postfix (this, "/packages/flutter_vision/versions/1.1.4.tar.gz");
36+
chef_set_sources_speed_measure_url_with_postfix (this, "/packages/flutter_vision/versions/1.1.4.tar.gz");
3737
}
3838

3939

src/recipe/lang/JavaScript/common.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pl_js_group_prelude (void)
4040
def_sources_end()
4141

4242
// 29MB 大小
43-
chsrc_set_sources_speed_measure_url_with_postfix (this, "/@tensorflow/tfjs/-/tfjs-4.22.0.tgz");
43+
chef_set_sources_speed_measure_url_with_postfix (this, "/@tensorflow/tfjs/-/tfjs-4.22.0.tgz");
4444
}
4545

4646

@@ -76,5 +76,5 @@ pl_js_nodejs_binary_prelude (void)
7676
{&Tencent, "https://mirrors.cloud.tencent.com/nodejs-release/", FeedByPrelude}
7777
def_sources_end()
7878

79-
chsrc_set_sources_speed_measure_url_with_postfix (this, "/v23.4.0/node-v23.4.0-linux-x64.tar.xz");
79+
chef_set_sources_speed_measure_url_with_postfix (this, "/v23.4.0/node-v23.4.0-linux-x64.tar.xz");
8080
}

src/recipe/lang/Python/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pl_python_group_prelude (void)
6363
// {&Netease, "https://mirrors.163.com/.help/pypi.html", NULL}
6464
def_sources_end()
6565

66-
chsrc_set_sources_speed_measure_url_with_func (this, pl_python_speed_url_constructor, NULL);
66+
chef_set_sources_speed_measure_url_with_func (this, pl_python_speed_url_constructor, NULL);
6767
}
6868

6969
void

src/recipe/lang/Rust/Cargo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pl_rust_cargo_prelude (void)
4848
{&Cqu, "https://mirrors.cqu.edu.cn/crates.io-index/", FeedByPrelude}
4949
def_sources_end()
5050

51-
chsrc_set_sources_speed_measure_url_with_postfix (this, "api/v1/crates/windows/0.58.0/download");
51+
chef_set_sources_speed_measure_url_with_postfix (this, "api/v1/crates/windows/0.58.0/download");
5252
}
5353

5454

src/recipe/lang/Rust/rustup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pl_rust_rustup_prelude (void)
4242
def_sources_end()
4343

4444
// 20MB大小
45-
chsrc_set_sources_speed_measure_url_with_postfix (this, "/dist/2025-06-26/cargo-1.88.0-x86_64-unknown-illumos.tar.gz");
45+
chef_set_sources_speed_measure_url_with_postfix (this, "/dist/2025-06-26/cargo-1.88.0-x86_64-unknown-illumos.tar.gz");
4646
}
4747

4848

src/recipe/os/APT/Debian.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ os_debian_prelude ()
4747
// {&Sohu, "https://mirrors.sohu.com/debian", FeedByPrelude}
4848
def_sources_end()
4949

50-
chsrc_set_sources_speed_measure_url_with_postfix (this, "/dists/bookworm/main/Contents-all.gz");
50+
chef_set_sources_speed_measure_url_with_postfix (this, "/dists/bookworm/main/Contents-all.gz");
5151
}
5252

5353

0 commit comments

Comments
 (0)