Subversion Repositories Kolibri OS

Rev

Rev 7031 | Rev 7590 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
6653 leency 1
#define MEMSIZE 4096*20
2
 
6662 leency 3
#ifndef AUTOBUILD
4
#include "lang.h--"
5
#endif
6
 
6653 leency 7
//===================================================//
8
//                                                   //
9
//                       LIB                         //
10
//                                                   //
11
//===================================================//
12
 
6631 leency 13
#include "../lib/gui.h"
6653 leency 14
#include "../lib/list_box.h"
15
#include "../lib/obj/box_lib.h"
7049 leency 16
#include "../lib/obj/libio.h"
6653 leency 17
#include "../lib/obj/libini.h"
6654 leency 18
#include "../lib/collection.h"
19
#include "../lib/io.h"
6653 leency 20
#include "../lib/patterns/select_list.h"
21
 
22
//===================================================//
23
//                                                   //
24
//                       DATA                        //
25
//                                                   //
26
//===================================================//
27
 
6631 leency 28
proc_info Form;
29
 
6662 leency 30
#ifdef LANG_RUS
31
	#define WINDOW_TITLE "Установщик драйверов"
32
	#define T_CAUTION_TITLE "ПРЕДУПРЕЖДЕНИЕ"
33
	#define T_CAUTION_PARAGRAPH "Установка дополнительных драйверов может нанести вред стабильности операционной системы и потенциально привести к порче оборудования."
34
	#define T_ASSEPT_RISK "Я принимаю риск"
35
	#define T_README "Readme"
36
	#define T_INSTALL "Установить"
37
#else
38
	#define WINDOW_TITLE "Driver Installer"
39
	#define T_CAUTION_TITLE "CAUTION"
40
	#define T_CAUTION_PARAGRAPH "Installing additional drivers can be harmful to the stability of the operation system and potentionally can harm hardware."
41
	#define T_ASSEPT_RISK "I accept the risk"
42
	#define T_README "Readme"
43
	#define T_INSTALL "Install"
44
#endif
6631 leency 45
 
46
#define BUTTON_ID_ASSEPT_RISK 10
6651 leency 47
#define BUTTON_ID_README 11
48
#define BUTTON_ID_INSTALL 12
6631 leency 49
 
6651 leency 50
//WINDOW STEPS
51
#define WINDOW_STEP_INTRO 1;
52
#define WINDOW_STEP_DRIVER_LIST 2;
53
char window_step = WINDOW_STEP_INTRO;
6631 leency 54
 
6654 leency 55
collection ini_sections;
56
 
6656 leency 57
char drvinf_path[4096] = "/kolibrios/drivers/drvinf.ini";
6654 leency 58
char cur_version[64];
59
char cur_description[1024];
60
char cur_readme_path[4096];
61
char cur_install_path[4096];
62
 
6653 leency 63
//===================================================//
64
//                                                   //
65
//                       CODE                        //
66
//                                                   //
67
//===================================================//
68
 
69
void GetIniData()
70
{
6654 leency 71
	select_list.count = 0;
72
	ini_enum_sections stdcall (#drvinf_path, #process_sections);
6653 leency 73
}
74
 
75
byte process_sections(dword sec_name, f_name)
76
{
6654 leency 77
	select_list.count++;
78
	ini_sections.add(sec_name);
6653 leency 79
	return true;
80
}
81
 
6631 leency 82
void main()
83
{
6653 leency 84
	load_dll(libio,  #libio_init,1);
85
	load_dll(libini, #lib_init,1);
86
	load_dll(boxlib, #box_lib_init,0);
6654 leency 87
	GetIniData();
7031 leency 88
	SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
6631 leency 89
	loop() switch(WaitEvent())
90
	{
6653 leency 91
		case evMouse:
92
			SelectList_ProcessMouse();
93
			break;
94
 
6631 leency 95
		case evButton:
7031 leency 96
			Event_ProcessButtonId(GetButtonID());
6631 leency 97
			break;
98
 
99
		case evKey:
100
			GetKeys();
7031 leency 101
			if (key_scancode == SCAN_CODE_ENTER) Event_ProcessButtonId(active_button_id);
102
			if (window_step == WINDOW_STEP_DRIVER_LIST)
103
			{
104
				if (select_list.ProcessKey(key_scancode)) SelectList_LineChanged();
105
				if (key_scancode == SCAN_CODE_TAB)
106
				{
107
					ActiveButtonSwitch(11, 12);
108
					Draw_DriverListWindow();
109
				}
110
			}
6631 leency 111
			break;
112
 
113
		case evReDraw:
6653 leency 114
			Event_DrawWindow();
6631 leency 115
	}
116
}
117
 
118
 
7031 leency 119
void Draw_IntroWindow()
6631 leency 120
{
121
	incn y;
6651 leency 122
	y.n = Form.cheight/2 - 80;
6631 leency 123
	WriteTextB(30+2,y.n+2,0x81,MixColors(system.color.work, 0xB92234,220),T_CAUTION_TITLE);
124
	WriteTextB(30,y.n,0x81,0xB92234,T_CAUTION_TITLE);
6651 leency 125
	y.n = DrawTextViewArea(30, y.inc(30), Form.cwidth-60, Form.cheight-140,
6631 leency 126
		T_CAUTION_PARAGRAPH, -1, system.color.work_text);
7031 leency 127
	active_button_id = BUTTON_ID_ASSEPT_RISK;
6631 leency 128
	DrawStandartCaptButton(30, y.inc(10), BUTTON_ID_ASSEPT_RISK, T_ASSEPT_RISK);
129
}
130
 
131
 
7031 leency 132
void Draw_DriverListWindow()
6651 leency 133
{
134
	int PADDING = 12;
6654 leency 135
	int right_frame_x = Form.cwidth*46/100;
136
	int readme_w = 0;
6651 leency 137
	//LEFT FRAME
6653 leency 138
	SelectList_Init(PADDING,
139
		PADDING,
6654 leency 140
		right_frame_x - PADDING - PADDING - 8 - scroll1.size_x,
6653 leency 141
		Form.cheight - PADDING - PADDING,
142
		false);
143
	SelectList_Draw();
6662 leency 144
	SelectList_DrawBorder();
6651 leency 145
	//RIGHT FRAME
6654 leency 146
	GetCurrentSectionData();
147
	DrawBar(right_frame_x, PADDING+3, Form.cwidth - right_frame_x - PADDING, 80, system.color.work);
148
	WriteTextB(right_frame_x, PADDING+3, 0x81, system.color.work_text, ini_sections.get(select_list.cur_y));
149
	WriteText(right_frame_x, PADDING+23, 0x80, system.color.work_text, #cur_version);
150
	if(cur_readme_path[0]) readme_w = DrawStandartCaptButton(right_frame_x, PADDING+45, BUTTON_ID_README, T_README);
151
	DrawStandartCaptButton(right_frame_x + readme_w, PADDING+45, BUTTON_ID_INSTALL, T_INSTALL);
152
	DrawTextViewArea(right_frame_x-2, PADDING+83, Form.cwidth - right_frame_x - PADDING, Form.cheight-PADDING-PADDING,
153
		#cur_description, system.color.work, system.color.work_text);
6651 leency 154
}
6653 leency 155
 
156
void SelectList_DrawLine(dword i)
157
{
158
	int yyy, list_last;
159
 
160
	yyy = i*select_list.item_h+select_list.y;
161
 
162
	if (select_list.cur_y-select_list.first==i)
163
	{
164
		DrawBar(select_list.x, yyy, select_list.w, select_list.item_h, system.color.work_button);
6654 leency 165
		WriteText(select_list.x+12,yyy+select_list.text_y,select_list.font_type,system.color.work_button_text, ini_sections.get(i));
6653 leency 166
	}
167
	else
168
	{
169
		DrawBar(select_list.x,yyy,select_list.w, select_list.item_h, 0xFFFfff);
6654 leency 170
		WriteText(select_list.x+12,yyy+select_list.text_y,select_list.font_type,0, ini_sections.get(i));
6653 leency 171
	}
172
}
173
 
174
void SelectList_LineChanged()
175
{
7031 leency 176
	Draw_DriverListWindow();
6653 leency 177
}
178
 
6662 leency 179
 
6654 leency 180
void GetCurrentSectionData()
181
{
6662 leency 182
	dword section_name = ini_sections.get(select_list.cur_y);
183
	dword description_name;
184
	if (GetSystemLanguage() == SYS_LANG_RUS) description_name = "description_ru"; else description_name = "description_en";
185
	ini_get_str stdcall (#drvinf_path, section_name, "ver", #cur_version, sizeof(cur_version), 0);
186
	ini_get_str stdcall (#drvinf_path, section_name, description_name, #cur_description, sizeof(cur_description), 0);
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
 
6653 leency 205
void Event_DrawWindow()
206
{
207
	system.color.get();
6746 leency 208
	DefineAndDrawWindow(215, 100, 600, 400, 0x33, system.color.work, WINDOW_TITLE,0);
6653 leency 209
	GetProcessInfo(#Form, SelfInfo);
6654 leency 210
	if (Form.status_window>2) return;
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
{
6918 leency 227
	io.run("/sys/txtread", #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);
234
	if (result) notify("'Driver installation started.\nPlease, open BOARD to check status.'I");
6653 leency 235
}