From f099a86e533532c8712a52b133af1ccb46ede3e6 Mon Sep 17 00:00:00 2001 From: Aoran Zeng Date: Mon, 11 Aug 2025 05:05:15 +0800 Subject: [PATCH] Use `chef_` --- doc/11-如何修改URL.md | 8 ++-- src/framework/chef.c | 60 ++++++++++++++++++++++++++ src/framework/core.c | 65 ----------------------------- src/recipe/lang/Dart/Flutter.c | 2 +- src/recipe/lang/Dart/Pub.c | 2 +- src/recipe/lang/JavaScript/common.h | 4 +- src/recipe/lang/Python/common.h | 2 +- src/recipe/lang/Rust/Cargo.c | 2 +- src/recipe/lang/Rust/rustup.c | 2 +- src/recipe/os/APT/Debian.c | 2 +- src/recipe/os/APT/Ubuntu.c | 2 +- src/recipe/os/Alpine-Linux.c | 2 +- src/recipe/os/OpenWrt.c | 2 +- src/recipe/os/Void-Linux.c | 2 +- src/recipe/os/YUM/AlmaLinux.c | 2 +- src/recipe/os/YUM/openEuler.c | 2 +- src/recipe/ware/Flatpak.c | 12 +++--- 17 files changed, 84 insertions(+), 89 deletions(-) diff --git a/doc/11-如何修改URL.md b/doc/11-如何修改URL.md index 5cd916e..4432e6e 100644 --- a/doc/11-如何修改URL.md +++ b/doc/11-如何修改URL.md @@ -52,12 +52,12 @@ def_sources_begin() def_sources_end() // 把所有上述源的测速 URL 设置为 "换源 URL" + postfix -chsrc_set_sources_speed_measure_url_with_postfix (this, "/dir/BigFile.tar.gz"); +chef_set_sources_speed_measure_url_with_postfix (this, "/dir/BigFile.tar.gz"); // 基于 "换源 URL" 做更自定义的操作 -chsrc_set_sources_speed_measure_url_with_func (this, func, data); +chef_set_sources_speed_measure_url_with_func (this, func, data); // 调整某一个镜像站(Provider)的测速 URL -chsrc_set_provider_speed_measure_url (&Tencent, "https://mirrors.cloud.tencent.com/npm/BigFile.tar.gz") +chef_set_provider_speed_measure_url (&Tencent, "https://mirrors.cloud.tencent.com/npm/BigFile.tar.gz") // 调整某一个镜像站(Provider)的测速精度 -chsrc_set_provider_speed_measure_accuracy (&UpstreamProvider, ROUGH);; +chef_set_provider_speed_measure_accuracy (&UpstreamProvider, ROUGH);; ``` diff --git a/src/framework/chef.c b/src/framework/chef.c index d598e1f..991ac0c 100644 --- a/src/framework/chef.c +++ b/src/framework/chef.c @@ -18,6 +18,66 @@ #define chef_allow_gs(t) this->getfn = t##_getsrc; this->setfn = t##_setsrc; this->resetfn = NULL; +/** + * @brief 修改 Provider 的测速地址 + */ +void +chef_set_provider_speed_measure_url (SourceProvider_t *provider, char *url) +{ + provider->psmi.skip = NotSkip; + provider->psmi.url = xy_strdup (url); + chsrc_debug ("m", xy_strjoin (4, "recipe 重新为 ", provider->code, " 设置测速链接: ", url)); +} + + +/** + * @brief 修改 Provider 的测速精度 + */ +void +chef_set_provider_speed_measure_accuracy (SourceProvider_t *provider, bool accuracy) +{ + provider->psmi.accurate = accuracy; + chsrc_debug ("m", xy_strjoin (4, "recipe 重新为 ", provider->code, " 设置测速精度: ", accuracy ? "精准" : "粗略")); +} + + +/** + * @brief 提供一个函数,这个函数基于 "换源 URL" 和用户提供的数据来构造和填充精准测速链接 + */ +void +chef_set_sources_speed_measure_url_with_func ( + Target_t *target, + char *(*func)(const char *url, const char *user_data), + char *user_data) +{ + Source_t *sources = target->sources; + int n = target->sources_n; + for (int i=0; iprovider->type; + if (src->url) + { + /* 为空时才修改 或者里面是脏数据 */ + if (NULL==src->speed_measure_url || !chef_is_url (src->speed_measure_url)) + { + src->speed_measure_url = func (src->url, user_data); + } + } + } +} + + +/** + * @brief 给 "换源 URL" 增加一个后缀来构造和填充专用测速链接 + */ +void +chef_set_sources_speed_measure_url_with_postfix (Target_t *target, char *postfix) +{ + chef_set_sources_speed_measure_url_with_func (target, xy_2strjoin, postfix); +} + + void chef_allow_english (Target_t *target) { diff --git a/src/framework/core.c b/src/framework/core.c index 2158086..ec6390f 100644 --- a/src/framework/core.c +++ b/src/framework/core.c @@ -1054,7 +1054,6 @@ chsrc_confirm_source (Source_t *source) } - Source_t chsrc_yield_source_and_confirm (Target_t *t, char *option) { @@ -1064,70 +1063,6 @@ chsrc_yield_source_and_confirm (Target_t *t, char *option) } -/** - * @brief 修改 Provider 的测速地址 - */ -void -chsrc_set_provider_speed_measure_url (SourceProvider_t *provider, char *url) -{ - provider->psmi.skip = NotSkip; - provider->psmi.url = xy_strdup (url); - chsrc_debug ("m", xy_strjoin (4, "recipe 重新为 ", provider->code, " 设置测速链接: ", url)); -} - - -/** - * @brief 修改 Provider 的测速精度 - */ -void -chsrc_set_provider_speed_measure_accuracy (SourceProvider_t *provider, bool accuracy) -{ - provider->psmi.accurate = accuracy; - chsrc_debug ("m", xy_strjoin (4, "recipe 重新为 ", provider->code, " 设置测速精度: ", accuracy ? "精准" : "粗略")); -} - - - -/** - * @brief 提供一个函数,这个函数基于 "换源 URL" 和用户提供的数据来构造和填充精准测速链接 - */ -static void -chsrc_set_sources_speed_measure_url_with_func ( - Target_t *target, - char *(*func)(const char *url, const char *user_data), - char *user_data) -{ - Source_t *sources = target->sources; - int n = target->sources_n; - for (int i=0; iprovider->type; - if (src->url) - { - /* 为空时才修改 或者里面是脏数据 */ - if (NULL==src->speed_measure_url || !chef_is_url (src->speed_measure_url)) - { - src->speed_measure_url = func (src->url, user_data); - } - } - } -} - - - -/** - * @brief 给 "换源 URL" 增加一个后缀来构造和填充专用测速链接 - */ -static void -chsrc_set_sources_speed_measure_url_with_postfix (Target_t *target, char *postfix) -{ - chsrc_set_sources_speed_measure_url_with_func (target, xy_2strjoin, postfix); -} - - - - void chsrc_determine_chgtype (ChgType_t type) { diff --git a/src/recipe/lang/Dart/Flutter.c b/src/recipe/lang/Dart/Flutter.c index 69189d8..0139575 100644 --- a/src/recipe/lang/Dart/Flutter.c +++ b/src/recipe/lang/Dart/Flutter.c @@ -33,7 +33,7 @@ pl_dart_flutter_prelude (void) {&Nju, "https://mirror.nju.edu.cn/flutter", FeedByPrelude} def_sources_end() - chsrc_set_sources_speed_measure_url_with_postfix (this, "/flutter_infra_release/releases/stable/linux/flutter_linux_v1.0.0-stable.tar.xz"); + chef_set_sources_speed_measure_url_with_postfix (this, "/flutter_infra_release/releases/stable/linux/flutter_linux_v1.0.0-stable.tar.xz"); } diff --git a/src/recipe/lang/Dart/Pub.c b/src/recipe/lang/Dart/Pub.c index b61c3bd..e53eee2 100644 --- a/src/recipe/lang/Dart/Pub.c +++ b/src/recipe/lang/Dart/Pub.c @@ -33,7 +33,7 @@ pl_dart_prelude (void) {&Nju, "https://mirror.nju.edu.cn/dart-pub", FeedByPrelude} def_sources_end() - chsrc_set_sources_speed_measure_url_with_postfix (this, "/packages/flutter_vision/versions/1.1.4.tar.gz"); + chef_set_sources_speed_measure_url_with_postfix (this, "/packages/flutter_vision/versions/1.1.4.tar.gz"); } diff --git a/src/recipe/lang/JavaScript/common.h b/src/recipe/lang/JavaScript/common.h index 763f463..cb00110 100644 --- a/src/recipe/lang/JavaScript/common.h +++ b/src/recipe/lang/JavaScript/common.h @@ -40,7 +40,7 @@ pl_js_group_prelude (void) def_sources_end() // 29MB 大小 - chsrc_set_sources_speed_measure_url_with_postfix (this, "/@tensorflow/tfjs/-/tfjs-4.22.0.tgz"); + chef_set_sources_speed_measure_url_with_postfix (this, "/@tensorflow/tfjs/-/tfjs-4.22.0.tgz"); } @@ -76,5 +76,5 @@ pl_js_nodejs_binary_prelude (void) {&Tencent, "https://mirrors.cloud.tencent.com/nodejs-release/", FeedByPrelude} def_sources_end() - chsrc_set_sources_speed_measure_url_with_postfix (this, "/v23.4.0/node-v23.4.0-linux-x64.tar.xz"); + chef_set_sources_speed_measure_url_with_postfix (this, "/v23.4.0/node-v23.4.0-linux-x64.tar.xz"); } diff --git a/src/recipe/lang/Python/common.h b/src/recipe/lang/Python/common.h index 1d61afe..9045dd5 100644 --- a/src/recipe/lang/Python/common.h +++ b/src/recipe/lang/Python/common.h @@ -63,7 +63,7 @@ pl_python_group_prelude (void) // {&Netease, "https://mirrors.163.com/.help/pypi.html", NULL} def_sources_end() - chsrc_set_sources_speed_measure_url_with_func (this, pl_python_speed_url_constructor, NULL); + chef_set_sources_speed_measure_url_with_func (this, pl_python_speed_url_constructor, NULL); } void diff --git a/src/recipe/lang/Rust/Cargo.c b/src/recipe/lang/Rust/Cargo.c index 6b21021..43a89cc 100644 --- a/src/recipe/lang/Rust/Cargo.c +++ b/src/recipe/lang/Rust/Cargo.c @@ -48,7 +48,7 @@ pl_rust_cargo_prelude (void) {&Cqu, "https://mirrors.cqu.edu.cn/crates.io-index/", FeedByPrelude} def_sources_end() - chsrc_set_sources_speed_measure_url_with_postfix (this, "api/v1/crates/windows/0.58.0/download"); + chef_set_sources_speed_measure_url_with_postfix (this, "api/v1/crates/windows/0.58.0/download"); } diff --git a/src/recipe/lang/Rust/rustup.c b/src/recipe/lang/Rust/rustup.c index 854aa1f..637c236 100644 --- a/src/recipe/lang/Rust/rustup.c +++ b/src/recipe/lang/Rust/rustup.c @@ -42,7 +42,7 @@ pl_rust_rustup_prelude (void) def_sources_end() // 20MB大小 - chsrc_set_sources_speed_measure_url_with_postfix (this, "/dist/2025-06-26/cargo-1.88.0-x86_64-unknown-illumos.tar.gz"); + chef_set_sources_speed_measure_url_with_postfix (this, "/dist/2025-06-26/cargo-1.88.0-x86_64-unknown-illumos.tar.gz"); } diff --git a/src/recipe/os/APT/Debian.c b/src/recipe/os/APT/Debian.c index 28032bc..ecb935a 100644 --- a/src/recipe/os/APT/Debian.c +++ b/src/recipe/os/APT/Debian.c @@ -47,7 +47,7 @@ os_debian_prelude () // {&Sohu, "https://mirrors.sohu.com/debian", FeedByPrelude} def_sources_end() - chsrc_set_sources_speed_measure_url_with_postfix (this, "/dists/bookworm/main/Contents-all.gz"); + chef_set_sources_speed_measure_url_with_postfix (this, "/dists/bookworm/main/Contents-all.gz"); } diff --git a/src/recipe/os/APT/Ubuntu.c b/src/recipe/os/APT/Ubuntu.c index 986636a..2d16f2b 100644 --- a/src/recipe/os/APT/Ubuntu.c +++ b/src/recipe/os/APT/Ubuntu.c @@ -48,7 +48,7 @@ os_ubuntu_prelude () // {&Sohu, "https://mirrors.sohu.com/ubuntu", FeedByPrelude} def_sources_end() - chsrc_set_sources_speed_measure_url_with_postfix (this, "/dists/noble/Contents-amd64.gz"); + chef_set_sources_speed_measure_url_with_postfix (this, "/dists/noble/Contents-amd64.gz"); } diff --git a/src/recipe/os/Alpine-Linux.c b/src/recipe/os/Alpine-Linux.c index 0b9fe54..f9f7a29 100644 --- a/src/recipe/os/Alpine-Linux.c +++ b/src/recipe/os/Alpine-Linux.c @@ -38,7 +38,7 @@ os_alpine_prelude () {&Huawei, "https://mirrors.huaweicloud.com/alpine", FeedByPrelude} def_sources_end() - chsrc_set_sources_speed_measure_url_with_postfix (this, "/latest-stable/releases/x86_64/alpine-standard-3.21.0-x86_64.iso"); + chef_set_sources_speed_measure_url_with_postfix (this, "/latest-stable/releases/x86_64/alpine-standard-3.21.0-x86_64.iso"); } diff --git a/src/recipe/os/OpenWrt.c b/src/recipe/os/OpenWrt.c index 75a42e2..6f02ba6 100644 --- a/src/recipe/os/OpenWrt.c +++ b/src/recipe/os/OpenWrt.c @@ -39,7 +39,7 @@ os_openwrt_prelude () {&Sustech, "https://mirrors.sustech.edu.cn/openwrt", DelegateToMirror} def_sources_end() - chsrc_set_provider_speed_measure_url (&UpstreamProvider, "https://downloads.openwrt.org/releases/23.05.5/targets/x86/64/openwrt-sdk-23.05.5-x86-64_gcc-12.3.0_musl.Linux-x86_64.tar.xz"); + chef_set_provider_speed_measure_url (&UpstreamProvider, "https://downloads.openwrt.org/releases/23.05.5/targets/x86/64/openwrt-sdk-23.05.5-x86-64_gcc-12.3.0_musl.Linux-x86_64.tar.xz"); } diff --git a/src/recipe/os/Void-Linux.c b/src/recipe/os/Void-Linux.c index e3cb9aa..c984e46 100644 --- a/src/recipe/os/Void-Linux.c +++ b/src/recipe/os/Void-Linux.c @@ -33,7 +33,7 @@ os_voidlinux_prelude () {&Bfsu, "https://mirrors.bfsu.edu.cn/voidlinux", FeedByPrelude} def_sources_end() - chsrc_set_sources_speed_measure_url_with_postfix (this, "/live/20240314/void-live-x86_64-musl-20240314-xfce.iso"); + chef_set_sources_speed_measure_url_with_postfix (this, "/live/20240314/void-live-x86_64-musl-20240314-xfce.iso"); } diff --git a/src/recipe/os/YUM/AlmaLinux.c b/src/recipe/os/YUM/AlmaLinux.c index 4b9c1bb..ecfb04c 100644 --- a/src/recipe/os/YUM/AlmaLinux.c +++ b/src/recipe/os/YUM/AlmaLinux.c @@ -35,7 +35,7 @@ os_almalinux_prelude () {&Nju, "https://mirror.nju.edu.cn/almalinux", FeedByPrelude} def_sources_end() - chsrc_set_provider_speed_measure_url (&UpstreamProvider, "https://raw.repo.almalinux.org/almalinux/9.5/isos/x86_64/AlmaLinux-9-latest-x86_64-minimal.iso"); + chef_set_provider_speed_measure_url (&UpstreamProvider, "https://raw.repo.almalinux.org/almalinux/9.5/isos/x86_64/AlmaLinux-9-latest-x86_64-minimal.iso"); } /** diff --git a/src/recipe/os/YUM/openEuler.c b/src/recipe/os/YUM/openEuler.c index a18be2e..98ddc6e 100644 --- a/src/recipe/os/YUM/openEuler.c +++ b/src/recipe/os/YUM/openEuler.c @@ -44,7 +44,7 @@ os_openeuler_prelude () // {&Sohu, "https://mirrors.sohu.com/openeuler/", FeedByPrelude} def_sources_end() - chsrc_set_sources_speed_measure_url_with_postfix (this, "https://repo.openeuler.org/openEuler-24.03-LTS/ISO/x86_64/openEuler-24.03-LTS-netinst-x86_64-dvd.iso"); + chef_set_sources_speed_measure_url_with_postfix (this, "https://repo.openeuler.org/openEuler-24.03-LTS/ISO/x86_64/openEuler-24.03-LTS-netinst-x86_64-dvd.iso"); } diff --git a/src/recipe/ware/Flatpak.c b/src/recipe/ware/Flatpak.c index 84a5603..7a010d4 100644 --- a/src/recipe/ware/Flatpak.c +++ b/src/recipe/ware/Flatpak.c @@ -34,9 +34,9 @@ wr_flatpak_prelude () def_sources_end() - chsrc_set_provider_speed_measure_url (&UpstreamProvider, "https://flathub.org/repo/flathub.gpg"); + chef_set_provider_speed_measure_url (&UpstreamProvider, "https://flathub.org/repo/flathub.gpg"); /* upstream 默认是 ACCURATE 的,但是我们给了一个超小的文件,测速效果严重失真,所以改为 ROUGH */ - chsrc_set_provider_speed_measure_accuracy (&UpstreamProvider, ROUGH); + chef_set_provider_speed_measure_accuracy (&UpstreamProvider, ROUGH); /** * @note 下述上海交大两个镜像站都可使用,但实际使用时出现过无法访问的情况 (GitHub-#178), @@ -44,11 +44,11 @@ wr_flatpak_prelude () * 若无速度,则证明无法访问。 * 注意,这会使得测速的效果严重失真。 */ - chsrc_set_provider_speed_measure_url (&Sjtug_Siyuan, "https://mirror.sjtu.edu.cn/flathub/flathub.gpg"); - chsrc_set_provider_speed_measure_url (&Sjtug_Zhiyuan, "https://mirrors.sjtug.sjtu.edu.cn/flathub/flathub.gpg"); + chef_set_provider_speed_measure_url (&Sjtug_Siyuan, "https://mirror.sjtu.edu.cn/flathub/flathub.gpg"); + chef_set_provider_speed_measure_url (&Sjtug_Zhiyuan, "https://mirrors.sjtug.sjtu.edu.cn/flathub/flathub.gpg"); /* 由于实在找不到其他可测文件,所以这也只能是 ROUGH */ - chsrc_set_provider_speed_measure_accuracy (&Sjtug_Siyuan, ROUGH); - chsrc_set_provider_speed_measure_accuracy (&Sjtug_Zhiyuan, ROUGH); + chef_set_provider_speed_measure_accuracy (&Sjtug_Siyuan, ROUGH); + chef_set_provider_speed_measure_accuracy (&Sjtug_Zhiyuan, ROUGH); }