From 8e5b315fd46add46254120a3a8e5e7d54858eb3b Mon Sep 17 00:00:00 2001 From: leency Date: Fri, 28 Feb 2025 01:44:59 +0200 Subject: [PATCH] Apps: Fix webview and downloader issue #22 - Fix #22 in both webview and downloader; - Get rid of app mode in webview; - Fix update link for webview. --- programs/cmm/browser/TWB/render.h | 6 +-- programs/cmm/browser/TWB/set_style.h | 20 -------- programs/cmm/browser/WebView.c | 73 +++++++++------------------- programs/cmm/browser/const.h | 4 +- programs/cmm/downloader/const.h | 12 +++-- programs/cmm/downloader/dl.c | 14 +++++- programs/cmm/lib/obj/http.h | 22 ++++----- 7 files changed, 59 insertions(+), 92 deletions(-) diff --git a/programs/cmm/browser/TWB/render.h b/programs/cmm/browser/TWB/render.h index c09369a11..80f3be413 100644 --- a/programs/cmm/browser/TWB/render.h +++ b/programs/cmm/browser/TWB/render.h @@ -10,10 +10,8 @@ void TWebBrowser::RenderLine(dword _line) if (style.title) { strncpy(#header, _line, sizeof(TWebBrowser.header)-1); - if (!application_mode) { - strncat(#header, " - ", sizeof(TWebBrowser.header)-1); - strncat(#header, #version, sizeof(TWebBrowser.header)-1); - } + strncat(#header, " - ", sizeof(TWebBrowser.header)-1); + strncat(#header, #version, sizeof(TWebBrowser.header)-1); } else if (t_html) && (!t_body) { // diff --git a/programs/cmm/browser/TWB/set_style.h b/programs/cmm/browser/TWB/set_style.h index dd9b9d764..608b432e7 100644 --- a/programs/cmm/browser/TWB/set_style.h +++ b/programs/cmm/browser/TWB/set_style.h @@ -56,10 +56,6 @@ void TWebBrowser::SetStyle() if (tag.is("tr")) { tag_table(); return; } if (tag.is("th")) { tag_table(); return; } if (tag.is("td")) { tag_table(); return; } - - if (application_mode) { - if (tag.is("exit")) { ExitProcess(); return; } - } } void TWebBrowser::tag_p() @@ -148,22 +144,6 @@ void TWebBrowser::tag_meta_xml() if (streq(tag.get_value_of("http-equiv"), "refresh")) && (tag.get_value_of("content")) { if (tag.value = strstri(tag.value, "url")) strcpy(#redirect, tag.value); } - if (streq(tag.get_value_of("name"), "application")) { - if (application_mode) { - if (tag.get_number_of("left")) { - MoveSize(tag.number,-1,-1,-1); - } - if (tag.get_number_of("top")) { - MoveSize(-1,tag.number,-1,-1); - } - if (tag.get_number_of("width")) { - MoveSize(-1,-1,tag.number,-1); - } - if (tag.get_number_of("height")) { - MoveSize(-1,-1,-1,tag.number); - } - } - } } signed int get_encoding_type_by_name(dword name) diff --git a/programs/cmm/browser/WebView.c b/programs/cmm/browser/WebView.c index d07b88a6d..e6e978a8e 100644 --- a/programs/cmm/browser/WebView.c +++ b/programs/cmm/browser/WebView.c @@ -45,7 +45,6 @@ bool debug_mode = false; bool show_images = true; bool source_mode = false; -bool application_mode = false; _history history; @@ -110,9 +109,6 @@ void HandleParam() history.add(#param + 8); } else if (!strncmp(#param, "-new ", 5)) { history.add(#param + 5); - } else if (!strncmp(#param, "-app ", 5)) { - history.add(#param + 5); - application_mode = true; } else { if (GetProcessesCount("WEBVIEW") == 1) { history.add(#param); @@ -136,14 +132,6 @@ void main() LoadLibraries(); HandleParam(); - if (application_mode) { - TOOLBAR_H = 0; - PADDING = 0; - TSZE = 0; - STATUSBAR_H = 0; - TAB_H = 0; - } - omnibox_edit.left = PADDING+TSZE*2+PADDING+6; omnibox_edit.top = PADDING+3; @@ -221,15 +209,6 @@ void main() if (http.transfer <= 0) break; http.receive(); - if (http_get_type==PAGE) { - CheckContentType(); - prbar.max = http.content_length; - if (prbar.value != http.content_received) { - prbar.value = http.content_received; - DrawProgress(); - } - } - if (http.receive_result != 0) break; if (debug_mode) { EAX = http.transfer; @@ -248,6 +227,15 @@ void main() notify("'Too many redirects.' -E"); } } else { + if (http_get_type==PAGE) { + CheckContentType(); + prbar.max = http.content_length; + if (prbar.value != http.content_received) { + prbar.value = http.content_received; + DrawProgress(); + } + } + // Loading the page is complete, free resources redirect_count = 0; if (http_get_type==PAGE) { @@ -382,23 +370,21 @@ void draw_window() SetElementSizes(); - if (!application_mode) { - DrawBar(0,0, Form.cwidth,PADDING, sc.work); - DrawBar(0,PADDING+TSZE+1, Form.cwidth,PADDING-1, sc.work); - DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, MixColors(sc.dark, sc.work, 180)); - DrawBar(0,TOOLBAR_H-1, Form.cwidth,1, sc.line); - DrawBar(0, PADDING, omnibox_edit.left-2, TSZE+1, sc.work); - DrawBar(omnibox_edit.left+omnibox_edit.width+18, PADDING, Form.cwidth-omnibox_edit.left-omnibox_edit.width-18, TSZE+1, sc.work); + DrawBar(0,0, Form.cwidth,PADDING, sc.work); + DrawBar(0,PADDING+TSZE+1, Form.cwidth,PADDING-1, sc.work); + DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, MixColors(sc.dark, sc.work, 180)); + DrawBar(0,TOOLBAR_H-1, Form.cwidth,1, sc.line); + DrawBar(0, PADDING, omnibox_edit.left-2, TSZE+1, sc.work); + DrawBar(omnibox_edit.left+omnibox_edit.width+18, PADDING, Form.cwidth-omnibox_edit.left-omnibox_edit.width-18, TSZE+1, sc.work); - DrawTopPanelButton(BACK_BUTTON, PADDING-1, PADDING, 30, false); - DrawTopPanelButton(FORWARD_BUTTON, PADDING+TSZE+PADDING-2, PADDING, 31, false); - DrawTopPanelButton(SANDWICH_BUTTON, Form.cwidth-PADDING-TSZE-3, PADDING, -1, burger_active); //burger menu + DrawTopPanelButton(BACK_BUTTON, PADDING-1, PADDING, 30, false); + DrawTopPanelButton(FORWARD_BUTTON, PADDING+TSZE+PADDING-2, PADDING, 31, false); + DrawTopPanelButton(SANDWICH_BUTTON, Form.cwidth-PADDING-TSZE-3, PADDING, -1, burger_active); //burger menu - DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, sc.line); + DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, sc.line); - DrawRectangle(WB1.list.x + WB1.list.w, WB1.list.y, scroll_wv.size_x, - WB1.list.h-1, scroll_wv.bckg_col); - } + DrawRectangle(WB1.list.x + WB1.list.w, WB1.list.y, scroll_wv.size_x, + WB1.list.h-1, scroll_wv.bckg_col); if (!canvas.bufw) { EventOpenFirstPage(); @@ -406,12 +392,9 @@ void draw_window() WB1.DrawPage(); DrawOmnibox(); } - if (!application_mode) { - DrawProgress(); - DrawStatusBar(NULL); - DrawTabsBar(); - } - + DrawProgress(); + DrawStatusBar(NULL); + DrawTabsBar(); } void EventOpenFirstPage() @@ -770,7 +753,6 @@ bool UrlExtIs(dword base, ext) void DrawProgress() { dword pct; - if (application_mode) return; if (!http.transfer) return; if (http_get_type==PAGE) && (prbar.max) pct = prbar.value*30/prbar.max; else pct = 10; if (http_get_type==IMG) pct = prbar.value * 70 / prbar.max + 30; @@ -779,21 +761,18 @@ void DrawProgress() void EventShowPageMenu() { - if (application_mode) return; open_lmenu(mouse.x, mouse.y, MENU_TOP_LEFT, NULL, #rmb_menu); menu_id = VIEW_SOURCE; } void EventShowLinkMenu() { - if (application_mode) return; open_lmenu(mouse.x, mouse.y, MENU_TOP_LEFT, NULL, #link_menu); menu_id = IN_NEW_TAB; } void EventShowMainMenu() { - if (application_mode) return; open_lmenu(Form.cwidth - PADDING -4, PADDING + TSZE + 3, MENU_TOP_RIGHT, NULL, #main_menu); menu_id = OPEN_FILE; @@ -801,7 +780,6 @@ void EventShowMainMenu() void EventShowEncodingsList() { - if (application_mode) return; open_lmenu(Form.cwidth-4, Form.cheight - STATUSBAR_H + 12, MENU_BOT_RIGHT, WB1.cur_encoding + 1, "UTF-8\nKOI8-RU\nCP1251\nCP1252\nISO8859-5\nCP866"); @@ -886,7 +864,6 @@ void DrawStatusBar(dword _msg) { dword status_y = Form.cheight - STATUSBAR_H + 4; dword status_w = Form.cwidth - 90; - if (application_mode) return; if (Form.status_window>2) return; DrawBar(0,Form.cheight - STATUSBAR_H+1, Form.cwidth,STATUSBAR_H-1, sc.work); if (_msg) { @@ -900,7 +877,6 @@ void DrawStatusBar(dword _msg) void DrawOmnibox() { int imgxoff; - if (application_mode) return; DrawOvalBorder(omnibox_edit.left-2, omnibox_edit.top-3, omnibox_edit.width+18, 24, sc.line, sc.line, sc.line, sc.dark); DrawBar(omnibox_edit.left-1, omnibox_edit.top-2, omnibox_edit.width+18, 1, 0xD8DCD8); @@ -919,7 +895,6 @@ void DrawOmnibox() void SetOmniboxText(dword _text) { - if (application_mode) return; edit_box_set_text stdcall (#omnibox_edit, _text); omnibox_edit.pos = omnibox_edit.flags = 0; DrawOmnibox(); diff --git a/programs/cmm/browser/const.h b/programs/cmm/browser/const.h index 013baa909..d14069f11 100644 --- a/programs/cmm/browser/const.h +++ b/programs/cmm/browser/const.h @@ -27,7 +27,7 @@ char link_menu[] = Скачать содержимое ссылки"; char loading_text[] = "Загрузка..."; -char update_param[] = "-e http://builds.kolibrios.org/rus/data/programs/cmm/browser/WebView.com"; +char update_param[] = "-e http://builds.kolibrios.org/ru_RU/data/programs/cmm/browser/WebView.com"; char update_download_error[] = "'WebView\nОшибка при получении обновлений!' -tE"; char update_ok[] = "'WebView\nБраузер был успешно обновлен!' -tO"; char update_is_current[] = "'WebView\nВы уже используете последнюю версию.' -tI"; @@ -63,7 +63,7 @@ Open in new window Copy link Download link contents"; char loading_text[] = "Loading..."; -char update_param[] = "-e http://builds.kolibrios.org/eng/data/programs/cmm/browser/WebView.com"; +char update_param[] = "-e http://builds.kolibrios.org/en_US/data/programs/cmm/browser/WebView.com"; char update_download_error[] = "'WebView\nError receiving an up to date information!' -tE"; char update_ok[] = "'WebView\nThe browser has been updated!' -tO"; char update_is_current[] = "'WebView\nThe browser is up to date.' -tI"; diff --git a/programs/cmm/downloader/const.h b/programs/cmm/downloader/const.h index 023b74462..51cca1555 100644 --- a/programs/cmm/downloader/const.h +++ b/programs/cmm/downloader/const.h @@ -17,8 +17,10 @@ #define T_STATUS_DL_P2 " MБ получено (" #define T_STATUS_DL_P3 " KБ/с) " - #define FILE_SAVED_AS "'Менеджер загрузок\nФайл сохранен как %s' -Dt" - #define FILE_NOT_SAVED "'Менеджер загрузок\nОшибка! Файл не может быть сохранен как\n%s' -Et" + #define T_ERROR_TOO_MANY_REDIRECTS "'Менеджер загрузок\nСлишком много редиректов (HTTP 3XX)' -Et" + + #define T_FILE_SAVED_AS "'Менеджер загрузок\nФайл сохранен как %s' -Dt" + #define T_FILE_NOT_SAVED "'Менеджер загрузок\nОшибка! Файл не может быть сохранен как\n%s' -Et" #define T_ERROR_STARTING_DOWNLOAD "'Невозможно начать скачивание.\nПроверьте введенный путь и соединение с Интернетом.' -E" char accept_language[]= "Accept-Language: ru\n"; #else @@ -38,8 +40,10 @@ #define T_STATUS_DL_P2 " MB received (" #define T_STATUS_DL_P3 " KB/s) " - #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 T_ERROR_TOO_MANY_REDIRECTS "'Download manager\nToo many redirects' -Et" + + #define T_FILE_SAVED_AS "'Download manager\nFile saved as %s' -Dt" + #define T_FILE_NOT_SAVED "'Download manager\nError! Can\96t save file as %s' -Et" #define T_ERROR_STARTING_DOWNLOAD "'Error while starting download process.\nCheck entered path and Internet connection.' -E" char accept_language[]= "Accept-Language: en\n"; #endif diff --git a/programs/cmm/downloader/dl.c b/programs/cmm/downloader/dl.c index f75ea637c..bd62c5757 100644 --- a/programs/cmm/downloader/dl.c +++ b/programs/cmm/downloader/dl.c @@ -11,6 +11,8 @@ bool open_file = false; dword speed; +int redirect_count; + _http http; checkbox autoclose = { T_AUTOCLOSE, false }; @@ -228,6 +230,7 @@ void InitDownload() pb.progress_color = PB_COL_PROGRESS; filepath = '\0'; active_status = T_STATUS_READY; + redirect_count = 0; } void MonitorProgress() @@ -241,6 +244,13 @@ void MonitorProgress() DrawDownloadingProgress(); } else { if (http.status_code >= 300) && (http.status_code < 400) { + redirect_count++; + if (redirect_count >= 5) { + notify(T_ERROR_TOO_MANY_REDIRECTS); + ProcessButtonClick(BTN_STOP); + EditBox_UpdateText(#ed, ed_focus + ed_always_focus); + return; + } http.header_field("location", #redirect_url, URL_SIZE); get_absolute_url(#redirect_url, #uEdit); edit_box_set_text stdcall (#ed, #redirect_url); @@ -307,9 +317,9 @@ void SaveFile(int attempt) } if (CreateFile(http.content_received, http.content_pointer, #filepath)==0) { - miniprintf(#notify_message, FILE_SAVED_AS, #filepath); + miniprintf(#notify_message, T_FILE_SAVED_AS, #filepath); } else { - miniprintf(#notify_message, FILE_NOT_SAVED, #filepath); + miniprintf(#notify_message, T_FILE_NOT_SAVED, #filepath); } if (!autoclose.checked) notify(#notify_message); diff --git a/programs/cmm/lib/obj/http.h b/programs/cmm/lib/obj/http.h index b450dfe53..14aff6902 100644 --- a/programs/cmm/lib/obj/http.h +++ b/programs/cmm/lib/obj/http.h @@ -70,17 +70,17 @@ char aURIunescape[] = "unescape"; #define FLAG_TRANSFER_FAILED 1 << 20 struct http_msg{ - dword socket; - dword flags; - dword write_ptr; - dword buffer_length; - dword chunk_ptr; - dword timestamp; - dword status; - dword header_length; - dword content_ptr; - dword content_length; - dword content_received; + dword socket; //socket on which the actual transfer happens + dword flags; //flags, reflects status of the transfer using bitflags + dword write_ptr; //internal use only (where to write new data in buffer) + dword buffer_length; //internal use only (number of available bytes in buffer) + dword chunk_ptr; //internal use only (where the next chunk begins) + dword timestamp; //internal use only (when last data was received) + dword status; //HTTP status + dword header_length; //length of HTTP header + dword content_ptr; //ptr to content + dword content_length; //total length of HTTP content + dword content_received; //number of currently received content bytes char http_header; };