mirror of
https://github.com/RubyMetric/chsrc
synced 2025-06-08 03:04:03 +08:00
Run cesu before set
This commit is contained in:
parent
565d9a55e8
commit
6c5140aada
73
chsrc.c
73
chsrc.c
@ -2,7 +2,7 @@
|
|||||||
* File : chsrc.c
|
* File : chsrc.c
|
||||||
* Authors : Aoran Zeng <ccmywish@qq.com>
|
* Authors : Aoran Zeng <ccmywish@qq.com>
|
||||||
* Created on : <2023-08-28>
|
* Created on : <2023-08-28>
|
||||||
* Last modified : <2023-09-02>
|
* Last modified : <2023-09-03>
|
||||||
*
|
*
|
||||||
* chsrc:
|
* 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换源
|
* Ruby换源
|
||||||
*
|
*
|
||||||
@ -243,9 +270,7 @@ void
|
|||||||
pl_ruby_setsrc (char* option)
|
pl_ruby_setsrc (char* option)
|
||||||
{
|
{
|
||||||
int selected = 0; char* check_cmd = NULL;
|
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";
|
if (xy_on_windows) check_cmd = "gem -v >nul 2>nul";
|
||||||
else check_cmd = "gem -v 1>/dev/null 2>&1";
|
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换源
|
* Go换源
|
||||||
|
22
chsrc.h
22
chsrc.h
@ -2,7 +2,7 @@
|
|||||||
* File : chsrc.h
|
* File : chsrc.h
|
||||||
* Authors : Aoran Zeng <ccmywish@qq.com>
|
* Authors : Aoran Zeng <ccmywish@qq.com>
|
||||||
* Created on : <2023-08-29>
|
* Created on : <2023-08-29>
|
||||||
* Last modified : <2023-09-02>
|
* Last modified : <2023-09-03>
|
||||||
*
|
*
|
||||||
* chsrc:
|
* 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);
|
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 {
|
typedef struct {
|
||||||
void (*setfn)(char* option);
|
void (*setfn)(char* option);
|
||||||
void (*getfn)(char* option);
|
void (*getfn)(char* option);
|
||||||
void (*cesufn)(char* option);
|
int (*cesufn)(char* option);
|
||||||
source_info* sources;
|
source_info* sources;
|
||||||
size_t sources_n;
|
size_t sources_n;
|
||||||
} target_info;
|
} target_info;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user