2016-11-02 15:30:45 +01:00
# define MEMSIZE 4096*20
2016-11-03 13:41:15 +01:00
# ifndef AUTOBUILD
# include "lang.h--"
# endif
2016-11-02 15:30:45 +01:00
//===================================================//
// //
// LIB //
// //
//===================================================//
2016-10-28 18:06:18 +02:00
# include "../lib/gui.h"
2016-11-02 15:30:45 +01:00
# include "../lib/list_box.h"
# include "../lib/obj/box_lib.h"
2020-04-15 15:44:21 +02:00
# include "../lib/obj/libimg.h"
2016-11-02 15:30:45 +01:00
# include "../lib/obj/libini.h"
2016-11-02 19:18:50 +01:00
# include "../lib/collection.h"
# include "../lib/io.h"
2016-11-02 15:30:45 +01:00
# include "../lib/patterns/select_list.h"
2020-04-15 15:44:21 +02:00
# include "../lib/patterns/restart_process.h"
2016-11-02 15:30:45 +01:00
//===================================================//
// //
// DATA //
// //
//===================================================//
2016-10-28 18:06:18 +02:00
proc_info Form ;
2016-11-03 13:41:15 +01:00
# ifdef LANG_RUS
# define WINDOW_TITLE "<22> <> ⠭<EFBFBD> <E2A0AD> 騪 <20> ࠩ<EFBFBD> <E0A0A9> "
# define T_CAUTION_TITLE "<22> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> "
# define T_CAUTION_PARAGRAPH "<22> <> ⠭<EFBFBD> <E2A0AD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ⥫<EFBFBD> <E2A5AB> <EFBFBD> <EFBFBD> <20> ࠩ<EFBFBD> <E0A0A9> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> । <20> ⠡<EFBFBD> <E2A0A1> 쭮<EFBFBD> <ECADAE> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> 樮<EFBFBD> <E6A8AE> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> ⥬<EFBFBD> <20> <20> <> ⥭樠<E2A5AD> 쭮 <20> ਢ<EFBFBD> <E0A8A2> <EFBFBD> <EFBFBD> <20> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> 㤮<EFBFBD> <E3A4AE> <EFBFBD> <EFBFBD> <EFBFBD> ."
# define T_ASSEPT_RISK "<22> <20> ਭ<EFBFBD> <E0A8AD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> "
# define T_README "Readme"
# define T_INSTALL "<22> <> ⠭<EFBFBD> <E2A0AD> <EFBFBD> <EFBFBD> <EFBFBD> "
2020-04-15 15:44:21 +02:00
# define T_DRIVER_INSTALLARION_STARTED "'<27> <> 砫<EFBFBD> <E7A0AB> <EFBFBD> <20> <> ⠭<EFBFBD> <E2A0AD> <EFBFBD> <EFBFBD> <20> ࠩ<EFBFBD> <E0A0A9> <EFBFBD> <EFBFBD> .\n<> <6E> <EFBFBD> <20> <> ⠭<EFBFBD> <E2A0AD> <EFBFBD> <EFBFBD> <20> <> 室<EFBFBD> <E5AEA4> <EFBFBD> <EFBFBD> <20> <20> ਫ<EFBFBD> <E0A8AB> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> BOARD.'I"
2019-03-10 13:09:50 +01:00
char description_name [ ] = " description_ru " ;
2016-11-03 13:41:15 +01:00
# else
# define WINDOW_TITLE "Driver Installer"
# define T_CAUTION_TITLE "CAUTION"
# define T_CAUTION_PARAGRAPH "Installing additional drivers can be harmful to the stability of the operation system and potentionally can harm hardware."
# define T_ASSEPT_RISK "I accept the risk"
# define T_README "Readme"
# define T_INSTALL "Install"
2020-04-15 15:44:21 +02:00
# define T_DRIVER_INSTALLARION_STARTED "'Driver installation started.\nInstallation log can be found in BOARD app.'I"
2019-03-10 13:09:50 +01:00
char description_name [ ] = " description_en " ;
2016-11-03 13:41:15 +01:00
# endif
2016-10-28 18:06:18 +02:00
# define BUTTON_ID_ASSEPT_RISK 10
2016-11-02 13:19:15 +01:00
# define BUTTON_ID_README 11
# define BUTTON_ID_INSTALL 12
2016-10-28 18:06:18 +02:00
2016-11-02 13:19:15 +01:00
//WINDOW STEPS
# define WINDOW_STEP_INTRO 1;
# define WINDOW_STEP_DRIVER_LIST 2;
char window_step = WINDOW_STEP_INTRO ;
2016-10-28 18:06:18 +02:00
2020-05-23 13:26:58 +02:00
collection ini_sections = 0 ;
2016-11-02 19:18:50 +01:00
2016-11-02 19:35:13 +01:00
char drvinf_path [ 4096 ] = " /kolibrios/drivers/drvinf.ini " ;
2016-11-02 19:18:50 +01:00
char cur_version [ 64 ] ;
2021-06-22 00:51:35 +02:00
int cur_icon ;
2016-11-02 19:18:50 +01:00
char cur_description [ 1024 ] ;
char cur_readme_path [ 4096 ] ;
char cur_install_path [ 4096 ] ;
2016-11-02 15:30:45 +01:00
//===================================================//
// //
// CODE //
// //
//===================================================//
void GetIniData ( )
{
2016-11-02 19:18:50 +01:00
select_list . count = 0 ;
ini_enum_sections stdcall ( # drvinf_path , # process_sections ) ;
2016-11-02 15:30:45 +01:00
}
byte process_sections ( dword sec_name , f_name )
{
2016-11-02 19:18:50 +01:00
select_list . count + + ;
ini_sections . add ( sec_name ) ;
2016-11-02 15:30:45 +01:00
return true ;
}
2016-10-28 18:06:18 +02:00
void main ( )
{
2016-11-02 15:30:45 +01:00
load_dll ( libini , # lib_init , 1 ) ;
load_dll ( boxlib , # box_lib_init , 0 ) ;
2020-04-15 15:44:21 +02:00
load_dll ( libimg , # libimg_init , 1 ) ;
2016-11-02 19:18:50 +01:00
GetIniData ( ) ;
2017-09-28 11:59:41 +02:00
SetEventMask ( EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER ) ;
2016-10-28 18:06:18 +02:00
loop ( ) switch ( WaitEvent ( ) )
{
2016-11-02 15:30:45 +01:00
case evMouse :
SelectList_ProcessMouse ( ) ;
break ;
2016-10-28 18:06:18 +02:00
case evButton :
2017-09-28 11:59:41 +02:00
Event_ProcessButtonId ( GetButtonID ( ) ) ;
2016-10-28 18:06:18 +02:00
break ;
case evKey :
GetKeys ( ) ;
2017-09-28 11:59:41 +02:00
if ( key_scancode = = SCAN_CODE_ENTER ) Event_ProcessButtonId ( active_button_id ) ;
if ( window_step = = WINDOW_STEP_DRIVER_LIST )
{
if ( select_list . ProcessKey ( key_scancode ) ) SelectList_LineChanged ( ) ;
if ( key_scancode = = SCAN_CODE_TAB )
{
ActiveButtonSwitch ( 11 , 12 ) ;
Draw_DriverListWindow ( ) ;
}
}
2016-10-28 18:06:18 +02:00
break ;
case evReDraw :
2016-11-02 15:30:45 +01:00
Event_DrawWindow ( ) ;
2016-10-28 18:06:18 +02:00
}
}
2017-09-28 11:59:41 +02:00
void Draw_IntroWindow ( )
2016-10-28 18:06:18 +02:00
{
incn y ;
2016-11-02 13:19:15 +01:00
y . n = Form . cheight / 2 - 80 ;
2020-04-18 01:52:24 +02:00
WriteTextB ( 30 + 2 , y . n + 2 , 0x81 , MixColors ( sc . work , 0xB92234 , 220 ) , T_CAUTION_TITLE ) ;
2016-10-28 18:06:18 +02:00
WriteTextB ( 30 , y . n , 0x81 , 0xB92234 , T_CAUTION_TITLE ) ;
2016-11-02 13:19:15 +01:00
y . n = DrawTextViewArea ( 30 , y . inc ( 30 ) , Form . cwidth - 60 , Form . cheight - 140 ,
2020-04-18 01:52:24 +02:00
T_CAUTION_PARAGRAPH , - 1 , sc . work_text ) ;
2017-09-28 11:59:41 +02:00
active_button_id = BUTTON_ID_ASSEPT_RISK ;
2016-10-28 18:06:18 +02:00
DrawStandartCaptButton ( 30 , y . inc ( 10 ) , BUTTON_ID_ASSEPT_RISK , T_ASSEPT_RISK ) ;
}
2017-09-28 11:59:41 +02:00
void Draw_DriverListWindow ( )
2016-11-02 13:19:15 +01:00
{
2021-06-22 00:51:35 +02:00
# define PADDING 12
2016-11-02 19:18:50 +01:00
int right_frame_x = Form . cwidth * 46 / 100 ;
int readme_w = 0 ;
2016-11-02 13:19:15 +01:00
//LEFT FRAME
2021-06-24 22:42:19 +02:00
SelectList_Init ( PADDING , PADDING ,
2016-11-02 19:18:50 +01:00
right_frame_x - PADDING - PADDING - 8 - scroll1 . size_x ,
2021-06-24 22:42:19 +02:00
Form . cheight - PADDING - PADDING ) ;
2016-11-02 15:30:45 +01:00
SelectList_Draw ( ) ;
2016-11-03 13:41:15 +01:00
SelectList_DrawBorder ( ) ;
2016-11-02 13:19:15 +01:00
//RIGHT FRAME
2016-11-02 19:18:50 +01:00
GetCurrentSectionData ( ) ;
2020-04-18 01:52:24 +02:00
DrawBar ( right_frame_x , PADDING + 3 , Form . cwidth - right_frame_x - PADDING , 80 , sc . work ) ;
2021-06-22 00:51:35 +02:00
DrawIcon32 ( right_frame_x , PADDING , sc . work , cur_icon ) ;
2020-04-18 01:52:24 +02:00
WriteTextB ( right_frame_x + 44 , PADDING + 3 , 0x81 , sc . work_text , ini_sections . get ( select_list . cur_y ) ) ;
WriteText ( right_frame_x + 44 , PADDING + 23 , 0x80 , sc . work_text , # cur_version ) ;
2016-11-02 19:18:50 +01:00
if ( cur_readme_path [ 0 ] ) readme_w = DrawStandartCaptButton ( right_frame_x , PADDING + 45 , BUTTON_ID_README , T_README ) ;
DrawStandartCaptButton ( right_frame_x + readme_w , PADDING + 45 , BUTTON_ID_INSTALL , T_INSTALL ) ;
DrawTextViewArea ( right_frame_x - 2 , PADDING + 83 , Form . cwidth - right_frame_x - PADDING , Form . cheight - PADDING - PADDING ,
2020-04-18 01:52:24 +02:00
# cur_description, sc.work, sc.work_text);
2016-11-02 13:19:15 +01:00
}
2016-11-02 15:30:45 +01:00
void SelectList_DrawLine ( dword i )
{
int yyy , list_last ;
yyy = i * select_list . item_h + select_list . y ;
if ( select_list . cur_y - select_list . first = = i )
{
2020-04-18 01:52:24 +02:00
DrawBar ( select_list . x , yyy , select_list . w , select_list . item_h , sc . button ) ;
WriteText ( select_list . x + 12 , yyy + select_list . text_y , select_list . font_type , sc . button_text , ini_sections . get ( i ) ) ;
2016-11-02 15:30:45 +01:00
}
else
{
DrawBar ( select_list . x , yyy , select_list . w , select_list . item_h , 0xFFFfff ) ;
2016-11-02 19:18:50 +01:00
WriteText ( select_list . x + 12 , yyy + select_list . text_y , select_list . font_type , 0 , ini_sections . get ( i ) ) ;
2016-11-02 15:30:45 +01:00
}
}
void SelectList_LineChanged ( )
{
2017-09-28 11:59:41 +02:00
Draw_DriverListWindow ( ) ;
2016-11-02 19:18:50 +01:00
}
2016-11-03 13:41:15 +01:00
2016-11-02 19:18:50 +01:00
void GetCurrentSectionData ( )
{
2016-11-03 13:41:15 +01:00
dword section_name = ini_sections . get ( select_list . cur_y ) ;
ini_get_str stdcall ( # drvinf_path , section_name , " ver " , # cur_version , sizeof ( cur_version ) , 0 ) ;
2021-06-22 00:51:35 +02:00
ini_get_int stdcall ( # drvinf_path , section_name , " icon " , 38 ) ; cur_icon = EAX ;
2019-03-10 13:09:50 +01:00
ini_get_str stdcall ( # drvinf_path , section_name , # description_name , # cur_description , sizeof ( cur_description ) , 0 ) ;
2016-11-03 13:41:15 +01:00
ini_get_str stdcall ( # drvinf_path , section_name , " readme " , # cur_readme_path , sizeof ( cur_readme_path ) , 0 ) ;
ini_get_str stdcall ( # drvinf_path , section_name , " install " , # cur_install_path , sizeof ( cur_install_path ) , 0 ) ;
2016-11-02 15:30:45 +01:00
}
//===================================================//
// //
// EVENTS //
// //
//===================================================//
2017-09-28 11:59:41 +02:00
void Event_ProcessButtonId ( int id )
{
if ( id = = 1 ) ExitProcess ( ) ;
if ( id = = BUTTON_ID_ASSEPT_RISK ) Event_AsseptRisk ( ) ;
if ( id = = BUTTON_ID_README ) Event_ShowReadme ( ) ;
if ( id = = BUTTON_ID_INSTALL ) Event_RunInstall ( ) ;
}
2016-11-02 15:30:45 +01:00
void Event_DrawWindow ( )
{
2020-04-18 01:52:24 +02:00
sc . get ( ) ;
DefineAndDrawWindow ( 215 , 100 , 600 , 400 , 0x33 , sc . work , WINDOW_TITLE , 0 ) ;
2016-11-02 15:30:45 +01:00
GetProcessInfo ( # Form , SelfInfo ) ;
2021-06-26 09:59:13 +02:00
if ( Form . status_window & ROLLED_UP ) return ;
2016-11-02 19:18:50 +01:00
if ( Form . width < 450 ) { MoveSize ( OLD , OLD , 450 , OLD ) ; return ; }
if ( Form . height < 250 ) { MoveSize ( OLD , OLD , OLD , 250 ) ; return ; }
2017-09-28 11:59:41 +02:00
if ( window_step = = WINDOW_STEP_INTRO ) Draw_IntroWindow ( ) ;
if ( window_step = = WINDOW_STEP_DRIVER_LIST ) Draw_DriverListWindow ( ) ;
2016-11-02 15:30:45 +01:00
return ;
}
void Event_AsseptRisk ( )
{
window_step = WINDOW_STEP_DRIVER_LIST ;
2017-09-28 11:59:41 +02:00
active_button_id = BUTTON_ID_INSTALL ;
2016-11-02 15:30:45 +01:00
Event_DrawWindow ( ) ;
}
void Event_ShowReadme ( )
{
2020-05-18 12:47:08 +02:00
io . run ( " /sys/@open " , # cur_readme_path ) ;
2016-11-02 15:30:45 +01:00
}
void Event_RunInstall ( )
{
2017-09-28 11:59:41 +02:00
int result ;
result = io . run ( # cur_install_path , NULL ) ;
2020-04-15 15:44:21 +02:00
if ( result ) notify ( T_DRIVER_INSTALLARION_STARTED ) ;
pause ( 300 ) ;
2021-06-22 00:51:35 +02:00
if ( cur_icon = = 61 ) {
2020-04-15 15:44:21 +02:00
RestartProcessByName ( " /sys/@taskbar " , SINGLE ) ;
RestartProcessByName ( " /sys/@docky " , SINGLE ) ;
2020-04-15 15:47:56 +02:00
RestartProcessByName ( " /sys/@icon " , MULTIPLE ) ;
2020-04-15 15:44:21 +02:00
}
2016-11-02 15:30:45 +01:00
}