forked from KolibriOS/kolibrios
http, dl, webview: refactoring
git-svn-id: svn://kolibrios.org@8305 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
eebb43e620
commit
1c88038821
@ -25,14 +25,13 @@
|
||||
|
||||
//useful patterns
|
||||
#include "..\lib\patterns\history.h"
|
||||
#include "..\lib\patterns\http_downloader.h"
|
||||
#include "..\lib\patterns\simple_open_dialog.h"
|
||||
#include "..\lib\patterns\toolbar_button.h"
|
||||
#include "..\lib\patterns\restart_process.h"
|
||||
|
||||
char editbox_icons[] = FROM "res/editbox_icons.raw";
|
||||
|
||||
char version[]="WebView 2.7a";
|
||||
char version[]="WebView 2.7b";
|
||||
|
||||
#include "texts.h"
|
||||
#include "cache.h"
|
||||
@ -60,7 +59,7 @@ enum {
|
||||
IN_NEW_TAB,
|
||||
IN_NEW_WINDOW,
|
||||
COPY_LINK_URL,
|
||||
DOWNLOAD_LINK_CONTENTS,
|
||||
DOWNLOAD_LINK_CT,
|
||||
TAB_ID,
|
||||
TAB_CLOSE_ID = 900
|
||||
};
|
||||
@ -143,7 +142,6 @@ void main()
|
||||
{
|
||||
int i, redirect_count=0;
|
||||
LoadLibraries();
|
||||
//CreateDir("/tmp0/1/WebView_Cache");
|
||||
HandleParam();
|
||||
WB1.list.SetFont(8, 14, 10011000b);
|
||||
WB1.list.no_selection = true;
|
||||
@ -238,23 +236,14 @@ void main()
|
||||
if (http.transfer <= 0) break;
|
||||
http.receive();
|
||||
EventUpdateProgressBar();
|
||||
if (http.check_content_type()) // application || image
|
||||
if (http.content_type[0] == 'a') || (http.content_type[0] == 'i') {
|
||||
EventOpenDownloader(history.current());
|
||||
StopLoading();
|
||||
history.back();
|
||||
EventRefreshPage();
|
||||
}
|
||||
CheckContentType();
|
||||
if (http.receive_result != 0) break;
|
||||
if (http.status_code >= 300) && (http.status_code < 400)
|
||||
{
|
||||
// Handle redirects
|
||||
if (redirect_count<=5) {
|
||||
redirect_count++;
|
||||
http.handle_redirect();
|
||||
history.back();
|
||||
if (http_get_type==PAGE) OpenPage(#http.redirect_url);
|
||||
else if (http_get_type==IMG) http.get(#http.redirect_url);
|
||||
HandleRedirect();
|
||||
} else {
|
||||
notify("'Too many redirects.' -E");
|
||||
StopLoading();
|
||||
@ -382,116 +371,78 @@ void ProcessEvent(dword id__)
|
||||
{
|
||||
switch (id__)
|
||||
{
|
||||
case 1:
|
||||
ExitProcess();
|
||||
break;
|
||||
case ENCODINGS...ENCODINGS+6:
|
||||
EventChangeEncodingAndLoadPage(id__-ENCODINGS);
|
||||
return;
|
||||
case NEW_WINDOW:
|
||||
RunProgram(#program_path, NULL);
|
||||
return;
|
||||
case 1: ExitProcess();
|
||||
case TAB_CLOSE_ID...TAB_CLOSE_ID+TABS_MAX: EventTabClose(id__ - TAB_CLOSE_ID); return;
|
||||
case TAB_ID...TAB_ID+TABS_MAX: EventAllTabsClick(id__ - TAB_ID); return;
|
||||
case ENCODINGS...ENCODINGS+6: EventChangeEncodingAndLoadPage(id__-ENCODINGS); return;
|
||||
case NEW_WINDOW: RunProgram(#program_path, NULL); return;
|
||||
case NEW_TAB: if (!http.transfer) EventOpenNewTab(URL_SERVICE_HOMEPAGE); return;
|
||||
case SCAN_CODE_BS:
|
||||
case BACK_BUTTON:
|
||||
if (history.back()) {
|
||||
OpenPage(history.current());
|
||||
}
|
||||
return;
|
||||
case FORWARD_BUTTON:
|
||||
if (history.forward()) {
|
||||
OpenPage(history.current());
|
||||
}
|
||||
return;
|
||||
case BACK_BUTTON: if (history.back()) OpenPage(history.current()); return;
|
||||
case FORWARD_BUTTON: if (history.forward()) OpenPage(history.current()); return;
|
||||
case GOTOURL_BUTTON:
|
||||
case SCAN_CODE_ENTER:
|
||||
EventSubmitOmnibox();
|
||||
return;
|
||||
case REFRESH_BUTTON:
|
||||
EventRefreshPage();
|
||||
return;
|
||||
case CHANGE_ENCODING:
|
||||
EventShowEncodingsList();
|
||||
return;
|
||||
case SANDWICH_BUTTON:
|
||||
EventShowMainMenu();
|
||||
return;
|
||||
case VIEW_SOURCE:
|
||||
EventViewSource();
|
||||
break;
|
||||
case EDIT_SOURCE:
|
||||
case SCAN_CODE_ENTER: EventSubmitOmnibox(); return;
|
||||
case REFRESH_BUTTON: EventRefreshPage(); return;
|
||||
case CHANGE_ENCODING: EventShowEncodingsList(); return;
|
||||
case SANDWICH_BUTTON: EventShowMainMenu(); return;
|
||||
case VIEW_SOURCE: EventViewSource(); return;
|
||||
case EDIT_SOURCE: EventEditSource(); return;
|
||||
case VIEW_HISTORY: OpenPage(URL_SERVICE_HISTORY); return;
|
||||
case DOWNLOAD_MANAGER: EventOpenDownloader(""); return;
|
||||
case UPDATE_BROWSER: EventUpdateBrowser(); return;
|
||||
case CLEAR_CACHE: EventClearCache(); return;
|
||||
case IN_NEW_TAB: EventClickLink(TARGET_NEW_TAB); return;
|
||||
case IN_NEW_WINDOW: EventClickLink(TARGET_NEW_WINDOW); return;
|
||||
case COPY_LINK_URL: EventCopyLinkToClipboard(); return;
|
||||
case DOWNLOAD_LINK_CT: EventOpenDownloader( GetAbsoluteActiveURL() ); return;
|
||||
case OPEN_FILE: EventOpenDialog(); return;
|
||||
case SCAN_CODE_F12: EventToggleDebugMode(); return;
|
||||
}
|
||||
}
|
||||
|
||||
void EventToggleDebugMode()
|
||||
{
|
||||
debug_mode ^= 1;
|
||||
if (debug_mode) notify("'Debug mode ON'-I");
|
||||
else notify("'Debug mode OFF'-I");
|
||||
}
|
||||
|
||||
void EventAllTabsClick(dword _n)
|
||||
{
|
||||
if (http.transfer) return;
|
||||
if (mouse.mkm) {
|
||||
EventTabClose(_n);
|
||||
} else {
|
||||
EventTabClick(_n);
|
||||
}
|
||||
}
|
||||
|
||||
void EventEditSource()
|
||||
{
|
||||
if (check_is_the_adress_local(history.current())) {
|
||||
RunProgram("/rd/1/tinypad", history.current());
|
||||
} else {
|
||||
CreateFile(WB1.bufsize, WB1.bufpointer, "/tmp0/1/WebView_tmp.htm");
|
||||
if (!EAX) RunProgram("/rd/1/tinypad", "/tmp0/1/WebView_tmp.htm");
|
||||
}
|
||||
return;
|
||||
case VIEW_HISTORY:
|
||||
OpenPage(URL_SERVICE_HISTORY);
|
||||
return;
|
||||
case DOWNLOAD_MANAGER:
|
||||
EventOpenDownloader("");
|
||||
return;
|
||||
case UPDATE_BROWSER:
|
||||
EventUpdateBrowser();
|
||||
return;
|
||||
case CLEAR_CACHE:
|
||||
}
|
||||
|
||||
void EventClearCache()
|
||||
{
|
||||
cache.clear();
|
||||
notify(#clear_cache_ok);
|
||||
EventRefreshPage();
|
||||
return;
|
||||
case IN_NEW_TAB:
|
||||
EventClickLink(TARGET_NEW_TAB);
|
||||
return;
|
||||
case IN_NEW_WINDOW:
|
||||
EventClickLink(TARGET_NEW_WINDOW);
|
||||
return;
|
||||
case COPY_LINK_URL:
|
||||
}
|
||||
|
||||
void EventCopyLinkToClipboard()
|
||||
{
|
||||
Clipboard__CopyText(GetAbsoluteActiveURL());
|
||||
notify("'URL copied to clipboard'O");
|
||||
return;
|
||||
case DOWNLOAD_LINK_CONTENTS:
|
||||
EventOpenDownloader( GetAbsoluteActiveURL() );
|
||||
return;
|
||||
case OPEN_FILE:
|
||||
EventOpenDialog();
|
||||
return;
|
||||
case SCAN_CODE_F12:
|
||||
debug_mode ^= 1;
|
||||
if (debug_mode) notify("'Debug mode ON'-I");
|
||||
else notify("'Debug mode OFF'-I");
|
||||
return;
|
||||
case NEW_TAB:
|
||||
if (http.transfer) break;
|
||||
EventOpenNewTab(URL_SERVICE_HOMEPAGE);
|
||||
return;
|
||||
case TAB_ID...TAB_ID+TABS_MAX:
|
||||
if (http.transfer) break;
|
||||
if (mouse.mkm) {
|
||||
EventTabClose(id__ - TAB_ID);
|
||||
} else {
|
||||
EventTabClick(id__ - TAB_ID);
|
||||
}
|
||||
return;
|
||||
case TAB_CLOSE_ID...TAB_CLOSE_ID+TABS_MAX:
|
||||
EventTabClose(id__ - TAB_CLOSE_ID);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void StopLoading()
|
||||
{
|
||||
if (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
|
||||
$pop EAX
|
||||
free(EAX); // free data
|
||||
http.transfer=0;
|
||||
pause(10);
|
||||
}
|
||||
if (http.stop()) pause(10);
|
||||
wv_progress_bar.value = 0;
|
||||
DrawOmnibox();
|
||||
}
|
||||
@ -842,10 +793,6 @@ void EventOpenDialog()
|
||||
|
||||
void EventViewSource()
|
||||
{
|
||||
char source_view_param[URL_SIZE+1];
|
||||
//strcpy(#source_view_param, "-source ");
|
||||
//strncat(#source_view_param, history.current(), URL_SIZE);
|
||||
//RunProgram(#program_path, #source_view_param);
|
||||
source_mode = true;
|
||||
EventOpenNewTab(history.current());
|
||||
}
|
||||
@ -961,6 +908,29 @@ dword GetAbsoluteActiveURL()
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CheckContentType()
|
||||
{
|
||||
char content_type[64];
|
||||
if (http.header_field("content-type\0", #content_type, sizeof(content_type))) // application || image
|
||||
if (content_type[0] == 'a') || (content_type[0] == 'i') {
|
||||
EventOpenDownloader(history.current());
|
||||
StopLoading();
|
||||
history.back();
|
||||
EventRefreshPage();
|
||||
}
|
||||
}
|
||||
|
||||
void HandleRedirect()
|
||||
{
|
||||
char redirect_url[URL_SIZE];
|
||||
http.header_field("location\0", #redirect_url, URL_SIZE);
|
||||
get_absolute_url(#redirect_url, history.current());
|
||||
history.back();
|
||||
http.hfree();
|
||||
if (http_get_type==PAGE) OpenPage(#redirect_url);
|
||||
else if (http_get_type==IMG) http.get(#redirect_url);
|
||||
}
|
||||
|
||||
dword GetImg()
|
||||
{
|
||||
while (WB1.page_img.next_url()) {
|
||||
|
@ -6,10 +6,10 @@
|
||||
|
||||
#ifdef LANG_RUS
|
||||
#define DL_WINDOW_HEADER "Œ¥¥¤¦¥à § £à㧮ª"
|
||||
#define START_DOWNLOADING "‘ª ç âì"
|
||||
#define STOP_DOWNLOADING "Žâ¬¥ "
|
||||
#define SHOW_IN_FOLDER "<22>®ª § âì ¢ ¯ ¯ª¥"
|
||||
#define OPEN_FILE_TEXT "Žâªàëâì ä ©«"
|
||||
#define T_DOWNLOAD "‘ª ç âì"
|
||||
#define T_CANCEL "Žâ¬¥ "
|
||||
#define T_OPEN_DIR "<22>®ª § âì ¢ ¯ ¯ª¥"
|
||||
#define T_RUN "Žâªàëâì ä ©«"
|
||||
#define FILE_SAVED_AS "'Œ¥¥¤¦¥à § £à㧮ª\n” ©« á®åà ¥ ª ª %s' -Dt"
|
||||
#define FILE_NOT_SAVED "'Œ¥¥¤¦¥à § £à㧮ª\nŽè¨¡ª ! ” ©« ¥ ¬®¦¥â ¡ëâì á®åà ¥ ª ª\n%s' -Et"
|
||||
#define KB_RECEIVED "ˆ¤¥â ᪠稢 ¨¥... %s ¯®«ã祮"
|
||||
@ -18,10 +18,10 @@
|
||||
char accept_language[]= "Accept-Language: ru\n";
|
||||
#else
|
||||
#define DL_WINDOW_HEADER "Download Manager"
|
||||
#define START_DOWNLOADING "Download"
|
||||
#define STOP_DOWNLOADING "Cancel"
|
||||
#define SHOW_IN_FOLDER "Show in folder"
|
||||
#define OPEN_FILE_TEXT "Open file"
|
||||
#define T_DOWNLOAD "Download"
|
||||
#define T_CANCEL "Cancel"
|
||||
#define T_OPEN_DIR " Show in folder "
|
||||
#define T_RUN "Open file"
|
||||
#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"
|
||||
@ -34,7 +34,13 @@
|
||||
#define WIN_W 580
|
||||
#define WIN_H 100
|
||||
|
||||
#define URL_SIZE 4000
|
||||
|
||||
char save_to[] = "/tmp0/1/Downloads";
|
||||
char dl_shared[] = "DL";
|
||||
|
||||
enum {
|
||||
BTN_EXIT=1,
|
||||
BTN_START,
|
||||
BTN_STOP,
|
||||
BTN_DIR,
|
||||
BTN_RUN,
|
||||
};
|
@ -1,27 +1,25 @@
|
||||
//Copyright 2020 by Leency
|
||||
|
||||
#define MEMSIZE 1024 * 100
|
||||
//Copyright 2020 by Leency
|
||||
#include "../lib/gui.h"
|
||||
#include "../lib/random.h"
|
||||
|
||||
#include "../lib/obj/box_lib.h"
|
||||
#include "../lib/obj/http.h"
|
||||
|
||||
#include "../lib/patterns/http_downloader.h"
|
||||
|
||||
#include "const.h"
|
||||
|
||||
DOWNLOADER downloader;
|
||||
dword bufpointer, bufsize;
|
||||
bool exit_param = false;
|
||||
|
||||
_http http;
|
||||
|
||||
checkbox autoclose = { T_AUTOCLOSE, false };
|
||||
|
||||
char downloader_edit[4000];
|
||||
char filepath[4096];
|
||||
edit_box ed = {WIN_W-GAPX-GAPX,GAPX,20,0xffffff,0x94AECE,0xffffff,0xffffff,0x10000000,
|
||||
sizeof(downloader_edit)-2,#downloader_edit,0,ed_focus,19,19};
|
||||
progress_bar pb = {0, GAPX, 58, 315, 17, 0, 0, 100, 0xFFFfff, 0x74DA00, 0x9F9F9F};
|
||||
//progress_bar: value, left, top, width, height, style, min, max, back_color, progress_color, frame_color;
|
||||
char main_url[URL_SIZE];
|
||||
char filepath[URL_SIZE+96];
|
||||
|
||||
bool exit_when_done = false;
|
||||
progress_bar pb = {0, GAPX, 58, 315, 17, 0, NULL, NULL, 0xFFFfff, 0x74DA00, NULL};
|
||||
edit_box ed = {WIN_W-GAPX-GAPX,GAPX,20,0xffffff,0x94AECE,0xffffff,0xffffff,
|
||||
0x10000000, sizeof(main_url)-2,#main_url,0,ed_focus,19,19};
|
||||
|
||||
|
||||
void main()
|
||||
@ -31,139 +29,205 @@ void main()
|
||||
load_dll(libHTTP, #http_lib_init,1);
|
||||
|
||||
if (!dir_exists(#save_to)) CreateDir(#save_to);
|
||||
SetCurDir(#save_to);
|
||||
|
||||
if (param) {
|
||||
if (!strncmp(#param, "-exit ", 6)) {
|
||||
exit_when_done = true;
|
||||
exit_param = true;
|
||||
param += 6;
|
||||
}
|
||||
|
||||
if (!strncmp(#param, "-mem", 5)) {
|
||||
//shared_url = memopen(#dl_shared, URL_SIZE+1, SHM_OPEN + SHM_WRITE);
|
||||
strcpy(#downloader_edit, shared_url);
|
||||
strcpy(#main_url, shared_url);
|
||||
} else {
|
||||
strcpy(#downloader_edit, #param);
|
||||
strcpy(#main_url, #param);
|
||||
}
|
||||
}
|
||||
if (downloader_edit[0]) StartDownloading(); else strcpy(#downloader_edit, "http://");
|
||||
ed.size = ed.pos = ed.shift = ed.shift_old = strlen(#downloader_edit);
|
||||
if (main_url[0]) StartDownloading(); else strcpy(#main_url, "http://");
|
||||
EditBox_UpdateText(#ed, #main_url);
|
||||
|
||||
@SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER + EVM_STACK);
|
||||
@SetWindowLayerBehaviour(-1, ZPOS_ALWAYS_TOP);
|
||||
loop() switch(@WaitEvent())
|
||||
{
|
||||
case evMouse:
|
||||
edit_box_mouse stdcall (#ed);
|
||||
break;
|
||||
case evMouse: edit_box_mouse stdcall (#ed); break;
|
||||
case evButton: ProcessButtonClick(); break;
|
||||
case evKey: ProcessKeyPress(); break;
|
||||
case evReDraw: DrawWindow(); break;
|
||||
default: MonitorProgress();
|
||||
}
|
||||
}
|
||||
|
||||
case evButton:
|
||||
ProcessEvent(GetButtonID());
|
||||
break;
|
||||
|
||||
case evKey:
|
||||
GetKeys();
|
||||
edit_box_key stdcall(#ed);
|
||||
if (key_scancode==SCAN_CODE_ENTER) ProcessEvent(301);
|
||||
break;
|
||||
|
||||
case evReDraw:
|
||||
DrawWindow();
|
||||
break;
|
||||
|
||||
default:
|
||||
if (!downloader.MonitorProgress()) break;
|
||||
pb.max = downloader.content_length / 100;
|
||||
EDI = downloader.content_received/100;
|
||||
if (pb.value != EDI)
|
||||
{
|
||||
pb.value = EDI;
|
||||
progressbar_draw stdcall(#pb);
|
||||
DrawDownloading();
|
||||
}
|
||||
if (downloader.state == STATE_COMPLETED)
|
||||
{
|
||||
SaveDownloadedFile();
|
||||
if (exit_when_done) ExitProcess();
|
||||
StopDownloading();
|
||||
DrawWindow();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ProcessEvent(int id)
|
||||
void ProcessButtonClick()
|
||||
{
|
||||
int id = @GetButtonID();
|
||||
autoclose.click(id);
|
||||
if (id==001) { StopDownloading(); ExitProcess(); }
|
||||
if (id==301) && (downloader.transfer <= 0) StartDownloading();
|
||||
if (id==302) StopDownloading();
|
||||
if (id==305) RunProgram("/sys/File managers/Eolite", #filepath);
|
||||
if (id==306) {
|
||||
SetCurDir(#save_to);
|
||||
RunProgram("/sys/@open", #filepath);
|
||||
if (id==BTN_EXIT) { StopDownloading(); ExitProcess(); }
|
||||
if (id==BTN_START) StartDownloading();
|
||||
if (id==BTN_STOP) StopDownloading();
|
||||
if (id==BTN_DIR) RunProgram("/sys/File managers/Eolite", #filepath);
|
||||
if (id==BTN_RUN) RunProgram("/sys/@open", #filepath);
|
||||
}
|
||||
|
||||
void ProcessKeyPress()
|
||||
{
|
||||
@GetKey();
|
||||
edit_box_key stdcall(#ed);
|
||||
EAX >>= 16;
|
||||
if (AL == SCAN_CODE_ENTER) StartDownloading();
|
||||
if (AL == SCAN_CODE_ESC) StopDownloading();
|
||||
}
|
||||
|
||||
void DrawWindow()
|
||||
{
|
||||
int but_x = 0;
|
||||
#define BUT_Y 58;
|
||||
|
||||
sc.get();
|
||||
pb.frame_color = sc.work_dark;
|
||||
DefineAndDrawWindow(110 + random(300), 100 + random(300), WIN_W+9, WIN_H + 5 + skin_height, 0x34, sc.work, DL_WINDOW_HEADER, 0);
|
||||
DefineAndDrawWindow(110 + random(300), 100 + random(300), WIN_W+9,
|
||||
WIN_H + 5 + skin_height, 0x34, sc.work, DL_WINDOW_HEADER, 0);
|
||||
|
||||
autoclose.draw(WIN_W-135, BUT_Y+6);
|
||||
|
||||
if (downloader.state == STATE_NOT_STARTED) || (downloader.state == STATE_COMPLETED)
|
||||
#define BUT_Y 58;
|
||||
//autoclose.draw(WIN_W-135, BUT_Y+6);
|
||||
if (!http.transfer)
|
||||
{
|
||||
but_x = GAPX + DrawStandartCaptButton(GAPX, BUT_Y, 301, START_DOWNLOADING);
|
||||
if (filepath[0])
|
||||
DrawStandartCaptButton(GAPX, BUT_Y, BTN_START, T_DOWNLOAD);
|
||||
if (filepath)
|
||||
{
|
||||
but_x += DrawStandartCaptButton(but_x, BUT_Y, 305, SHOW_IN_FOLDER);
|
||||
DrawStandartCaptButton(but_x, BUT_Y, 306, OPEN_FILE_TEXT);
|
||||
DrawStandartCaptButton(GAPX+102, BUT_Y, BTN_DIR, T_OPEN_DIR);
|
||||
DrawStandartCaptButton(GAPX+276, BUT_Y, BTN_RUN, T_RUN);
|
||||
}
|
||||
} else {
|
||||
DrawStandartCaptButton(WIN_W - 240, BUT_Y, BTN_STOP, T_CANCEL);
|
||||
DrawDownloadingProgress();
|
||||
}
|
||||
if (downloader.state == STATE_IN_PROGRESS)
|
||||
{
|
||||
DrawStandartCaptButton(WIN_W - 240, BUT_Y, 302, STOP_DOWNLOADING);
|
||||
DrawDownloading();
|
||||
}
|
||||
ed.offset=0;
|
||||
//ed.offset=0; //DEL?
|
||||
DrawEditBox(#ed);
|
||||
}
|
||||
|
||||
void StartDownloading()
|
||||
{
|
||||
char http_url[URL_SIZE];
|
||||
char proxy_url[URL_SIZE];
|
||||
StopDownloading();
|
||||
if (!strncmp(#downloader_edit,"https://",7)) {
|
||||
if (http.transfer > 0) return;
|
||||
filepath = '\0';
|
||||
if (!strncmp(#main_url,"https:",6)) {
|
||||
miniprintf(#proxy_url, "http://gate.aspero.pro/?site=%s", #main_url);
|
||||
strcpy(#main_url, #proxy_url);
|
||||
EditBox_UpdateText(#ed, #main_url);
|
||||
//notify("'HTTPS for download is not supported, trying to download the file via HTTP' -W");
|
||||
//miniprintf(#http_url, "http://%s", #downloader_edit+8);
|
||||
//miniprintf(#http_url, "http://%s", #main_url+8);
|
||||
//if (!downloader.Start(#http_url)) {
|
||||
// notify("'Download failed.' -E");
|
||||
// StopDownloading();
|
||||
//}
|
||||
miniprintf(#proxy_url, "http://gate.aspero.pro/?site=%s", #downloader_edit);
|
||||
if (!downloader.Start(#proxy_url)) {
|
||||
notify("'Download failed.' -E");
|
||||
StopDownloading();
|
||||
}
|
||||
DrawWindow();
|
||||
return;
|
||||
}
|
||||
if (!downloader.Start(#downloader_edit)) {
|
||||
if (exit_when_done) ExitProcess();
|
||||
notify(T_ERROR_STARTING_DOWNLOAD);
|
||||
StopDownloading();
|
||||
return;
|
||||
}
|
||||
if (http.get(#main_url)) {
|
||||
ed.blur_border_color = 0xCACACA;
|
||||
ed.flags = 100000000000b;
|
||||
pb.value = 0;
|
||||
DrawWindow();
|
||||
} else {
|
||||
notify(T_ERROR_STARTING_DOWNLOAD);
|
||||
StopDownloading();
|
||||
if (exit_param) ExitProcess();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DrawDownloadingProgress()
|
||||
{
|
||||
char bytes_received[70];
|
||||
|
||||
EDI = http.content_received / 100;
|
||||
if (pb.value == EDI) return;
|
||||
|
||||
pb.value = EDI;
|
||||
pb.max = http.content_length / 100;
|
||||
progressbar_draw stdcall(#pb);
|
||||
miniprintf(#bytes_received, KB_RECEIVED, ConvertSizeToKb(http.content_received) );
|
||||
WriteTextWithBg(GAPX, pb.top + 22, 0xD0, sc.work_text, #bytes_received, sc.work);
|
||||
//CalculateSpeed();
|
||||
}
|
||||
|
||||
void StopDownloading()
|
||||
{
|
||||
if (http.stop()) {
|
||||
bufsize = 0;
|
||||
bufpointer = free(bufpointer);
|
||||
}
|
||||
http.content_received = http.content_length = 0;
|
||||
|
||||
ed.blur_border_color = 0xFFFfff;
|
||||
ed.flags = 10b;
|
||||
DrawWindow();
|
||||
}
|
||||
|
||||
void MonitorProgress()
|
||||
{
|
||||
char redirect_url[URL_SIZE];
|
||||
if (http.transfer <= 0) return;
|
||||
http.receive();
|
||||
if (!http.content_length) http.content_length = http.content_received * 20; //MOVE?
|
||||
|
||||
if (http.receive_result == 0) {
|
||||
if (http.status_code >= 300) && (http.status_code < 400)
|
||||
{
|
||||
http.header_field("location\0", #redirect_url, URL_SIZE);
|
||||
get_absolute_url(#redirect_url, #main_url);
|
||||
strcpy(#main_url, #redirect_url);
|
||||
EditBox_UpdateText(#ed, #main_url);
|
||||
StopDownloading();
|
||||
StartDownloading();
|
||||
return;
|
||||
}
|
||||
bufpointer = http.content_pointer;
|
||||
bufsize = http.content_received;
|
||||
http.hfree();
|
||||
}
|
||||
|
||||
DrawDownloadingProgress();
|
||||
|
||||
if (!http.receive_result)
|
||||
{
|
||||
SaveFile();
|
||||
if (exit_param) ExitProcess();
|
||||
StopDownloading();
|
||||
DrawWindow();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void SaveFile()
|
||||
{
|
||||
int i;
|
||||
char aux[2048];
|
||||
char notify_message[4296];
|
||||
|
||||
//char file_name[URL_SIZE];
|
||||
//Content-Disposition: attachment; filename="RealFootball_2018_Nokia_5800_EN_IGP_EU_TS_101.zip"
|
||||
//header_field("Content-Disposition\0", #redirect_url, URL_SIZE);
|
||||
|
||||
// Clean all slashes at the end
|
||||
strcpy(#aux, #main_url);
|
||||
while (aux[strlen(#aux)-1] == '/') {
|
||||
aux[strlen(#aux)-1] = 0;
|
||||
}
|
||||
|
||||
strcpy(#filepath, #save_to);
|
||||
chrcat(#filepath, '/');
|
||||
strcat(#filepath, #aux+strrchr(#aux, '/'));
|
||||
|
||||
for (i=0; i<strlen(#filepath); i++) if(filepath[i]==':')||(filepath[i]=='?')filepath[i]='-';
|
||||
|
||||
if (CreateFile(http.content_received, bufpointer, #filepath)==0) {
|
||||
miniprintf(#notify_message, FILE_SAVED_AS, #filepath);
|
||||
} else {
|
||||
miniprintf(#notify_message, FILE_NOT_SAVED, #filepath);
|
||||
}
|
||||
|
||||
if (!exit_param) notify(#notify_message);
|
||||
if (autoclose.checked) ExitProcess();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
struct TIME
|
||||
@ -183,67 +247,13 @@ void CalculateSpeed()
|
||||
if (time.old) {
|
||||
time.gone = time.cur - time.old;
|
||||
if (time.gone > 200) {
|
||||
speed = downloader.content_received - netdata_received / time.gone * 100;
|
||||
speed = http.content_received - netdata_received / time.gone * 100;
|
||||
debugval("speed", speed);
|
||||
debugln(ConvertSizeToKb(speed) );
|
||||
time.old = time.cur;
|
||||
netdata_received = downloader.content_received;
|
||||
netdata_received = http.content_received;
|
||||
}
|
||||
}
|
||||
else time.old = time.cur;
|
||||
}
|
||||
*/
|
||||
|
||||
void DrawDownloading()
|
||||
{
|
||||
char bytes_received[70];
|
||||
miniprintf(#bytes_received, KB_RECEIVED, ConvertSizeToKb(downloader.content_received) );
|
||||
WriteTextWithBg(GAPX, pb.top + 22, 0xD0, sc.work_text, #bytes_received, sc.work);
|
||||
//CalculateSpeed();
|
||||
progressbar_draw stdcall(#pb);
|
||||
}
|
||||
|
||||
void StopDownloading()
|
||||
{
|
||||
downloader.Stop();
|
||||
ed.blur_border_color = 0xFFFfff;
|
||||
ed.flags = 10b;
|
||||
DrawWindow();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
//miniprintf(#filepath, "%s/", #save_to);
|
||||
strcpy(#filepath, #save_to);
|
||||
chrcat(#filepath, '/');
|
||||
strcat(#filepath, #aux+strrchr(#aux, '/'));
|
||||
|
||||
for (i=0; i<strlen(#filepath); i++) if(filepath[i]==':')||(filepath[i]=='?')filepath[i]='-';
|
||||
|
||||
if (CreateFile(downloader.content_received, downloader.bufpointer, #filepath)==0) {
|
||||
miniprintf(#notify_message, FILE_SAVED_AS, #filepath);
|
||||
} else {
|
||||
miniprintf(#notify_message, FILE_NOT_SAVED, #filepath);
|
||||
}
|
||||
|
||||
/*
|
||||
if (CreateFile(downloader.content_received, downloader.bufpointer, #filepath)==0) {
|
||||
strcpy(#notify_message, "'Download complete' -Dt");
|
||||
} else {
|
||||
strcpy(#notify_message, "'Error saving downloaded file!' -Et");
|
||||
}
|
||||
*/
|
||||
|
||||
if (!exit_when_done) notify(#notify_message);
|
||||
if (autoclose.checked) ExitProcess();
|
||||
}
|
@ -178,7 +178,7 @@
|
||||
DrawEditBox(dword edit_box_pointer);
|
||||
}
|
||||
|
||||
:void DrawProgressBar(dword st_x, st_y, st_w, st_h, col_fon, col_border, col_fill, col_text, progress_percent)
|
||||
:void DrawProgressBar(dword st_x, st_y, st_w, st_h, col_fon, col_border, col_fill, progress_percent)
|
||||
{
|
||||
int progress_w;
|
||||
static int fill_old;
|
||||
|
@ -72,4 +72,177 @@ struct http_msg{
|
||||
};
|
||||
|
||||
|
||||
#define URL_SIZE 4000
|
||||
//===================================================//
|
||||
// //
|
||||
// HTTP //
|
||||
// //
|
||||
//===================================================//
|
||||
|
||||
struct _http
|
||||
{
|
||||
dword cur_url;
|
||||
dword transfer;
|
||||
dword content_length;
|
||||
dword content_received;
|
||||
dword status_code;
|
||||
dword receive_result;
|
||||
dword content_pointer;
|
||||
|
||||
dword get();
|
||||
bool stop();
|
||||
void hfree();
|
||||
void receive();
|
||||
dword header_field();
|
||||
};
|
||||
|
||||
dword _http::get(dword _url)
|
||||
{
|
||||
cur_url = _url;
|
||||
http_get stdcall (_url, 0, 0, #accept_language);
|
||||
transfer = EAX;
|
||||
return transfer;
|
||||
}
|
||||
|
||||
void _http::hfree()
|
||||
{
|
||||
http_free stdcall (transfer);
|
||||
transfer=0;
|
||||
}
|
||||
|
||||
bool _http::stop()
|
||||
{
|
||||
if (transfer)
|
||||
{
|
||||
EAX = transfer;
|
||||
EAX = EAX.http_msg.content_ptr; // get pointer to data
|
||||
$push EAX // save it on the stack
|
||||
http_free stdcall (transfer); // abort connection
|
||||
$pop EAX
|
||||
free(EAX); // free data
|
||||
transfer=0;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void _http::receive()
|
||||
{
|
||||
http_receive stdcall (transfer);
|
||||
receive_result = EAX;
|
||||
|
||||
EDI = transfer;
|
||||
if (!EAX) {
|
||||
status_code = EDI.http_msg.status;
|
||||
content_pointer = EDI.http_msg.content_ptr;
|
||||
}
|
||||
content_length = EDI.http_msg.content_length;
|
||||
content_received = EDI.http_msg.content_received;
|
||||
}
|
||||
|
||||
:dword _http::header_field(dword _header_field, _dst, _size)
|
||||
{
|
||||
http_find_header_field stdcall (transfer, _header_field);
|
||||
if (EAX!=0) {
|
||||
ESI = EAX;
|
||||
EDI = _dst;
|
||||
EDX = _size;
|
||||
do {
|
||||
$lodsb;
|
||||
$stosb;
|
||||
$dec edx
|
||||
} while (AL != 0) && (AL != 13) && (AL != 10) && (EDX>0);
|
||||
DSBYTE[EDI-1]='\0';
|
||||
debugln(_dst);
|
||||
return _dst;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
//===================================================//
|
||||
// //
|
||||
// CHECK PATH TYPE //
|
||||
// //
|
||||
//===================================================//
|
||||
|
||||
:int check_is_the_adress_local(dword _in)
|
||||
{
|
||||
if (ESBYTE[_in]!='/') return false;
|
||||
_in++;
|
||||
if(!strncmp(_in,"rd/",3)) return true;
|
||||
if(!strncmp(_in,"fd/",3)) return true;
|
||||
if(!strncmp(_in,"hd",2)) return true;
|
||||
if(!strncmp(_in,"bd",2)) return true;
|
||||
if(!strncmp(_in,"cd",2)) return true;
|
||||
if(!strncmp(_in,"sys/",4)) return true;
|
||||
if(!strncmp(_in,"tmp",3)) return true;
|
||||
if(!strncmp(_in,"usbhd",5)) return true;
|
||||
if(!strncmp(_in,"kolibrios",9)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
:int check_is_the_url_absolute(dword _in)
|
||||
{
|
||||
if(!strncmp(_in,"ftp:",4)) return true;
|
||||
if(!strncmp(_in,"http:",5)) return true;
|
||||
if(!strncmp(_in,"https:",6)) return true;
|
||||
if(!strncmp(_in,"mailto:",7)) return true;
|
||||
if(!strncmp(_in,"tel:",4)) return true;
|
||||
if(!strncmp(_in,"#",1)) return true;
|
||||
if(!strncmp(_in,"WebView:",8)) return true;
|
||||
if(check_is_the_adress_local(_in)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
:dword get_absolute_url(dword new_URL, base_URL)
|
||||
{
|
||||
int i;
|
||||
dword orig_URL = new_URL;
|
||||
char newurl[URL_SIZE+1];
|
||||
strcpy(#newurl, base_URL);
|
||||
|
||||
while (i=strstr(new_URL, "&")) strcpy(i+1, i+5);
|
||||
|
||||
if (check_is_the_url_absolute(new_URL)) return orig_URL;
|
||||
|
||||
IF (!strncmp(new_URL,"//", 2))
|
||||
{
|
||||
strcpy(#newurl, "http:");
|
||||
strcat(#newurl, new_URL);
|
||||
strcpy(orig_URL, #newurl);
|
||||
return orig_URL;
|
||||
}
|
||||
|
||||
IF (!strncmp(new_URL,"./", 2)) new_URL+=2;
|
||||
|
||||
if (ESBYTE[new_URL] == '/') //remove everything after site domain name
|
||||
{
|
||||
i = strchr(#newurl+8, '/');
|
||||
if (i) ESBYTE[i]=0;
|
||||
new_URL+=1;
|
||||
}
|
||||
|
||||
_CUT_ST_LEVEL_MARK:
|
||||
|
||||
if (newurl[strrchr(#newurl, '/')-2]<>'/')
|
||||
{
|
||||
newurl[strrchr(#newurl, '/')] = 0x00;
|
||||
}
|
||||
|
||||
IF (!strncmp(new_URL,"../",3))
|
||||
{
|
||||
new_URL+=3;
|
||||
newurl[strrchr(#newurl, '/')-1] = 0x00;
|
||||
goto _CUT_ST_LEVEL_MARK;
|
||||
}
|
||||
|
||||
if (newurl[strlen(#newurl)-1]<>'/') strcat(#newurl, "/");
|
||||
|
||||
strcat(#newurl, new_URL);
|
||||
strcpy(orig_URL, #newurl);
|
||||
return orig_URL;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
@ -1,248 +0,0 @@
|
||||
#define URL_SIZE 4000
|
||||
|
||||
//===================================================//
|
||||
// //
|
||||
// HTTP //
|
||||
// //
|
||||
//===================================================//
|
||||
|
||||
struct _http
|
||||
{
|
||||
dword cur_url;
|
||||
dword transfer;
|
||||
dword content_length;
|
||||
dword content_received;
|
||||
dword status_code;
|
||||
dword receive_result;
|
||||
dword content_pointer;
|
||||
char redirect_url[4096*3];
|
||||
char content_type[64];
|
||||
|
||||
dword get();
|
||||
void hfree();
|
||||
void receive();
|
||||
bool handle_redirect();
|
||||
dword check_content_type();
|
||||
};
|
||||
|
||||
dword _http::get(dword _url)
|
||||
{
|
||||
cur_url = _url;
|
||||
http_get stdcall (_url, 0, 0, #accept_language);
|
||||
content_type[0] = '\0';
|
||||
transfer = EAX;
|
||||
return transfer;
|
||||
}
|
||||
|
||||
void _http::hfree()
|
||||
{
|
||||
http_free stdcall (transfer);
|
||||
transfer=0;
|
||||
}
|
||||
|
||||
void _http::receive()
|
||||
{
|
||||
http_receive stdcall (transfer);
|
||||
receive_result = EAX;
|
||||
|
||||
EDI = transfer;
|
||||
if (!EAX) {
|
||||
status_code = EDI.http_msg.status;
|
||||
content_pointer = EDI.http_msg.content_ptr;
|
||||
}
|
||||
content_length = EDI.http_msg.content_length;
|
||||
content_received = EDI.http_msg.content_received;
|
||||
|
||||
}
|
||||
|
||||
:bool _http::handle_redirect()
|
||||
{
|
||||
http_find_header_field stdcall (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';
|
||||
get_absolute_url(#redirect_url, cur_url);
|
||||
hfree();
|
||||
return #redirect_url;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
:dword _http::check_content_type()
|
||||
{
|
||||
if (content_type[0]) return NULL;
|
||||
http_find_header_field stdcall (transfer, "content-type\0");
|
||||
if (EAX!=0) {
|
||||
ESI = EAX;
|
||||
EDI = #content_type;
|
||||
do {
|
||||
$lodsb;
|
||||
$stosb;
|
||||
} while (AL != 0) && (AL != 13) && (AL != 10);
|
||||
DSBYTE[EDI-1]='\0';
|
||||
debugln(#content_type);
|
||||
return #content_type;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//===================================================//
|
||||
// //
|
||||
// DOWNLOADER //
|
||||
// //
|
||||
//===================================================//
|
||||
|
||||
|
||||
enum {
|
||||
STATE_NOT_STARTED,
|
||||
STATE_IN_PROGRESS,
|
||||
STATE_COMPLETED
|
||||
};
|
||||
|
||||
struct DOWNLOADER : _http {
|
||||
dword bufpointer, bufsize, url;
|
||||
int state;
|
||||
dword Start();
|
||||
void Stop();
|
||||
bool MonitorProgress();
|
||||
};
|
||||
|
||||
dword DOWNLOADER::Start(dword _url)
|
||||
{
|
||||
url = _url;
|
||||
state = STATE_IN_PROGRESS;
|
||||
get(_url);
|
||||
if (!transfer) Stop();
|
||||
return transfer;
|
||||
}
|
||||
|
||||
void DOWNLOADER::Stop()
|
||||
{
|
||||
state = STATE_NOT_STARTED;
|
||||
if (transfer!=0)
|
||||
{
|
||||
EAX = transfer;
|
||||
EAX = EAX.http_msg.content_ptr; // get pointer to data
|
||||
$push EAX // save it on the stack
|
||||
http_free stdcall (transfer); // abort connection
|
||||
$pop EAX
|
||||
free(EAX); // free data
|
||||
transfer=0;
|
||||
bufsize = 0;
|
||||
bufpointer = free(bufpointer);
|
||||
}
|
||||
content_received = content_length = 0;
|
||||
}
|
||||
|
||||
bool DOWNLOADER::MonitorProgress()
|
||||
{
|
||||
if (transfer <= 0) return false;
|
||||
receive();
|
||||
if (!content_length) content_length = content_received * 20;
|
||||
|
||||
if (receive_result == 0) {
|
||||
if (status_code >= 300) && (status_code < 400)
|
||||
{
|
||||
url = handle_redirect();
|
||||
Stop();
|
||||
Start(url);
|
||||
return false;
|
||||
}
|
||||
state = STATE_COMPLETED;
|
||||
bufpointer = content_pointer;
|
||||
bufsize = content_received;
|
||||
hfree();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*=====================================
|
||||
== ==
|
||||
== CHECK PATH TYPE ==
|
||||
== ==
|
||||
=====================================*/
|
||||
|
||||
|
||||
:int check_is_the_adress_local(dword _in)
|
||||
{
|
||||
if (ESBYTE[_in]!='/') return false;
|
||||
_in++;
|
||||
if(!strncmp(_in,"rd/",3)) return true;
|
||||
if(!strncmp(_in,"fd/",3)) return true;
|
||||
if(!strncmp(_in,"hd",2)) return true;
|
||||
if(!strncmp(_in,"bd",2)) return true;
|
||||
if(!strncmp(_in,"cd",2)) return true;
|
||||
if(!strncmp(_in,"sys/",4)) return true;
|
||||
if(!strncmp(_in,"tmp/",4)) return true;
|
||||
if(!strncmp(_in,"usbhd",5)) return true;
|
||||
if(!strncmp(_in,"kolibrios",9)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
:int check_is_the_url_absolute(dword _in)
|
||||
{
|
||||
if(!strncmp(_in,"ftp:",4)) return true;
|
||||
if(!strncmp(_in,"http:",5)) return true;
|
||||
if(!strncmp(_in,"https:",6)) return true;
|
||||
if(!strncmp(_in,"mailto:",7)) return true;
|
||||
if(!strncmp(_in,"tel:",4)) return true;
|
||||
if(!strncmp(_in,"#",1)) return true;
|
||||
if(!strncmp(_in,"WebView:",8)) return true;
|
||||
if(check_is_the_adress_local(_in)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
:dword get_absolute_url(dword new_URL, base_URL)
|
||||
{
|
||||
int i;
|
||||
dword orig_URL = new_URL;
|
||||
char newurl[URL_SIZE+1];
|
||||
strcpy(#newurl, base_URL);
|
||||
|
||||
while (i=strstr(new_URL, "&")) strcpy(i+1, i+5);
|
||||
|
||||
if (check_is_the_url_absolute(new_URL)) return orig_URL;
|
||||
|
||||
IF (!strncmp(new_URL,"//", 2))
|
||||
{
|
||||
strcpy(#newurl, "http:");
|
||||
strcat(#newurl, new_URL);
|
||||
strcpy(orig_URL, #newurl);
|
||||
return orig_URL;
|
||||
}
|
||||
|
||||
IF (!strncmp(new_URL,"./", 2)) new_URL+=2;
|
||||
|
||||
if (ESBYTE[new_URL] == '/') //remove everything after site domain name
|
||||
{
|
||||
i = strchr(#newurl+8, '/');
|
||||
if (i) ESBYTE[i]=0;
|
||||
new_URL+=1;
|
||||
}
|
||||
|
||||
_CUT_ST_LEVEL_MARK:
|
||||
|
||||
if (newurl[strrchr(#newurl, '/')-2]<>'/')
|
||||
{
|
||||
newurl[strrchr(#newurl, '/')] = 0x00;
|
||||
}
|
||||
|
||||
IF (!strncmp(new_URL,"../",3))
|
||||
{
|
||||
new_URL+=3;
|
||||
newurl[strrchr(#newurl, '/')-1] = 0x00;
|
||||
goto _CUT_ST_LEVEL_MARK;
|
||||
}
|
||||
|
||||
if (newurl[strlen(#newurl)-1]<>'/') strcat(#newurl, "/");
|
||||
|
||||
strcat(#newurl, new_URL);
|
||||
strcpy(orig_URL, #newurl);
|
||||
return orig_URL;
|
||||
}
|
@ -21,8 +21,6 @@
|
||||
#include "../lib/obj/libimg.h"
|
||||
#include "../lib/obj/netcode.h"
|
||||
#include "../lib/obj/iconv.h"
|
||||
//patterns
|
||||
#include "../lib/patterns/http_downloader.h"
|
||||
//images
|
||||
byte letter_icons[sizeof(file "img/letter_icons.raw")] = FROM "img/letter_icons.raw";
|
||||
#include "img/letter_icons.h"
|
||||
|
Loading…
Reference in New Issue
Block a user