Subversion Repositories Kolibri OS

Rev

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