diff --git a/programs/cmm/TWB/absolute_url.h b/programs/cmm/TWB/absolute_url.h index 3623b49572..f29d0955e2 100644 --- a/programs/cmm/TWB/absolute_url.h +++ b/programs/cmm/TWB/absolute_url.h @@ -42,7 +42,7 @@ void GetAbsoluteURL(dword in_URL) } IF (!strcmpn(in_URL,"./", 2)) in_URL+=2; - if (!http_transfer) + if (!http.transfer) { strcpy(#newurl, history.current()); } diff --git a/programs/cmm/browser/WebView.c b/programs/cmm/browser/WebView.c index 9b62bc2f6c..c1d6902b76 100644 --- a/programs/cmm/browser/WebView.c +++ b/programs/cmm/browser/WebView.c @@ -27,10 +27,12 @@ #include "..\lib\patterns\history.h" #include "..\lib\patterns\http_downloader.h" +_http http = {0, 0, 0, 0, 0, 0, 0}; + char homepage[] = FROM "html\\homepage.htm""\0"; #ifdef LANG_RUS -char version[]="Текстовый браузер 1.73"; +char version[]="Текстовый браузер 1.74"; ?define IMAGES_CACHE_CLEARED "Кэш картинок очищен" ?define T_LAST_SLIDE "Это последний слайд" char loading[] = "Загрузка страницы...
"; @@ -45,7 +47,7 @@ char link_menu[] = "Копировать ссылку Скачать содержимое ссылки"; #else -char version[]="Text-based Browser 1.73"; +char version[]="Text-based Browser 1.74"; ?define IMAGES_CACHE_CLEARED "Images cache cleared" ?define T_LAST_SLIDE "This slide is the last" char loading[] = "Loading...
"; @@ -75,9 +77,6 @@ char stak[4096]; int action_buf; -dword http_transfer = 0; -dword http_buffer; - dword TOOLBAR_H = 40; dword STATUSBAR_H = 15; dword col_bg; @@ -185,34 +184,17 @@ void main() break; case evNetwork: - if (http_transfer > 0) { - http_receive stdcall (http_transfer); - $push EAX - ESI = http_transfer; - wv_progress_bar.max = ESI.http_msg.content_length; - if (wv_progress_bar.value != ESI.http_msg.content_received) - { - wv_progress_bar.value = ESI.http_msg.content_received; - DrawProgress(); - } - $pop EAX - if (EAX == 0) { - ESI = http_transfer; + if (http.transfer > 0) { + http.receive(); + EventUpdateProgressBar(); + if (http.receive_result == 0) { // Handle redirects - if (ESI.http_msg.status >= 300) && (ESI.http_msg.status < 400) + if (http.status_code >= 300) && (http.status_code < 400) { redirected++; if (redirected<=5) { - http_find_header_field stdcall (http_transfer, "location\0"); - if (EAX!=0) { - ESI = EAX; - EDI = #URL; - do { - $lodsb; - $stosb; - } while (AL != 0) && (AL != 13) && (AL != 10); - DSBYTE[EDI-1]='\0'; + if (http.handle_redirect()) { if (!strncmp(#URL,"https://",8)) { history.back(); @@ -238,8 +220,7 @@ void main() // Loading the page is complete, free resources if (redirected>0) { - http_free stdcall (http_transfer); - http_transfer=0; + http.free(); GetAbsoluteURL(#URL); history.back(); strcpy(#editURL, #URL); @@ -249,11 +230,10 @@ void main() else { history.add(#URL); - ESI = http_transfer; + ESI = http.transfer; bufpointer = ESI.http_msg.content_ptr; bufsize = ESI.http_msg.content_received; - http_free stdcall (http_transfer); - http_transfer=0; + http.free(); SetPageDefaults(); ShowPage(); } @@ -338,7 +318,7 @@ void ProcessEvent(dword id__) case 063: //F5 IF(address_box.flags & 0b10) return; case REFRESH_BUTTON: - if (http_transfer > 0) + if (http.transfer > 0) { StopLoading(); Draw_Window(); @@ -391,15 +371,15 @@ void ProcessEvent(dword id__) void StopLoading() { - if (http_transfer) + if (http.transfer) { - EAX = http_transfer; + EAX = http.transfer; EAX = EAX.http_msg.content_ptr; // get pointer to data $push EAX // save it on the stack - http_free stdcall (http_transfer); // abort connection + http_free stdcall (http.transfer); // abort connection $pop EAX free(EAX); // free data - http_transfer=0; + http.transfer=0; bufsize = 0; bufpointer = free(bufpointer); } @@ -432,9 +412,8 @@ void OpenPage() if (!strncmp(#URL,"http:",5)) { img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-3, 17, skin.h, 131, 0); - http_get stdcall (#URL, 0, 0, #accept_language); - http_transfer = EAX; - if (!http_transfer) + http.get(#URL); + if (!http.transfer) { StopLoading(); bufsize = 0; @@ -465,7 +444,7 @@ DrawEditBoxWebView() address_box.size = address_box.pos = address_box.shift = address_box.shift_old = strlen(#editURL); address_box.offset = 0; edit_box_draw stdcall(#address_box); - if (http_transfer > 0) EAX = 131; else EAX = 54; + if (http.transfer > 0) EAX = 131; else EAX = 54; img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-3, 17, skin.h, EAX, 0); } @@ -476,7 +455,7 @@ void ShowPage() debugval("bufsize", bufsize); if (!bufsize) { - if (http_transfer) WB1.LoadInternalPage(#loading, sizeof(loading)); + if (http.transfer) WB1.LoadInternalPage(#loading, sizeof(loading)); else WB1.LoadInternalPage(#page_not_found, sizeof(page_not_found)); } else @@ -508,7 +487,7 @@ int SetSkinColors() void DrawProgress() { unsigned long btn; - if (http_transfer == 0) return; + if (http.transfer == 0) return; if (wv_progress_bar.max) btn = address_box.width*wv_progress_bar.value/wv_progress_bar.max; else btn = 30; DrawBar(address_box.left-2, address_box.top+20, btn, 2, wv_progress_bar.progress_color); } @@ -517,7 +496,7 @@ void DrawProgress() char anchor[256]; void ClickLink() { - if (http_transfer > 0) + if (http.transfer > 0) { StopLoading(); history.back(); @@ -611,6 +590,16 @@ void EventShowLinkMenu(dword _left, _top) menu.show(Form.left+_left-6,Form.top+_top+skin_height+3, 220, #link_menu, COPY_LINK); } +void EventUpdateProgressBar() +{ + wv_progress_bar.max = http.content_length; + if (wv_progress_bar.value != http.content_received) + { + wv_progress_bar.value = http.content_received; + DrawProgress(); + } +} + void ShowErrorMessageThatHttpsIsNotSupportedYet() { diff --git a/programs/cmm/browser/download_manager.h b/programs/cmm/browser/download_manager.h index e49f31527b..b83a060f8b 100644 --- a/programs/cmm/browser/download_manager.h +++ b/programs/cmm/browser/download_manager.h @@ -1,186 +1,191 @@ #ifdef LANG_RUS - #define DL_WINDOW_HEADER "Менеджер загрузок" - #define START_DOWNLOADING "Начать закачку" - #define STOP_DOWNLOADING "Остановить" - #define SHOW_IN_FOLDER "Показать в папке" - #define OPEN_FILE_TEXT "Открыть файл" - #define FILE_SAVED_AS "'Менеджер загрузок\nФайл сохранен как " - #define KB_RECEIVED "Идет скачивание... %s получено" + #define DL_WINDOW_HEADER "Менеджер загрузок" + #define START_DOWNLOADING "Начать закачку" + #define STOP_DOWNLOADING "Остановить" + #define SHOW_IN_FOLDER "Показать в папке" + #define OPEN_FILE_TEXT "Открыть файл" + #define FILE_SAVED_AS "'Менеджер загрузок\nФайл сохранен как " + #define KB_RECEIVED "Идет скачивание... %s получено" #else - #define DL_WINDOW_HEADER "Download Manager" - #define START_DOWNLOADING "Start downloading" - #define STOP_DOWNLOADING "Stop downloading" - #define SHOW_IN_FOLDER "Show in folder" - #define OPEN_FILE_TEXT "Open file" - #define FILE_SAVED_AS "'Download manager\nFile saved as " - #define KB_RECEIVED "Downloading... %s received" + #define DL_WINDOW_HEADER "Download Manager" + #define START_DOWNLOADING "Start downloading" + #define STOP_DOWNLOADING "Stop downloading" + #define SHOW_IN_FOLDER "Show in folder" + #define OPEN_FILE_TEXT "Open file" + #define FILE_SAVED_AS "'Download manager\nFile saved as " + #define KB_RECEIVED "Downloading... %s received" #endif char save_to[4096] = "/tmp0/1/Downloads"; proc_info DL_Form; char downloader_edit[10000]; char filepath[4096]; -int mouse_twbi; -edit_box ed = {250,20,20,0xffffff,0x94AECE,0xffffff,0xffffff,0x10000000,sizeof(downloader_edit),#downloader_edit,#mouse_twbi,2,19,19}; +edit_box ed = {NULL,57,20,0xffffff,0x94AECE,0xffffff,0xffffff,0x10000000,sizeof(downloader_edit),#downloader_edit,0,2,19,19}; progress_bar pb = {0, 20, 58, 350, 17, 0, 0, 100, 0xFFFfff, 0x74DA00, 0x9F9F9F}; //progress_bar pb = {0, 180, 55, 225, 12, 0, 0, 100, 0xFFFfff, 0x74DA00, 0x9F9F9F}; //progress_bar: value, left, top, width, height, style, min, max, back_color, progress_color, frame_color; - + -byte downloader_opened; +bool downloader_opened; char downloader_stak[4096]; -char str[2048]; -char aux[2048]; void Downloader() { - int key, i; - char notify_message[4296]; - downloader_opened = 1; - SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER + EVM_STACK); + if (!dir_exists(#save_to)) CreateDir(#save_to); + downloader_opened = true; + SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER + EVM_STACK); - system.color.get(); - pb.frame_color = system.color.work_dark; + system.color.get(); + pb.frame_color = system.color.work_dark; - filepath[0] = NULL; - - downloader.Stop(); - if (downloader_edit[0]) StartDownloading(); else strcpy(#downloader_edit, "http://"); - ed.size = ed.pos = ed.shift = ed.shift_old = strlen(#downloader_edit); + filepath[0] = NULL; + + downloader.Stop(); + if (downloader_edit[0]) StartDownloading(); else strcpy(#downloader_edit, "http://"); + ed.size = ed.pos = ed.shift = ed.shift_old = strlen(#downloader_edit); - loop() switch(WaitEvent()) - { - case evMouse: - if (!CheckActiveProcess(DL_Form.ID)) break; - edit_box_mouse stdcall (#ed); - break; + loop() switch(WaitEvent()) + { + case evMouse: + edit_box_mouse stdcall (#ed); + break; - case evButton: - Key_Scan(GetButtonID()); - break; + case evButton: + Key_Scan(GetButtonID()); + break; - case evKey: - GetKeys(); - edit_box_key stdcall(#ed); - if (key_scancode==SCAN_CODE_ENTER) Key_Scan(301); - break; + case evKey: + GetKeys(); + edit_box_key stdcall(#ed); + if (key_scancode==SCAN_CODE_ENTER) Key_Scan(301); + break; - case evReDraw: - DefineAndDrawWindow(215, 100, 580, 130, 0x74, system.color.work, DL_WINDOW_HEADER, 0); - GetProcessInfo(#DL_Form, SelfInfo); - if (DL_Form.status_window>2) break; - if (DL_Form.height<120) MoveSize(OLD,OLD,OLD,120); - if (DL_Form.width<280) MoveSize(OLD,OLD,280,OLD); - DL_Draw_Window(); - break; - - default: - if (!downloader.MonitorProgress()) break; - pb.max = downloader.data_full_size; - if (pb.value != downloader.data_downloaded_size) - { - pb.value = downloader.data_downloaded_size; - progressbar_draw stdcall(#pb); - DrawDownloading(); - } - if (downloader.state == STATE_COMPLETED) - { - if (!dir_exists(#save_to)) CreateDir(#save_to); - strcpy(#filepath, #save_to); - chrcat(#filepath, '/'); - // Clean all slashes at the end - strcpy(#aux, #downloader_edit); - while (aux[strlen(#aux)-1] == '/') { - aux[strlen(#aux)-1] = 0; - } - strcat(#filepath, #aux+strrchr(#aux, '/')); - - for (i=0; i2) break; + if (DL_Form.height<120) MoveSize(OLD,OLD,OLD,120); + if (DL_Form.width<280) MoveSize(OLD,OLD,280,OLD); + DL_Draw_Window(); + break; + + default: + if (!downloader.MonitorProgress()) break; + pb.max = downloader.data_full_size; + if (pb.value != downloader.data_downloaded_size) + { + pb.value = downloader.data_downloaded_size; + progressbar_draw stdcall(#pb); + DrawDownloading(); + } + if (downloader.state == STATE_COMPLETED) + { + SaveDownloadedFile(); + StopDownloading(); + DL_Draw_Window(); + break; + } + } } void Key_Scan(int id) { - if (id==001) { downloader_opened=0; StopDownloading(); ExitProcess(); } - if (id==301) && (downloader.http_transfer <= 0) StartDownloading(); - if (id==302) StopDownloading(); - if (id==305) RunProgram("/sys/File managers/Eolite", #save_to); - if (id==306) RunProgram("/sys/@open", #filepath); + if (id==001) { downloader_opened=false; StopDownloading(); ExitProcess(); } + if (id==301) && (downloader.httpd.transfer <= 0) StartDownloading(); + if (id==302) StopDownloading(); + if (id==305) RunProgram("/sys/File managers/Eolite", #save_to); + if (id==306) { + SetCurDir(#save_to); + RunProgram("/sys/@open", #filepath); + } } void DL_Draw_Window() { - int cleft = 15; - int but_x = 0; - int but_y = 58; - DrawBar(0,0, DL_Form.cwidth, DL_Form.cheight, system.color.work); - DeleteButton(305); - DeleteButton(306); - if (downloader.state == STATE_NOT_STARTED) || (downloader.state == STATE_COMPLETED) - { - but_x = cleft + DrawStandartCaptButton(cleft, but_y, 301, START_DOWNLOADING); - if (filepath[0]) - { - but_x += DrawStandartCaptButton(but_x, but_y, 305, SHOW_IN_FOLDER); - DrawStandartCaptButton(but_x, but_y, 306, OPEN_FILE_TEXT); - } - } - if (downloader.state == STATE_IN_PROGRESS) - { - DrawCaptButton(DL_Form.width - 190, but_y, 167, 26, 302, system.color.work_button, system.color.work_button_text, STOP_DOWNLOADING); - DrawDownloading(); - } - WriteText(cleft, ed.top + 4, 0x90, system.color.work_text, "URL:"); - ed.left = strlen("URL:")*8 + 10 + cleft; + int cleft = 15; + int but_x = 0; + int but_y = 58; + DrawBar(0,0, DL_Form.cwidth, DL_Form.cheight, system.color.work); + DeleteButton(301); + DeleteButton(302); + DeleteButton(305); + DeleteButton(306); + if (downloader.state == STATE_NOT_STARTED) || (downloader.state == STATE_COMPLETED) + { + but_x = cleft + DrawStandartCaptButton(cleft, but_y, 301, START_DOWNLOADING); + if (filepath[0]) + { + but_x += DrawStandartCaptButton(but_x, but_y, 305, SHOW_IN_FOLDER); + DrawStandartCaptButton(but_x, but_y, 306, OPEN_FILE_TEXT); + } + } + if (downloader.state == STATE_IN_PROGRESS) + { + DrawStandartCaptButton(DL_Form.width - 190, but_y, 302, STOP_DOWNLOADING); + DrawDownloading(); + } + WriteText(cleft, ed.top + 4, 0x90, system.color.work_text, "URL:"); ed.width = DL_Form.cwidth - ed.left - cleft - 3; - ed.offset=0; - DrawEditBox(#ed); + ed.offset=0; + DrawEditBox(#ed); } void StartDownloading() { - StopDownloading(); - if (strncmp(#downloader_edit,"http://",7)!=0) { - notify("'File address should start from http://' -E"); - return; - } - if (!downloader.Start(#downloader_edit)) { - notify("'Error while starting download process.\nPlease, check entered path and internet connection.' -E"); - StopDownloading(); - return; - } - ed.blur_border_color = 0xCACACA; - ed.flags = 100000000000b; - pb.value = 0; - DL_Draw_Window(); + StopDownloading(); + if (strncmp(#downloader_edit,"http://",7)!=0) { + notify("'File address should start from http://' -E"); + return; + } + if (!downloader.Start(#downloader_edit)) { + notify("'Error while starting download process.\nPlease, check entered path and internet connection.' -E"); + StopDownloading(); + return; + } + ed.blur_border_color = 0xCACACA; + ed.flags = 100000000000b; + pb.value = 0; + DL_Draw_Window(); } void DrawDownloading() { - char bytes_received[70]; - sprintf(#bytes_received, KB_RECEIVED, ConvertSizeToKb(downloader.data_downloaded_size) ); - DrawBar(15, pb.top + 22, strlen(#bytes_received+4)*12, 16, system.color.work); - WriteText(15, pb.top + 22, 0x90, system.color.work_text, #bytes_received); - progressbar_draw stdcall(#pb); + char bytes_received[70]; + sprintf(#bytes_received, KB_RECEIVED, ConvertSizeToKb(downloader.data_downloaded_size) ); + DrawBar(15, pb.top + 22, strlen(#bytes_received+4)*12, 16, system.color.work); + WriteText(15, pb.top + 22, 0x90, system.color.work_text, #bytes_received); + progressbar_draw stdcall(#pb); } void StopDownloading() { - downloader.Stop(); - ed.blur_border_color = 0xFFFfff; - ed.flags = 10b; - DL_Draw_Window(); + downloader.Stop(); + ed.blur_border_color = 0xFFFfff; + ed.flags = 10b; + DL_Draw_Window(); +} + +void SaveDownloadedFile() +{ + int i; + char aux[2048]; + char notify_message[4296]; + + // Clean all slashes at the end + strcpy(#aux, #downloader_edit); + while (aux[strlen(#aux)-1] == '/') { + aux[strlen(#aux)-1] = 0; + } + sprintf(#filepath, "%s/%s", #save_to, #aux+strrchr(#aux, '/')); + + for (i=0; i= 300) && (http_status_code < 400) + if (httpd.status_code >= 300) && (httpd.status_code < 400) { - http_find_header_field stdcall (http_transfer, "location\0"); - if (EAX!=0) { - ESI = EAX; - EDI = #redirect_url; - do { - $lodsb; - $stosb; - } while ((AL != 0) && (AL != 13) && (AL != 10)); - DSBYTE[EDI-1]='\0'; - } + httpd.handle_redirect(); + strcpy(url, httpd.url); get_absolute_url(#finaladress, url, #redirect_url); Stop(); Start(#finaladress); @@ -94,7 +157,7 @@ int DOWNLOADER::MonitorProgress() /*===================================== == == -== CHECK URL TYPE == +== CHECK PATH TYPE == == == =====================================*/ diff --git a/programs/cmm/liza/liza.c b/programs/cmm/liza/liza.c index ff9baf39b1..9c6c63a171 100644 --- a/programs/cmm/liza/liza.c +++ b/programs/cmm/liza/liza.c @@ -26,6 +26,11 @@ byte letter_icons[sizeof(file "img/letter_icons.raw")] = FROM "img/letter_icons.raw"; #include "img/letter_icons.h" +struct mockup +{ + dword transfer; +} http = {0}; + //connection algorithm enum { STOP,