Rev 5640 | Go to most recent revision | Details | Compare with Previous | 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 DL_URL[10000]; |
||
5519 | leency | 21 | dword DL_bufpointer, DL_bufsize, DL_http_transfer, DL_http_buffer; |
5493 | leency | 22 | char filepath[4096]; |
23 | int downloaded_size, full_size; |
||
24 | int mouse_twbi; |
||
25 | edit_box DL_address_box = {250,20,20,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(DL_URL),#DL_URL,#mouse_twbi,2,19,19}; |
||
5519 | leency | 26 | progress_bar DL_progress_bar = {0, 170, 51, 225, 12, 0, 0, 100, 0xFFFfff, 0x74DA00, 0x9F9F9F}; |
5493 | leency | 27 | |
28 | char save_to[4096] = "/tmp0/1/Downloads/"; |
||
5519 | leency | 29 | byte cleft = 15; |
5493 | leency | 30 | |
5519 | leency | 31 | byte downloader_opened; |
5493 | leency | 32 | |
5519 | leency | 33 | byte download_state; |
34 | enum { STATE_NOT_STARTED, STATE_IN_PROGRESS, STATE_COMPLETED }; |
||
35 | |||
36 | |||
5493 | leency | 37 | void Downloader() |
38 | { |
||
39 | int key, btn; |
||
5640 | pavelyakov | 40 | |
5493 | leency | 41 | char notify_message[4296]; |
42 | |||
43 | if (DL_URL[0]) { |
||
44 | StartDownloading(); |
||
45 | } |
||
46 | else strcpy(#DL_URL, "http://"); |
||
47 | DL_address_box.size = DL_address_box.pos = DL_address_box.shift = DL_address_box.shift_old = strlen(#DL_URL); |
||
48 | |||
49 | downloaded_size = full_size = 0; |
||
5519 | leency | 50 | downloader_opened = 1; |
5493 | leency | 51 | |
52 | SetEventMask(0x27); |
||
53 | loop() |
||
54 | { |
||
55 | WaitEventTimeout(40); |
||
56 | switch(EAX & 0xFF) |
||
57 | { |
||
58 | CASE evMouse: |
||
59 | if (!CheckActiveProcess(DL_Form.ID)) break; |
||
60 | if (DL_http_transfer <= 0) edit_box_mouse stdcall (#DL_address_box); |
||
61 | break; |
||
62 | |||
63 | case evButton: |
||
64 | btn=GetButtonID(); |
||
65 | DL_Scan(btn); |
||
66 | break; |
||
67 | |||
68 | case evKey: |
||
69 | key = GetKey(); |
||
70 | if (DL_address_box.flags & 0b10) |
||
71 | { |
||
72 | EAX=key<<8; |
||
73 | edit_box_key stdcall(#DL_address_box); |
||
74 | } |
||
75 | if (key==13) DL_Scan(301); |
||
76 | break; |
||
77 | |||
78 | case evReDraw: |
||
5674 | pavelyakov | 79 | system.color.get(); |
80 | DefineAndDrawWindow(215, 100, 420, 120, 0x74, system.color.work, DL_WINDOW_HEADER, 0); |
||
5493 | leency | 81 | GetProcessInfo(#DL_Form, SelfInfo); |
82 | if (DL_Form.status_window>2) break; |
||
83 | if (DL_Form.height<120) MoveSize(OLD,OLD,OLD,120); |
||
84 | if (DL_Form.width<280) MoveSize(OLD,OLD,280,OLD); |
||
85 | DL_Draw_Window(); |
||
86 | break; |
||
87 | |||
88 | default: |
||
5519 | leency | 89 | if (DL_Form.width==0) || (DL_http_transfer <= 0) break; |
5534 | hidnplayr | 90 | http_receive stdcall (DL_http_transfer); |
5519 | leency | 91 | $push EAX |
92 | ESI = DL_http_transfer; |
||
93 | DL_progress_bar.max = ESI.http_msg.content_length; |
||
94 | if (DL_progress_bar.value != ESI.http_msg.content_received) |
||
95 | { |
||
96 | DL_progress_bar.value = ESI.http_msg.content_received; |
||
97 | progressbar_draw stdcall(#DL_progress_bar); |
||
98 | } |
||
99 | $pop EAX |
||
5493 | leency | 100 | if (EAX == 0) { |
101 | ESI = DL_http_transfer; |
||
102 | DL_bufpointer = ESI.http_msg.content_ptr; |
||
103 | DL_bufsize = ESI.http_msg.content_received; |
||
104 | http_free stdcall (DL_http_transfer); |
||
105 | DL_http_transfer=0; |
||
106 | strcpy(#filepath, #save_to); |
||
107 | strcat(#filepath, #DL_URL+strrchr(#DL_URL, '/')); |
||
108 | if (WriteFile(DL_bufsize, DL_bufpointer, #filepath)==0) |
||
109 | { |
||
110 | strcpy(#notify_message, FILE_SAVED_AS); |
||
111 | strcat(#notify_message, #filepath); |
||
112 | strcat(#notify_message, "' -Dt"); |
||
113 | } |
||
114 | else |
||
115 | { |
||
116 | strcpy(#notify_message, "'Download manager\nError! Can\96t save file as "); |
||
117 | strcat(#notify_message, #filepath); |
||
118 | strcat(#notify_message, "' -Et"); |
||
119 | } |
||
120 | notify(#notify_message); |
||
121 | DL_address_box.color = DL_address_box.blur_border_color = DL_address_box.focus_border_color = 0xFFFfff; |
||
5519 | leency | 122 | download_state = STATE_COMPLETED; |
5493 | leency | 123 | DL_Draw_Window(); |
5519 | leency | 124 | break; |
5493 | leency | 125 | } |
126 | ESI = DL_http_transfer; |
||
127 | downloaded_size = ESI.http_msg.content_received; |
||
128 | full_size = ESI.http_msg.content_length; |
||
129 | DrawDownloading(); |
||
130 | } |
||
131 | } |
||
132 | } |
||
133 | |||
134 | |||
135 | |||
136 | void DL_Draw_Window() |
||
137 | { |
||
5674 | pavelyakov | 138 | DrawBar(0,0, DL_Form.cwidth, DL_Form.cheight, system.color.work); |
5519 | leency | 139 | DeleteButton(305); |
140 | DeleteButton(306); |
||
141 | if (download_state == STATE_NOT_STARTED) || (download_state == STATE_COMPLETED) |
||
5493 | leency | 142 | { |
5674 | pavelyakov | 143 | DrawCaptButton(cleft, 50, 130, 27, 301, system.color.work_button, system.color.work_button_text, START_DOWNLOADING); |
5493 | leency | 144 | } |
5519 | leency | 145 | if (download_state == STATE_IN_PROGRESS) |
5493 | leency | 146 | { |
5674 | pavelyakov | 147 | DrawCaptButton(cleft, 50, 140, 27, 302, system.color.work_button, system.color.work_button_text, STOP_DOWNLOADING); |
5519 | leency | 148 | DrawDownloading(); |
5493 | leency | 149 | } |
5519 | leency | 150 | if (download_state == STATE_COMPLETED) |
5493 | leency | 151 | { |
5674 | pavelyakov | 152 | DrawCaptButton(cleft+140, 50, 110, 27, 305, system.color.work_button, system.color.work_button_text, SHOW_IN_FOLDER); |
153 | DrawCaptButton(cleft+260, 50, 120, 27, 306, system.color.work_button, system.color.work_button_text, OPEN_FILE); |
||
5493 | leency | 154 | } |
5674 | pavelyakov | 155 | WriteText(cleft, DL_address_box.top + 4, 0x80, system.color.work_text, "URL:"); |
5493 | leency | 156 | DL_address_box.left = strlen("URL:")*6 + 10 + cleft; |
157 | DL_address_box.width = DL_Form.cwidth - DL_address_box.left - cleft - 3; |
||
158 | DL_address_box.offset=0; |
||
159 | edit_box_draw stdcall(#DL_address_box); |
||
5519 | leency | 160 | DrawRectangle(DL_address_box.left-1, DL_address_box.top-1, DL_address_box.width+2, 16, DL_address_box.color); |
161 | DrawRectangle(DL_address_box.left-2, DL_address_box.top-2, DL_address_box.width+4, 18, border_color); |
||
162 | } |
||
5493 | leency | 163 | |
5519 | leency | 164 | |
165 | void DrawDownloading() |
||
166 | { |
||
167 | dword tmp; |
||
168 | char bytes_received[70]; |
||
169 | |||
170 | tmp = ConvertSizeToKb(downloaded_size); |
||
171 | strcpy(#bytes_received, tmp); |
||
172 | strcat(#bytes_received, KB_RECEIVED); |
||
5674 | pavelyakov | 173 | DrawBar(DL_progress_bar.left, DL_progress_bar.top + 17, DL_Form.cwidth - DL_progress_bar.left, 9, system.color.work); |
174 | WriteText(DL_progress_bar.left, DL_progress_bar.top + 17, 0x80, system.color.work_text, #bytes_received); |
||
5519 | leency | 175 | progressbar_draw stdcall(#DL_progress_bar); |
5493 | leency | 176 | } |
177 | |||
5519 | leency | 178 | |
179 | |||
180 | |||
5493 | leency | 181 | void DL_Scan(int id) |
182 | { |
||
5519 | leency | 183 | if (id==001) { |
184 | downloader_opened=0; |
||
185 | StopDownloading(); |
||
186 | ExitProcess(); |
||
187 | } |
||
5493 | leency | 188 | if (id==301) && (DL_http_transfer <= 0) StartDownloading(); |
189 | if (id==302) StopDownloading(); |
||
190 | if (id==305) RunProgram("/sys/File managers/Eolite", #save_to); |
||
191 | if (id==306) RunProgram("@open", #filepath); |
||
192 | } |
||
193 | |||
194 | |||
195 | void StopDownloading() |
||
196 | { |
||
5519 | leency | 197 | download_state = STATE_NOT_STARTED; |
5493 | leency | 198 | if (DL_http_transfer<>0) |
199 | { |
||
200 | EAX = DL_http_transfer; |
||
201 | EAX = EAX.http_msg.content_ptr; // get pointer to data |
||
202 | $push EAX // save it on the stack |
||
203 | http_free stdcall (DL_http_transfer); // abort connection |
||
204 | $pop EAX |
||
205 | mem_Free(EAX); // free data |
||
206 | DL_http_transfer=0; |
||
207 | DL_bufsize = 0; |
||
208 | DL_bufpointer = mem_Free(DL_bufpointer); |
||
209 | downloaded_size = full_size = 0; |
||
210 | } |
||
211 | DL_address_box.color = DL_address_box.blur_border_color = DL_address_box.focus_border_color = 0xFFFfff; |
||
212 | DL_Draw_Window(); |
||
213 | } |
||
214 | |||
215 | void StartDownloading() |
||
216 | { |
||
217 | StopDownloading(); |
||
218 | if (strncmp(#DL_URL,"http:",5)==0) |
||
219 | { |
||
5519 | leency | 220 | download_state = STATE_IN_PROGRESS; |
221 | DL_address_box.color = DL_address_box.blur_border_color = DL_address_box.focus_border_color = 0xdddDDD; |
||
5534 | hidnplayr | 222 | http_get stdcall (#DL_URL, 0, 0, #accept_language); |
5493 | leency | 223 | DL_http_transfer = EAX; |
5519 | leency | 224 | DL_progress_bar.value = 0; |
5493 | leency | 225 | DL_Draw_Window(); |
226 | if (DL_http_transfer == 0) |
||
227 | { |
||
228 | StopDownloading(); |
||
229 | DL_bufsize = 0; |
||
230 | DL_bufpointer = mem_Free(DL_bufpointer); |
||
231 | return; |
||
232 | } |
||
233 | } |
||
234 | else |
||
235 | { |
||
236 | notify("File adress should starts from http://"); |
||
237 | } |
||
238 | }>=>=>280)>120)>8;><8;>=> |