Run cesu before set

This commit is contained in:
Aoran Zeng 2023-09-03 14:48:53 +08:00
parent 565d9a55e8
commit 6c5140aada
2 changed files with 49 additions and 46 deletions

73
chsrc.c
View File

@ -2,7 +2,7 @@
* File : chsrc.c
* Authors : Aoran Zeng <ccmywish@qq.com>
* Created on : <2023-08-28>
* Last modified : <2023-09-02>
* Last modified : <2023-09-03>
*
* chsrc:
*
@ -234,6 +234,33 @@ pl_python_setsrc (char* option)
}
/* Ruby源 @maintainer ccmywish */
/**
* https://mirrors.bfsu.edu.cn/rubygems/gems/nokogiri-1.15.0-java.gem 大小为9.9MB
*
* @return
*/
int
pl_ruby_cesu (char* option)
{
size_t size = pl_ruby_sources_n;
source_info* sources = pl_ruby_sources;
double speeds[size];
for (int i=0;i<size;i++)
{
source_info src = sources[i];
const char* baseurl = src.url;
char* testurl = xy_2strjoin(baseurl, "gems/nokogiri-1.15.0-java.gem");
double speed = test_speed (testurl);
speeds[i] = speed;
}
int fastidx = dblary_maxidx (speeds, size);
xy_success (xy_2strjoin("最快镜像站为: ", sources[fastidx].mirror->name));
return fastidx;
}
/**
* Ruby换源
*
@ -243,9 +270,7 @@ void
pl_ruby_setsrc (char* option)
{
int selected = 0; char* check_cmd = NULL;
for (int i=0;i<sizeof(pl_ruby_sources);i++) {
// 循环测速
}
selected = pl_ruby_cesu ("");
if (xy_on_windows) check_cmd = "gem -v >nul 2>nul";
else check_cmd = "gem -v 1>/dev/null 2>&1";
@ -297,46 +322,6 @@ pl_ruby_getsrc (char* option)
}
int
dblary_maxidx(double* array, int size)
{
double maxval = array[0];
double maxidx = 0;
for (int i=1; i<size; i++) {
if (array[i]>maxval) {
maxval = array[i];
maxidx = i;
}
}
return maxidx;
}
/**
* @maintainer ccmywish
*
* https://mirrors.bfsu.edu.cn/rubygems/gems/nokogiri-1.15.0-java.gem 大小为9.9MB
*/
void
pl_ruby_cesu (char* option)
{
size_t size = pl_ruby_sources_n;
source_info* sources = pl_ruby_sources;
double speeds[size];
for (int i=0;i<size;i++)
{
source_info src = sources[i];
const char* baseurl = src.url;
char* testurl = xy_2strjoin(baseurl, "gems/nokogiri-1.15.0-java.gem");
double speed = test_speed (testurl);
speeds[i] = speed;
}
int maxidx = dblary_maxidx (speeds, size);
xy_success (xy_2strjoin("最快镜像站为: ", sources[maxidx].mirror->name));
}
/**
* Go换源

22
chsrc.h
View File

@ -2,7 +2,7 @@
* File : chsrc.h
* Authors : Aoran Zeng <ccmywish@qq.com>
* Created on : <2023-08-29>
* Last modified : <2023-09-02>
* Last modified : <2023-09-03>
*
* chsrc:
*
@ -339,6 +339,24 @@ os_mysys2_sources[] = {
}
;
/* 辅助函数 */
int
dblary_maxidx(double* array, int size)
{
double maxval = array[0];
double maxidx = 0;
for (int i=1; i<size; i++) {
if (array[i]>maxval) {
maxval = array[i];
maxidx = i;
}
}
return maxidx;
}
/* 函数签名 */
bool does_the_program_exist (char* check_cmd, char* progname);
@ -356,7 +374,7 @@ def_target_sources_n(os_kali); def_target_sources_n(os_openbsd); def_target_sour
typedef struct {
void (*setfn)(char* option);
void (*getfn)(char* option);
void (*cesufn)(char* option);
int (*cesufn)(char* option);
source_info* sources;
size_t sources_n;
} target_info;