Subversion Repositories Kolibri OS

Rev

Rev 9439 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
6653 leency 1
#define MEMSIZE 4096*20
2
 
3
//===================================================//
4
//                                                   //
5
//                       LIB                         //
6
//                                                   //
7
//===================================================//
8
 
6631 leency 9
#include "../lib/gui.h"
6653 leency 10
#include "../lib/list_box.h"
11
#include "../lib/obj/box_lib.h"
7793 leency 12
#include "../lib/obj/libimg.h"
6653 leency 13
#include "../lib/obj/libini.h"
6654 leency 14
#include "../lib/collection.h"
15
#include "../lib/io.h"
6653 leency 16
#include "../lib/patterns/select_list.h"
7793 leency 17
#include "../lib/patterns/restart_process.h"
6653 leency 18
 
19
//===================================================//
20
//                                                   //
21
//                       DATA                        //
22
//                                                   //
23
//===================================================//
24
 
6631 leency 25
proc_info Form;
26
 
6662 leency 27
#ifdef LANG_RUS
28
	#define WINDOW_TITLE "Установщик драйверов"
29
	#define T_CAUTION_TITLE "ПРЕДУПРЕЖДЕНИЕ"
30
	#define T_CAUTION_PARAGRAPH "Установка дополнительных драйверов может нанести вред стабильности операционной системы и потенциально привести к порче оборудования."
31
	#define T_ASSEPT_RISK "Я принимаю риск"
32
	#define T_README "Readme"
33
	#define T_INSTALL "Установить"
7793 leency 34
	#define T_DRIVER_INSTALLARION_STARTED "'Началась установка драйвера.\nЛог установки находится в приложении BOARD.'I"
7590 leency 35
	char description_name[] = "description_ru";
6662 leency 36
#else
37
	#define WINDOW_TITLE "Driver Installer"
38
	#define T_CAUTION_TITLE "CAUTION"
39
	#define T_CAUTION_PARAGRAPH "Installing additional drivers can be harmful to the stability of the operation system and potentionally can harm hardware."
40
	#define T_ASSEPT_RISK "I accept the risk"
41
	#define T_README "Readme"
42
	#define T_INSTALL "Install"
7793 leency 43
	#define T_DRIVER_INSTALLARION_STARTED "'Driver installation started.\nInstallation log can be found in BOARD app.'I"
7590 leency 44
	char description_name[] = "description_en";
6662 leency 45
#endif
6631 leency 46
 
47
#define BUTTON_ID_ASSEPT_RISK 10
6651 leency 48
#define BUTTON_ID_README 11
49
#define BUTTON_ID_INSTALL 12
6631 leency 50
 
6651 leency 51
//WINDOW STEPS
52
#define WINDOW_STEP_INTRO 1;
53
#define WINDOW_STEP_DRIVER_LIST 2;
54
char window_step = WINDOW_STEP_INTRO;
6631 leency 55
 
7972 leency 56
collection ini_sections=0;
6654 leency 57
 
6656 leency 58
char drvinf_path[4096] = "/kolibrios/drivers/drvinf.ini";
6654 leency 59
char cur_version[64];
8915 leency 60
int  cur_icon;
6654 leency 61
char cur_description[1024];
62
char cur_readme_path[4096];
63
char cur_install_path[4096];
64
 
6653 leency 65
//===================================================//
66
//                                                   //
67
//                       CODE                        //
68
//                                                   //
69
//===================================================//
70
 
71
void GetIniData()
72
{
6654 leency 73
	select_list.count = 0;
74
	ini_enum_sections stdcall (#drvinf_path, #process_sections);
6653 leency 75
}
76
 
77
byte process_sections(dword sec_name, f_name)
78
{
6654 leency 79
	select_list.count++;
80
	ini_sections.add(sec_name);
6653 leency 81
	return true;
82
}
83
 
6631 leency 84
void main()
85
{
6653 leency 86
	load_dll(libini, #lib_init,1);
87
	load_dll(boxlib, #box_lib_init,0);
7793 leency 88
	load_dll(libimg, #libimg_init,1);
6654 leency 89
	GetIniData();
7031 leency 90
	SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
6631 leency 91
	loop() switch(WaitEvent())
92
	{
6653 leency 93
		case evMouse:
94
			SelectList_ProcessMouse();
95
			break;
96
 
6631 leency 97
		case evButton:
7031 leency 98
			Event_ProcessButtonId(GetButtonID());
6631 leency 99
			break;
9887 Doczom 100
 
6631 leency 101
		case evKey:
102
			GetKeys();
7031 leency 103
			if (key_scancode == SCAN_CODE_ENTER) Event_ProcessButtonId(active_button_id);
9887 Doczom 104
			if (window_step == WINDOW_STEP_DRIVER_LIST)
7031 leency 105
			{
106
				if (select_list.ProcessKey(key_scancode)) SelectList_LineChanged();
9887 Doczom 107
				if (key_scancode == SCAN_CODE_TAB)
7031 leency 108
				{
109
					ActiveButtonSwitch(11, 12);
110
					Draw_DriverListWindow();
111
				}
9887 Doczom 112
			}
6631 leency 113
			break;
9887 Doczom 114
 
6631 leency 115
		case evReDraw:
6653 leency 116
			Event_DrawWindow();
6631 leency 117
	}
9887 Doczom 118
}
6631 leency 119
 
120
 
7031 leency 121
void Draw_IntroWindow()
6631 leency 122
{
123
	incn y;
6651 leency 124
	y.n = Form.cheight/2 - 80;
7806 leency 125
	WriteTextB(30+2,y.n+2,0x81,MixColors(sc.work, 0xB92234,220),T_CAUTION_TITLE);
6631 leency 126
	WriteTextB(30,y.n,0x81,0xB92234,T_CAUTION_TITLE);
9887 Doczom 127
	y.n = DrawTextViewArea(30, y.inc(30), Form.cwidth-60, Form.cheight-140,
7806 leency 128
		T_CAUTION_PARAGRAPH, -1, sc.work_text);
7031 leency 129
	active_button_id = BUTTON_ID_ASSEPT_RISK;
6631 leency 130
	DrawStandartCaptButton(30, y.inc(10), BUTTON_ID_ASSEPT_RISK, T_ASSEPT_RISK);
131
}
132
 
133
 
7031 leency 134
void Draw_DriverListWindow()
6651 leency 135
{
8915 leency 136
	#define PADDING 12
6654 leency 137
	int right_frame_x = Form.cwidth*46/100;
138
	int readme_w = 0;
6651 leency 139
	//LEFT FRAME
9887 Doczom 140
	SelectList_Init(PADDING, PADDING,
141
		right_frame_x - PADDING - PADDING - 8 - scroll1.size_x,
8933 leency 142
		Form.cheight - PADDING - PADDING);
6653 leency 143
	SelectList_Draw();
6662 leency 144
	SelectList_DrawBorder();
6651 leency 145
	//RIGHT FRAME
6654 leency 146
	GetCurrentSectionData();
7806 leency 147
	DrawBar(right_frame_x, PADDING+3, Form.cwidth - right_frame_x - PADDING, 80, sc.work);
9887 Doczom 148
	draw_icon_32(right_frame_x, PADDING, sc.work, cur_icon);
7806 leency 149
	WriteTextB(right_frame_x+44, PADDING+3, 0x81, sc.work_text, ini_sections.get(select_list.cur_y));
150
	WriteText(right_frame_x+44, PADDING+23, 0x80, sc.work_text, #cur_version);
6654 leency 151
	if(cur_readme_path[0]) readme_w = DrawStandartCaptButton(right_frame_x, PADDING+45, BUTTON_ID_README, T_README);
152
	DrawStandartCaptButton(right_frame_x + readme_w, PADDING+45, BUTTON_ID_INSTALL, T_INSTALL);
9887 Doczom 153
	DrawTextViewArea(right_frame_x-2, PADDING+83, Form.cwidth - right_frame_x - PADDING, Form.cheight-PADDING-PADDING,
7806 leency 154
		#cur_description, sc.work, sc.work_text);
6651 leency 155
}
6653 leency 156
 
157
void SelectList_DrawLine(dword i)
158
{
159
	int yyy, list_last;
160
 
161
	yyy = i*select_list.item_h+select_list.y;
9887 Doczom 162
 
6653 leency 163
	if (select_list.cur_y-select_list.first==i)
164
	{
7806 leency 165
		DrawBar(select_list.x, yyy, select_list.w, select_list.item_h, sc.button);
9887 Doczom 166
		WriteText(select_list.x+12,yyy+select_list.text_y,select_list.font_type,sc.button_text, ini_sections.get(i+select_list.first));
6653 leency 167
	}
168
	else
169
	{
170
		DrawBar(select_list.x,yyy,select_list.w, select_list.item_h, 0xFFFfff);
9887 Doczom 171
		WriteText(select_list.x+12,yyy+select_list.text_y,select_list.font_type,0, ini_sections.get(i+select_list.first));
6653 leency 172
	}
173
}
174
 
175
void SelectList_LineChanged()
176
{
7031 leency 177
	Draw_DriverListWindow();
6653 leency 178
}
179
 
6662 leency 180
 
6654 leency 181
void GetCurrentSectionData()
182
{
6662 leency 183
	dword section_name = ini_sections.get(select_list.cur_y);
184
	ini_get_str stdcall (#drvinf_path, section_name, "ver", #cur_version, sizeof(cur_version), 0);
8915 leency 185
	ini_get_int stdcall (#drvinf_path, section_name, "icon", 38); cur_icon = EAX;
7590 leency 186
	ini_get_str stdcall (#drvinf_path, section_name, #description_name, #cur_description, sizeof(cur_description), 0);
6662 leency 187
	ini_get_str stdcall (#drvinf_path, section_name, "readme", #cur_readme_path, sizeof(cur_readme_path), 0);
188
	ini_get_str stdcall (#drvinf_path, section_name, "install", #cur_install_path, sizeof(cur_install_path), 0);
6654 leency 189
}
190
 
6653 leency 191
//===================================================//
192
//                                                   //
193
//                     EVENTS                        //
194
//                                                   //
195
//===================================================//
196
 
7031 leency 197
void Event_ProcessButtonId(int id)
198
{
199
	if (id==1) ExitProcess();
200
	if (id==BUTTON_ID_ASSEPT_RISK) Event_AsseptRisk();
201
	if (id==BUTTON_ID_README) Event_ShowReadme();
202
	if (id==BUTTON_ID_INSTALL) Event_RunInstall();
203
}
204
 
9887 Doczom 205
void Event_DrawWindow()
6653 leency 206
{
7806 leency 207
	sc.get();
208
	DefineAndDrawWindow(215, 100, 600, 400, 0x33, sc.work, WINDOW_TITLE,0);
6653 leency 209
	GetProcessInfo(#Form, SelfInfo);
8946 leency 210
	if (Form.status_window&ROLLED_UP) return;
6654 leency 211
	if (Form.width  < 450) { MoveSize(OLD,OLD,450,OLD); return; }
212
	if (Form.height < 250) { MoveSize(OLD,OLD,OLD,250); return; }
7031 leency 213
	if (window_step == WINDOW_STEP_INTRO) Draw_IntroWindow();
214
	if (window_step == WINDOW_STEP_DRIVER_LIST) Draw_DriverListWindow();
6653 leency 215
	return;
216
}
217
 
218
void Event_AsseptRisk()
219
{
220
	window_step = WINDOW_STEP_DRIVER_LIST;
7031 leency 221
	active_button_id = BUTTON_ID_INSTALL;
6653 leency 222
	Event_DrawWindow();
223
}
224
 
225
void Event_ShowReadme()
226
{
7946 leency 227
	io.run("/sys/@open", #cur_readme_path);
6653 leency 228
}
229
 
230
void Event_RunInstall()
231
{
7031 leency 232
	int result;
233
	result = io.run(#cur_install_path, NULL);
7793 leency 234
	if (result) notify(T_DRIVER_INSTALLARION_STARTED);
235
	pause(300);
8915 leency 236
	if (cur_icon == 61) {
7793 leency 237
		RestartProcessByName("/sys/@taskbar", SINGLE);
9887 Doczom 238
		RestartProcessByName("/sys/@docky", SINGLE);
239
		RestartProcessByName("/sys/@icon", MULTIPLE);
7793 leency 240
	}
6653 leency 241
}