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