forked from KolibriOS/kolibrios
WebView: code refactoring, minor fixes
git-svn-id: svn://kolibrios.org@7281 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
0c70ce5009
commit
e59b0f053b
@ -42,7 +42,7 @@ void GetAbsoluteURL(dword in_URL)
|
|||||||
}
|
}
|
||||||
|
|
||||||
IF (!strcmpn(in_URL,"./", 2)) in_URL+=2;
|
IF (!strcmpn(in_URL,"./", 2)) in_URL+=2;
|
||||||
if (!http_transfer)
|
if (!http.transfer)
|
||||||
{
|
{
|
||||||
strcpy(#newurl, history.current());
|
strcpy(#newurl, history.current());
|
||||||
}
|
}
|
||||||
|
@ -27,10 +27,12 @@
|
|||||||
#include "..\lib\patterns\history.h"
|
#include "..\lib\patterns\history.h"
|
||||||
#include "..\lib\patterns\http_downloader.h"
|
#include "..\lib\patterns\http_downloader.h"
|
||||||
|
|
||||||
|
_http http = {0, 0, 0, 0, 0, 0, 0};
|
||||||
|
|
||||||
char homepage[] = FROM "html\\homepage.htm""\0";
|
char homepage[] = FROM "html\\homepage.htm""\0";
|
||||||
|
|
||||||
#ifdef LANG_RUS
|
#ifdef LANG_RUS
|
||||||
char version[]="’¥ªáâ®¢ë© ¡à 㧥à 1.73";
|
char version[]="’¥ªáâ®¢ë© ¡à 㧥à 1.74";
|
||||||
?define IMAGES_CACHE_CLEARED "Šíè ª à⨮ª ®ç¨é¥"
|
?define IMAGES_CACHE_CLEARED "Šíè ª à⨮ª ®ç¨é¥"
|
||||||
?define T_LAST_SLIDE "<EFBFBD>â® ¯®á«¥¤¨© á« ©¤"
|
?define T_LAST_SLIDE "<EFBFBD>â® ¯®á«¥¤¨© á« ©¤"
|
||||||
char loading[] = "‡ £à㧪 áâà ¨æë...<br>";
|
char loading[] = "‡ £à㧪 áâà ¨æë...<br>";
|
||||||
@ -45,7 +47,7 @@ char link_menu[] =
|
|||||||
"Š®¯¨à®¢ âì áá뫪ã
|
"Š®¯¨à®¢ âì áá뫪ã
|
||||||
‘ª ç âì ᮤ¥à¦¨¬®¥ áá뫪¨";
|
‘ª ç âì ᮤ¥à¦¨¬®¥ áá뫪¨";
|
||||||
#else
|
#else
|
||||||
char version[]="Text-based Browser 1.73";
|
char version[]="Text-based Browser 1.74";
|
||||||
?define IMAGES_CACHE_CLEARED "Images cache cleared"
|
?define IMAGES_CACHE_CLEARED "Images cache cleared"
|
||||||
?define T_LAST_SLIDE "This slide is the last"
|
?define T_LAST_SLIDE "This slide is the last"
|
||||||
char loading[] = "Loading...<br>";
|
char loading[] = "Loading...<br>";
|
||||||
@ -75,9 +77,6 @@ char stak[4096];
|
|||||||
|
|
||||||
int action_buf;
|
int action_buf;
|
||||||
|
|
||||||
dword http_transfer = 0;
|
|
||||||
dword http_buffer;
|
|
||||||
|
|
||||||
dword TOOLBAR_H = 40;
|
dword TOOLBAR_H = 40;
|
||||||
dword STATUSBAR_H = 15;
|
dword STATUSBAR_H = 15;
|
||||||
dword col_bg;
|
dword col_bg;
|
||||||
@ -185,34 +184,17 @@ void main()
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case evNetwork:
|
case evNetwork:
|
||||||
if (http_transfer > 0) {
|
if (http.transfer > 0) {
|
||||||
http_receive stdcall (http_transfer);
|
http.receive();
|
||||||
$push EAX
|
EventUpdateProgressBar();
|
||||||
ESI = http_transfer;
|
if (http.receive_result == 0) {
|
||||||
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;
|
|
||||||
// Handle redirects
|
// Handle redirects
|
||||||
if (ESI.http_msg.status >= 300) && (ESI.http_msg.status < 400)
|
if (http.status_code >= 300) && (http.status_code < 400)
|
||||||
{
|
{
|
||||||
redirected++;
|
redirected++;
|
||||||
if (redirected<=5)
|
if (redirected<=5)
|
||||||
{
|
{
|
||||||
http_find_header_field stdcall (http_transfer, "location\0");
|
if (http.handle_redirect()) {
|
||||||
if (EAX!=0) {
|
|
||||||
ESI = EAX;
|
|
||||||
EDI = #URL;
|
|
||||||
do {
|
|
||||||
$lodsb;
|
|
||||||
$stosb;
|
|
||||||
} while (AL != 0) && (AL != 13) && (AL != 10);
|
|
||||||
DSBYTE[EDI-1]='\0';
|
|
||||||
if (!strncmp(#URL,"https://",8))
|
if (!strncmp(#URL,"https://",8))
|
||||||
{
|
{
|
||||||
history.back();
|
history.back();
|
||||||
@ -238,8 +220,7 @@ void main()
|
|||||||
// Loading the page is complete, free resources
|
// Loading the page is complete, free resources
|
||||||
if (redirected>0)
|
if (redirected>0)
|
||||||
{
|
{
|
||||||
http_free stdcall (http_transfer);
|
http.free();
|
||||||
http_transfer=0;
|
|
||||||
GetAbsoluteURL(#URL);
|
GetAbsoluteURL(#URL);
|
||||||
history.back();
|
history.back();
|
||||||
strcpy(#editURL, #URL);
|
strcpy(#editURL, #URL);
|
||||||
@ -249,11 +230,10 @@ void main()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
history.add(#URL);
|
history.add(#URL);
|
||||||
ESI = http_transfer;
|
ESI = http.transfer;
|
||||||
bufpointer = ESI.http_msg.content_ptr;
|
bufpointer = ESI.http_msg.content_ptr;
|
||||||
bufsize = ESI.http_msg.content_received;
|
bufsize = ESI.http_msg.content_received;
|
||||||
http_free stdcall (http_transfer);
|
http.free();
|
||||||
http_transfer=0;
|
|
||||||
SetPageDefaults();
|
SetPageDefaults();
|
||||||
ShowPage();
|
ShowPage();
|
||||||
}
|
}
|
||||||
@ -338,7 +318,7 @@ void ProcessEvent(dword id__)
|
|||||||
case 063: //F5
|
case 063: //F5
|
||||||
IF(address_box.flags & 0b10) return;
|
IF(address_box.flags & 0b10) return;
|
||||||
case REFRESH_BUTTON:
|
case REFRESH_BUTTON:
|
||||||
if (http_transfer > 0)
|
if (http.transfer > 0)
|
||||||
{
|
{
|
||||||
StopLoading();
|
StopLoading();
|
||||||
Draw_Window();
|
Draw_Window();
|
||||||
@ -391,15 +371,15 @@ void ProcessEvent(dword id__)
|
|||||||
|
|
||||||
void StopLoading()
|
void StopLoading()
|
||||||
{
|
{
|
||||||
if (http_transfer)
|
if (http.transfer)
|
||||||
{
|
{
|
||||||
EAX = http_transfer;
|
EAX = http.transfer;
|
||||||
EAX = EAX.http_msg.content_ptr; // get pointer to data
|
EAX = EAX.http_msg.content_ptr; // get pointer to data
|
||||||
$push EAX // save it on the stack
|
$push EAX // save it on the stack
|
||||||
http_free stdcall (http_transfer); // abort connection
|
http_free stdcall (http.transfer); // abort connection
|
||||||
$pop EAX
|
$pop EAX
|
||||||
free(EAX); // free data
|
free(EAX); // free data
|
||||||
http_transfer=0;
|
http.transfer=0;
|
||||||
bufsize = 0;
|
bufsize = 0;
|
||||||
bufpointer = free(bufpointer);
|
bufpointer = free(bufpointer);
|
||||||
}
|
}
|
||||||
@ -432,9 +412,8 @@ void OpenPage()
|
|||||||
if (!strncmp(#URL,"http:",5))
|
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);
|
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.get(#URL);
|
||||||
http_transfer = EAX;
|
if (!http.transfer)
|
||||||
if (!http_transfer)
|
|
||||||
{
|
{
|
||||||
StopLoading();
|
StopLoading();
|
||||||
bufsize = 0;
|
bufsize = 0;
|
||||||
@ -465,7 +444,7 @@ DrawEditBoxWebView()
|
|||||||
address_box.size = address_box.pos = address_box.shift = address_box.shift_old = strlen(#editURL);
|
address_box.size = address_box.pos = address_box.shift = address_box.shift_old = strlen(#editURL);
|
||||||
address_box.offset = 0;
|
address_box.offset = 0;
|
||||||
edit_box_draw stdcall(#address_box);
|
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);
|
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);
|
debugval("bufsize", bufsize);
|
||||||
if (!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 WB1.LoadInternalPage(#page_not_found, sizeof(page_not_found));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -508,7 +487,7 @@ int SetSkinColors()
|
|||||||
void DrawProgress()
|
void DrawProgress()
|
||||||
{
|
{
|
||||||
unsigned long btn;
|
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;
|
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);
|
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];
|
char anchor[256];
|
||||||
void ClickLink()
|
void ClickLink()
|
||||||
{
|
{
|
||||||
if (http_transfer > 0)
|
if (http.transfer > 0)
|
||||||
{
|
{
|
||||||
StopLoading();
|
StopLoading();
|
||||||
history.back();
|
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);
|
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()
|
void ShowErrorMessageThatHttpsIsNotSupportedYet()
|
||||||
{
|
{
|
||||||
|
@ -20,25 +20,21 @@ char save_to[4096] = "/tmp0/1/Downloads";
|
|||||||
proc_info DL_Form;
|
proc_info DL_Form;
|
||||||
char downloader_edit[10000];
|
char downloader_edit[10000];
|
||||||
char filepath[4096];
|
char filepath[4096];
|
||||||
int mouse_twbi;
|
edit_box ed = {NULL,57,20,0xffffff,0x94AECE,0xffffff,0xffffff,0x10000000,sizeof(downloader_edit),#downloader_edit,0,2,19,19};
|
||||||
edit_box ed = {250,20,20,0xffffff,0x94AECE,0xffffff,0xffffff,0x10000000,sizeof(downloader_edit),#downloader_edit,#mouse_twbi,2,19,19};
|
|
||||||
progress_bar pb = {0, 20, 58, 350, 17, 0, 0, 100, 0xFFFfff, 0x74DA00, 0x9F9F9F};
|
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 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;
|
//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 downloader_stak[4096];
|
||||||
char str[2048];
|
|
||||||
char aux[2048];
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Downloader()
|
void Downloader()
|
||||||
{
|
{
|
||||||
int key, i;
|
if (!dir_exists(#save_to)) CreateDir(#save_to);
|
||||||
char notify_message[4296];
|
downloader_opened = true;
|
||||||
downloader_opened = 1;
|
|
||||||
SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER + EVM_STACK);
|
SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER + EVM_STACK);
|
||||||
|
|
||||||
system.color.get();
|
system.color.get();
|
||||||
@ -53,7 +49,6 @@ void Downloader()
|
|||||||
loop() switch(WaitEvent())
|
loop() switch(WaitEvent())
|
||||||
{
|
{
|
||||||
case evMouse:
|
case evMouse:
|
||||||
if (!CheckActiveProcess(DL_Form.ID)) break;
|
|
||||||
edit_box_mouse stdcall (#ed);
|
edit_box_mouse stdcall (#ed);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -87,24 +82,7 @@ void Downloader()
|
|||||||
}
|
}
|
||||||
if (downloader.state == STATE_COMPLETED)
|
if (downloader.state == STATE_COMPLETED)
|
||||||
{
|
{
|
||||||
if (!dir_exists(#save_to)) CreateDir(#save_to);
|
SaveDownloadedFile();
|
||||||
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; i<strlen(#filepath); i++) if(filepath[i]==':')||(filepath[i]=='?')filepath[i]='-';
|
|
||||||
|
|
||||||
if (CreateFile(downloader.data_downloaded_size, downloader.bufpointer, #filepath)==0)
|
|
||||||
sprintf(#notify_message, "%s%s%s",FILE_SAVED_AS,#filepath,"' -Dt");
|
|
||||||
else
|
|
||||||
sprintf(#notify_message, "%s%s%s","'Download manager\nError! Can\96t save file as ",#filepath,"' -Et");
|
|
||||||
|
|
||||||
notify(#notify_message);
|
|
||||||
StopDownloading();
|
StopDownloading();
|
||||||
DL_Draw_Window();
|
DL_Draw_Window();
|
||||||
break;
|
break;
|
||||||
@ -114,11 +92,14 @@ void Downloader()
|
|||||||
|
|
||||||
void Key_Scan(int id)
|
void Key_Scan(int id)
|
||||||
{
|
{
|
||||||
if (id==001) { downloader_opened=0; StopDownloading(); ExitProcess(); }
|
if (id==001) { downloader_opened=false; StopDownloading(); ExitProcess(); }
|
||||||
if (id==301) && (downloader.http_transfer <= 0) StartDownloading();
|
if (id==301) && (downloader.httpd.transfer <= 0) StartDownloading();
|
||||||
if (id==302) StopDownloading();
|
if (id==302) StopDownloading();
|
||||||
if (id==305) RunProgram("/sys/File managers/Eolite", #save_to);
|
if (id==305) RunProgram("/sys/File managers/Eolite", #save_to);
|
||||||
if (id==306) RunProgram("/sys/@open", #filepath);
|
if (id==306) {
|
||||||
|
SetCurDir(#save_to);
|
||||||
|
RunProgram("/sys/@open", #filepath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DL_Draw_Window()
|
void DL_Draw_Window()
|
||||||
@ -127,6 +108,8 @@ void DL_Draw_Window()
|
|||||||
int but_x = 0;
|
int but_x = 0;
|
||||||
int but_y = 58;
|
int but_y = 58;
|
||||||
DrawBar(0,0, DL_Form.cwidth, DL_Form.cheight, system.color.work);
|
DrawBar(0,0, DL_Form.cwidth, DL_Form.cheight, system.color.work);
|
||||||
|
DeleteButton(301);
|
||||||
|
DeleteButton(302);
|
||||||
DeleteButton(305);
|
DeleteButton(305);
|
||||||
DeleteButton(306);
|
DeleteButton(306);
|
||||||
if (downloader.state == STATE_NOT_STARTED) || (downloader.state == STATE_COMPLETED)
|
if (downloader.state == STATE_NOT_STARTED) || (downloader.state == STATE_COMPLETED)
|
||||||
@ -140,11 +123,10 @@ void DL_Draw_Window()
|
|||||||
}
|
}
|
||||||
if (downloader.state == STATE_IN_PROGRESS)
|
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);
|
DrawStandartCaptButton(DL_Form.width - 190, but_y, 302, STOP_DOWNLOADING);
|
||||||
DrawDownloading();
|
DrawDownloading();
|
||||||
}
|
}
|
||||||
WriteText(cleft, ed.top + 4, 0x90, system.color.work_text, "URL:");
|
WriteText(cleft, ed.top + 4, 0x90, system.color.work_text, "URL:");
|
||||||
ed.left = strlen("URL:")*8 + 10 + cleft;
|
|
||||||
ed.width = DL_Form.cwidth - ed.left - cleft - 3;
|
ed.width = DL_Form.cwidth - ed.left - cleft - 3;
|
||||||
ed.offset=0;
|
ed.offset=0;
|
||||||
DrawEditBox(#ed);
|
DrawEditBox(#ed);
|
||||||
@ -184,3 +166,26 @@ void StopDownloading()
|
|||||||
ed.flags = 10b;
|
ed.flags = 10b;
|
||||||
DL_Draw_Window();
|
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<strlen(#filepath); i++) if(filepath[i]==':')||(filepath[i]=='?')filepath[i]='-';
|
||||||
|
|
||||||
|
if (CreateFile(downloader.data_downloaded_size, downloader.bufpointer, #filepath)==0)
|
||||||
|
sprintf(#notify_message, "%s%s%s",FILE_SAVED_AS,#filepath,"' -Dt");
|
||||||
|
else
|
||||||
|
sprintf(#notify_message, "%s%s%s","'Download manager\nError! Can\96t save file as ",#filepath,"' -Et");
|
||||||
|
|
||||||
|
notify(#notify_message);
|
||||||
|
}
|
@ -1,3 +1,77 @@
|
|||||||
|
//===================================================//
|
||||||
|
// //
|
||||||
|
// HTTP //
|
||||||
|
// //
|
||||||
|
//===================================================//
|
||||||
|
|
||||||
|
struct _http
|
||||||
|
{
|
||||||
|
dword url;
|
||||||
|
dword transfer;
|
||||||
|
dword content_length;
|
||||||
|
dword content_received;
|
||||||
|
dword status_code;
|
||||||
|
dword receive_result;
|
||||||
|
dword content_pointer;
|
||||||
|
|
||||||
|
dword get();
|
||||||
|
void free();
|
||||||
|
void receive();
|
||||||
|
bool handle_redirect();
|
||||||
|
};
|
||||||
|
|
||||||
|
dword _http::get(dword _url)
|
||||||
|
{
|
||||||
|
url = _url;
|
||||||
|
http_get stdcall (url, 0, 0, #accept_language);
|
||||||
|
transfer = EAX;
|
||||||
|
return transfer;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _http::free()
|
||||||
|
{
|
||||||
|
http_free stdcall (transfer);
|
||||||
|
transfer=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _http::receive()
|
||||||
|
{
|
||||||
|
http_receive stdcall (transfer);
|
||||||
|
receive_result = EAX;
|
||||||
|
|
||||||
|
ESI = transfer;
|
||||||
|
if (!EAX) status_code = ESI.http_msg.status;
|
||||||
|
content_length = ESI.http_msg.content_length;
|
||||||
|
content_received = ESI.http_msg.content_received;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool _http::handle_redirect()
|
||||||
|
{
|
||||||
|
dword redirect, i;
|
||||||
|
char redirect_url[4096*3], finaladress[4096*3];
|
||||||
|
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(#finaladress, url, #redirect_url);
|
||||||
|
strcpy(url, #finaladress);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//===================================================//
|
||||||
|
// //
|
||||||
|
// DOWNLOADER //
|
||||||
|
// //
|
||||||
|
//===================================================//
|
||||||
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
STATE_NOT_STARTED,
|
STATE_NOT_STARTED,
|
||||||
@ -6,11 +80,10 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct DOWNLOADER {
|
struct DOWNLOADER {
|
||||||
|
_http httpd;
|
||||||
unsigned data_downloaded_size, data_full_size;
|
unsigned data_downloaded_size, data_full_size;
|
||||||
dword bufpointer, bufsize, url;
|
dword bufpointer, bufsize, url;
|
||||||
byte state;
|
int state;
|
||||||
dword http_transfer;
|
|
||||||
int http_status_code;
|
|
||||||
dword Start();
|
dword Start();
|
||||||
void Stop();
|
void Stop();
|
||||||
void Completed();
|
void Completed();
|
||||||
@ -21,25 +94,24 @@ dword DOWNLOADER::Start(dword _url)
|
|||||||
{
|
{
|
||||||
url = _url;
|
url = _url;
|
||||||
state = STATE_IN_PROGRESS;
|
state = STATE_IN_PROGRESS;
|
||||||
http_get stdcall (url, 0, 0, #accept_language);
|
httpd.get(url);
|
||||||
http_transfer = EAX;
|
return httpd.transfer;
|
||||||
return http_transfer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DOWNLOADER::Stop()
|
void DOWNLOADER::Stop()
|
||||||
{
|
{
|
||||||
state = STATE_NOT_STARTED;
|
state = STATE_NOT_STARTED;
|
||||||
if (http_transfer!=0)
|
if (httpd.transfer!=0)
|
||||||
{
|
{
|
||||||
EAX = http_transfer;
|
EAX = httpd.transfer;
|
||||||
EAX = EAX.http_msg.content_ptr; // get pointer to data
|
EAX = EAX.http_msg.content_ptr; // get pointer to data
|
||||||
$push EAX // save it on the stack
|
$push EAX // save it on the stack
|
||||||
http_free stdcall (http_transfer); // abort connection
|
http_free stdcall (httpd.transfer); // abort connection
|
||||||
$pop EAX
|
$pop EAX
|
||||||
mem_Free(EAX); // free data
|
free(EAX); // free data
|
||||||
http_transfer=0;
|
httpd.transfer=0;
|
||||||
bufsize = 0;
|
bufsize = 0;
|
||||||
bufpointer = mem_Free(bufpointer);
|
bufpointer = free(bufpointer);
|
||||||
}
|
}
|
||||||
data_downloaded_size = data_full_size = 0;
|
data_downloaded_size = data_full_size = 0;
|
||||||
}
|
}
|
||||||
@ -47,39 +119,30 @@ void DOWNLOADER::Stop()
|
|||||||
void DOWNLOADER::Completed()
|
void DOWNLOADER::Completed()
|
||||||
{
|
{
|
||||||
state = STATE_COMPLETED;
|
state = STATE_COMPLETED;
|
||||||
ESI = http_transfer;
|
ESI = httpd.transfer;
|
||||||
bufpointer = ESI.http_msg.content_ptr;
|
bufpointer = ESI.http_msg.content_ptr;
|
||||||
bufsize = ESI.http_msg.content_received;
|
bufsize = ESI.http_msg.content_received;
|
||||||
http_free stdcall (http_transfer);
|
httpd.free();
|
||||||
http_transfer=0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int DOWNLOADER::MonitorProgress()
|
int DOWNLOADER::MonitorProgress()
|
||||||
{
|
{
|
||||||
dword receive_result;
|
dword receive_result;
|
||||||
char redirect_url[4096*3], finaladress[4096*3];
|
char redirect_url[4096*3], finaladress[4096*3];
|
||||||
if (http_transfer <= 0) return false;
|
if (httpd.transfer <= 0) return false;
|
||||||
http_receive stdcall (http_transfer);
|
http_receive stdcall (httpd.transfer);
|
||||||
receive_result = EAX;
|
receive_result = EAX;
|
||||||
EDI = http_transfer;
|
EDI = httpd.transfer;
|
||||||
http_status_code = EDI.http_msg.status;
|
httpd.status_code = EDI.http_msg.status;
|
||||||
data_full_size = EDI.http_msg.content_length;
|
data_full_size = EDI.http_msg.content_length;
|
||||||
data_downloaded_size = EDI.http_msg.content_received;
|
data_downloaded_size = EDI.http_msg.content_received;
|
||||||
if (!data_full_size) data_full_size = data_downloaded_size * 6 + 1;
|
if (!data_full_size) data_full_size = data_downloaded_size * 6 + 1;
|
||||||
|
|
||||||
if (receive_result == 0) {
|
if (receive_result == 0) {
|
||||||
if (http_status_code >= 300) && (http_status_code < 400)
|
if (httpd.status_code >= 300) && (httpd.status_code < 400)
|
||||||
{
|
{
|
||||||
http_find_header_field stdcall (http_transfer, "location\0");
|
httpd.handle_redirect();
|
||||||
if (EAX!=0) {
|
strcpy(url, httpd.url);
|
||||||
ESI = EAX;
|
|
||||||
EDI = #redirect_url;
|
|
||||||
do {
|
|
||||||
$lodsb;
|
|
||||||
$stosb;
|
|
||||||
} while ((AL != 0) && (AL != 13) && (AL != 10));
|
|
||||||
DSBYTE[EDI-1]='\0';
|
|
||||||
}
|
|
||||||
get_absolute_url(#finaladress, url, #redirect_url);
|
get_absolute_url(#finaladress, url, #redirect_url);
|
||||||
Stop();
|
Stop();
|
||||||
Start(#finaladress);
|
Start(#finaladress);
|
||||||
@ -94,7 +157,7 @@ int DOWNLOADER::MonitorProgress()
|
|||||||
|
|
||||||
/*=====================================
|
/*=====================================
|
||||||
== ==
|
== ==
|
||||||
== CHECK URL TYPE ==
|
== CHECK PATH TYPE ==
|
||||||
== ==
|
== ==
|
||||||
=====================================*/
|
=====================================*/
|
||||||
|
|
||||||
|
@ -26,6 +26,11 @@
|
|||||||
byte letter_icons[sizeof(file "img/letter_icons.raw")] = FROM "img/letter_icons.raw";
|
byte letter_icons[sizeof(file "img/letter_icons.raw")] = FROM "img/letter_icons.raw";
|
||||||
#include "img/letter_icons.h"
|
#include "img/letter_icons.h"
|
||||||
|
|
||||||
|
struct mockup
|
||||||
|
{
|
||||||
|
dword transfer;
|
||||||
|
} http = {0};
|
||||||
|
|
||||||
//connection algorithm
|
//connection algorithm
|
||||||
enum {
|
enum {
|
||||||
STOP,
|
STOP,
|
||||||
|
Loading…
Reference in New Issue
Block a user