Bump version to v0.1.3

This commit is contained in:
Aoran Zeng 2024-04-18 23:16:50 +08:00
parent 6ff06c41b4
commit 58da758b21

574
chsrc.c
View File

@ -12,68 +12,71 @@
* GPLv3 LICENSE.txt * GPLv3 LICENSE.txt
* ------------------------------------------------------------*/ * ------------------------------------------------------------*/
#define Chsrc_Version "v0.1.2-2023/10/05" #define Chsrc_Version "v0.1.3-2024/04/18"
#include "chsrc.h" #include "chsrc.h"
void void
pl_ruby_getsrc (char* option) pl_ruby_getsrc (char *option)
{ {
chsrc_run("gem sources"); chsrc_run ("gem sources");
chsrc_run("bundle config get mirror.https://rubygems.org"); chsrc_run ("bundle config get mirror.https://rubygems.org");
} }
void void
pl_ruby_remove_gem_source (const char* source) pl_ruby_remove_gem_source (const char *source)
{ {
char* cmd = NULL; char *cmd = NULL;
if (xy_str_start_with(source, "http")){ if (xy_str_start_with (source, "http"))
cmd = xy_str_delete_suffix(source, "\n"); {
cmd = xy_2strjoin("gem sources -r ", cmd); cmd = xy_str_delete_suffix (source, "\n");
chsrc_run(cmd); cmd = xy_2strjoin ("gem sources -r ", cmd);
} chsrc_run (cmd);
}
} }
/** /**
* Ruby换源https://gitee.com/RubyMetric/rbenv-cn * Ruby换源https://gitee.com/RubyMetric/rbenv-cn
*/ */
void void
pl_ruby_setsrc (char* option) pl_ruby_setsrc (char *option)
{ {
int index = 0; int index = 0;
char* check_cmd = xy_str_to_quietcmd("gem -v"); char *check_cmd = xy_str_to_quietcmd ("gem -v");
bool exist = query_program_exist (check_cmd, "gem"); bool exist = query_program_exist (check_cmd, "gem");
if (!exist) { if (!exist)
chsrc_error ("未找到 gem 命令,请检查是否存在"); {
return; chsrc_error ("未找到 gem 命令,请检查是否存在");
} return;
}
index = use_specific_mirror_or_auto_select (option, pl_ruby); index = use_specific_mirror_or_auto_select (option, pl_ruby);
SourceInfo source = pl_ruby_sources[index]; SourceInfo source = pl_ruby_sources[index];
chsrc_say_selection (&source); chsrc_say_selection (&source);
char* cmd = NULL; char *cmd = NULL;
xy_getcmd ("gem sources -l", 0, pl_ruby_remove_gem_source); xy_getcmd ("gem sources -l", 0, pl_ruby_remove_gem_source);
cmd = xy_2strjoin("gem source -a ", source.url); cmd = xy_2strjoin ("gem source -a ", source.url);
chsrc_run(cmd); chsrc_run (cmd);
check_cmd = xy_str_to_quietcmd("bundle -v"); check_cmd = xy_str_to_quietcmd ("bundle -v");
exist = query_program_exist (check_cmd, "bundle"); exist = query_program_exist (check_cmd, "bundle");
if (!exist) { if (!exist)
chsrc_error ("未找到 bundle 命令,请检查是否存在"); {
return; chsrc_error ("未找到 bundle 命令,请检查是否存在");
} return;
}
cmd = xy_2strjoin("bundle config 'mirror.https://rubygems.org' ", source.url); cmd = xy_2strjoin ("bundle config 'mirror.https://rubygems.org' ", source.url);
chsrc_run(cmd); chsrc_run (cmd);
chsrc_say_thanks(&source); chsrc_say_thanks (&source);
// puts(""); // puts ("");
// chsrc_warn("维护者提醒您: Ruby的镜像源目前仅有 腾讯软件源RubyChina华为开源镜像站 实现正确"); // chsrc_warn ("维护者提醒您: Ruby的镜像源目前仅有 腾讯软件源RubyChina华为开源镜像站 实现正确");
// chsrc_warn("而其它如Tuna,Bfsu,Ali目前都实现的有问题请勿使用"); // chsrc_warn ("而其它如Tuna,Bfsu,Ali目前都实现的有问题请勿使用");
} }
@ -82,35 +85,38 @@ pl_ruby_setsrc (char* option)
* @param[out] prog Python NULL * @param[out] prog Python NULL
*/ */
void void
pl_python_check_cmd (char** prog) pl_python_check_cmd (char **prog)
{ {
*prog = NULL; *prog = NULL;
// 不要调用 python 自己,而是使用 python --version避免Windows弹出Microsoft Store // 不要调用 python 自己,而是使用 python --version避免Windows弹出Microsoft Store
char* check_cmd = xy_str_to_quietcmd("python --version"); char *check_cmd = xy_str_to_quietcmd ("python --version");
bool exist = query_program_exist (check_cmd, "python"); bool exist = query_program_exist (check_cmd, "python");
if (!exist) { if (!exist)
check_cmd = xy_str_to_quietcmd("python3 --version"); {
exist = query_program_exist (check_cmd, "python3"); check_cmd = xy_str_to_quietcmd ("python3 --version");
if (exist) *prog = "python3"; exist = query_program_exist (check_cmd, "python3");
} if (exist) *prog = "python3";
else { }
*prog = "python"; else
} {
*prog = "python";
}
if (!exist) { if (!exist)
chsrc_error ("未找到 Python 相关命令,请检查是否存在"); {
exit(1); chsrc_error ("未找到 Python 相关命令,请检查是否存在");
} exit (1);
}
} }
void void
pl_python_getsrc (char* option) pl_python_getsrc (char *option)
{ {
char* prog = NULL; char *prog = NULL;
pl_python_check_cmd (&prog); pl_python_check_cmd (&prog);
char* cmd = xy_2strjoin(prog, " -m pip config get global.index-url"); char *cmd = xy_2strjoin (prog, " -m pip config get global.index-url");
chsrc_run(cmd); chsrc_run (cmd);
} }
/** /**
@ -119,65 +125,69 @@ pl_python_getsrc (char* option)
* Windows上调用换源命令 C:\Users\RubyMetric\AppData\Roaming\pip\pip.ini * Windows上调用换源命令 C:\Users\RubyMetric\AppData\Roaming\pip\pip.ini
*/ */
void void
pl_python_setsrc (char* option) pl_python_setsrc (char *option)
{ {
int index = 0; int index = 0;
char* prog = NULL; char *prog = NULL;
pl_python_check_cmd (&prog); pl_python_check_cmd (&prog);
index = use_specific_mirror_or_auto_select (option, pl_python); index = use_specific_mirror_or_auto_select (option, pl_python);
SourceInfo source = pl_python_sources[index]; SourceInfo source = pl_python_sources[index];
chsrc_say_selection(&source); chsrc_say_selection (&source);
char* cmd = xy_2strjoin(prog, xy_2strjoin(" -m pip config set global.index-url ", source.url)); char* cmd = xy_2strjoin (prog, xy_2strjoin (" -m pip config set global.index-url ", source.url));
chsrc_run(cmd); chsrc_run (cmd);
chsrc_say_thanks(&source); chsrc_say_thanks (&source);
} }
void void
pl_nodejs_check_cmd (bool* npm_exist, bool* yarn_exist, bool* pnpm_exist) pl_nodejs_check_cmd (bool *npm_exist, bool *yarn_exist, bool *pnpm_exist)
{ {
char* check_cmd = xy_str_to_quietcmd("npm -v"); char *check_cmd = xy_str_to_quietcmd ("npm -v");
*npm_exist = query_program_exist (check_cmd, "npm"); *npm_exist = query_program_exist (check_cmd, "npm");
check_cmd = xy_str_to_quietcmd("yarn -v"); check_cmd = xy_str_to_quietcmd ("yarn -v");
*yarn_exist = query_program_exist (check_cmd, "yarn"); *yarn_exist = query_program_exist (check_cmd, "yarn");
check_cmd = xy_str_to_quietcmd("pnpm -v"); check_cmd = xy_str_to_quietcmd ("pnpm -v");
*pnpm_exist = query_program_exist (check_cmd, "pnpm"); *pnpm_exist = query_program_exist (check_cmd, "pnpm");
if (!*npm_exist && !*yarn_exist && !*pnpm_exist) { if (!*npm_exist && !*yarn_exist && !*pnpm_exist)
chsrc_error ("未找到 npm 或 yarn 或 pnpm 命令,请检查是否存在其一"); {
exit(1); chsrc_error ("未找到 npm 或 yarn 或 pnpm 命令,请检查是否存在其一");
} exit (1);
}
} }
void void
pl_nodejs_getsrc (char* option) pl_nodejs_getsrc (char *option)
{ {
bool npm_exist, yarn_exist, pnpm_exist; bool npm_exist, yarn_exist, pnpm_exist;
pl_nodejs_check_cmd (&npm_exist, &yarn_exist, &pnpm_exist); pl_nodejs_check_cmd (&npm_exist, &yarn_exist, &pnpm_exist);
if (npm_exist) { if (npm_exist)
chsrc_run("npm config get registry"); {
} chsrc_run ("npm config get registry");
if (yarn_exist) { }
chsrc_run("yarn config get registry"); if (yarn_exist)
} {
if (pnpm_exist) { chsrc_run ("yarn config get registry");
chsrc_run("pnpm config get registry"); }
} if (pnpm_exist)
{
chsrc_run ("pnpm config get registry");
}
} }
/** /**
* NodeJS换源https://npmmirror.com/ * NodeJS换源https://npmmirror.com/
*/ */
void void
pl_nodejs_setsrc (char* option) pl_nodejs_setsrc (char *option)
{ {
bool npm_exist, yarn_exist, pnpm_exist; bool npm_exist, yarn_exist, pnpm_exist;
pl_nodejs_check_cmd (&npm_exist, &yarn_exist, &pnpm_exist); pl_nodejs_check_cmd (&npm_exist, &yarn_exist, &pnpm_exist);
@ -187,25 +197,27 @@ pl_nodejs_setsrc (char* option)
SourceInfo source = pl_nodejs_sources[index]; SourceInfo source = pl_nodejs_sources[index];
chsrc_say_selection (&source); chsrc_say_selection (&source);
char *cmd = NULL;
if (npm_exist) if (npm_exist)
{ {
char* cmd = xy_2strjoin("npm config set registry ", source.url); cmd = xy_2strjoin ("npm config set registry ", source.url);
chsrc_run(cmd); chsrc_run (cmd);
} }
if (yarn_exist) if (yarn_exist)
{ {
char* cmd = xy_str_to_quietcmd(xy_2strjoin("yarn config set registry ", source.url)); cmd = xy_str_to_quietcmd (xy_2strjoin ("yarn config set registry ", source.url));
chsrc_run(cmd); chsrc_run (cmd);
} }
if (pnpm_exist) if (pnpm_exist)
{ {
char* cmd = xy_str_to_quietcmd(xy_2strjoin("pnpm config set registry ", source.url)); cmd = xy_str_to_quietcmd (xy_2strjoin ("pnpm config set registry ", source.url));
chsrc_run(cmd); chsrc_run (cmd);
} }
chsrc_say_thanks(&source); chsrc_say_thanks (&source);
} }
@ -213,44 +225,45 @@ pl_nodejs_setsrc (char* option)
void void
pl_perl_check_cmd () pl_perl_check_cmd ()
{ {
char* check_cmd = xy_str_to_quietcmd("perl --version"); char *check_cmd = xy_str_to_quietcmd ("perl --version");
bool exist = query_program_exist (check_cmd, "perl"); bool exist = query_program_exist (check_cmd, "perl");
if (!exist) { if (!exist)
chsrc_error ("未找到 perl 命令,请检查是否存在"); {
exit(1); chsrc_error ("未找到 perl 命令,请检查是否存在");
} exit (1);
}
} }
void void
pl_perl_getsrc (char* option) pl_perl_getsrc (char *option)
{ {
pl_perl_check_cmd (); pl_perl_check_cmd ();
// @ccmywish: 注意prettyprint 仅仅是一个内部实现,可能不稳定,如果需要更稳定的, // @ccmywish: 注意prettyprint 仅仅是一个内部实现,可能不稳定,如果需要更稳定的,
// 可以使用 CPAN::Shell->o('conf', 'urllist'); // 可以使用 CPAN::Shell->o('conf', 'urllist');
// 另外上述两种方法无论哪种都要首先load() // 另外上述两种方法无论哪种都要首先load()
char* cmd = "perl -MCPAN -e \"CPAN::HandleConfig->load(); CPAN::HandleConfig->prettyprint('urllist')\" "; char *cmd = "perl -MCPAN -e \"CPAN::HandleConfig->load(); CPAN::HandleConfig->prettyprint('urllist')\" ";
chsrc_run(cmd); chsrc_run (cmd);
} }
/** /**
* Perl换源https://help.mirrors.cernet.edu.cn/CPAN/ * Perl换源https://help.mirrors.cernet.edu.cn/CPAN/
*/ */
void void
pl_perl_setsrc (char* option) pl_perl_setsrc (char *option)
{ {
int index = use_specific_mirror_or_auto_select (option, pl_perl); int index = use_specific_mirror_or_auto_select (option, pl_perl);
SourceInfo source = pl_perl_sources[index]; SourceInfo source = pl_perl_sources[index];
chsrc_say_selection (&source); chsrc_say_selection (&source);
char* cmd = xy_strjoin(3, char *cmd = xy_strjoin (3,
"perl -MCPAN -e \"CPAN::HandleConfig->load(); CPAN::HandleConfig->edit('urllist', 'unshift', '", source.url, "'); CPAN::HandleConfig->commit()\""); "perl -MCPAN -e \"CPAN::HandleConfig->load(); CPAN::HandleConfig->edit('urllist', 'unshift', '", source.url, "'); CPAN::HandleConfig->commit()\"");
chsrc_run(cmd); chsrc_run (cmd);
chsrc_warn ("请您使用 perl -v 以及 cpan -v若 Perl >= v5.36 或 CPAN >= 2.29,请额外手动调用下面的命令"); chsrc_warn ("请您使用 perl -v 以及 cpan -v若 Perl >= v5.36 或 CPAN >= 2.29,请额外手动调用下面的命令");
puts("perl -MCPAN -e \"CPAN::HandleConfig->load(); CPAN::HandleConfig->edit('pushy_https', 0);; CPAN::HandleConfig->commit()\""); puts ("perl -MCPAN -e \"CPAN::HandleConfig->load(); CPAN::HandleConfig->edit('pushy_https', 0);; CPAN::HandleConfig->commit()\"");
chsrc_say_thanks(&source); chsrc_say_thanks (&source);
} }
@ -258,47 +271,48 @@ pl_perl_setsrc (char* option)
void void
pl_php_check_cmd () pl_php_check_cmd ()
{ {
char* check_cmd = xy_str_to_quietcmd("composer --version"); char *check_cmd = xy_str_to_quietcmd ("composer --version");
bool exist = query_program_exist (check_cmd, "composer"); bool exist = query_program_exist (check_cmd, "composer");
if (!exist) { if (!exist)
chsrc_error ("未找到 composer 命令,请检查是否存在"); {
exit(1); chsrc_error ("未找到 composer 命令,请检查是否存在");
} exit (1);
}
} }
/** /**
* Windows上测试通过PHP用户确认 * Windows上测试通过PHP用户确认
*/ */
void void
pl_php_getsrc (char* option) pl_php_getsrc (char *option)
{ {
pl_php_check_cmd (); pl_php_check_cmd ();
chsrc_run("composer config -g repositories"); chsrc_run ("composer config -g repositories");
} }
/** /**
* PHP https://developer.aliyun.com/composer * PHP https://developer.aliyun.com/composer
*/ */
void void
pl_php_setsrc (char* option) pl_php_setsrc (char *option)
{ {
pl_php_check_cmd(); pl_php_check_cmd ();
int index = use_specific_mirror_or_auto_select (option, pl_php); int index = use_specific_mirror_or_auto_select (option, pl_php);
SourceInfo source = pl_php_sources[index]; SourceInfo source = pl_php_sources[index];
chsrc_say_selection (&source); chsrc_say_selection (&source);
char* cmd = xy_2strjoin("composer config -g repo.packagist composer ", source.url); char* cmd = xy_2strjoin ("composer config -g repo.packagist composer ", source.url);
chsrc_run(cmd); chsrc_run (cmd);
chsrc_say_thanks(&source); chsrc_say_thanks (&source);
} }
void void
pl_lua_getsrc (char* option) pl_lua_getsrc (char *option)
{ {
chsrc_check_file ("~/.luarocks/config.lua"); chsrc_check_file ("~/.luarocks/config.lua");
chsrc_check_file ("~/.luarocks/upload_config.lua"); chsrc_check_file ("~/.luarocks/upload_config.lua");
@ -308,27 +322,27 @@ pl_lua_getsrc (char* option)
* Lua https://luarocks.cn/ * Lua https://luarocks.cn/
*/ */
void void
pl_lua_setsrc (char* option) pl_lua_setsrc (char *option)
{ {
int index = use_specific_mirror_or_auto_select (option, pl_lua); int index = use_specific_mirror_or_auto_select (option, pl_lua);
SourceInfo source = pl_lua_sources[index]; SourceInfo source = pl_lua_sources[index];
chsrc_say_selection (&source); chsrc_say_selection (&source);
char* config = xy_strjoin(3, "rocks_servers = {\n" char *config = xy_strjoin (3, "rocks_servers = {\n"
" \"", source.url, "\"\n" " \"", source.url, "\"\n"
"}"); "}");
chsrc_info ("请手动修改 ~/.luarocks/config.lua 文件 (用于下载):"); chsrc_info ("请手动修改 ~/.luarocks/config.lua 文件 (用于下载):");
puts(config); puts (config);
char* upload_config = xy_strjoin(3, "key = \"<Your API Key>\"\n" char *upload_config = xy_strjoin (3, "key = \"<Your API Key>\"\n"
"server = \"", source.url, "\""); "server = \"", source.url, "\"");
chsrc_info ("请手动修改 ~/.luarocks/upload_config.lua 文件 (用于上传):"); chsrc_info ("请手动修改 ~/.luarocks/upload_config.lua 文件 (用于上传):");
puts(upload_config); puts (upload_config);
chsrc_say_thanks(&source); chsrc_say_thanks (&source);
} }
@ -336,20 +350,21 @@ pl_lua_setsrc (char* option)
void void
pl_go_check_cmd () pl_go_check_cmd ()
{ {
char* check_cmd = xy_str_to_quietcmd("go version"); char *check_cmd = xy_str_to_quietcmd ("go version");
bool exist = query_program_exist (check_cmd, "go"); bool exist = query_program_exist (check_cmd, "go");
if (!exist) { if (!exist)
chsrc_error ("未找到 go 相关命令,请检查是否存在"); {
exit(1); chsrc_error ("未找到 go 相关命令,请检查是否存在");
} exit (1);
}
} }
void void
pl_go_getsrc (char* option) pl_go_getsrc (char *option)
{ {
pl_go_check_cmd (); pl_go_check_cmd ();
chsrc_run("go env GOPROXY"); chsrc_run ("go env GOPROXY");
} }
/** /**
@ -358,19 +373,19 @@ pl_go_getsrc (char* option)
void void
pl_go_setsrc (char* option) pl_go_setsrc (char* option)
{ {
pl_go_check_cmd(); pl_go_check_cmd ();
int index = use_specific_mirror_or_auto_select (option, pl_go); int index = use_specific_mirror_or_auto_select (option, pl_go);
SourceInfo source = pl_go_sources[index]; SourceInfo source = pl_go_sources[index];
chsrc_say_selection (&source); chsrc_say_selection (&source);
char* cmd = "go env -w GO111MODULE=on"; char *cmd = "go env -w GO111MODULE=on";
chsrc_run(cmd); chsrc_run (cmd);
cmd = xy_strjoin(3, "go env -w GOPROXY=", source.url, ",direct"); cmd = xy_strjoin (3, "go env -w GOPROXY=", source.url, ",direct");
chsrc_run(cmd); chsrc_run (cmd);
chsrc_say_thanks(&source); chsrc_say_thanks (&source);
} }
@ -390,7 +405,7 @@ pl_rust_setsrc (char* option)
int index = use_specific_mirror_or_auto_select (option, pl_rust); int index = use_specific_mirror_or_auto_select (option, pl_rust);
SourceInfo source = pl_rust_sources[index]; SourceInfo source = pl_rust_sources[index];
chsrc_say_selection(&source); chsrc_say_selection (&source);
const char* file = xy_strjoin (3, const char* file = xy_strjoin (3,
"[source.crates-io]\n" "[source.crates-io]\n"
@ -399,9 +414,9 @@ pl_rust_setsrc (char* option)
"[source.mirror]\n" "[source.mirror]\n"
"registry = \"sparse+", source.url, "\""); "registry = \"sparse+", source.url, "\"");
chsrc_warn (xy_strjoin(3, "请您手动写入以下内容到 ", xy_uniform_path("~/.cargo"), " 文件中:")); chsrc_warn (xy_strjoin (3, "请您手动写入以下内容到 ", xy_uniform_path("~/.cargo"), " 文件中:"));
puts(file); puts (file);
chsrc_say_thanks(&source); chsrc_say_thanks (&source);
} }
@ -426,38 +441,39 @@ pl_dotnet_setsrc (char* option)
void void
pl_java_check_cmd (bool* maven_exist, bool* gradle_exist) pl_java_check_cmd (bool* maven_exist, bool* gradle_exist)
{ {
char* check_cmd = NULL; char *check_cmd = NULL;
check_cmd = xy_str_to_quietcmd("mvn --version"); check_cmd = xy_str_to_quietcmd ("mvn --version");
*maven_exist = query_program_exist (check_cmd, "mvn"); *maven_exist = query_program_exist (check_cmd, "mvn");
check_cmd = xy_str_to_quietcmd("gradle --version"); check_cmd = xy_str_to_quietcmd ("gradle --version");
*gradle_exist = query_program_exist (check_cmd, "gradle"); *gradle_exist = query_program_exist (check_cmd, "gradle");
if (! *maven_exist && ! *gradle_exist) { if (! *maven_exist && ! *gradle_exist)
chsrc_error ("maven 与 gradle 命令均未找到,请检查是否存在其一"); {
exit(1); chsrc_error ("maven 与 gradle 命令均未找到,请检查是否存在其一");
} exit (1);
}
} }
char* char*
pl_java_find_maven_config () pl_java_find_maven_config ()
{ {
char* buf = xy_getcmd ("mvn -v", 2, NULL); char *buf = xy_getcmd ("mvn -v", 2, NULL);
char* maven_home = xy_str_delete_prefix(buf, "Maven home: "); char *maven_home = xy_str_delete_prefix (buf, "Maven home: ");
maven_home = xy_str_strip(maven_home); maven_home = xy_str_strip (maven_home);
char* maven_config = xy_uniform_path(xy_2strjoin(maven_home, "/conf/settings.xml")); char *maven_config = xy_uniform_path (xy_2strjoin (maven_home, "/conf/settings.xml"));
return maven_config; return maven_config;
} }
void void
pl_java_getsrc (char* option) pl_java_getsrc (char *option)
{ {
bool maven_exist, gradle_exist; bool maven_exist, gradle_exist;
pl_java_check_cmd (&maven_exist, &gradle_exist); pl_java_check_cmd (&maven_exist, &gradle_exist);
char* maven_config = pl_java_find_maven_config (); char *maven_config = pl_java_find_maven_config ();
char* echo = xy_2strjoin("chsrc: 请查看 ", maven_config); char *echo = xy_2strjoin ("chsrc: 请查看 ", maven_config);
xy_info (echo); xy_info (echo);
} }
@ -465,7 +481,7 @@ pl_java_getsrc (char* option)
* Java https://developer.aliyun.com/mirror/maven * Java https://developer.aliyun.com/mirror/maven
*/ */
void void
pl_java_setsrc (char* option) pl_java_setsrc (char *option)
{ {
bool maven_exist, gradle_exist; bool maven_exist, gradle_exist;
pl_java_check_cmd (&maven_exist, &gradle_exist); pl_java_check_cmd (&maven_exist, &gradle_exist);
@ -475,142 +491,146 @@ pl_java_setsrc (char* option)
SourceInfo source = pl_java_sources[index]; SourceInfo source = pl_java_sources[index];
chsrc_say_selection(&source); chsrc_say_selection(&source);
if (maven_exist) { if (maven_exist)
const char* file = xy_strjoin(7, {
"<mirror>\n" const char *file = xy_strjoin (7,
" <id>", source.mirror->code, "</id>\n" "<mirror>\n"
" <mirrorOf>*</mirrorOf>\n" " <id>", source.mirror->code, "</id>\n"
" <name>", source.mirror->name, "</name>\n" " <mirrorOf>*</mirrorOf>\n"
" <url>", source.url, "</url>\n" " <name>", source.mirror->name, "</name>\n"
"</mirror>"); " <url>", source.url, "</url>\n"
"</mirror>");
char* maven_config = pl_java_find_maven_config (); char *maven_config = pl_java_find_maven_config ();
char* echo = xy_strjoin(3, "chsrc: 请在您的 maven 配置文件 ", maven_config, " 中添加:"); char *echo = xy_strjoin (3, "chsrc: 请在您的 maven 配置文件 ", maven_config, " 中添加:");
xy_info(echo); xy_info (echo);
puts (file); puts (file);
} }
if (gradle_exist) { if (gradle_exist)
if (maven_exist) puts(""); {
const char* file = xy_strjoin(3, if (maven_exist) puts("");
"allprojects {\n" const char* file = xy_strjoin (3,
" repositories {\n" "allprojects {\n"
" maven { url '", source.url, "' }\n" " repositories {\n"
" mavenLocal()\n" " maven { url '", source.url, "' }\n"
" mavenCentral()\n" " mavenLocal()\n"
" }\n" " mavenCentral()\n"
"}"); " }\n"
"}");
chsrc_info ("请在您的 build.gradle 中添加:"); chsrc_info ("请在您的 build.gradle 中添加:");
puts (file); puts (file);
} }
chsrc_say_thanks(&source);
}
void
pl_clojure_setsrc(char* option)
{
int index = use_specific_mirror_or_auto_select (option, pl_clojure);
SourceInfo source = pl_clojure_sources[index];
chsrc_say_selection (&source);
chsrc_warn("抱歉Clojure换源较复杂您可手动查阅并换源:");
puts(source.url);
chsrc_say_thanks (&source); chsrc_say_thanks (&source);
} }
void void
pl_dart_getsrc(char* option) pl_clojure_setsrc (char *option)
{ {
char* cmd = NULL; int index = use_specific_mirror_or_auto_select (option, pl_clojure);
if (xy_on_windows) {
cmd = "set PUB_HOSTED_URL & set FLUTTER_STORAGE_BASE_URL"; SourceInfo source = pl_clojure_sources[index];
chsrc_run(cmd); chsrc_say_selection (&source);
} else {
cmd = "echo $PUB_HOSTED_URL; echo $FLUTTER_STORAGE_BASE_URL"; chsrc_warn ("抱歉Clojure换源较复杂您可手动查阅并换源:");
chsrc_run(cmd); puts (source.url);
} chsrc_say_thanks (&source);
}
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);
}
else
{
cmd = "echo $PUB_HOSTED_URL; echo $FLUTTER_STORAGE_BASE_URL";
chsrc_run (cmd);
}
} }
/** /**
* Dart pub https://mirrors.tuna.tsinghua.edu.cn/help/dart-pub/ * Dart pub https://mirrors.tuna.tsinghua.edu.cn/help/dart-pub/
*/ */
void void
pl_dart_setsrc (char* option) pl_dart_setsrc (char *option)
{ {
int index = use_specific_mirror_or_auto_select (option, pl_dart); int index = use_specific_mirror_or_auto_select (option, pl_dart);
SourceInfo source = pl_dart_sources[index]; SourceInfo source = pl_dart_sources[index];
chsrc_say_selection(&source); chsrc_say_selection(&source);
char* towrite = NULL; char *towrite = NULL;
char* pub = xy_2strjoin(source.url, "dart-pub"); char *pub = xy_2strjoin(source.url, "dart-pub");
char* flutter = xy_2strjoin(source.url, "flutter"); char *flutter = xy_2strjoin(source.url, "flutter");
if (xy_on_windows) if (xy_on_windows)
{
if (xy_file_exist(xy_win_powershell_profile))
{ {
towrite = xy_strjoin(4, "$env:PUB_HOSTED_URL = \"", pub, "\""); if (xy_file_exist (xy_win_powershell_profile))
chsrc_append_to_file (towrite, xy_win_powershell_profile); {
towrite = xy_strjoin (4, "$env:PUB_HOSTED_URL = \"", pub, "\"");
chsrc_append_to_file (towrite, xy_win_powershell_profile);
towrite = xy_strjoin(4, "$env:FLUTTER_STORAGE_BASE_URL = \"", flutter, "\""); towrite = xy_strjoin (4, "$env:FLUTTER_STORAGE_BASE_URL = \"", flutter, "\"");
chsrc_append_to_file (towrite, xy_win_powershell_profile); chsrc_append_to_file (towrite, xy_win_powershell_profile);
}
if (xy_file_exist (xy_win_powershellv5_profile))
{
towrite = xy_strjoin (4, "$env:PUB_HOSTED_URL = \"", pub, "\"");
chsrc_append_to_file (towrite, xy_win_powershellv5_profile);
towrite = xy_strjoin (4, "$env:FLUTTER_STORAGE_BASE_URL = \"", flutter, "\"");
chsrc_append_to_file (towrite, xy_win_powershellv5_profile);
}
} }
if (xy_file_exist(xy_win_powershellv5_profile))
{
towrite = xy_strjoin(4, "$env:PUB_HOSTED_URL = \"", pub, "\"");
chsrc_append_to_file (towrite, xy_win_powershellv5_profile);
towrite = xy_strjoin(4, "$env:FLUTTER_STORAGE_BASE_URL = \"", flutter, "\"");
chsrc_append_to_file (towrite, xy_win_powershellv5_profile);
}
}
else else
{ {
towrite = xy_strjoin(3, "export PUB_HOSTED_URL=\"", pub, "\""); towrite = xy_strjoin (3, "export PUB_HOSTED_URL=\"", pub, "\"");
chsrc_append_to_file (towrite, "~/.bashrc >> ~/.zshrc"); chsrc_append_to_file (towrite, "~/.bashrc >> ~/.zshrc");
towrite = xy_strjoin(3, "export FLUTTER_STORAGE_BASE_URL=\"", flutter, "\""); towrite = xy_strjoin (3, "export FLUTTER_STORAGE_BASE_URL=\"", flutter, "\"");
chsrc_append_to_file (towrite, "~/.bashrc >> ~/.zshrc"); chsrc_append_to_file (towrite, "~/.bashrc >> ~/.zshrc");
} }
chsrc_say_thanks(&source); chsrc_say_thanks (&source);
} }
void void
pl_haskell_setsrc(char* option) pl_haskell_setsrc(char *option)
{ {
int index = use_specific_mirror_or_auto_select (option, pl_haskell); int index = use_specific_mirror_or_auto_select (option, pl_haskell);
SourceInfo source = pl_haskell_sources[index]; SourceInfo source = pl_haskell_sources[index];
chsrc_say_selection (&source); chsrc_say_selection (&source);
char* file = xy_strjoin(3, "repository mirror\n" char* file = xy_strjoin (3, "repository mirror\n"
" url: ", source.url, " url: ", source.url,
"\n secure: True"); "\n secure: True");
char* config = NULL; char *config = NULL;
if (xy_on_windows) { if (xy_on_windows) {
config = xy_uniform_path ("~/AppData/Roaming/cabal/config"); config = xy_uniform_path ("~/AppData/Roaming/cabal/config");
} else { } else {
config = "~/.cabal/config"; config = "~/.cabal/config";
} }
xy_info(xy_strjoin(3,"chsrc: 请向 ", config, " 中手动添加:")); xy_info (xy_strjoin (3,"chsrc: 请向 ", config, " 中手动添加:"));
puts(file); puts(""); puts (file); puts ("");
config = xy_uniform_path ("~/.stack/config.yaml"); config = xy_uniform_path ("~/.stack/config.yaml");
file = xy_strjoin(3, "package-indices:\n" file = xy_strjoin (3, "package-indices:\n"
" - download-prefix: ", source.url, " - download-prefix: ", source.url,
"\n hackage-security:\n" "\n hackage-security:\n"
" keyids:\n" " keyids:\n"
@ -625,8 +645,8 @@ pl_haskell_setsrc(char* option)
" - fe331502606802feac15e514d9b9ea83fee8b6ffef71335479a2e68d84adc6b0\n" " - fe331502606802feac15e514d9b9ea83fee8b6ffef71335479a2e68d84adc6b0\n"
" key-threshold: 3\n" " key-threshold: 3\n"
" ignore-expiry: no"); " ignore-expiry: no");
xy_info(xy_strjoin(3,"chsrc: 请向 ", config, " 中手动添加:")); xy_info (xy_strjoin (3,"chsrc: 请向 ", config, " 中手动添加:"));
puts(file); puts (file);
chsrc_say_thanks (&source); chsrc_say_thanks (&source);
} }
@ -635,43 +655,44 @@ pl_haskell_setsrc(char* option)
void void
pl_ocaml_check_cmd () pl_ocaml_check_cmd ()
{ {
char* check_cmd = xy_str_to_quietcmd("opam --version"); char *check_cmd = xy_str_to_quietcmd("opam --version");
bool exist = query_program_exist (check_cmd, "opam"); bool exist = query_program_exist (check_cmd, "opam");
if (!exist) { if (!exist)
chsrc_error ("未找到 opam 命令,请检查是否存在"); {
exit(1); chsrc_error ("未找到 opam 命令,请检查是否存在");
} exit (1);
}
} }
void void
pl_ocaml_getsrc(char* option) pl_ocaml_getsrc(char *option)
{ {
pl_ocaml_check_cmd(); pl_ocaml_check_cmd ();
chsrc_run("opam repo get-url default"); chsrc_run ("opam repo get-url default");
} }
/** /**
* : https://mirrors.sjtug.sjtu.edu.cn/docs/git/opam-repository.git * : https://mirrors.sjtug.sjtu.edu.cn/docs/git/opam-repository.git
*/ */
void void
pl_ocaml_setsrc(char* option) pl_ocaml_setsrc(char *option)
{ {
pl_ocaml_check_cmd(); pl_ocaml_check_cmd ();
int index = use_specific_mirror_or_auto_select (option, pl_ocaml); int index = use_specific_mirror_or_auto_select (option, pl_ocaml);
SourceInfo source = pl_ocaml_sources[index]; SourceInfo source = pl_ocaml_sources[index];
chsrc_say_selection (&source); chsrc_say_selection (&source);
char* cmd = xy_strjoin(3, "opam repo set-url default ", char *cmd = xy_strjoin (3, "opam repo set-url default ",
source.url, source.url,
" --all --set-default"); " --all --set-default");
chsrc_run(cmd); chsrc_run (cmd);
chsrc_info("如果是首次使用 opam ,请使用以下命令进行初始化"); chsrc_info ("如果是首次使用 opam ,请使用以下命令进行初始化");
puts(xy_2strjoin("opam init default ", source.url)); puts (xy_2strjoin ("opam init default ", source.url));
chsrc_say_thanks (&source); chsrc_say_thanks (&source);
} }
@ -686,42 +707,45 @@ pl_r_getsrc (char* option)
// options()$repos // options()$repos
// options()$BioC_mirror // options()$BioC_mirror
// //
if (xy_on_windows) { if (xy_on_windows)
chsrc_check_file ("~/Documents/.Rprofile"); {
} else { chsrc_check_file ("~/Documents/.Rprofile");
chsrc_check_file ("~/.Rprofile"); }
} else
{
chsrc_check_file ("~/.Rprofile");
}
} }
/** /**
* R https://help.mirrors.cernet.edu.cn/CRAN/ * R https://help.mirrors.cernet.edu.cn/CRAN/
*/ */
void void
pl_r_setsrc (char* option) pl_r_setsrc (char *option)
{ {
int index = use_specific_mirror_or_auto_select (option, pl_r); int index = use_specific_mirror_or_auto_select (option, pl_r);
SourceInfo source = pl_r_sources[index]; SourceInfo source = pl_r_sources[index];
chsrc_say_selection(&source); chsrc_say_selection (&source);
char* bioconductor_url = xy_str_delete_suffix(xy_str_delete_suffix(source.url, "cran/"), "CRAN/"); char *bioconductor_url = xy_str_delete_suffix (xy_str_delete_suffix (source.url, "cran/"), "CRAN/");
bioconductor_url = xy_2strjoin(bioconductor_url, "bioconductor"); bioconductor_url = xy_2strjoin(bioconductor_url, "bioconductor");
const char* towrite1 = xy_strjoin (3, "options(\"repos\" = c(CRAN=\"", source.url, "\"))" ); const char *towrite1 = xy_strjoin (3, "options(\"repos\" = c(CRAN=\"", source.url, "\"))" );
const char* towrite2 = xy_strjoin (3, "options(BioC_mirror=\"", bioconductor_url, "\")" ); const char *towrite2 = xy_strjoin (3, "options(BioC_mirror=\"", bioconductor_url, "\")" );
// 或者我们调用 r.exe --slave -e 上面的内容 // 或者我们调用 r.exe --slave -e 上面的内容
if (xy_on_windows) if (xy_on_windows)
{ {
chsrc_append_to_file (towrite1, "~/Documents/.Rprofile"); chsrc_append_to_file (towrite1, "~/Documents/.Rprofile");
chsrc_append_to_file (towrite2, "~/Documents/.Rprofile"); chsrc_append_to_file (towrite2, "~/Documents/.Rprofile");
} }
else else
{ {
chsrc_append_to_file (towrite1, "~/.Rprofile"); chsrc_append_to_file (towrite1, "~/.Rprofile");
chsrc_append_to_file (towrite2, "~/.Rprofile"); chsrc_append_to_file (towrite2, "~/.Rprofile");
} }
chsrc_say_thanks(&source); chsrc_say_thanks (&source);
} }
@ -734,7 +758,7 @@ pl_r_setsrc (char* option)
* *
*/ */
void void
pl_julia_getsrc (char* option) pl_julia_getsrc (char *option)
{ {
chsrc_check_file ("~/.julia/config/startup.jl"); chsrc_check_file ("~/.julia/config/startup.jl");
} }
@ -745,17 +769,17 @@ pl_julia_getsrc (char* option)
* 2. https://docs.julialang.org/en/v1/manual/command-line-interface/#Startup-file * 2. https://docs.julialang.org/en/v1/manual/command-line-interface/#Startup-file
*/ */
void void
pl_julia_setsrc (char* option) pl_julia_setsrc (char *option)
{ {
int index = use_specific_mirror_or_auto_select (option, pl_julia); int index = use_specific_mirror_or_auto_select (option, pl_julia);
SourceInfo source = pl_julia_sources[index]; SourceInfo source = pl_julia_sources[index];
chsrc_say_selection(&source); chsrc_say_selection (&source);
const char* towrite = xy_strjoin (3, "ENV[\"JULIA_PKG_SERVER\"] = \"", source.url, "\""); const char *towrite = xy_strjoin (3, "ENV[\"JULIA_PKG_SERVER\"] = \"", source.url, "\"");
chsrc_append_to_file (towrite, "~/.julia/config/startup.jl"); chsrc_append_to_file (towrite, "~/.julia/config/startup.jl");
chsrc_say_thanks(&source); chsrc_say_thanks (&source);
} }