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