Aelia 0.36: port Download manager from WebView, fix two issues in it

git-svn-id: svn://kolibrios.org@6366 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2016-03-23 11:13:28 +00:00
parent 287dc2ef20
commit e33b239aec
5 changed files with 21 additions and 76 deletions

View File

@ -15,6 +15,7 @@
#include "../lib/patterns/simple_open_dialog.h"
#include "../lib/patterns/history.h"
#include "../lib/patterns/http_downloader.h"
#include "../browser/download_manager.h"
char default_dir[] = "/rd/1";
od_filter filter2 = {0,0};
@ -68,7 +69,7 @@ dword CursorFile = FROM "pointer.cur";
#include "prepare_page.h"
//#include "special_symbols.h"
#define SANDWICH_MENU "Refresh page\nEdit page\nHistory\nAbout"
#define SANDWICH_MENU "Refresh page\nEdit page\nHistory\nDownloader\nAbout"
void InitDlls()
{
@ -117,7 +118,8 @@ void main()
if (menu.list.cur_y==0) EventPageRefresh();
if (menu.list.cur_y==1) EventRunEdit();
if (menu.list.cur_y==2) EventShowHistory();
if (menu.list.cur_y==3) EventShowInfo();
if (menu.list.cur_y==3) EventShowDownloader();
if (menu.list.cur_y==4) EventShowInfo();
menu.list.cur_y = 0;
}
}
@ -391,6 +393,14 @@ void EventPageRefresh()
EventOpenAddress(history.current());
}
void EventShowDownloader()
{
if (!downloader_opened) {
downloader_edit = NULL;
CreateThread(#Downloader,#downloader_stak+4092);
}
}
/* ------------------------------------------- */

View File

@ -565,6 +565,4 @@ void ClickLink()
return;
}
char downloader_stak[4096];
stop:

View File

@ -3,7 +3,7 @@
#define START_DOWNLOADING "<22> ç âì § ª çªã"
#define STOP_DOWNLOADING "Žáâ ­®¢¨âì"
#define SHOW_IN_FOLDER "<22>®ª § âì ¢ ¯ ¯ª¥"
#define OPEN_FILE "<22>âªàëâì ä ©«"
#define OPEN_FILE_TEXT "<22>âªàëâì ä ©«"
#define FILE_SAVED_AS "'Œ¥­¥¤¦¥à § £à㧮ª\n” ©« á®åà ­¥­ ª ª "
#define KB_RECEIVED " ¯®«ã祭®"
#else
@ -11,11 +11,11 @@
#define START_DOWNLOADING "Start downloading"
#define STOP_DOWNLOADING "Stop downloading"
#define SHOW_IN_FOLDER "Show in folder"
#define OPEN_FILE "Open file"
#define OPEN_FILE_TEXT "Open file"
#define FILE_SAVED_AS "'Download manager\nFile saved as "
#define KB_RECEIVED " received"
#endif
char save_to[4096] = "/tmp0/1/Downloads/";
char save_to[4096] = "/tmp0/1/Downloads";
proc_info DL_Form;
char downloader_edit[10000];
@ -25,6 +25,7 @@ edit_box ed = {250,20,20,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(downloader
progress_bar pb = {0, 170, 51, 225, 12, 0, 0, 100, 0xFFFfff, 0x74DA00, 0x9F9F9F};
byte downloader_opened;
char downloader_stak[4096];
void Downloader()
@ -80,9 +81,11 @@ void Downloader()
}
if (downloader.state == STATE_COMPLETED)
{
if (!dir_exists(#save_to)) CreateDir(#save_to);
strcpy(#filepath, #save_to);
strcat(#filepath, #save_to+strrchr(#save_to, '/'));
if (WriteFile(downloader.bufsize, downloader.bufpointer, #filepath)==0)
chrcat(#filepath, '/');
strcat(#filepath, #downloader_edit+strrchr(#downloader_edit, '/'));
if (WriteFile(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");
@ -122,7 +125,7 @@ void DL_Draw_Window()
if (downloader.state == STATE_COMPLETED)
{
DrawCaptButton(cleft+140, 50, 110, 27, 305, system.color.work_button, system.color.work_button_text, SHOW_IN_FOLDER);
DrawCaptButton(cleft+260, 50, 120, 27, 306, system.color.work_button, system.color.work_button_text, OPEN_FILE);
DrawCaptButton(cleft+260, 50, 120, 27, 306, system.color.work_button, system.color.work_button_text, OPEN_FILE_TEXT);
}
WriteText(cleft, ed.top + 4, 0x80, system.color.work_text, "URL:");
ed.left = strlen("URL:")*6 + 10 + cleft;

View File

@ -1,66 +0,0 @@
enum {
STATE_NOT_STARTED,
STATE_IN_PROGRESS,
STATE_COMPLETED
};
struct DOWNLOADER {
int data_downloaded_size, data_full_size;
dword bufpointer, bufsize;
byte state;
dword http_transfer;
dword Start();
void Stop();
void Completed();
int MonitorProgress();
} downloader;
dword DOWNLOADER::Start(dword _url)
{
state = STATE_IN_PROGRESS;
http_get stdcall (_url, 0, 0, #accept_language);
http_transfer = EAX;
return http_transfer;
}
void DOWNLOADER::Stop()
{
state = STATE_NOT_STARTED;
if (http_transfer!=0)
{
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
mem_Free(EAX); // free data
http_transfer=0;
bufsize = 0;
bufpointer = mem_Free(bufpointer);
}
data_downloaded_size = data_full_size = 0;
}
void DOWNLOADER::Completed()
{
state = STATE_COMPLETED;
ESI = http_transfer;
bufpointer = ESI.http_msg.content_ptr;
bufsize = ESI.http_msg.content_received;
http_free stdcall (http_transfer);
http_transfer=0;
}
int DOWNLOADER::MonitorProgress()
{
dword receive_result;
if (http_transfer <= 0) return false;
http_receive stdcall (http_transfer);
receive_result = EAX;
EDI = http_transfer;
data_full_size = EDI.http_msg.content_length;
data_downloaded_size = EDI.http_msg.content_received;
if (receive_result == 0) Completed();
return true;
}