diff --git a/src/chsrc-main.c b/src/chsrc-main.c index 010efe0..56abb1b 100644 --- a/src/chsrc-main.c +++ b/src/chsrc-main.c @@ -13,13 +13,13 @@ * | Terrasse * | * Created On : <2023-08-28> - * Last Modified : <2024-09-13> + * Last Modified : <2024-09-14> * * chsrc: Change Source —— 全平台通用命令行换源工具 * ------------------------------------------------------------*/ -#define Chsrc_Version "0.1.8.2.dev1" -#define Chsrc_Release_Date "2024/09/13" +#define Chsrc_Version "0.1.8.2.dev2" +#define Chsrc_Release_Date "2024/09/14" #define Chsrc_Banner_Version "v" Chsrc_Version "-" Chsrc_Release_Date #define Chsrc_Maintain_URL "https://github.com/RubyMetric/chsrc" #define Chsrc_Maintain_URL2 "https://gitee.com/RubyMetric/chsrc" @@ -46,7 +46,10 @@ #include "recipe/lang/Go.c" #include "recipe/lang/Java.c" #include "recipe/lang/Rust.c" -#include "recipe/lang/Dart.c" + +#include "recipe/lang/Dart/Pub.c" +#include "recipe/lang/Dart/Flutter.c" + #include "recipe/lang/Haskell.c" #include "recipe/lang/OCaml.c" #include "recipe/lang/R.c" diff --git a/src/recipe/lang/Dart.c b/src/recipe/lang/Dart.c deleted file mode 100644 index 84a257a..0000000 --- a/src/recipe/lang/Dart.c +++ /dev/null @@ -1,119 +0,0 @@ -/** ------------------------------------------------------------ - * SPDX-License-Identifier: GPL-3.0-or-later - * ------------------------------------------------------------- - * File Authors : Aoran Zeng - * Contributors : Nil Null - * Created On : <2023-09-10> - * Major Revision : 2 - * Last Modified : <2024-09-14> - * ------------------------------------------------------------*/ - -/** - * @update 2024-09-14 - * @note { - * 我们这里挑选的必须也支持 Flutter - * 我们将会在setsrc函数中生成 - * 1. https://mirrors.tuna.tsinghua.edu.cn/dart-pub - * 2. https://mirrors.tuna.tsinghua.edu.cn/flutter - * } - */ -static SourceInfo -pl_dart_sources[] = { - {&Upstream, NULL}, - {&Sjtug_Zhiyuan, "https://mirror.sjtu.edu.cn/"}, // 不确定SJTUG的flutter镜像给的对不对 - {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/"}, - {&Tencent, "https://mirrors.cloud.tencent.com/"}, - // {&Tencent_Intra, "https://mirrors.cloud.tencentyun.com/"}, - {&Nju, "https://mirror.nju.edu.cn/"} -}; -def_sources_n(pl_dart); - - -void -pl_dart_getsrc (char *option) -{ - char *cmd = NULL; - if (xy_on_windows) - { - cmd = "set PUB_HOSTED_URL & set FLUTTER_STORAGE_BASE_URL"; - chsrc_run (cmd, RunOpt_Default); - } - else - { - cmd = "echo $PUB_HOSTED_URL; echo $FLUTTER_STORAGE_BASE_URL"; - chsrc_run (cmd, RunOpt_Default); - } -} - -/** - * Dart pub 换源,参考:https://mirrors.tuna.tsinghua.edu.cn/help/dart-pub/ - */ -void -pl_dart_setsrc (char *option) -{ - chsrc_yield_source_and_confirm (pl_dart); - - char *towrite1, *towrite2 = NULL; - - char *pub = xy_2strjoin (source.url, "dart-pub"); - char *flutter = xy_2strjoin (source.url, "flutter"); - - if (xy_on_windows) - { - towrite1 = xy_strjoin (3, "$env:PUB_HOSTED_URL = \"", pub, "\""); - towrite2 = xy_strjoin (3, "$env:FLUTTER_STORAGE_BASE_URL = \"", flutter, "\""); - - if (xy_file_exist (xy_win_powershell_profile)) - { - chsrc_append_to_file (towrite1, xy_win_powershell_profile); - chsrc_append_to_file (towrite2, xy_win_powershell_profile); - } - - if (xy_file_exist (xy_win_powershellv5_profile)) - { - chsrc_append_to_file (towrite1, xy_win_powershellv5_profile); - chsrc_append_to_file (towrite2, xy_win_powershellv5_profile); - } - } - else - { - char *zshrc = "~/.zshrc"; - char *bashrc = "~/.bashrc"; - - chsrc_backup (zshrc); - towrite1 = xy_strjoin (3, "export PUB_HOSTED_URL=\"", pub, "\""); - towrite2 = xy_strjoin (3, "export FLUTTER_STORAGE_BASE_URL=\"", flutter, "\""); - chsrc_append_to_file (towrite1, zshrc); - chsrc_append_to_file (towrite2, zshrc); - - if (xy_file_exist (bashrc)) - { - chsrc_backup (bashrc); - chsrc_append_to_file (towrite1, bashrc); - chsrc_append_to_file (towrite2, bashrc); - } - } - chsrc_conclude (&source, ChsrcTypeAuto); -} - - -FeatInfo -pl_dart_feat (char *option) -{ - FeatInfo fi = {0}; - - fi.can_get = true; - fi.can_reset = false; - - fi.stcan_locally = CanNot; - fi.locally = NULL; - fi.can_english = true; - - /* 该换源方案中,URL存在拼凑,因此不能让用户手动使用某URL来换源 */ - fi.can_user_define = false; - - fi.note = "该换源通过写入环境变量实现,若多次换源,请手动清理profile文件"; - return fi; -} - -def_target_gsf(pl_dart); diff --git a/src/recipe/lang/Dart/Flutter.c b/src/recipe/lang/Dart/Flutter.c new file mode 100644 index 0000000..19081c4 --- /dev/null +++ b/src/recipe/lang/Dart/Flutter.c @@ -0,0 +1,110 @@ +/** ------------------------------------------------------------ + * SPDX-License-Identifier: GPL-3.0-or-later + * ------------------------------------------------------------- + * File Authors : Aoran Zeng + * Contributors : Nil Null + * Created On : <2023-09-10> + * Major Revision : 2 + * Last Modified : <2024-09-14> + * + * 2024-09-14: 不得不将Dart和Flutter拆分为两个Target, + * 因为3家教育网镜像站给出的 Dart 和 Flutter 换源URL模式都不一样 + * ------------------------------------------------------------*/ + +/** + * @update 2024-09-14 + */ +static SourceInfo +pl_dart_flutter_sources[] = { + {&Upstream, NULL}, + {&Sjtug_Zhiyuan, "https://mirror.sjtu.edu.cn"}, // 没有后缀,怀疑是否存在问题 + {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/git/flutter"}, // URL 带 git + {&Nju, "https://mirror.nju.edu.cn/flutter"} +}; +def_sources_n(pl_dart_flutter); + + +/** + * chsrc get flutter + */ +void +pl_dart_flutter_getsrc (char *option) +{ + char *cmd = NULL; + if (xy_on_windows) + { + // cmd = "set PUB_HOSTED_URL & set FLUTTER_STORAGE_BASE_URL"; + cmd = "set FLUTTER_STORAGE_BASE_URL"; + chsrc_run (cmd, RunOpt_No_Last_New_Line); + } + else + { + cmd = "echo $FLUTTER_STORAGE_BASE_URL"; + chsrc_run (cmd, RunOpt_No_Last_New_Line); + } +} + + +/** + * @consult https://mirrors.tuna.tsinghua.edu.cn/flutter + * @consult https://mirror.sjtu.edu.cn/docs/flutter_infra + * @consult https://mirror.nju.edu.cn/mirrorz-help/flutter/?mirror=NJU + */ +void +pl_dart_flutter_setsrc (char *option) +{ + chsrc_yield_source_and_confirm (pl_dart_flutter); + + char *towrite = NULL; + + if (xy_on_windows) + { + towrite = xy_strjoin (3, "$env:FLUTTER_STORAGE_BASE_URL = \"", source.url, "\""); + + if (xy_file_exist (xy_win_powershell_profile)) + chsrc_append_to_file (towrite, xy_win_powershell_profile); + + if (xy_file_exist (xy_win_powershellv5_profile)) + chsrc_append_to_file (towrite, xy_win_powershellv5_profile); + } + else + { + char *zshrc = "~/.zshrc"; + char *bashrc = "~/.bashrc"; + + chsrc_backup (zshrc); + towrite = xy_strjoin (3, "export FLUTTER_STORAGE_BASE_URL=\"", source.url, "\""); + chsrc_append_to_file (towrite, zshrc); + + if (xy_file_exist (bashrc)) + { + chsrc_backup (bashrc); + chsrc_append_to_file (towrite, bashrc); + } + } + chsrc_conclude (&source, ChsrcTypeAuto); +} + + +/** + * chsrc ls flutter + */ +FeatInfo +pl_dart_flutter_feat (char *option) +{ + FeatInfo fi = {0}; + + fi.can_get = true; + fi.can_reset = false; + + fi.stcan_locally = CanNot; + fi.locally = NULL; + fi.can_english = true; + + fi.can_user_define = true; + + fi.note = "该换源通过写入环境变量实现,若多次换源,请手动清理profile文件"; + return fi; +} + +def_target_gsf(pl_dart_flutter); diff --git a/src/recipe/lang/Dart/Pub.c b/src/recipe/lang/Dart/Pub.c new file mode 100644 index 0000000..cf8a66a --- /dev/null +++ b/src/recipe/lang/Dart/Pub.c @@ -0,0 +1,103 @@ +/** ------------------------------------------------------------ + * SPDX-License-Identifier: GPL-3.0-or-later + * ------------------------------------------------------------- + * File Authors : Aoran Zeng + * Contributors : Nil Null + * Created On : <2023-09-10> + * Major Revision : 3 + * Last Modified : <2024-09-14> + * + * Dart Pub 软件仓库 + * ------------------------------------------------------------*/ + +/** + * @update 2024-09-14 + */ +static SourceInfo +pl_dart_sources[] = { + {&Upstream, NULL}, + {&Sjtug_Zhiyuan, "https://mirror.sjtu.edu.cn/dart-pub"}, + {&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/dart-pub"}, + {&Nju, "https://mirror.nju.edu.cn/dart-pub"} +}; +def_sources_n(pl_dart); + + +void +pl_dart_getsrc (char *option) +{ + char *cmd = NULL; + if (xy_on_windows) + { + // cmd = "set PUB_HOSTED_URL & set FLUTTER_STORAGE_BASE_URL"; + cmd = "set PUB_HOSTED_URL"; + chsrc_run (cmd, RunOpt_Default); + } + else + { + cmd = "echo $PUB_HOSTED_URL"; + chsrc_run (cmd, RunOpt_Default); + } +} + +/** + * @consult https://mirrors.tuna.tsinghua.edu.cn/help/dart-pub/ + * @consult https://mirror.sjtu.edu.cn/docs/dart-pub + * @consult https://mirror.nju.edu.cn/mirrorz-help/dart-pub/?mirror=NJU + */ +void +pl_dart_setsrc (char *option) +{ + chsrc_yield_source_and_confirm (pl_dart); + + char *towrite = NULL; + + if (xy_on_windows) + { + towrite = xy_strjoin (3, "$env:PUB_HOSTED_URL = \"", source.url, "\""); + + if (xy_file_exist (xy_win_powershell_profile)) + chsrc_append_to_file (towrite, xy_win_powershell_profile); + + if (xy_file_exist (xy_win_powershellv5_profile)) + chsrc_append_to_file (towrite, xy_win_powershellv5_profile); + } + else + { + char *zshrc = "~/.zshrc"; + char *bashrc = "~/.bashrc"; + + chsrc_backup (zshrc); + towrite = xy_strjoin (3, "export PUB_HOSTED_URL=\"", source.url, "\""); + + chsrc_append_to_file (towrite, zshrc); + + if (xy_file_exist (bashrc)) + { + chsrc_backup (bashrc); + chsrc_append_to_file (towrite, bashrc); + } + } + chsrc_conclude (&source, ChsrcTypeAuto); +} + + +FeatInfo +pl_dart_feat (char *option) +{ + FeatInfo fi = {0}; + + fi.can_get = true; + fi.can_reset = false; + + fi.stcan_locally = CanNot; + fi.locally = NULL; + fi.can_english = true; + + fi.can_user_define = true; + + fi.note = "该换源通过写入环境变量实现,若多次换源,请手动清理profile文件"; + return fi; +} + +def_target_gsf(pl_dart); diff --git a/src/recipe/menu.c b/src/recipe/menu.c index 08cc3c5..534f0cc 100644 --- a/src/recipe/menu.c +++ b/src/recipe/menu.c @@ -29,7 +29,10 @@ static const char *pl_rust [] = {"rust", "cargo", "crate", "crates", NULL, t(&pl_rust_target)}, *pl_java [] = {"java", "maven", "mvn", "gradle", NULL, t(&pl_java_target)}, *pl_clojure[]= {"clojure","clojars","cloj", "lein", "leiningen", NULL, t(&pl_clojure_target)}, -*pl_dart [] = {"dart", "pub", "flutter", NULL, t(&pl_dart_target)}, + +*pl_dart [] = {"dart", "pub", NULL, t(&pl_dart_target)}, +*pl_dart_flutter [] = {"flutter",NULL, t(&pl_dart_flutter_target)}, + *pl_nuget[] = {"nuget", "net", ".net", "dotnet", NULL, t(&pl_nuget_target)}, *pl_haskell[]= {"haskell", "cabal", "stack", "hackage", NULL, t(&pl_haskell_target)}, *pl_ocaml[] = {"ocaml", "opam", NULL, t(&pl_ocaml_target)}, @@ -45,7 +48,7 @@ static const char pl_rust, pl_go, /*pl_nuget,*/ pl_java, pl_clojure, - pl_dart, + pl_dart, pl_dart_flutter, pl_ocaml, pl_r, pl_julia, pl_haskell,