Rev 5685 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5685 | Rev 6001 | ||
---|---|---|---|
Line 13... | Line 13... | ||
13 | #define SHOW_IN_FOLDER "Show in folder" |
13 | #define SHOW_IN_FOLDER "Show in folder" |
14 | #define OPEN_FILE "Open file" |
14 | #define OPEN_FILE "Open file" |
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 |
- | 18 | char save_to[4096] = "/tmp0/1/Downloads/"; |
|
Line 18... | Line 19... | ||
18 | 19 | ||
- | 20 | proc_info DL_Form; |
|
19 | proc_info DL_Form; |
21 | char downloader_edit[10000]; |
20 | char filepath[4096]; |
22 | char filepath[4096]; |
21 | int mouse_twbi; |
23 | int mouse_twbi; |
22 | edit_box dl_edit = {250,20,20,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(DL_URL),#DL_URL,#mouse_twbi,2,19,19}; |
24 | edit_box ed = {250,20,20,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(downloader_edit),#downloader_edit,#mouse_twbi,2,19,19}; |
23 | progress_bar DL_progress_bar = {0, 170, 51, 225, 12, 0, 0, 100, 0xFFFfff, 0x74DA00, 0x9F9F9F}; |
- | |
24 | - | ||
25 | char save_to[4096] = "/tmp0/1/Downloads/"; |
- | |
Line 26... | Line 25... | ||
26 | byte cleft = 15; |
25 | progress_bar pb = {0, 170, 51, 225, 12, 0, 0, 100, 0xFFFfff, 0x74DA00, 0x9F9F9F}; |
Line 27... | Line 26... | ||
27 | 26 | ||
Line 33... | Line 32... | ||
33 | int key; |
32 | int key; |
34 | char notify_message[4296]; |
33 | char notify_message[4296]; |
35 | downloader_opened = 1; |
34 | downloader_opened = 1; |
36 | SetEventMask(0x27); |
35 | SetEventMask(0x27); |
Line -... | Line 36... | ||
- | 36 | ||
37 | 37 | downloader.Stop(); |
|
38 | if (DL_URL[0]) StartDownloading(); else strcpy(#DL_URL, "http://"); |
38 | if (downloader_edit[0]) StartDownloading(); else strcpy(#downloader_edit, "http://"); |
39 | dl_edit.size = dl_edit.pos = dl_edit.shift = dl_edit.shift_old = strlen(#DL_URL); |
- | |
40 | - | ||
Line 41... | Line 39... | ||
41 | Downloading_SetDefaults(); |
39 | ed.size = ed.pos = ed.shift = ed.shift_old = strlen(#downloader_edit); |
42 | 40 | ||
43 | loop() |
41 | loop() |
44 | { |
42 | { |
45 | WaitEventTimeout(40); |
43 | WaitEventTimeout(40); |
46 | switch(EAX & 0xFF) |
44 | switch(EAX & 0xFF) |
47 | { |
45 | { |
48 | CASE evMouse: |
46 | CASE evMouse: |
49 | if (!CheckActiveProcess(DL_Form.ID)) break; |
47 | if (!CheckActiveProcess(DL_Form.ID)) break; |
Line 50... | Line 48... | ||
50 | edit_box_mouse stdcall (#dl_edit); |
48 | edit_box_mouse stdcall (#ed); |
51 | break; |
49 | break; |
52 | 50 | ||
Line 53... | Line 51... | ||
53 | case evButton: |
51 | case evButton: |
54 | DL_Scan(GetButtonID()); |
52 | Key_Scan(GetButtonID()); |
55 | break; |
53 | break; |
56 | 54 | ||
57 | case evKey: |
55 | case evKey: |
58 | key = GetKey(); |
56 | GetKeys(); |
Line 59... | Line 57... | ||
59 | EAX=key<<8; |
57 | EAX = key_ascii << 8; |
60 | edit_box_key stdcall(#dl_edit); |
58 | edit_box_key stdcall(#ed); |
61 | if (key==13) DL_Scan(301); |
59 | if (key_scancode==SCAN_CODE_ENTER) Key_Scan(301); |
Line 70... | Line 68... | ||
70 | if (DL_Form.width<280) MoveSize(OLD,OLD,280,OLD); |
68 | if (DL_Form.width<280) MoveSize(OLD,OLD,280,OLD); |
71 | DL_Draw_Window(); |
69 | DL_Draw_Window(); |
72 | break; |
70 | break; |
Line 73... | Line 71... | ||
73 | 71 | ||
74 | default: |
72 | default: |
75 | if (DL_Form.width==0) || (DL_http_transfer <= 0) break; |
73 | if (DL_Form.width==0) break; //WTF? |
76 | http_receive stdcall (DL_http_transfer); |
- | |
77 | $push EAX |
- | |
78 | ESI = DL_http_transfer; |
74 | if (!downloader.MonitorProgress()) break; |
79 | DL_progress_bar.max = ESI.http_msg.content_length; |
75 | pb.max = downloader.data_full_size; |
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 |
- | |
86 | if (EAX == 0) { |
- | |
87 | Downloading_Completed(); |
- | |
88 | strcpy(#filepath, #save_to); |
- | |
89 | strcat(#filepath, #DL_URL+strrchr(#DL_URL, '/')); |
- | |
90 | if (WriteFile(DL_bufsize, DL_bufpointer, #filepath)==0) |
76 | if (pb.value != downloader.data_downloaded_size) |
91 | { |
77 | { |
- | 78 | pb.value = downloader.data_downloaded_size; |
|
- | 79 | progressbar_draw stdcall(#pb); |
|
92 | sprintf(#notify_message, "%s%s%s",FILE_SAVED_AS,#filepath,"' -Dt"); |
80 | DrawDownloading(); |
93 | } |
81 | } |
94 | else |
82 | if (downloader.state == STATE_COMPLETED) |
- | 83 | { |
|
- | 84 | strcpy(#filepath, #save_to); |
|
- | 85 | strcat(#filepath, #downloader.url+strrchr(#downloader.url, '/')); |
|
- | 86 | if (WriteFile(downloader.bufsize, downloader.bufpointer, #filepath)==0) |
|
- | 87 | sprintf(#notify_message, "%s%s%s",FILE_SAVED_AS,#filepath,"' -Dt"); |
|
95 | { |
88 | else |
96 | sprintf(#notify_message, "%s%s%s","'Download manager\nError! Can\96t save file as ",#filepath,"' -Et"); |
- | |
97 | } |
89 | sprintf(#notify_message, "%s%s%s","'Download manager\nError! Can\96t save file as ",#filepath,"' -Et"); |
98 | notify(#notify_message); |
- | |
99 | dl_edit.blur_border_color = 0xFFFfff; |
90 | notify(#notify_message); |
100 | dl_edit.flags = 10b; |
91 | StopDownloading(); |
101 | DL_Draw_Window(); |
92 | DL_Draw_Window(); |
102 | break; |
93 | break; |
103 | } |
- | |
104 | ESI = DL_http_transfer; |
- | |
105 | downloaded_size = ESI.http_msg.content_received; |
- | |
106 | full_size = ESI.http_msg.content_length; |
- | |
107 | DrawDownloading(); |
94 | } |
108 | } |
95 | } |
109 | } |
96 | } |
Line -... | Line 97... | ||
- | 97 | } |
|
110 | } |
98 | |
- | 99 | void Key_Scan(int id) |
|
- | 100 | { |
|
- | 101 | if (id==001) { downloader_opened=0; StopDownloading(); ExitProcess(); } |
|
- | 102 | if (id==301) && (downloader.http_transfer <= 0) StartDownloading(); |
|
- | 103 | if (id==302) StopDownloading(); |
|
- | 104 | if (id==305) RunProgram("/sys/File managers/Eolite", #save_to); |
|
Line 111... | Line 105... | ||
111 | 105 | if (id==306) RunProgram("@open", #filepath); |
|
112 | 106 | } |
|
- | 107 | ||
113 | 108 | void DL_Draw_Window() |
|
114 | void DL_Draw_Window() |
109 | { |
115 | { |
110 | byte cleft = 15; |
116 | DrawBar(0,0, DL_Form.cwidth, DL_Form.cheight, system.color.work); |
111 | DrawBar(0,0, DL_Form.cwidth, DL_Form.cheight, system.color.work); |
117 | DeleteButton(305); |
112 | DeleteButton(305); |
118 | DeleteButton(306); |
113 | DeleteButton(306); |
119 | if (download_state == STATE_NOT_STARTED) || (download_state == STATE_COMPLETED) |
114 | if (downloader.state == STATE_NOT_STARTED) || (downloader.state == STATE_COMPLETED) |
120 | { |
115 | { |
121 | DrawCaptButton(cleft, 50, 130, 27, 301, system.color.work_button, system.color.work_button_text, START_DOWNLOADING); |
116 | DrawCaptButton(cleft, 50, 130, 27, 301, system.color.work_button, system.color.work_button_text, START_DOWNLOADING); |
122 | } |
117 | } |
123 | if (download_state == STATE_IN_PROGRESS) |
118 | if (downloader.state == STATE_IN_PROGRESS) |
124 | { |
119 | { |
125 | DrawCaptButton(cleft, 50, 140, 27, 302, system.color.work_button, system.color.work_button_text, STOP_DOWNLOADING); |
120 | DrawCaptButton(cleft, 50, 140, 27, 302, system.color.work_button, system.color.work_button_text, STOP_DOWNLOADING); |
126 | DrawDownloading(); |
121 | DrawDownloading(); |
127 | } |
122 | } |
128 | if (download_state == STATE_COMPLETED) |
123 | if (downloader.state == STATE_COMPLETED) |
129 | { |
124 | { |
130 | DrawCaptButton(cleft+140, 50, 110, 27, 305, system.color.work_button, system.color.work_button_text, SHOW_IN_FOLDER); |
125 | 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); |
126 | DrawCaptButton(cleft+260, 50, 120, 27, 306, system.color.work_button, system.color.work_button_text, OPEN_FILE); |
132 | } |
127 | } |
133 | WriteText(cleft, dl_edit.top + 4, 0x80, system.color.work_text, "URL:"); |
128 | WriteText(cleft, ed.top + 4, 0x80, system.color.work_text, "URL:"); |
134 | dl_edit.left = strlen("URL:")*6 + 10 + cleft; |
129 | ed.left = strlen("URL:")*6 + 10 + cleft; |
135 | dl_edit.width = DL_Form.cwidth - dl_edit.left - cleft - 3; |
130 | ed.width = DL_Form.cwidth - ed.left - cleft - 3; |
136 | dl_edit.offset=0; |
131 | ed.offset=0; |
137 | edit_box_draw stdcall(#dl_edit); |
132 | edit_box_draw stdcall(#ed); |
Line 138... | Line -... | ||
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); |
133 | DrawRectangle(ed.left-1, ed.top-1, ed.width+2, 16, ed.blur_border_color); |
140 | } |
134 | DrawRectangle(ed.left-2, ed.top-2, ed.width+4, 18, border_color); |
141 | 135 | } |
|
142 | - | ||
143 | void DrawDownloading() |
- | |
144 | { |
- | |
145 | dword tmp; |
136 | |
146 | char bytes_received[70]; |
137 | void StartDownloading() |
147 | - | ||
148 | tmp = ConvertSizeToKb(downloaded_size); |
- | |
149 | strcpy(#bytes_received, tmp); |
138 | { |
150 | strcat(#bytes_received, KB_RECEIVED); |
139 | StopDownloading(); |
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); |
- | |
153 | progressbar_draw stdcall(#DL_progress_bar); |
- | |
154 | } |
- | |
155 | - | ||
156 | - | ||
157 | - | ||
158 | 140 | if (strncmp(#downloader_edit,"http://",7)!=0) { |
|
- | 141 | notify("'File address should start from http://' -E"); |
|
159 | void DL_Scan(int id) |
142 | return; |
160 | { |
143 | } |
161 | if (id==001) { |
144 | if (!downloader.Start(#downloader_edit)) { |
162 | downloader_opened=0; |
145 | notify("'Error while starting download process.\nPlease, check entered path and internet connection.' -E"); |
163 | StopDownloading(); |
146 | StopDownloading(); |
164 | ExitProcess(); |
147 | return; |
165 | } |
148 | } |
166 | if (id==301) && (DL_http_transfer <= 0) StartDownloading(); |
149 | ed.blur_border_color = 0xCACACA; |
Line 167... | Line -... | ||
167 | if (id==302) StopDownloading(); |
- | |
168 | if (id==305) RunProgram("/sys/File managers/Eolite", #save_to); |
150 | ed.flags = 100000000000b; |
169 | if (id==306) RunProgram("@open", #filepath); |
151 | pb.value = 0; |
170 | } |
152 | DL_Draw_Window(); |
171 | 153 | } |
|
172 | 154 | ||
- | 155 | void DrawDownloading() |
|
- | 156 | { |
|
173 | void StopDownloading() |
157 | char bytes_received[70]; |
174 | { |
158 | dword tmp = ConvertSizeToKb(downloader.data_downloaded_size); |
Line 175... | Line 159... | ||
175 | Downloading_Stop(); |
159 | sprintf(#bytes_received, "%s%s", tmp, KB_RECEIVED); |
176 | dl_edit.blur_border_color = 0xFFFfff; |
- | |
177 | dl_edit.flags = 10b; |
- | |
178 | DL_Draw_Window(); |
- | |
179 | } |
160 | DrawBar(pb.left, pb.top + 17, DL_Form.cwidth - pb.left, 9, system.color.work); |
180 | 161 | WriteText(pb.left, pb.top + 17, 0x80, system.color.work_text, #bytes_received); |
|
181 | void StartDownloading() |
162 | progressbar_draw stdcall(#pb); |
182 | { |
163 | } |
183 | StopDownloading(); |
- | |
184 | if (strncmp(#DL_URL,"http:",5)==0) |
164 | |
185 | { |
- | |
186 | Downloading_Start(); |
- | |
187 | dl_edit.blur_border_color = 0xCACACA; |
- | |
188 | dl_edit.flags = 100000000000b; |
- | |
189 | DL_progress_bar.value = 0; |
- | |
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 | } |
165 | void StopDownloading() |
- | 166 | { |
|
- | 167 | downloader.Stop(); |