From 1a964f239fdc4fe04644268478a24ad476b829c7 Mon Sep 17 00:00:00 2001 From: "Kirill Lipatov (Leency)" Date: Wed, 17 Nov 2021 23:43:09 +0000 Subject: [PATCH] C-- downloader: show download speed and size in Mb git-svn-id: svn://kolibrios.org@9287 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/cmm/downloader/const.h | 10 ++-- programs/cmm/downloader/dl.c | 36 ++++++----- programs/cmm/lib/socket.h | 103 +++++++++++++++----------------- programs/cmm/liza/mail_box.c | 82 +++++++++++-------------- 4 files changed, 108 insertions(+), 123 deletions(-) diff --git a/programs/cmm/downloader/const.h b/programs/cmm/downloader/const.h index 8d5cdc7555..7f2791ab0f 100644 --- a/programs/cmm/downloader/const.h +++ b/programs/cmm/downloader/const.h @@ -1,4 +1,4 @@ -//Copyright 2020 by Leency +//Copyright 2021 by Leency #ifdef LANG_RUS #define DL_WINDOW_HEADER "Менеджер загрузок" @@ -9,10 +9,9 @@ #define T_SPEED_TEST "Тест скорости" #define FILE_SAVED_AS "'Менеджер загрузок\nФайл сохранен как %s' -Dt" #define FILE_NOT_SAVED "'Менеджер загрузок\nОшибка! Файл не может быть сохранен как\n%s' -Et" - #define KB_RECEIVED "Идет скачивание... %s получено" + #define KB_RECEIVED "Идет скачивание: %i.%i Mb получено (%i Kb/s) " #define T_ERROR_STARTING_DOWNLOAD "'Невозможно начать скачивание.\nПроверьте введенный путь и соединение с Интернетом.' -E" #define T_AUTOCLOSE "Автозакрытие" -#define SPEED_TEST_INFO_MESSAGE "'Скорость загрузки отображается в поле Download программы Network status.'-Id" char accept_language[]= "Accept-Language: ru\n"; #else #define DL_WINDOW_HEADER "Download Manager" @@ -23,15 +22,14 @@ #define T_SPEED_TEST "Speed test" #define FILE_SAVED_AS "'Download manager\nFile saved as %s' -Dt" #define FILE_NOT_SAVED "'Download manager\nError! Can\96t save file as %s' -Et" - #define KB_RECEIVED "Downloading... %s received" + #define KB_RECEIVED "Downloading: %i.%i Mb received (%i Kb/s) " #define T_ERROR_STARTING_DOWNLOAD "'Error while starting download process.\nCheck entered path and Internet connection.' -E" #define T_AUTOCLOSE "Autoclose" - #define SPEED_TEST_INFO_MESSAGE "'Download speed is shown after `Download`\nlabel in the Network status program.'-Id" char accept_language[]= "Accept-Language: en\n"; #endif #define GAPX 15 -#define WIN_W 580 +#define WIN_W 540 #define WIN_H 100 char save_dir[] = "/tmp0/1/Downloads"; diff --git a/programs/cmm/downloader/dl.c b/programs/cmm/downloader/dl.c index 9a764825a7..86fa2e120b 100644 --- a/programs/cmm/downloader/dl.c +++ b/programs/cmm/downloader/dl.c @@ -10,6 +10,8 @@ bool exit_param = false; bool open_file = false; +dword speed; + _http http; checkbox autoclose = { T_AUTOCLOSE, false }; @@ -17,7 +19,7 @@ checkbox autoclose = { T_AUTOCLOSE, false }; char uEdit[URL_SIZE]; char filepath[URL_SIZE+96]; -progress_bar pb = {0, GAPX, 58, 315, 17, 0, NULL, NULL, 0xFFFfff, 0x74DA00, NULL}; +progress_bar pb = {0, GAPX, 58, 380, 17, 0, NULL, NULL, 0xFFFfff, 0x74DA00, NULL}; edit_box ed = {WIN_W-GAPX-GAPX,GAPX,20,0xffffff,0x94AECE,0xffffff,0xffffff, 0x10000000, sizeof(uEdit)-2,#uEdit,0,ed_focus,19,19}; @@ -51,8 +53,6 @@ void main() if (streq(#param, "-test")) { strcpy(#uEdit, URL_SPEED_TEST); - RunProgram("/sys/network/netstat", NULL); - notify(SPEED_TEST_INFO_MESSAGE); } } if (uEdit[0]) StartDownloading(); else { @@ -107,7 +107,7 @@ void DrawWindow() DrawStandartCaptButton(GAPX+276, BUT_Y, BTN_RUN, T_RUN); } } else { - DrawStandartCaptButton(WIN_W - 240, BUT_Y, BTN_STOP, T_CANCEL); + DrawStandartCaptButton(WIN_W - 120, BUT_Y, BTN_STOP, T_CANCEL); DrawDownloadingProgress(); } //ed.offset=0; //DEL? @@ -118,6 +118,7 @@ void StartDownloading() { char get_url[URL_SIZE+33]; if (http.transfer > 0) return; + ResetDownloadSpeed(); filepath = '\0'; if (!strncmp(#uEdit,"https:",6)) { miniprintf(#get_url, "http://gate.aspero.pro/?site=%s", #uEdit); @@ -146,6 +147,7 @@ void StartDownloading() void DrawDownloadingProgress() { char bytes_received[70]; + dword gotkb = http.content_received/1024; EDI = http.content_received / 100; if (pb.value == EDI) return; @@ -153,9 +155,9 @@ void DrawDownloadingProgress() pb.value = EDI; pb.max = http.content_length / 100; progressbar_draw stdcall(#pb); - miniprintf(#bytes_received, KB_RECEIVED, ConvertSizeToKb(http.content_received) ); + CalculateDownloadSpeed(); + sprintf(#bytes_received, KB_RECEIVED, gotkb/1024, gotkb%1024/103, speed); WriteTextWithBg(GAPX, pb.top + 22, 0xD0, sc.work_text, #bytes_received, sc.work); - //CalculateSpeed(); } void StopDownloading() @@ -269,7 +271,6 @@ void Unarchive(dword _arc) } -/* struct TIME { dword old; @@ -278,22 +279,25 @@ struct TIME } time = {0,0,0}; dword netdata_received; -dword speed; -void CalculateSpeed() +void ResetDownloadSpeed() +{ + time.old = 0; + netdata_received = 0; +} + +void CalculateDownloadSpeed() { time.cur = GetStartTime(); if (time.old) { time.gone = time.cur - time.old; - if (time.gone > 200) { - speed = http.content_received - netdata_received / time.gone * 100; - debugval("speed", speed); - debugln(ConvertSizeToKb(speed) ); + if (time.gone >= 200) { + speed = http.content_received - netdata_received / time.gone / 10; time.old = time.cur; netdata_received = http.content_received; } + } else { + time.old = time.cur; } - else time.old = time.cur; -} -*/ \ No newline at end of file +} \ No newline at end of file diff --git a/programs/cmm/lib/socket.h b/programs/cmm/lib/socket.h index 860eee6d55..5bd24bdada 100644 --- a/programs/cmm/lib/socket.h +++ b/programs/cmm/lib/socket.h @@ -9,99 +9,94 @@ #define SOCK_STREAM 1 #define SOCK_DGRAM 2 -#define AF_INET4 2 +#define AF_INET4 2 #define MSG_PEEK 0x02 #define MSG_DONTWAIT 0x40 -dword errorcode; - -struct sockaddr_in +struct SockAddr { - word sin_family; - word sin_port; - dword sin_addr; - char padding[8]; -}; + word sin_family; + char data[14]; +}; -inline fastcall dword Socket(ECX, EDX, ESI) +// ecx = domain +// edx = type +// esi = protocol +inline fastcall dword socket_open(ECX, EDX, ESI) { - $push ebx $mov eax, 75 - $mov ebx, 0 + $mov bl, 0 $int 0x40 - errorcode = EBX; - $pop ebx -} - -inline fastcall dword Close(ECX) -{ - $push ebx - $mov eax, 75 - $mov ebx, 1 - $int 0x40 - errorcode = EBX; - $pop ebx } -inline fastcall dword Bind(ECX, EDX, ESI) +// ecx = socket number +inline fastcall dword socket_close(ECX) { - $push ebx $mov eax, 75 - $mov ebx, 2 + $mov bl, 1 $int 0x40 - errorcode = EBX; - $pop ebx } -inline fastcall dword Listen(ECX, EDX) +// ecx = socket number +// edx = pointer to sockaddr structure +// esi = length of sockaddr structure +inline fastcall dword socket_bind(ECX, EDX, ESI) { - $push ebx $mov eax, 75 - $mov ebx, 3 + $mov bl, 2 $int 0x40 - errorcode = EBX; - $pop ebx } -inline fastcall dword Connect(ECX, EDX, ESI) +// ecx = socket number +// edx = backlog +inline fastcall dword socket_listen(ECX, EDX) { - $push ebx $mov eax, 75 - $mov ebx, 4 + $mov bl, 3 $int 0x40 - errorcode = EBX; - $pop ebx } -inline fastcall dword Accept(ECX, EDX, ESI) +// ecx = socket number +// edx = pointer to sockaddr structure +// esi = length of sockaddr structure +inline fastcall dword socket_connect(ECX, EDX, ESI) { - $push ebx $mov eax, 75 - $mov ebx, 5 + $mov bl, 4 $int 0x40 - errorcode = EBX; - $pop ebx } -inline fastcall dword Send(ECX, EDX, ESI, EDI) +// ecx = socket number +// edx = pointer to sockaddr structure +// esi = length of sockaddr structure +inline fastcall dword socket_accept(ECX, EDX, ESI) { - $push ebx $mov eax, 75 - $mov ebx, 6 + $mov bl, 5 $int 0x40 - errorcode = EBX; - $pop ebx } -inline fastcall dword Receive(ECX, EDX, ESI, EDI) +// ecx = socket number +// edx = pointer to buffer +// esi = length of buffer +// edi = flags +inline fastcall dword socket_send(ECX, EDX, ESI, EDI) { - $push ebx $mov eax, 75 - $mov ebx, 7 + $mov bl, 6 + $int 0x40 +} + +// ecx = socket number +// edx = pointer to buffer +// esi = length of buffer +// edi = flags +inline fastcall dword socket_receive(ECX, EDX, ESI, EDI) +{ + $mov eax, 75 + $mov bl, 7 $int 0x40 - errorcode = EBX; - $pop ebx } #endif \ No newline at end of file diff --git a/programs/cmm/liza/mail_box.c b/programs/cmm/liza/mail_box.c index df747faf64..688b41cf49 100644 --- a/programs/cmm/liza/mail_box.c +++ b/programs/cmm/liza/mail_box.c @@ -1,12 +1,11 @@ //Leency & SoUrcerer, LGPL //Hidnplayer -TWebBrowser WB1; - #define LIST_INFO_H 59 int status_bar_h = 15; scroll_bar scroll1 = { 17,200,210, LIST_INFO_H-3,18,0,115,15,0,0xCCCccc,0xD2CED0,0x555555,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1}; +scroll_bar scroll_wv; char *listbuffer; char *listpointer; @@ -17,6 +16,7 @@ int mailsize; int cur_charset; +llist list; enum { GET_MAIL = 20, @@ -34,7 +34,7 @@ void MailBoxNetworkProcess() { if (aim) switch(aim) { case SEND_NSTAT: - SetMailBoxStatus(NULL, "Counting mail, awaiting answer..."); + SetMailBoxStatus(NULL, "Counting mail, awaiting answer..."); request_len = GetRequest("STAT", NULL); Send(socketnum, #request, request_len, 0); if (EAX == 0xffffffff) { debugln("Error sending STAT. Retry..."w); break;} @@ -44,7 +44,7 @@ void MailBoxNetworkProcess() { case GET_ANSWER_NSTAT: ticks = Receive(socketnum, #immbuffer, BUFFERSIZE, 0); if ((ticks == 0xffffff) || (ticks < 2)) break; - + if (immbuffer[ticks-2]=='\n') { debugln(#immbuffer); @@ -54,7 +54,7 @@ void MailBoxNetworkProcess() { mail_list.count = atoi(#param); free(listbuffer); listbuffer = mem_Alloc(30*mail_list.count); //24* original - listpointer = listbuffer; + listpointer = listbuffer; aim = SEND_NLIST; debugln("Receiving mail list..."); } @@ -75,16 +75,16 @@ void MailBoxNetworkProcess() { case GET_ANSWER_NLIST: ticks = Receive(socketnum, listpointer, listbuffer + 30*mail_list.count - listpointer, MSG_DONTWAIT); - if (ticks == 0xffffffff) break; - listpointer = listpointer + ticks; - + if (ticks == 0xffffffff) break; + listpointer = listpointer + ticks; + if (listpointer - listbuffer < 5) break; - if (strncmp(listpointer-5,"\n.\n",5)==0) // note that c-- assembles "\n.\n" to 0x0d, 0x0a, 0x2e, 0x0d, 0x0a + if (strncmp(listpointer-5,"\n.\n",5)==0) // note that c-- assembles "\n.\n" to 0x0d, 0x0a, 0x2e, 0x0d, 0x0a { aim = SEND_RETR; debugln("goto SEND_RETR"); DrawMailBox(); - + *listpointer='\0'; atr.CreateArray(); atr.SetSizes(); @@ -93,7 +93,6 @@ void MailBoxNetworkProcess() { case SEND_RETR: from = to = date = subj = cur_charset = NULL; - WB1.list.ClearList(); DrawMailBox(); request_len = GetRequest("RETR", itoa(mail_list.cur_y+1)); if (Send(socketnum, #request, request_len, 0) == 0xffffffff) @@ -115,7 +114,7 @@ void MailBoxNetworkProcess() { aim = GET_ANSWER_RETR; debugln("goto GET_ANSWER_RETR"); break; - + case GET_ANSWER_RETR: debugval("mailsize", mailsize); debugval("mailstart", mailstart); @@ -150,21 +149,20 @@ void MailBoxLoop() { mail_list.h = Form.cheight/4; mail_list.ClearList(); - WB1.list.no_selection = true; SetMailBoxStatus( NULL , NULL); cur_charset = 0; aim = SEND_NSTAT; - + goto _MB_DRAW; - loop() + loop() { WaitEventTimeout(2); switch(EAX & 0xFF) { case evMouse: mouse.get(); - + if (!mouse.lkm) panels_drag=0; if (mouse.lkm) && (mouse.y>mail_list.y+mail_list.h-1) && (mouse.y scroll1.position) { mail_list.first = scroll1.position; DrawMailList(); break; }; - if (WB1.list.first <> scroll_wv.position) + if (list.first <> scroll_wv.position) { - WB1.list.first = scroll_wv.position; + list.first = scroll_wv.position; DrawLetter(); break; }; - + if (mail_list.y+mail_list.h + 10 > mouse.y) { if (mail_list.MouseScroll(mouse.vert)) DrawMailList(); } else { - if (WB1.list.MouseScroll(mouse.vert)) DrawLetter(); + if (list.MouseScroll(mouse.vert)) DrawLetter(); } if (mouse.lkm) && (mail_list.MouseOver(mouse.x, mouse.y)) && (!clicked_list) clicked_list=1; - if (!mouse.lkm) && (clicked_list) if (mail_list.ProcessMouse(mouse.x, mouse.y)) + if (!mouse.lkm) && (clicked_list) if (mail_list.ProcessMouse(mouse.x, mouse.y)) { clicked_list = 0; if (aim) break; @@ -211,9 +209,9 @@ void MailBoxLoop() { aim = SEND_RETR; } - break; + break; case evButton: - id = GetButtonID(); + id = GetButtonID(); if (id==1) SaveAndExit(); if (id==GET_MAIL) aim = SEND_NSTAT; if (id==SAVE_LETTER) @@ -223,19 +221,19 @@ void MailBoxLoop() { pause(10); RunProgram("/sys/tinypad", "mail.txt"); } - if (id==STOP_LOADING) + if (id==STOP_LOADING) { StopLoading(); DrawStatusBar(); DrawMailList(); } - if (id==EXIT_MAIL) + if (id==EXIT_MAIL) { StopLoading(); Close(socketnum); LoginBoxLoop(); } - if (id==CHANGE_CHARSET) + if (id==CHANGE_CHARSET) { DefineButton(0,0,Form.cwidth,Form.cheight, CLOSE_CHANGE_CHARSET+BT_HIDE+BT_NOFRAME); DrawRectangle(Form.cwidth-100, Form.cheight-status_bar_h- 70, 70, 82, sc.work_graph); @@ -251,7 +249,7 @@ void MailBoxLoop() { } if (id==CLOSE_CHANGE_CHARSET) goto _MB_DRAW; - break; + break; case evKey: GetKeys(); @@ -282,7 +280,6 @@ void DrawMailBox() { DrawMailList(); DrawLetterInfo(); - InitTWB(); DrawLetter(); DrawStatusBar(); } @@ -310,7 +307,7 @@ void DrawMailList() { dword sel_col; mail_list.visible = mail_list.h / mail_list.item_h; - for (i=30; i<150; i++) DeleteButton(i); + for (i=30; i<150; i++) DeleteButton(i); for (i=0; (i