Subversion Repositories Kolibri OS

Rev

Rev 7049 | Rev 7793 | 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 "Установить"
7590 leency 37
	char description_name[] = "description_ru";
6662 leency 38
#else
39
	#define WINDOW_TITLE "Driver Installer"
40
	#define T_CAUTION_TITLE "CAUTION"
41
	#define T_CAUTION_PARAGRAPH "Installing additional drivers can be harmful to the stability of the operation system and potentionally can harm hardware."
42
	#define T_ASSEPT_RISK "I accept the risk"
43
	#define T_README "Readme"
44
	#define T_INSTALL "Install"
7590 leency 45
	char description_name[] = "description_en";
6662 leency 46
#endif
6631 leency 47
 
48
#define BUTTON_ID_ASSEPT_RISK 10
6651 leency 49
#define BUTTON_ID_README 11
50
#define BUTTON_ID_INSTALL 12
6631 leency 51
 
6651 leency 52
//WINDOW STEPS
53
#define WINDOW_STEP_INTRO 1;
54
#define WINDOW_STEP_DRIVER_LIST 2;
55
char window_step = WINDOW_STEP_INTRO;
6631 leency 56
 
6654 leency 57
collection ini_sections;
58
 
6656 leency 59
char drvinf_path[4096] = "/kolibrios/drivers/drvinf.ini";
6654 leency 60
char cur_version[64];
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(libio,  #libio_init,1);
87
	load_dll(libini, #lib_init,1);
88
	load_dll(boxlib, #box_lib_init,0);
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;
100
 
101
		case evKey:
102
			GetKeys();
7031 leency 103
			if (key_scancode == SCAN_CODE_ENTER) Event_ProcessButtonId(active_button_id);
104
			if (window_step == WINDOW_STEP_DRIVER_LIST)
105
			{
106
				if (select_list.ProcessKey(key_scancode)) SelectList_LineChanged();
107
				if (key_scancode == SCAN_CODE_TAB)
108
				{
109
					ActiveButtonSwitch(11, 12);
110
					Draw_DriverListWindow();
111
				}
112
			}
6631 leency 113
			break;
114
 
115
		case evReDraw:
6653 leency 116
			Event_DrawWindow();
6631 leency 117
	}
118
}
119
 
120
 
7031 leency 121
void Draw_IntroWindow()
6631 leency 122
{
123
	incn y;
6651 leency 124
	y.n = Form.cheight/2 - 80;
6631 leency 125
	WriteTextB(30+2,y.n+2,0x81,MixColors(system.color.work, 0xB92234,220),T_CAUTION_TITLE);
126
	WriteTextB(30,y.n,0x81,0xB92234,T_CAUTION_TITLE);
6651 leency 127
	y.n = DrawTextViewArea(30, y.inc(30), Form.cwidth-60, Form.cheight-140,
6631 leency 128
		T_CAUTION_PARAGRAPH, -1, system.color.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
{
136
	int PADDING = 12;
6654 leency 137
	int right_frame_x = Form.cwidth*46/100;
138
	int readme_w = 0;
6651 leency 139
	//LEFT FRAME
6653 leency 140
	SelectList_Init(PADDING,
141
		PADDING,
6654 leency 142
		right_frame_x - PADDING - PADDING - 8 - scroll1.size_x,
6653 leency 143
		Form.cheight - PADDING - PADDING,
144
		false);
145
	SelectList_Draw();
6662 leency 146
	SelectList_DrawBorder();
6651 leency 147
	//RIGHT FRAME
6654 leency 148
	GetCurrentSectionData();
149
	DrawBar(right_frame_x, PADDING+3, Form.cwidth - right_frame_x - PADDING, 80, system.color.work);
150
	WriteTextB(right_frame_x, PADDING+3, 0x81, system.color.work_text, ini_sections.get(select_list.cur_y));
151
	WriteText(right_frame_x, PADDING+23, 0x80, system.color.work_text, #cur_version);
152
	if(cur_readme_path[0]) readme_w = DrawStandartCaptButton(right_frame_x, PADDING+45, BUTTON_ID_README, T_README);
153
	DrawStandartCaptButton(right_frame_x + readme_w, PADDING+45, BUTTON_ID_INSTALL, T_INSTALL);
154
	DrawTextViewArea(right_frame_x-2, PADDING+83, Form.cwidth - right_frame_x - PADDING, Form.cheight-PADDING-PADDING,
155
		#cur_description, system.color.work, system.color.work_text);
6651 leency 156
}
6653 leency 157
 
158
void SelectList_DrawLine(dword i)
159
{
160
	int yyy, list_last;
161
 
162
	yyy = i*select_list.item_h+select_list.y;
163
 
164
	if (select_list.cur_y-select_list.first==i)
165
	{
166
		DrawBar(select_list.x, yyy, select_list.w, select_list.item_h, system.color.work_button);
6654 leency 167
		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 168
	}
169
	else
170
	{
171
		DrawBar(select_list.x,yyy,select_list.w, select_list.item_h, 0xFFFfff);
6654 leency 172
		WriteText(select_list.x+12,yyy+select_list.text_y,select_list.font_type,0, ini_sections.get(i));
6653 leency 173
	}
174
}
175
 
176
void SelectList_LineChanged()
177
{
7031 leency 178
	Draw_DriverListWindow();
6653 leency 179
}
180
 
6662 leency 181
 
6654 leency 182
void GetCurrentSectionData()
183
{
6662 leency 184
	dword section_name = ini_sections.get(select_list.cur_y);
185
	ini_get_str stdcall (#drvinf_path, section_name, "ver", #cur_version, sizeof(cur_version), 0);
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
 
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
}