Subversion Repositories Kolibri OS

Rev

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

  1. #define MEMSIZE 4096*20
  2.  
  3. #ifndef AUTOBUILD
  4. #include "lang.h--"
  5. #endif
  6.  
  7. //===================================================//
  8. //                                                   //
  9. //                       LIB                         //
  10. //                                                   //
  11. //===================================================//
  12.  
  13. #include "../lib/gui.h"
  14. #include "../lib/list_box.h"
  15. #include "../lib/obj/box_lib.h"
  16. #include "../lib/obj/libio.h"
  17. #include "../lib/obj/libimg.h"
  18. #include "../lib/obj/libini.h"
  19. #include "../lib/collection.h"
  20. #include "../lib/io.h"
  21. #include "../lib/patterns/select_list.h"
  22. #include "../lib/patterns/restart_process.h"
  23.  
  24. //===================================================//
  25. //                                                   //
  26. //                       DATA                        //
  27. //                                                   //
  28. //===================================================//
  29.  
  30. proc_info Form;
  31.  
  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 "“áâ ­®¢¨âì"
  39.         #define T_DRIVER_INSTALLARION_STARTED "' ç « áì ãáâ ­®¢ª  ¤à ©¢¥à .\n‹®£ ãáâ ­®¢ª¨ ­ å®¤¨âáï ¢ ¯à¨«®¦¥­¨¨ BOARD.'I"
  40.         char description_name[] = "description_ru";
  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"
  48.         #define T_DRIVER_INSTALLARION_STARTED "'Driver installation started.\nInstallation log can be found in BOARD app.'I"
  49.         char description_name[] = "description_en";
  50. #endif
  51.  
  52. #define BUTTON_ID_ASSEPT_RISK 10
  53. #define BUTTON_ID_README 11
  54. #define BUTTON_ID_INSTALL 12
  55.  
  56. //WINDOW STEPS
  57. #define WINDOW_STEP_INTRO 1;
  58. #define WINDOW_STEP_DRIVER_LIST 2;
  59. char window_step = WINDOW_STEP_INTRO;
  60.  
  61. collection ini_sections=0;
  62.  
  63. char drvinf_path[4096] = "/kolibrios/drivers/drvinf.ini";
  64. char cur_version[64];
  65. char cur_type[12];
  66. char cur_description[1024];
  67. char cur_readme_path[4096];
  68. char cur_install_path[4096];
  69.  
  70. //===================================================//
  71. //                                                   //
  72. //                       CODE                        //
  73. //                                                   //
  74. //===================================================//
  75.  
  76. void GetIniData()
  77. {
  78.         select_list.count = 0;
  79.         ini_enum_sections stdcall (#drvinf_path, #process_sections);
  80. }
  81.  
  82. byte process_sections(dword sec_name, f_name)
  83. {
  84.         select_list.count++;
  85.         ini_sections.add(sec_name);
  86.         return true;
  87. }
  88.  
  89. void main()
  90. {
  91.         load_dll(libio,  #libio_init,1);
  92.         load_dll(libini, #lib_init,1);
  93.         load_dll(boxlib, #box_lib_init,0);
  94.         load_dll(libimg, #libimg_init,1);
  95.         GetIniData();
  96.         SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
  97.         loop() switch(WaitEvent())
  98.         {
  99.                 case evMouse:
  100.                         SelectList_ProcessMouse();
  101.                         break;
  102.  
  103.                 case evButton:
  104.                         Event_ProcessButtonId(GetButtonID());
  105.                         break;
  106.          
  107.                 case evKey:
  108.                         GetKeys();
  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.                         }
  119.                         break;
  120.                  
  121.                 case evReDraw:
  122.                         Event_DrawWindow();
  123.         }
  124. }
  125.  
  126.  
  127. void Draw_IntroWindow()
  128. {
  129.         incn y;
  130.         y.n = Form.cheight/2 - 80;
  131.         WriteTextB(30+2,y.n+2,0x81,MixColors(sc.work, 0xB92234,220),T_CAUTION_TITLE);
  132.         WriteTextB(30,y.n,0x81,0xB92234,T_CAUTION_TITLE);
  133.         y.n = DrawTextViewArea(30, y.inc(30), Form.cwidth-60, Form.cheight-140,
  134.                 T_CAUTION_PARAGRAPH, -1, sc.work_text);
  135.         active_button_id = BUTTON_ID_ASSEPT_RISK;
  136.         DrawStandartCaptButton(30, y.inc(10), BUTTON_ID_ASSEPT_RISK, T_ASSEPT_RISK);
  137. }
  138.  
  139.  
  140. void Draw_DriverListWindow()
  141. {
  142.         int PADDING = 12;
  143.         int right_frame_x = Form.cwidth*46/100;
  144.         int readme_w = 0;
  145.         int icon_n = 38;
  146.         //LEFT FRAME
  147.         SelectList_Init(PADDING,
  148.                 PADDING,
  149.                 right_frame_x - PADDING - PADDING - 8 - scroll1.size_x,
  150.                 Form.cheight - PADDING - PADDING,
  151.                 false);
  152.         SelectList_Draw();
  153.         SelectList_DrawBorder();
  154.         //RIGHT FRAME
  155.         GetCurrentSectionData();
  156.         DrawBar(right_frame_x, PADDING+3, Form.cwidth - right_frame_x - PADDING, 80, sc.work);
  157.         if (streq(#cur_type, "disk")) icon_n = 50;
  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);
  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,
  164.                 #cur_description, sc.work, sc.work_text);
  165. }
  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.         {
  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));
  177.         }
  178.         else
  179.         {
  180.                 DrawBar(select_list.x,yyy,select_list.w, select_list.item_h, 0xFFFfff);
  181.                 WriteText(select_list.x+12,yyy+select_list.text_y,select_list.font_type,0, ini_sections.get(i));
  182.         }
  183. }
  184.  
  185. void SelectList_LineChanged()
  186. {
  187.         Draw_DriverListWindow();
  188. }
  189.  
  190.  
  191. void GetCurrentSectionData()
  192. {
  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);
  195.         ini_get_str stdcall (#drvinf_path, section_name, "type", #cur_type, sizeof(cur_type), 0);
  196.         ini_get_str stdcall (#drvinf_path, section_name, #description_name, #cur_description, sizeof(cur_description), 0);
  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);
  199. }
  200.  
  201. //===================================================//
  202. //                                                   //
  203. //                     EVENTS                        //
  204. //                                                   //
  205. //===================================================//
  206.  
  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.  
  215. void Event_DrawWindow()
  216. {
  217.         sc.get();
  218.         DefineAndDrawWindow(215, 100, 600, 400, 0x33, sc.work, WINDOW_TITLE,0);
  219.         GetProcessInfo(#Form, SelfInfo);
  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; }
  223.         if (window_step == WINDOW_STEP_INTRO) Draw_IntroWindow();
  224.         if (window_step == WINDOW_STEP_DRIVER_LIST) Draw_DriverListWindow();
  225.         return;
  226. }
  227.  
  228. void Event_AsseptRisk()
  229. {
  230.         window_step = WINDOW_STEP_DRIVER_LIST;
  231.         active_button_id = BUTTON_ID_INSTALL;
  232.         Event_DrawWindow();
  233. }
  234.  
  235. void Event_ShowReadme()
  236. {
  237.         io.run("/sys/@open", #cur_readme_path);
  238. }
  239.  
  240. void Event_RunInstall()
  241. {
  242.         int result;
  243.         result = io.run(#cur_install_path, NULL);
  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);   
  249.                 RestartProcessByName("/sys/@icon", MULTIPLE);  
  250.         }
  251. }