Subversion Repositories Kolibri OS

Rev

Rev 6918 | Rev 7590 | 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_lib.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.  
  22. //===================================================//
  23. //                                                   //
  24. //                       DATA                        //
  25. //                                                   //
  26. //===================================================//
  27.  
  28. proc_info Form;
  29.  
  30. #ifdef LANG_RUS
  31.         #define WINDOW_TITLE "“áâ ­®¢é¨ª ¤à ©¢¥à®¢"
  32.         #define T_CAUTION_TITLE "…„“…†„…ˆ…"
  33.         #define T_CAUTION_PARAGRAPH "“áâ ­®¢ª  ¤®¯®«­¨â¥«ì­ëå ¤à ©¢¥à®¢ ¬®¦¥â ­ ­¥á⨠¢à¥¤ áâ ¡¨«ì­®á⨠®¯¥à æ¨®­­®© á¨áâ¥¬ë ¨ ¯®â¥­æ¨ «ì­® ¯à¨¢¥á⨠ª ¯®àç¥ ®¡®à㤮¢ ­¨ï."
  34.         #define T_ASSEPT_RISK "Ÿ ¯à¨­¨¬ î à¨áª"
  35.         #define T_README "Readme"
  36.         #define T_INSTALL "“áâ ­®¢¨âì"
  37. #else
  38.         #define WINDOW_TITLE "Driver Installer"
  39.         #define T_CAUTION_TITLE "CAUTION"
  40.         #define T_CAUTION_PARAGRAPH "Installing additional drivers can be harmful to the stability of the operation system and potentionally can harm hardware."
  41.         #define T_ASSEPT_RISK "I accept the risk"
  42.         #define T_README "Readme"
  43.         #define T_INSTALL "Install"
  44. #endif
  45.  
  46. #define BUTTON_ID_ASSEPT_RISK 10
  47. #define BUTTON_ID_README 11
  48. #define BUTTON_ID_INSTALL 12
  49.  
  50. //WINDOW STEPS
  51. #define WINDOW_STEP_INTRO 1;
  52. #define WINDOW_STEP_DRIVER_LIST 2;
  53. char window_step = WINDOW_STEP_INTRO;
  54.  
  55. collection ini_sections;
  56.  
  57. char drvinf_path[4096] = "/kolibrios/drivers/drvinf.ini";
  58. char cur_version[64];
  59. char cur_description[1024];
  60. char cur_readme_path[4096];
  61. char cur_install_path[4096];
  62.  
  63. //===================================================//
  64. //                                                   //
  65. //                       CODE                        //
  66. //                                                   //
  67. //===================================================//
  68.  
  69. void GetIniData()
  70. {
  71.         select_list.count = 0;
  72.         ini_enum_sections stdcall (#drvinf_path, #process_sections);
  73. }
  74.  
  75. byte process_sections(dword sec_name, f_name)
  76. {
  77.         select_list.count++;
  78.         ini_sections.add(sec_name);
  79.         return true;
  80. }
  81.  
  82. void main()
  83. {
  84.         load_dll(libio,  #libio_init,1);
  85.         load_dll(libini, #lib_init,1);
  86.         load_dll(boxlib, #box_lib_init,0);
  87.         GetIniData();
  88.         SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
  89.         loop() switch(WaitEvent())
  90.         {
  91.                 case evMouse:
  92.                         SelectList_ProcessMouse();
  93.                         break;
  94.  
  95.                 case evButton:
  96.                         Event_ProcessButtonId(GetButtonID());
  97.                         break;
  98.          
  99.                 case evKey:
  100.                         GetKeys();
  101.                         if (key_scancode == SCAN_CODE_ENTER) Event_ProcessButtonId(active_button_id);
  102.                         if (window_step == WINDOW_STEP_DRIVER_LIST)
  103.                         {
  104.                                 if (select_list.ProcessKey(key_scancode)) SelectList_LineChanged();
  105.                                 if (key_scancode == SCAN_CODE_TAB)
  106.                                 {
  107.                                         ActiveButtonSwitch(11, 12);
  108.                                         Draw_DriverListWindow();
  109.                                 }
  110.                         }
  111.                         break;
  112.                  
  113.                 case evReDraw:
  114.                         Event_DrawWindow();
  115.         }
  116. }
  117.  
  118.  
  119. void Draw_IntroWindow()
  120. {
  121.         incn y;
  122.         y.n = Form.cheight/2 - 80;
  123.         WriteTextB(30+2,y.n+2,0x81,MixColors(system.color.work, 0xB92234,220),T_CAUTION_TITLE);
  124.         WriteTextB(30,y.n,0x81,0xB92234,T_CAUTION_TITLE);
  125.         y.n = DrawTextViewArea(30, y.inc(30), Form.cwidth-60, Form.cheight-140,
  126.                 T_CAUTION_PARAGRAPH, -1, system.color.work_text);
  127.         active_button_id = BUTTON_ID_ASSEPT_RISK;
  128.         DrawStandartCaptButton(30, y.inc(10), BUTTON_ID_ASSEPT_RISK, T_ASSEPT_RISK);
  129. }
  130.  
  131.  
  132. void Draw_DriverListWindow()
  133. {
  134.         int PADDING = 12;
  135.         int right_frame_x = Form.cwidth*46/100;
  136.         int readme_w = 0;
  137.         //LEFT FRAME
  138.         SelectList_Init(PADDING,
  139.                 PADDING,
  140.                 right_frame_x - PADDING - PADDING - 8 - scroll1.size_x,
  141.                 Form.cheight - PADDING - PADDING,
  142.                 false);
  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, system.color.work);
  148.         WriteTextB(right_frame_x, PADDING+3, 0x81, system.color.work_text, ini_sections.get(select_list.cur_y));
  149.         WriteText(right_frame_x, PADDING+23, 0x80, system.color.work_text, #cur_version);
  150.         if(cur_readme_path[0]) readme_w = DrawStandartCaptButton(right_frame_x, PADDING+45, BUTTON_ID_README, T_README);
  151.         DrawStandartCaptButton(right_frame_x + readme_w, PADDING+45, BUTTON_ID_INSTALL, T_INSTALL);
  152.         DrawTextViewArea(right_frame_x-2, PADDING+83, Form.cwidth - right_frame_x - PADDING, Form.cheight-PADDING-PADDING,
  153.                 #cur_description, system.color.work, system.color.work_text);
  154. }
  155.  
  156. void SelectList_DrawLine(dword i)
  157. {
  158.         int yyy, list_last;
  159.  
  160.         yyy = i*select_list.item_h+select_list.y;
  161.        
  162.         if (select_list.cur_y-select_list.first==i)
  163.         {
  164.                 DrawBar(select_list.x, yyy, select_list.w, select_list.item_h, system.color.work_button);
  165.                 WriteText(select_list.x+12,yyy+select_list.text_y,select_list.font_type,system.color.work_button_text, ini_sections.get(i));
  166.         }
  167.         else
  168.         {
  169.                 DrawBar(select_list.x,yyy,select_list.w, select_list.item_h, 0xFFFfff);
  170.                 WriteText(select_list.x+12,yyy+select_list.text_y,select_list.font_type,0, ini_sections.get(i));
  171.         }
  172. }
  173.  
  174. void SelectList_LineChanged()
  175. {
  176.         Draw_DriverListWindow();
  177. }
  178.  
  179.  
  180. void GetCurrentSectionData()
  181. {
  182.         dword section_name = ini_sections.get(select_list.cur_y);
  183.         dword description_name;
  184.         if (GetSystemLanguage() == SYS_LANG_RUS) description_name = "description_ru"; else description_name = "description_en";
  185.         ini_get_str stdcall (#drvinf_path, section_name, "ver", #cur_version, sizeof(cur_version), 0);
  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.         system.color.get();
  208.         DefineAndDrawWindow(215, 100, 600, 400, 0x33, system.color.work, WINDOW_TITLE,0);
  209.         GetProcessInfo(#Form, SelfInfo);
  210.         if (Form.status_window>2) 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/txtread", #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("'Driver installation started.\nPlease, open BOARD to check status.'I");
  235. }