Subversion Repositories Kolibri OS

Rev

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