Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5493 | leency | 1 | #ifdef LANG_RUS |
5519 | leency | 2 | #define DL_WINDOW_HEADER "Менеджер загрузок" |
3 | #define START_DOWNLOADING "Начать закачку" |
||
4 | #define STOP_DOWNLOADING "Остановить скачивание" |
||
5 | #define SHOW_IN_FOLDER "Показать в папке" |
||
6 | #define OPEN_FILE "Открыть файл" |
||
7 | #define FILE_SAVED_AS "'Менеджер загрузок\nФайл сохранен как " |
||
8 | #define KB_RECEIVED " получено" |
||
5493 | leency | 9 | #else |
10 | #define DL_WINDOW_HEADER "Download Manager" |
||
11 | #define START_DOWNLOADING "Start downloading" |
||
12 | #define STOP_DOWNLOADING "Stop downloading" |
||
5519 | leency | 13 | #define SHOW_IN_FOLDER "Show in folder" |
14 | #define OPEN_FILE "Open file" |
||
5493 | leency | 15 | #define FILE_SAVED_AS "'Download manager\nFile saved as " |
5519 | leency | 16 | #define KB_RECEIVED " received" |
5493 | leency | 17 | #endif |
18 | |||
19 | proc_info DL_Form; |
||
20 | char filepath[4096]; |
||
21 | int mouse_twbi; |
||
5685 | leency | 22 | edit_box dl_edit = {250,20,20,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(DL_URL),#DL_URL,#mouse_twbi,2,19,19}; |
5519 | leency | 23 | progress_bar DL_progress_bar = {0, 170, 51, 225, 12, 0, 0, 100, 0xFFFfff, 0x74DA00, 0x9F9F9F}; |
5493 | leency | 24 | |
25 | char save_to[4096] = "/tmp0/1/Downloads/"; |
||
5519 | leency | 26 | byte cleft = 15; |
5493 | leency | 27 | |
5519 | leency | 28 | byte downloader_opened; |
5493 | leency | 29 | |
5519 | leency | 30 | |
5493 | leency | 31 | void Downloader() |
32 | { |
||
5685 | leency | 33 | int key; |
5493 | leency | 34 | char notify_message[4296]; |
5685 | leency | 35 | downloader_opened = 1; |
36 | SetEventMask(0x27); |
||
5493 | leency | 37 | |
5685 | leency | 38 | if (DL_URL[0]) StartDownloading(); else strcpy(#DL_URL, "http://"); |
39 | dl_edit.size = dl_edit.pos = dl_edit.shift = dl_edit.shift_old = strlen(#DL_URL); |
||
5493 | leency | 40 | |
5685 | leency | 41 | Downloading_SetDefaults(); |
5493 | leency | 42 | |
43 | loop() |
||
44 | { |
||
45 | WaitEventTimeout(40); |
||
46 | switch(EAX & 0xFF) |
||
47 | { |
||
48 | CASE evMouse: |
||
49 | if (!CheckActiveProcess(DL_Form.ID)) break; |
||
5685 | leency | 50 | edit_box_mouse stdcall (#dl_edit); |
5493 | leency | 51 | break; |
52 | |||
53 | case evButton: |
||
5685 | leency | 54 | DL_Scan(GetButtonID()); |
5493 | leency | 55 | break; |
56 | |||
57 | case evKey: |
||
58 | key = GetKey(); |
||
5683 | leency | 59 | EAX=key<<8; |
5685 | leency | 60 | edit_box_key stdcall(#dl_edit); |
5493 | leency | 61 | if (key==13) DL_Scan(301); |
62 | break; |
||
63 | |||
64 | case evReDraw: |
||
5674 | pavelyakov | 65 | system.color.get(); |
66 | DefineAndDrawWindow(215, 100, 420, 120, 0x74, system.color.work, DL_WINDOW_HEADER, 0); |
||
5493 | leency | 67 | GetProcessInfo(#DL_Form, SelfInfo); |
68 | if (DL_Form.status_window>2) break; |
||
69 | if (DL_Form.height<120) MoveSize(OLD,OLD,OLD,120); |
||
70 | if (DL_Form.width<280) MoveSize(OLD,OLD,280,OLD); |
||
71 | DL_Draw_Window(); |
||
72 | break; |
||
73 | |||
74 | default: |
||
5519 | leency | 75 | if (DL_Form.width==0) || (DL_http_transfer <= 0) break; |
5534 | hidnplayr | 76 | http_receive stdcall (DL_http_transfer); |
5519 | leency | 77 | $push EAX |
78 | ESI = DL_http_transfer; |
||
79 | DL_progress_bar.max = ESI.http_msg.content_length; |
||
80 | if (DL_progress_bar.value != ESI.http_msg.content_received) |
||
81 | { |
||
82 | DL_progress_bar.value = ESI.http_msg.content_received; |
||
83 | progressbar_draw stdcall(#DL_progress_bar); |
||
84 | } |
||
85 | $pop EAX |
||
5493 | leency | 86 | if (EAX == 0) { |
5685 | leency | 87 | Downloading_Completed(); |
5493 | leency | 88 | strcpy(#filepath, #save_to); |
89 | strcat(#filepath, #DL_URL+strrchr(#DL_URL, '/')); |
||
90 | if (WriteFile(DL_bufsize, DL_bufpointer, #filepath)==0) |
||
91 | { |
||
5685 | leency | 92 | sprintf(#notify_message, "%s%s%s",FILE_SAVED_AS,#filepath,"' -Dt"); |
5493 | leency | 93 | } |
94 | else |
||
95 | { |
||
5685 | leency | 96 | sprintf(#notify_message, "%s%s%s","'Download manager\nError! Can\96t save file as ",#filepath,"' -Et"); |
5493 | leency | 97 | } |
98 | notify(#notify_message); |
||
5685 | leency | 99 | dl_edit.blur_border_color = 0xFFFfff; |
100 | dl_edit.flags = 10b; |
||
5493 | leency | 101 | DL_Draw_Window(); |
5519 | leency | 102 | break; |
5493 | leency | 103 | } |
104 | ESI = DL_http_transfer; |
||
105 | downloaded_size = ESI.http_msg.content_received; |
||
106 | full_size = ESI.http_msg.content_length; |
||
107 | DrawDownloading(); |
||
108 | } |
||
109 | } |
||
110 | } |
||
111 | |||
112 | |||
113 | |||
114 | void DL_Draw_Window() |
||
115 | { |
||
5674 | pavelyakov | 116 | DrawBar(0,0, DL_Form.cwidth, DL_Form.cheight, system.color.work); |
5519 | leency | 117 | DeleteButton(305); |
118 | DeleteButton(306); |
||
119 | if (download_state == STATE_NOT_STARTED) || (download_state == STATE_COMPLETED) |
||
5493 | leency | 120 | { |
5674 | pavelyakov | 121 | DrawCaptButton(cleft, 50, 130, 27, 301, system.color.work_button, system.color.work_button_text, START_DOWNLOADING); |
5493 | leency | 122 | } |
5519 | leency | 123 | if (download_state == STATE_IN_PROGRESS) |
5493 | leency | 124 | { |
5674 | pavelyakov | 125 | DrawCaptButton(cleft, 50, 140, 27, 302, system.color.work_button, system.color.work_button_text, STOP_DOWNLOADING); |
5519 | leency | 126 | DrawDownloading(); |
5493 | leency | 127 | } |
5519 | leency | 128 | if (download_state == STATE_COMPLETED) |
5493 | leency | 129 | { |
5674 | pavelyakov | 130 | DrawCaptButton(cleft+140, 50, 110, 27, 305, system.color.work_button, system.color.work_button_text, SHOW_IN_FOLDER); |
131 | DrawCaptButton(cleft+260, 50, 120, 27, 306, system.color.work_button, system.color.work_button_text, OPEN_FILE); |
||
5493 | leency | 132 | } |
5685 | leency | 133 | WriteText(cleft, dl_edit.top + 4, 0x80, system.color.work_text, "URL:"); |
134 | dl_edit.left = strlen("URL:")*6 + 10 + cleft; |
||
135 | dl_edit.width = DL_Form.cwidth - dl_edit.left - cleft - 3; |
||
136 | dl_edit.offset=0; |
||
137 | edit_box_draw stdcall(#dl_edit); |
||
138 | DrawRectangle(dl_edit.left-1, dl_edit.top-1, dl_edit.width+2, 16, dl_edit.blur_border_color); |
||
139 | DrawRectangle(dl_edit.left-2, dl_edit.top-2, dl_edit.width+4, 18, border_color); |
||
5519 | leency | 140 | } |
5493 | leency | 141 | |
5519 | leency | 142 | |
143 | void DrawDownloading() |
||
144 | { |
||
145 | dword tmp; |
||
146 | char bytes_received[70]; |
||
147 | |||
148 | tmp = ConvertSizeToKb(downloaded_size); |
||
149 | strcpy(#bytes_received, tmp); |
||
150 | strcat(#bytes_received, KB_RECEIVED); |
||
5674 | pavelyakov | 151 | DrawBar(DL_progress_bar.left, DL_progress_bar.top + 17, DL_Form.cwidth - DL_progress_bar.left, 9, system.color.work); |
152 | WriteText(DL_progress_bar.left, DL_progress_bar.top + 17, 0x80, system.color.work_text, #bytes_received); |
||
5519 | leency | 153 | progressbar_draw stdcall(#DL_progress_bar); |
5493 | leency | 154 | } |
155 | |||
5519 | leency | 156 | |
157 | |||
158 | |||
5493 | leency | 159 | void DL_Scan(int id) |
160 | { |
||
5519 | leency | 161 | if (id==001) { |
162 | downloader_opened=0; |
||
163 | StopDownloading(); |
||
164 | ExitProcess(); |
||
165 | } |
||
5493 | leency | 166 | if (id==301) && (DL_http_transfer <= 0) StartDownloading(); |
167 | if (id==302) StopDownloading(); |
||
168 | if (id==305) RunProgram("/sys/File managers/Eolite", #save_to); |
||
169 | if (id==306) RunProgram("@open", #filepath); |
||
170 | } |
||
171 | |||
172 | |||
173 | void StopDownloading() |
||
174 | { |
||
5685 | leency | 175 | Downloading_Stop(); |
176 | dl_edit.blur_border_color = 0xFFFfff; |
||
177 | dl_edit.flags = 10b; |
||
5493 | leency | 178 | DL_Draw_Window(); |
179 | } |
||
180 | |||
181 | void StartDownloading() |
||
182 | { |
||
183 | StopDownloading(); |
||
184 | if (strncmp(#DL_URL,"http:",5)==0) |
||
185 | { |
||
5685 | leency | 186 | Downloading_Start(); |
187 | dl_edit.blur_border_color = 0xCACACA; |
||
188 | dl_edit.flags = 100000000000b; |
||
5519 | leency | 189 | DL_progress_bar.value = 0; |
5493 | leency | 190 | DL_Draw_Window(); |
191 | if (DL_http_transfer == 0) |
||
192 | { |
||
193 | StopDownloading(); |
||
194 | DL_bufsize = 0; |
||
195 | DL_bufpointer = mem_Free(DL_bufpointer); |
||
196 | return; |
||
197 | } |
||
198 | } |
||
199 | else |
||
200 | { |
||
201 | notify("File adress should starts from http://"); |
||
202 | } |
||
203 | }=>=>280)>120)>8;><8;> |