diff --git a/ftree.h b/ftree.h index b35b0d2..2d00479 100644 --- a/ftree.h +++ b/ftree.h @@ -28,6 +28,10 @@ #define PORT 30100 #endif +# 进度条 +#define PROCBAR_LEN 101 +#define PROC_STYLE '#' + struct request { int type; // Request type is REGFILE, REGDIR, TRANSFILE char path[MAXPATH]; diff --git a/server.c b/server.c index b12ba66..9123885 100644 --- a/server.c +++ b/server.c @@ -26,6 +26,8 @@ struct request *createrequest(void); void complete_path(const char *child, char *s); int handleclient(struct client *p); int checkfile(struct client *p); +// 百分比进度条 +void procbar(double total,double current); int bindandlisten(unsigned short port); @@ -109,6 +111,7 @@ void rcopy_server(unsigned short port, char *dest) { /* * Based on the state of the client complete task. + ✔ ✖ */ int handleclient(struct client *p) { @@ -211,6 +214,7 @@ int handleclient(struct client *p) { status = ERROR; } } while((len == 1) && ++s < p->info->size); + //close file handle fclose(in); if (len != 1) { perror("server: reading file"); @@ -378,3 +382,27 @@ int checkfile(struct client *p) { } } } + +/** + * 进度条 +*/ +void procbar(double total,double current){ + char bar[PROCBAR_LEN]; + memset(bar,'\0',sizeof(bar)); + // + int cnt=0; + int len= strlen(label); + // 占比 + double rate = (100*current)/total; + int loop_count = (int) rate; + //loop print + whiel(cnt<=loop_count){ + printf("[%-100s][%.11f%%][%c]\r",bar,rate,label[cnt%len]); + // 直接输出不,非缓冲区 + fflush(stdout); + bar[cnt++] = PROC_STYLE; + usleep(2000); + } + // 输出换行,反正被覆盖 + printf("\n"); +} \ No newline at end of file