Subversion Repositories Kolibri OS

Rev

Rev 6653 | Rev 6656 | 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
 
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"
12
#include "../lib/obj/libio_lib.h"
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"
17
 
18
//===================================================//
19
//                                                   //
20
//                       DATA                        //
21
//                                                   //
22
//===================================================//
23
 
6631 leency 24
proc_info Form;
25
 
26
#define WINDOW_TITLE "Driver Installer"
27
#define T_CAUTION_TITLE "CAUTION"
28
#define T_CAUTION_PARAGRAPH "Installing additional drivers can be harmful to the stability of the operation system and potentionally can harm hardware."
29
#define T_ASSEPT_RISK "I assept the risk"
6651 leency 30
#define T_README "Readme"
31
#define T_INSTALL "Install"
6631 leency 32
 
33
#define BUTTON_ID_ASSEPT_RISK 10
6651 leency 34
#define BUTTON_ID_README 11
35
#define BUTTON_ID_INSTALL 12
6631 leency 36
 
6651 leency 37
//WINDOW STEPS
38
#define WINDOW_STEP_INTRO 1;
39
#define WINDOW_STEP_DRIVER_LIST 2;
40
char window_step = WINDOW_STEP_INTRO;
6631 leency 41
 
6654 leency 42
collection ini_sections;
43
 
44
char drvinf_path[4096] = "/sys/drvinf.ini";
45
char cur_version[64];
46
char cur_description[1024];
47
char cur_readme_path[4096];
48
char cur_install_path[4096];
49
 
6653 leency 50
//===================================================//
51
//                                                   //
52
//                       CODE                        //
53
//                                                   //
54
//===================================================//
55
 
56
void GetIniData()
57
{
6654 leency 58
	select_list.count = 0;
59
	ini_enum_sections stdcall (#drvinf_path, #process_sections);
6653 leency 60
}
61
 
62
byte process_sections(dword sec_name, f_name)
63
{
6654 leency 64
	select_list.count++;
65
	ini_sections.add(sec_name);
6653 leency 66
	return true;
67
}
68
 
6631 leency 69
void main()
70
{
6653 leency 71
	int id;
72
	load_dll(libio,  #libio_init,1);
73
	load_dll(libini, #lib_init,1);
74
	load_dll(boxlib, #box_lib_init,0);
6654 leency 75
	GetIniData();
6653 leency 76
	SetEventMask(0x27);
6631 leency 77
	loop() switch(WaitEvent())
78
	{
6653 leency 79
		case evMouse:
6654 leency 80
			if (!CheckActiveProcess(Form.ID)) break;
6653 leency 81
			SelectList_ProcessMouse();
82
			break;
83
 
6631 leency 84
		case evButton:
85
			id=GetButtonID();
86
			if (id==1) ExitProcess();
6653 leency 87
			if (id==BUTTON_ID_ASSEPT_RISK) Event_AsseptRisk();
88
			if (id==BUTTON_ID_README) Event_ShowReadme();
89
			if (id==BUTTON_ID_INSTALL) Event_RunInstall();
6631 leency 90
			break;
91
 
92
		case evKey:
93
			GetKeys();
6653 leency 94
			if (select_list.ProcessKey(key_scancode)) SelectList_LineChanged();
6631 leency 95
			break;
96
 
97
		case evReDraw:
6653 leency 98
			Event_DrawWindow();
6631 leency 99
	}
100
}
101
 
102
 
6651 leency 103
void draw_intro_window()
6631 leency 104
{
105
	incn y;
6651 leency 106
	y.n = Form.cheight/2 - 80;
6631 leency 107
	WriteTextB(30+2,y.n+2,0x81,MixColors(system.color.work, 0xB92234,220),T_CAUTION_TITLE);
108
	WriteTextB(30,y.n,0x81,0xB92234,T_CAUTION_TITLE);
6651 leency 109
	y.n = DrawTextViewArea(30, y.inc(30), Form.cwidth-60, Form.cheight-140,
6631 leency 110
		T_CAUTION_PARAGRAPH, -1, system.color.work_text);
111
	DrawStandartCaptButton(30, y.inc(10), BUTTON_ID_ASSEPT_RISK, T_ASSEPT_RISK);
112
}
113
 
114
 
6651 leency 115
void draw_driver_list_window()
116
{
117
	int PADDING = 12;
6654 leency 118
	int right_frame_x = Form.cwidth*46/100;
119
	int readme_w = 0;
6651 leency 120
	//LEFT FRAME
6653 leency 121
	SelectList_Init(PADDING,
122
		PADDING,
6654 leency 123
		right_frame_x - PADDING - PADDING - 8 - scroll1.size_x,
6653 leency 124
		Form.cheight - PADDING - PADDING,
125
		false);
126
	SelectList_Draw();
6651 leency 127
	//RIGHT FRAME
6654 leency 128
	GetCurrentSectionData();
129
	DrawBar(right_frame_x, PADDING+3, Form.cwidth - right_frame_x - PADDING, 80, system.color.work);
130
	WriteTextB(right_frame_x, PADDING+3, 0x81, system.color.work_text, ini_sections.get(select_list.cur_y));
131
	WriteText(right_frame_x, PADDING+23, 0x80, system.color.work_text, #cur_version);
132
	if(cur_readme_path[0]) readme_w = DrawStandartCaptButton(right_frame_x, PADDING+45, BUTTON_ID_README, T_README);
133
	DrawStandartCaptButton(right_frame_x + readme_w, PADDING+45, BUTTON_ID_INSTALL, T_INSTALL);
134
	DrawTextViewArea(right_frame_x-2, PADDING+83, Form.cwidth - right_frame_x - PADDING, Form.cheight-PADDING-PADDING,
135
		#cur_description, system.color.work, system.color.work_text);
6651 leency 136
}
6653 leency 137
 
138
void SelectList_DrawLine(dword i)
139
{
140
	int yyy, list_last;
141
 
142
	yyy = i*select_list.item_h+select_list.y;
143
 
144
	if (select_list.cur_y-select_list.first==i)
145
	{
146
		DrawBar(select_list.x, yyy, select_list.w, select_list.item_h, system.color.work_button);
6654 leency 147
		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 148
	}
149
	else
150
	{
151
		DrawBar(select_list.x,yyy,select_list.w, select_list.item_h, 0xFFFfff);
6654 leency 152
		WriteText(select_list.x+12,yyy+select_list.text_y,select_list.font_type,0, ini_sections.get(i));
6653 leency 153
	}
154
}
155
 
156
void SelectList_LineChanged()
157
{
6654 leency 158
	draw_driver_list_window();
6653 leency 159
}
160
 
6654 leency 161
void GetCurrentSectionData()
162
{
163
	dword cur_section_name = ini_sections.get(select_list.cur_y);
164
	ini_get_str stdcall (#drvinf_path, cur_section_name, "ver", #cur_version, sizeof(cur_version), 0);
165
	ini_get_str stdcall (#drvinf_path, cur_section_name, "description", #cur_description, sizeof(cur_description), 0);
166
	ini_get_str stdcall (#drvinf_path, cur_section_name, "readme", #cur_readme_path, sizeof(cur_readme_path), 0);
167
	ini_get_str stdcall (#drvinf_path, cur_section_name, "install", #cur_install_path, sizeof(cur_install_path), 0);
168
}
169
 
6653 leency 170
//===================================================//
171
//                                                   //
172
//                     EVENTS                        //
173
//                                                   //
174
//===================================================//
175
 
176
void Event_DrawWindow()
177
{
178
	system.color.get();
179
	DefineAndDrawWindow(215, 100, 600, 400, 0x33, system.color.work, WINDOW_TITLE);
180
	GetProcessInfo(#Form, SelfInfo);
6654 leency 181
	if (Form.status_window>2) return;
182
	if (Form.width  < 450) { MoveSize(OLD,OLD,450,OLD); return; }
183
	if (Form.height < 250) { MoveSize(OLD,OLD,OLD,250); return; }
6653 leency 184
	if (window_step == WINDOW_STEP_INTRO) draw_intro_window();
185
	if (window_step == WINDOW_STEP_DRIVER_LIST) draw_driver_list_window();
186
	return;
187
}
188
 
189
void Event_AsseptRisk()
190
{
191
	window_step = WINDOW_STEP_DRIVER_LIST;
192
	Event_DrawWindow();
193
}
194
 
195
void Event_ShowReadme()
196
{
6654 leency 197
	io.run("/sys/textreader", #cur_readme_path);
6653 leency 198
}
199
 
200
void Event_RunInstall()
201
{
6654 leency 202
	io.run(#cur_install_path, NULL);
6653 leency 203
}