Subversion Repositories Kolibri OS

Rev

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