Subversion Repositories Kolibri OS

Rev

Rev 8946 | Rev 9439 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #define MEMSIZE 4096*20
  2.  
  3. //===================================================//
  4. //                                                   //
  5. //                       LIB                         //
  6. //                                                   //
  7. //===================================================//
  8.  
  9. #include "../lib/gui.h"
  10. #include "../lib/list_box.h"
  11. #include "../lib/obj/box_lib.h"
  12. #include "../lib/obj/libimg.h"
  13. #include "../lib/obj/libini.h"
  14. #include "../lib/collection.h"
  15. #include "../lib/io.h"
  16. #include "../lib/patterns/select_list.h"
  17. #include "../lib/patterns/restart_process.h"
  18.  
  19. //===================================================//
  20. //                                                   //
  21. //                       DATA                        //
  22. //                                                   //
  23. //===================================================//
  24.  
  25. proc_info Form;
  26.  
  27. #ifdef LANG_RUS
  28.         #define WINDOW_TITLE "“áâ ­®¢é¨ª ¤à ©¢¥à®¢"
  29.         #define T_CAUTION_TITLE "…„“…†„…ˆ…"
  30.         #define T_CAUTION_PARAGRAPH "“áâ ­®¢ª  ¤®¯®«­¨â¥«ì­ëå ¤à ©¢¥à®¢ ¬®¦¥â ­ ­¥á⨠¢à¥¤ áâ ¡¨«ì­®á⨠®¯¥à æ¨®­­®© á¨áâ¥¬ë ¨ ¯®â¥­æ¨ «ì­® ¯à¨¢¥á⨠ª ¯®àç¥ ®¡®à㤮¢ ­¨ï."
  31.         #define T_ASSEPT_RISK "Ÿ ¯à¨­¨¬ î à¨áª"
  32.         #define T_README "Readme"
  33.         #define T_INSTALL "“áâ ­®¢¨âì"
  34.         #define T_DRIVER_INSTALLARION_STARTED "' ç « áì ãáâ ­®¢ª  ¤à ©¢¥à .\n‹®£ ãáâ ­®¢ª¨ ­ å®¤¨âáï ¢ ¯à¨«®¦¥­¨¨ BOARD.'I"
  35.         char description_name[] = "description_ru";
  36. #else
  37.         #define WINDOW_TITLE "Driver Installer"
  38.         #define T_CAUTION_TITLE "CAUTION"
  39.         #define T_CAUTION_PARAGRAPH "Installing additional drivers can be harmful to the stability of the operation system and potentionally can harm hardware."
  40.         #define T_ASSEPT_RISK "I accept the risk"
  41.         #define T_README "Readme"
  42.         #define T_INSTALL "Install"
  43.         #define T_DRIVER_INSTALLARION_STARTED "'Driver installation started.\nInstallation log can be found in BOARD app.'I"
  44.         char description_name[] = "description_en";
  45. #endif
  46.  
  47. #define BUTTON_ID_ASSEPT_RISK 10
  48. #define BUTTON_ID_README 11
  49. #define BUTTON_ID_INSTALL 12
  50.  
  51. //WINDOW STEPS
  52. #define WINDOW_STEP_INTRO 1;
  53. #define WINDOW_STEP_DRIVER_LIST 2;
  54. char window_step = WINDOW_STEP_INTRO;
  55.  
  56. collection ini_sections=0;
  57.  
  58. char drvinf_path[4096] = "/kolibrios/drivers/drvinf.ini";
  59. char cur_version[64];
  60. int  cur_icon;
  61. char cur_description[1024];
  62. char cur_readme_path[4096];
  63. char cur_install_path[4096];
  64.  
  65. //===================================================//
  66. //                                                   //
  67. //                       CODE                        //
  68. //                                                   //
  69. //===================================================//
  70.  
  71. void GetIniData()
  72. {
  73.         select_list.count = 0;
  74.         ini_enum_sections stdcall (#drvinf_path, #process_sections);
  75. }
  76.  
  77. byte process_sections(dword sec_name, f_name)
  78. {
  79.         select_list.count++;
  80.         ini_sections.add(sec_name);
  81.         return true;
  82. }
  83.  
  84. void main()
  85. {
  86.         load_dll(libini, #lib_init,1);
  87.         load_dll(boxlib, #box_lib_init,0);
  88.         load_dll(libimg, #libimg_init,1);
  89.         GetIniData();
  90.         SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
  91.         loop() switch(WaitEvent())
  92.         {
  93.                 case evMouse:
  94.                         SelectList_ProcessMouse();
  95.                         break;
  96.  
  97.                 case evButton:
  98.                         Event_ProcessButtonId(GetButtonID());
  99.                         break;
  100.          
  101.                 case evKey:
  102.                         GetKeys();
  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.                         }
  113.                         break;
  114.                  
  115.                 case evReDraw:
  116.                         Event_DrawWindow();
  117.         }
  118. }
  119.  
  120.  
  121. void Draw_IntroWindow()
  122. {
  123.         incn y;
  124.         y.n = Form.cheight/2 - 80;
  125.         WriteTextB(30+2,y.n+2,0x81,MixColors(sc.work, 0xB92234,220),T_CAUTION_TITLE);
  126.         WriteTextB(30,y.n,0x81,0xB92234,T_CAUTION_TITLE);
  127.         y.n = DrawTextViewArea(30, y.inc(30), Form.cwidth-60, Form.cheight-140,
  128.                 T_CAUTION_PARAGRAPH, -1, sc.work_text);
  129.         active_button_id = BUTTON_ID_ASSEPT_RISK;
  130.         DrawStandartCaptButton(30, y.inc(10), BUTTON_ID_ASSEPT_RISK, T_ASSEPT_RISK);
  131. }
  132.  
  133.  
  134. void Draw_DriverListWindow()
  135. {
  136.         #define PADDING 12
  137.         int right_frame_x = Form.cwidth*46/100;
  138.         int readme_w = 0;
  139.         //LEFT FRAME
  140.         SelectList_Init(PADDING, PADDING,
  141.                 right_frame_x - PADDING - PADDING - 8 - scroll1.size_x,
  142.                 Form.cheight - PADDING - PADDING);
  143.         SelectList_Draw();
  144.         SelectList_DrawBorder();
  145.         //RIGHT FRAME
  146.         GetCurrentSectionData();
  147.         DrawBar(right_frame_x, PADDING+3, Form.cwidth - right_frame_x - PADDING, 80, sc.work);
  148.         DrawIcon32(right_frame_x, PADDING, sc.work, cur_icon); 
  149.         WriteTextB(right_frame_x+44, PADDING+3, 0x81, sc.work_text, ini_sections.get(select_list.cur_y));
  150.         WriteText(right_frame_x+44, PADDING+23, 0x80, sc.work_text, #cur_version);
  151.         if(cur_readme_path[0]) readme_w = DrawStandartCaptButton(right_frame_x, PADDING+45, BUTTON_ID_README, T_README);
  152.         DrawStandartCaptButton(right_frame_x + readme_w, PADDING+45, BUTTON_ID_INSTALL, T_INSTALL);
  153.         DrawTextViewArea(right_frame_x-2, PADDING+83, Form.cwidth - right_frame_x - PADDING, Form.cheight-PADDING-PADDING,
  154.                 #cur_description, sc.work, sc.work_text);
  155. }
  156.  
  157. void SelectList_DrawLine(dword i)
  158. {
  159.         int yyy, list_last;
  160.  
  161.         yyy = i*select_list.item_h+select_list.y;
  162.        
  163.         if (select_list.cur_y-select_list.first==i)
  164.         {
  165.                 DrawBar(select_list.x, yyy, select_list.w, select_list.item_h, sc.button);
  166.                 WriteText(select_list.x+12,yyy+select_list.text_y,select_list.font_type,sc.button_text, ini_sections.get(i));
  167.         }
  168.         else
  169.         {
  170.                 DrawBar(select_list.x,yyy,select_list.w, select_list.item_h, 0xFFFfff);
  171.                 WriteText(select_list.x+12,yyy+select_list.text_y,select_list.font_type,0, ini_sections.get(i));
  172.         }
  173. }
  174.  
  175. void SelectList_LineChanged()
  176. {
  177.         Draw_DriverListWindow();
  178. }
  179.  
  180.  
  181. void GetCurrentSectionData()
  182. {
  183.         dword section_name = ini_sections.get(select_list.cur_y);
  184.         ini_get_str stdcall (#drvinf_path, section_name, "ver", #cur_version, sizeof(cur_version), 0);
  185.         ini_get_int stdcall (#drvinf_path, section_name, "icon", 38); cur_icon = EAX;
  186.         ini_get_str stdcall (#drvinf_path, section_name, #description_name, #cur_description, sizeof(cur_description), 0);
  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);
  189. }
  190.  
  191. //===================================================//
  192. //                                                   //
  193. //                     EVENTS                        //
  194. //                                                   //
  195. //===================================================//
  196.  
  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.  
  205. void Event_DrawWindow()
  206. {
  207.         sc.get();
  208.         DefineAndDrawWindow(215, 100, 600, 400, 0x33, sc.work, WINDOW_TITLE,0);
  209.         GetProcessInfo(#Form, SelfInfo);
  210.         if (Form.status_window&ROLLED_UP) return;
  211.         if (Form.width  < 450) { MoveSize(OLD,OLD,450,OLD); return; }
  212.         if (Form.height < 250) { MoveSize(OLD,OLD,OLD,250); return; }
  213.         if (window_step == WINDOW_STEP_INTRO) Draw_IntroWindow();
  214.         if (window_step == WINDOW_STEP_DRIVER_LIST) Draw_DriverListWindow();
  215.         return;
  216. }
  217.  
  218. void Event_AsseptRisk()
  219. {
  220.         window_step = WINDOW_STEP_DRIVER_LIST;
  221.         active_button_id = BUTTON_ID_INSTALL;
  222.         Event_DrawWindow();
  223. }
  224.  
  225. void Event_ShowReadme()
  226. {
  227.         io.run("/sys/@open", #cur_readme_path);
  228. }
  229.  
  230. void Event_RunInstall()
  231. {
  232.         int result;
  233.         result = io.run(#cur_install_path, NULL);
  234.         if (result) notify(T_DRIVER_INSTALLARION_STARTED);
  235.         pause(300);
  236.         if (cur_icon == 61) {
  237.                 RestartProcessByName("/sys/@taskbar", SINGLE);
  238.                 RestartProcessByName("/sys/@docky", SINGLE);   
  239.                 RestartProcessByName("/sys/@icon", MULTIPLE);  
  240.         }
  241. }