Subversion Repositories Kolibri OS

Rev

Rev 5674 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5674 Rev 5690
1
#define MEMSIZE 0x100000
1
#define MEMSIZE 0x100000
2
//libraries
2
//libraries
3
#include "..\lib\kolibri.h"
3
#include "..\lib\kolibri.h"
4
#include "..\lib\strings.h"
4
#include "..\lib\strings.h"
5
#include "..\lib\gui.h"
5
#include "..\lib\gui.h"
6
#include "..\lib\encoding.h"
-
 
7
#include "..\lib\draw_buf.h"
6
#include "..\lib\draw_buf.h"
8
#include "..\lib\file_system.h"
7
#include "..\lib\file_system.h"
9
#include "..\lib\mem.h"
8
#include "..\lib\mem.h"
10
#include "..\lib\dll.h"
9
#include "..\lib\dll.h"
11
#include "..\lib\list_box.h"
10
#include "..\lib\list_box.h"
12
//*.obj libraries
11
//*.obj libraries
13
#include "..\lib\obj\box_lib.h"
12
#include "..\lib\obj\box_lib.h"
14
#include "..\lib\obj\libio_lib.h"
13
#include "..\lib\obj\libio_lib.h"
15
#include "..\lib\obj\http.h"
14
#include "..\lib\obj\http.h"
16
 
15
 
17
char header[]="New Downloader v0.6";
16
char header[]="New Downloader v0.6";
18
 
17
 
19
#ifdef LANG_RUS
18
#ifdef LANG_RUS
20
	char accept_language[]= "Accept-Language: ru\n";
19
	char accept_language[]= "Accept-Language: ru\n";
21
#else
20
#else
22
	char accept_language[]= "Accept-Language: en\n";	
21
	char accept_language[]= "Accept-Language: en\n";	
23
#endif
22
#endif
24
 
23
 
25
proc_info Form;
24
proc_info Form;
26
#define WIN_W 400
25
#define WIN_W 400
27
#define WIN_H 220
26
#define WIN_H 220
28
 
27
 
29
#define URL param
28
#define URL param
30
 
29
 
31
int	mouse_twb;
30
int	mouse_twb;
32
edit_box address_box= {250,20,20,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(URL),#URL,#mouse_twb,2,19,19};
31
edit_box address_box= {250,20,20,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(URL),#URL,#mouse_twb,2,19,19};
33
 
32
 
34
dword speed[2000];
33
dword speed[2000];
35
dword speed_position;
34
dword speed_position;
36
dword bufpointer;
35
dword bufpointer;
37
dword bufsize;
36
dword bufsize;
38
 
37
 
39
dword http_transfer = 0;
38
dword http_transfer = 0;
40
dword http_buffer;
39
dword http_buffer;
41
 
40
 
42
DrawBufer diagram;
41
DrawBufer diagram;
43
 
42
 
44
void main()
43
void main()
45
{
44
{
46
	int key, btn;
45
	int key, btn;
47
 
46
 
48
	char filepath[4096];
47
	char filepath[4096];
49
	char notify_message[4296];
48
	char notify_message[4296];
50
	
49
	
51
	load_dll(boxlib, #box_lib_init,0);
50
	load_dll(boxlib, #box_lib_init,0);
52
	load_dll(libio, #libio_init,1);
51
	load_dll(libio, #libio_init,1);
53
	load_dll(libHTTP, #http_lib_init,1);	
52
	load_dll(libHTTP, #http_lib_init,1);	
54
	if (!URL) strcpy(#URL, "http://builds.kolibrios.org/eng/latest-iso.7z");
53
	if (!URL) strcpy(#URL, "http://builds.kolibrios.org/eng/latest-iso.7z");
55
	address_box.size = address_box.pos = strlen(#URL);
54
	address_box.size = address_box.pos = strlen(#URL);
56
 
55
 
57
	SetEventMask(0x27); //a7
56
	SetEventMask(0x27); //a7
58
	loop()
57
	loop()
59
	{
58
	{
60
		WaitEventTimeout(40);
59
		WaitEventTimeout(40);
61
		switch(EAX & 0xFF)
60
		switch(EAX & 0xFF)
62
		{
61
		{
63
			CASE evMouse:
62
			CASE evMouse:
64
				if (!CheckActiveProcess(Form.ID)) break;
63
				if (!CheckActiveProcess(Form.ID)) break;
65
				if (http_transfer <= 0) edit_box_mouse stdcall (#address_box);
64
				if (http_transfer <= 0) edit_box_mouse stdcall (#address_box);
66
				break;
65
				break;
67
 
66
 
68
			case evButton:
67
			case evButton:
69
				btn=GetButtonID();
68
				btn=GetButtonID();
70
				if (btn==1)	ExitProcess();
69
				if (btn==1)	ExitProcess();
71
				Scan(btn);
70
				Scan(btn);
72
				break;
71
				break;
73
 
72
 
74
			case evKey:
73
			case evKey:
75
				key = GetKey();
74
				key = GetKey();
76
				if (address_box.flags & 0b10)
75
				if (address_box.flags & 0b10)
77
				{
76
				{
78
					EAX=key<<8; 
77
					EAX=key<<8; 
79
					edit_box_key stdcall(#address_box);
78
					edit_box_key stdcall(#address_box);
80
				}
79
				}
81
				if (key==13) Scan(301);
80
				if (key==13) Scan(301);
82
				break;
81
				break;
83
 
82
 
84
			case evReDraw:
83
			case evReDraw:
85
				system.color.get();
84
				system.color.get();
86
				DefineAndDrawWindow(215,100,WIN_W,WIN_H,0x73,system.color.work,#header,0);
85
				DefineAndDrawWindow(215,100,WIN_W,WIN_H,0x73,system.color.work,#header,0);
87
				GetProcessInfo(#Form, SelfInfo);
86
				GetProcessInfo(#Form, SelfInfo);
88
				if (Form.status_window>2) break;
87
				if (Form.status_window>2) break;
89
				if (Form.height<120) MoveSize(OLD,OLD,OLD,120);
88
				if (Form.height<120) MoveSize(OLD,OLD,OLD,120);
90
				if (Form.width<280) MoveSize(OLD,OLD,280,OLD);
89
				if (Form.width<280) MoveSize(OLD,OLD,280,OLD);
91
				diagram.Init(20, 87, Form.cwidth - 40, Form.cheight - 87 - 28);
90
				diagram.Init(20, 87, Form.cwidth - 40, Form.cheight - 87 - 28);
92
				Draw_Window();
91
				Draw_Window();
93
				break;
92
				break;
94
				
93
				
95
			default:
94
			default:
96
				if (Form.width==0) break;
95
				if (Form.width==0) break;
97
				if (http_transfer <= 0) break;
96
				if (http_transfer <= 0) break;
98
				http_receive stdcall (http_transfer);
97
				http_receive stdcall (http_transfer);
99
				if (EAX == 0) {
98
				if (EAX == 0) {
100
					ESI = http_transfer;
99
					ESI = http_transfer;
101
					bufpointer = ESI.http_msg.content_ptr;
100
					bufpointer = ESI.http_msg.content_ptr;
102
					bufsize = ESI.http_msg.content_received;
101
					bufsize = ESI.http_msg.content_received;
103
					http_free stdcall (http_transfer);
102
					http_free stdcall (http_transfer);
104
					http_transfer=0;
103
					http_transfer=0;
105
					strcpy(#filepath, "/tmp0/1/");
104
					strcpy(#filepath, "/tmp0/1/");
106
					strcat(#filepath, #URL+strrchr(#URL, '/'));
105
					strcat(#filepath, #URL+strrchr(#URL, '/'));
107
					if (!WriteFile(bufsize, bufpointer, #filepath))
106
					if (!WriteFile(bufsize, bufpointer, #filepath))
108
					{
107
					{
109
						strcpy(#notify_message, "File saved as ");
108
						strcpy(#notify_message, "File saved as ");
110
					}
109
					}
111
					else
110
					else
112
					{
111
					{
113
						strcpy(#notify_message, "Error! Can't save file as ");
112
						strcpy(#notify_message, "Error! Can't save file as ");
114
					}
113
					}
115
					strcat(#notify_message, #filepath);	
114
					strcat(#notify_message, #filepath);	
116
					notify(#notify_message);
115
					notify(#notify_message);
117
					address_box.color = address_box.blur_border_color = address_box.focus_border_color = 0xFFFfff;
116
					address_box.color = address_box.blur_border_color = address_box.focus_border_color = 0xFFFfff;
118
					Draw_Window();
117
					Draw_Window();
119
				}
118
				}
120
				ESI = http_transfer;
119
				ESI = http_transfer;
121
				speed[speed_position] = ESI.http_msg.content_received;
120
				speed[speed_position] = ESI.http_msg.content_received;
122
				DrawSpeed();
121
				DrawSpeed();
123
				speed_position++;
122
				speed_position++;
124
		}
123
		}
125
	}
124
	}
126
}
125
}
127
 
126
 
128
void DrawSpeed()
127
void DrawSpeed()
129
{
128
{
130
	int i;
129
	int i;
131
	int speed_in_position, speed_string;
130
	int speed_in_position, speed_string;
132
	int max_speed, start_from;
131
	int max_speed, start_from;
133
	char bytes_received[70];
132
	char bytes_received[70];
134
 
133
 
135
	diagram.Fill(0xFCF8F7);
134
	diagram.Fill(0xFCF8F7);
136
	max_speed = speed[speed_position];
135
	max_speed = speed[speed_position];
137
	if (speed_position < diagram.bufw) start_from = 0; else start_from = speed_position - diagram.bufw + 1;
136
	if (speed_position < diagram.bufw) start_from = 0; else start_from = speed_position - diagram.bufw + 1;
138
	if (speed_position>0) for (i = 0; i <= speed_position-start_from; i++)
137
	if (speed_position>0) for (i = 0; i <= speed_position-start_from; i++)
139
	{
138
	{
140
		if (max_speed>0)
139
		if (max_speed>0)
141
		{
140
		{
142
			speed_in_position = diagram.bufh - 1 * speed[i+start_from] / max_speed;
141
			speed_in_position = diagram.bufh - 1 * speed[i+start_from] / max_speed;
143
			diagram.DrawBar(i, diagram.bufh - speed_in_position, 1, speed_in_position, 0x00A3CB);
142
			diagram.DrawBar(i, diagram.bufh - speed_in_position, 1, speed_in_position, 0x00A3CB);
144
		}
143
		}
145
	}
144
	}
146
	diagram.Show();
145
	diagram.Show();
147
	if (speed_position==0) return;
146
	if (speed_position==0) return;
148
	if (http_transfer > 0)
147
	if (http_transfer > 0)
149
	{
148
	{
150
		strcpy(#bytes_received, "Downloading... ");	
149
		strcpy(#bytes_received, "Downloading... ");	
151
	} 
150
	} 
152
	else
151
	else
153
	{
152
	{
154
		strcpy(#bytes_received, "Downloading competle. ");	
153
		strcpy(#bytes_received, "Downloading competle. ");	
155
	}
154
	}
156
	speed_string = ConvertSize(speed[speed_position-1]);
155
	speed_string = ConvertSize(speed[speed_position-1]);
157
	strcat(#bytes_received, speed_string);
156
	strcat(#bytes_received, speed_string);
158
	strcat(#bytes_received, " received.");
157
	strcat(#bytes_received, " received.");
159
	DrawBar(diagram.bufx, diagram.bufy + diagram.bufh + 10, diagram.bufw, 9, system.color.work);
158
	DrawBar(diagram.bufx, diagram.bufy + diagram.bufh + 10, diagram.bufw, 9, system.color.work);
160
	WriteText(diagram.bufx, diagram.bufy + diagram.bufh + 10, 0x80, system.color.work_text, #bytes_received);
159
	WriteText(diagram.bufx, diagram.bufy + diagram.bufh + 10, 0x80, system.color.work_text, #bytes_received);
161
}
160
}
162
 
161
 
163
void Draw_Window()
162
void Draw_Window()
164
{	
163
{	
165
	DrawBar(0,0,Form.cwidth,Form.cheight,system.color.work); //bg
164
	DrawBar(0,0,Form.cwidth,Form.cheight,system.color.work); //bg
166
	if (http_transfer <= 0)
165
	if (http_transfer <= 0)
167
	{
166
	{
168
		DrawCaptButton(diagram.bufx, 50, 120, 20, 301, system.color.work_button, system.color.work_button_text, "Start downloading");	
167
		DrawCaptButton(diagram.bufx, 50, 120, 20, 301, system.color.work_button, system.color.work_button_text, "Start downloading");	
169
	}
168
	}
170
	else
169
	else
171
	{
170
	{
172
		DrawCaptButton(diagram.bufx, 50, 120, 20, 302, system.color.work_button, system.color.work_button_text, "Stop downloading");
171
		DrawCaptButton(diagram.bufx, 50, 120, 20, 302, system.color.work_button, system.color.work_button_text, "Stop downloading");
173
	}
172
	}
174
	if (http_transfer <= 0) && (speed_position>0)
173
	if (http_transfer <= 0) && (speed_position>0)
175
	{
174
	{
176
		DrawCaptButton(diagram.bufx+130, 50, 120, 20, 305, system.color.work_button, system.color.work_button_text, "Show in folder");	
175
		DrawCaptButton(diagram.bufx+130, 50, 120, 20, 305, system.color.work_button, system.color.work_button_text, "Show in folder");	
177
	} 
176
	} 
178
	WriteText(diagram.bufx, address_box.top + 4, 0x80, system.color.work_text, "URL:");
177
	WriteText(diagram.bufx, address_box.top + 4, 0x80, system.color.work_text, "URL:");
179
	address_box.left = strlen("URL:")*6 + 10 + diagram.bufx;
178
	address_box.left = strlen("URL:")*6 + 10 + diagram.bufx;
180
	address_box.width = Form.cwidth - address_box.left - diagram.bufx - 3;
179
	address_box.width = Form.cwidth - address_box.left - diagram.bufx - 3;
181
	address_box.offset=0;
180
	address_box.offset=0;
182
	edit_box_draw stdcall(#address_box);
181
	edit_box_draw stdcall(#address_box);
183
	DrawRectangle(address_box.left-1, address_box.top-1, address_box.width+2, 16,address_box.color);
182
	DrawRectangle(address_box.left-1, address_box.top-1, address_box.width+2, 16,address_box.color);
184
	DrawRectangle(address_box.left-2, address_box.top-2, address_box.width+4, 18,system.color.work_graph);
183
	DrawRectangle(address_box.left-2, address_box.top-2, address_box.width+4, 18,system.color.work_graph);
185
 
184
 
186
	DrawRectangle(diagram.bufx-2, diagram.bufy-2, diagram.bufw+2, diagram.bufh+2, system.color.work_graph);
185
	DrawRectangle(diagram.bufx-2, diagram.bufy-2, diagram.bufw+2, diagram.bufh+2, system.color.work_graph);
187
	DrawSpeed();
186
	DrawSpeed();
188
}
187
}
189
 
188
 
190
void Scan(int id)
189
void Scan(int id)
191
{
190
{
192
	if (id==301) && (http_transfer <= 0) StartDownloading();
191
	if (id==301) && (http_transfer <= 0) StartDownloading();
193
	if (id==302) StopDownloading();
192
	if (id==302) StopDownloading();
194
	if (id==305) RunProgram("/sys/File managers/Eolite", "/tmp0/1/");
193
	if (id==305) RunProgram("/sys/File managers/Eolite", "/tmp0/1/");
195
}
194
}
196
 
195
 
197
 
196
 
198
void StopDownloading()
197
void StopDownloading()
199
{
198
{
200
	if (http_transfer<>0)
199
	if (http_transfer<>0)
201
	{
200
	{
202
		EAX = http_transfer;
201
		EAX = http_transfer;
203
		EAX = EAX.http_msg.content_ptr;		// get pointer to data
202
		EAX = EAX.http_msg.content_ptr;		// get pointer to data
204
		$push	EAX							// save it on the stack
203
		$push	EAX							// save it on the stack
205
		http_free stdcall (http_transfer);	// abort connection
204
		http_free stdcall (http_transfer);	// abort connection
206
		$pop	EAX							
205
		$pop	EAX							
207
		mem_Free(EAX);						// free data
206
		mem_Free(EAX);						// free data
208
		http_transfer=0;
207
		http_transfer=0;
209
		bufsize = 0;
208
		bufsize = 0;
210
		bufpointer = mem_Free(bufpointer);
209
		bufpointer = mem_Free(bufpointer);
211
	}
210
	}
212
	address_box.color = address_box.blur_border_color = address_box.focus_border_color = 0xFFFfff;
211
	address_box.color = address_box.blur_border_color = address_box.focus_border_color = 0xFFFfff;
213
	speed_position = 0;
212
	speed_position = 0;
214
	Draw_Window();
213
	Draw_Window();
215
}
214
}
216
 
215
 
217
void StartDownloading()
216
void StartDownloading()
218
{
217
{
219
	StopDownloading();
218
	StopDownloading();
220
	speed_position = 0;
219
	speed_position = 0;
221
	if (strncmp(#URL,"http:",5)==0)
220
	if (strncmp(#URL,"http:",5)==0)
222
	{
221
	{
223
		address_box.color = address_box.blur_border_color = address_box.focus_border_color = 0xededed;
222
		address_box.color = address_box.blur_border_color = address_box.focus_border_color = 0xededed;
224
		http_get stdcall (#URL, 0, 0, #accept_language);
223
		http_get stdcall (#URL, 0, 0, #accept_language);
225
		http_transfer = EAX;
224
		http_transfer = EAX;
226
		Draw_Window();
225
		Draw_Window();
227
		if (http_transfer == 0)
226
		if (http_transfer == 0)
228
		{
227
		{
229
			StopDownloading();
228
			StopDownloading();
230
			bufsize = 0;
229
			bufsize = 0;
231
			bufpointer = mem_Free(bufpointer);
230
			bufpointer = mem_Free(bufpointer);
232
			return;
231
			return;
233
		}
232
		}
234
	}
233
	}
235
	else
234
	else
236
	{
235
	{
237
		notify("File adress should starts from http://");
236
		notify("File adress should starts from http://");
238
	}
237
	}
239
}
238
}
240
 
239
 
241
 
240
 
242
 
241
 
243
stop:
242
stop: