Rev 5683 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5683 | Rev 5685 | ||
---|---|---|---|
Line 15... | Line 15... | ||
15 | #define FILE_SAVED_AS "'Download manager\nFile saved as " |
15 | #define FILE_SAVED_AS "'Download manager\nFile saved as " |
16 | #define KB_RECEIVED " received" |
16 | #define KB_RECEIVED " received" |
17 | #endif |
17 | #endif |
Line 18... | Line 18... | ||
18 | 18 | ||
19 | proc_info DL_Form; |
- | |
20 | char DL_URL[10000]; |
- | |
21 | dword DL_bufpointer, DL_bufsize, DL_http_transfer, DL_http_buffer; |
19 | proc_info DL_Form; |
22 | char filepath[4096]; |
- | |
23 | int downloaded_size, full_size; |
20 | char filepath[4096]; |
24 | int mouse_twbi; |
21 | 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}; |
22 | edit_box dl_edit = {250,20,20,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(DL_URL),#DL_URL,#mouse_twbi,2,19,19}; |
Line 26... | Line 23... | ||
26 | progress_bar DL_progress_bar = {0, 170, 51, 225, 12, 0, 0, 100, 0xFFFfff, 0x74DA00, 0x9F9F9F}; |
23 | progress_bar DL_progress_bar = {0, 170, 51, 225, 12, 0, 0, 100, 0xFFFfff, 0x74DA00, 0x9F9F9F}; |
27 | 24 | ||
Line 28... | Line 25... | ||
28 | char save_to[4096] = "/tmp0/1/Downloads/"; |
25 | char save_to[4096] = "/tmp0/1/Downloads/"; |
Line 29... | Line -... | ||
29 | byte cleft = 15; |
- | |
30 | - | ||
31 | byte downloader_opened; |
- | |
Line 32... | Line 26... | ||
32 | 26 | byte cleft = 15; |
|
33 | byte download_state; |
27 | |
34 | enum { STATE_NOT_STARTED, STATE_IN_PROGRESS, STATE_COMPLETED }; |
28 | byte downloader_opened; |
35 | - | ||
36 | 29 | ||
- | 30 | ||
- | 31 | void Downloader() |
|
Line 37... | Line -... | ||
37 | void Downloader() |
- | |
38 | { |
- | |
39 | int key, btn; |
- | |
40 | 32 | { |
|
41 | char notify_message[4296]; |
33 | int key; |
Line 42... | Line -... | ||
42 | - | ||
43 | if (DL_URL[0]) { |
34 | char notify_message[4296]; |
Line 44... | Line -... | ||
44 | StartDownloading(); |
- | |
45 | } |
35 | downloader_opened = 1; |
46 | else strcpy(#DL_URL, "http://"); |
36 | SetEventMask(0x27); |
47 | DL_address_box.size = DL_address_box.pos = DL_address_box.shift = DL_address_box.shift_old = strlen(#DL_URL); |
37 | |
48 | 38 | if (DL_URL[0]) StartDownloading(); else strcpy(#DL_URL, "http://"); |
|
49 | downloaded_size = full_size = 0; |
39 | dl_edit.size = dl_edit.pos = dl_edit.shift = dl_edit.shift_old = strlen(#DL_URL); |
50 | downloader_opened = 1; |
40 | |
51 | 41 | Downloading_SetDefaults(); |
|
52 | SetEventMask(0x27); |
42 | |
53 | loop() |
43 | loop() |
Line 54... | Line 44... | ||
54 | { |
44 | { |
55 | WaitEventTimeout(40); |
45 | WaitEventTimeout(40); |
56 | switch(EAX & 0xFF) |
- | |
57 | { |
46 | switch(EAX & 0xFF) |
Line 58... | Line 47... | ||
58 | CASE evMouse: |
47 | { |
59 | if (!CheckActiveProcess(DL_Form.ID)) break; |
48 | CASE evMouse: |
60 | if (DL_http_transfer <= 0) edit_box_mouse stdcall (#DL_address_box); |
49 | if (!CheckActiveProcess(DL_Form.ID)) break; |
61 | break; |
50 | edit_box_mouse stdcall (#dl_edit); |
62 | 51 | break; |
|
63 | case evButton: |
52 | |
Line 64... | Line 53... | ||
64 | btn=GetButtonID(); |
53 | case evButton: |
65 | DL_Scan(btn); |
54 | DL_Scan(GetButtonID()); |
Line 93... | Line 82... | ||
93 | DL_progress_bar.value = ESI.http_msg.content_received; |
82 | DL_progress_bar.value = ESI.http_msg.content_received; |
94 | progressbar_draw stdcall(#DL_progress_bar); |
83 | progressbar_draw stdcall(#DL_progress_bar); |
95 | } |
84 | } |
96 | $pop EAX |
85 | $pop EAX |
97 | if (EAX == 0) { |
86 | if (EAX == 0) { |
98 | ESI = DL_http_transfer; |
- | |
99 | DL_bufpointer = ESI.http_msg.content_ptr; |
- | |
100 | DL_bufsize = ESI.http_msg.content_received; |
- | |
101 | http_free stdcall (DL_http_transfer); |
- | |
102 | DL_http_transfer=0; |
87 | Downloading_Completed(); |
103 | strcpy(#filepath, #save_to); |
88 | strcpy(#filepath, #save_to); |
104 | strcat(#filepath, #DL_URL+strrchr(#DL_URL, '/')); |
89 | strcat(#filepath, #DL_URL+strrchr(#DL_URL, '/')); |
105 | if (WriteFile(DL_bufsize, DL_bufpointer, #filepath)==0) |
90 | if (WriteFile(DL_bufsize, DL_bufpointer, #filepath)==0) |
106 | { |
91 | { |
107 | strcpy(#notify_message, FILE_SAVED_AS); |
92 | sprintf(#notify_message, "%s%s%s",FILE_SAVED_AS,#filepath,"' -Dt"); |
108 | strcat(#notify_message, #filepath); |
- | |
109 | strcat(#notify_message, "' -Dt"); |
- | |
110 | } |
93 | } |
111 | else |
94 | else |
112 | { |
95 | { |
113 | strcpy(#notify_message, "'Download manager\nError! Can\96t save file as "); |
96 | sprintf(#notify_message, "%s%s%s","'Download manager\nError! Can\96t save file as ",#filepath,"' -Et"); |
114 | strcat(#notify_message, #filepath); |
- | |
115 | strcat(#notify_message, "' -Et"); |
- | |
116 | } |
97 | } |
117 | notify(#notify_message); |
98 | notify(#notify_message); |
118 | DL_address_box.color = DL_address_box.blur_border_color = DL_address_box.focus_border_color = 0xFFFfff; |
99 | dl_edit.blur_border_color = 0xFFFfff; |
119 | download_state = STATE_COMPLETED; |
100 | dl_edit.flags = 10b; |
120 | DL_Draw_Window(); |
101 | DL_Draw_Window(); |
121 | break; |
102 | break; |
122 | } |
103 | } |
123 | ESI = DL_http_transfer; |
104 | ESI = DL_http_transfer; |
124 | downloaded_size = ESI.http_msg.content_received; |
105 | downloaded_size = ESI.http_msg.content_received; |
Line 147... | Line 128... | ||
147 | if (download_state == STATE_COMPLETED) |
128 | if (download_state == STATE_COMPLETED) |
148 | { |
129 | { |
149 | DrawCaptButton(cleft+140, 50, 110, 27, 305, system.color.work_button, system.color.work_button_text, SHOW_IN_FOLDER); |
130 | DrawCaptButton(cleft+140, 50, 110, 27, 305, system.color.work_button, system.color.work_button_text, SHOW_IN_FOLDER); |
150 | DrawCaptButton(cleft+260, 50, 120, 27, 306, system.color.work_button, system.color.work_button_text, OPEN_FILE); |
131 | DrawCaptButton(cleft+260, 50, 120, 27, 306, system.color.work_button, system.color.work_button_text, OPEN_FILE); |
151 | } |
132 | } |
152 | WriteText(cleft, DL_address_box.top + 4, 0x80, system.color.work_text, "URL:"); |
133 | WriteText(cleft, dl_edit.top + 4, 0x80, system.color.work_text, "URL:"); |
153 | DL_address_box.left = strlen("URL:")*6 + 10 + cleft; |
134 | dl_edit.left = strlen("URL:")*6 + 10 + cleft; |
154 | DL_address_box.width = DL_Form.cwidth - DL_address_box.left - cleft - 3; |
135 | dl_edit.width = DL_Form.cwidth - dl_edit.left - cleft - 3; |
155 | DL_address_box.offset=0; |
136 | dl_edit.offset=0; |
156 | edit_box_draw stdcall(#DL_address_box); |
137 | edit_box_draw stdcall(#dl_edit); |
157 | DrawRectangle(DL_address_box.left-1, DL_address_box.top-1, DL_address_box.width+2, 16, DL_address_box.color); |
138 | DrawRectangle(dl_edit.left-1, dl_edit.top-1, dl_edit.width+2, 16, dl_edit.blur_border_color); |
158 | DrawRectangle(DL_address_box.left-2, DL_address_box.top-2, DL_address_box.width+4, 18, border_color); |
139 | DrawRectangle(dl_edit.left-2, dl_edit.top-2, dl_edit.width+4, 18, border_color); |
159 | } |
140 | } |
Line 160... | Line 141... | ||
160 | 141 | ||
161 | 142 | ||
Line 189... | Line 170... | ||
189 | } |
170 | } |
Line 190... | Line 171... | ||
190 | 171 | ||
191 | 172 | ||
192 | void StopDownloading() |
- | |
193 | { |
- | |
194 | download_state = STATE_NOT_STARTED; |
- | |
195 | if (DL_http_transfer<>0) |
- | |
196 | { |
- | |
197 | EAX = DL_http_transfer; |
- | |
198 | EAX = EAX.http_msg.content_ptr; // get pointer to data |
- | |
199 | $push EAX // save it on the stack |
- | |
200 | http_free stdcall (DL_http_transfer); // abort connection |
- | |
201 | $pop EAX |
- | |
202 | mem_Free(EAX); // free data |
- | |
203 | DL_http_transfer=0; |
- | |
204 | DL_bufsize = 0; |
173 | void StopDownloading() |
205 | DL_bufpointer = mem_Free(DL_bufpointer); |
- | |
206 | downloaded_size = full_size = 0; |
174 | { |
207 | } |
175 | Downloading_Stop(); |
208 | DL_address_box.color = DL_address_box.blur_border_color = 0xFFFfff; |
176 | dl_edit.blur_border_color = 0xFFFfff; |
209 | DL_address_box.flags = 10b; |
177 | dl_edit.flags = 10b; |
Line 210... | Line 178... | ||
210 | DL_Draw_Window(); |
178 | DL_Draw_Window(); |
211 | } |
179 | } |
212 | 180 | ||
213 | void StartDownloading() |
181 | void StartDownloading() |
214 | { |
182 | { |
215 | StopDownloading(); |
183 | StopDownloading(); |
216 | if (strncmp(#DL_URL,"http:",5)==0) |
184 | if (strncmp(#DL_URL,"http:",5)==0) |
217 | { |
185 | { |
218 | download_state = STATE_IN_PROGRESS; |
- | |
219 | DL_address_box.color = DL_address_box.blur_border_color = 0xCACACA; |
- | |
220 | DL_address_box.flags = 100000000000b; |
186 | Downloading_Start(); |
221 | http_get stdcall (#DL_URL, 0, 0, #accept_language); |
187 | dl_edit.blur_border_color = 0xCACACA; |
222 | DL_http_transfer = EAX; |
188 | dl_edit.flags = 100000000000b; |
223 | DL_progress_bar.value = 0; |
189 | DL_progress_bar.value = 0; |
224 | DL_Draw_Window(); |
190 | DL_Draw_Window(); |