Subversion Repositories Kolibri OS

Rev

Rev 7049 | Rev 7793 | 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/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.         char description_name[] = "description_ru";
  38. #else
  39.         #define WINDOW_TITLE "Driver Installer"
  40.         #define T_CAUTION_TITLE "CAUTION"
  41.         #define T_CAUTION_PARAGRAPH "Installing additional drivers can be harmful to the stability of the operation system and potentionally can harm hardware."
  42.         #define T_ASSEPT_RISK "I accept the risk"
  43.         #define T_README "Readme"
  44.         #define T_INSTALL "Install"
  45.         char description_name[] = "description_en";
  46. #endif
  47.  
  48. #define BUTTON_ID_ASSEPT_RISK 10
  49. #define BUTTON_ID_README 11
  50. #define BUTTON_ID_INSTALL 12
  51.  
  52. //WINDOW STEPS
  53. #define WINDOW_STEP_INTRO 1;
  54. #define WINDOW_STEP_DRIVER_LIST 2;
  55. char window_step = WINDOW_STEP_INTRO;
  56.  
  57. collection ini_sections;
  58.  
  59. char drvinf_path[4096] = "/kolibrios/drivers/drvinf.ini";
  60. char cur_version[64];
  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(libio,  #libio_init,1);
  87.         load_dll(libini, #lib_init,1);
  88.         load_dll(boxlib, #box_lib_init,0);
  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(system.color.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, system.color.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.         int PADDING = 12;
  137.         int right_frame_x = Form.cwidth*46/100;
  138.         int readme_w = 0;
  139.         //LEFT FRAME
  140.         SelectList_Init(PADDING,
  141.                 PADDING,
  142.                 right_frame_x - PADDING - PADDING - 8 - scroll1.size_x,
  143.                 Form.cheight - PADDING - PADDING,
  144.                 false);
  145.         SelectList_Draw();
  146.         SelectList_DrawBorder();
  147.         //RIGHT FRAME
  148.         GetCurrentSectionData();
  149.         DrawBar(right_frame_x, PADDING+3, Form.cwidth - right_frame_x - PADDING, 80, system.color.work);
  150.         WriteTextB(right_frame_x, PADDING+3, 0x81, system.color.work_text, ini_sections.get(select_list.cur_y));
  151.         WriteText(right_frame_x, PADDING+23, 0x80, system.color.work_text, #cur_version);
  152.         if(cur_readme_path[0]) readme_w = DrawStandartCaptButton(right_frame_x, PADDING+45, BUTTON_ID_README, T_README);
  153.         DrawStandartCaptButton(right_frame_x + readme_w, PADDING+45, BUTTON_ID_INSTALL, T_INSTALL);
  154.         DrawTextViewArea(right_frame_x-2, PADDING+83, Form.cwidth - right_frame_x - PADDING, Form.cheight-PADDING-PADDING,
  155.                 #cur_description, system.color.work, system.color.work_text);
  156. }
  157.  
  158. void SelectList_DrawLine(dword i)
  159. {
  160.         int yyy, list_last;
  161.  
  162.         yyy = i*select_list.item_h+select_list.y;
  163.        
  164.         if (select_list.cur_y-select_list.first==i)
  165.         {
  166.                 DrawBar(select_list.x, yyy, select_list.w, select_list.item_h, system.color.work_button);
  167.                 WriteText(select_list.x+12,yyy+select_list.text_y,select_list.font_type,system.color.work_button_text, ini_sections.get(i));
  168.         }
  169.         else
  170.         {
  171.                 DrawBar(select_list.x,yyy,select_list.w, select_list.item_h, 0xFFFfff);
  172.                 WriteText(select_list.x+12,yyy+select_list.text_y,select_list.font_type,0, ini_sections.get(i));
  173.         }
  174. }
  175.  
  176. void SelectList_LineChanged()
  177. {
  178.         Draw_DriverListWindow();
  179. }
  180.  
  181.  
  182. void GetCurrentSectionData()
  183. {
  184.         dword section_name = ini_sections.get(select_list.cur_y);
  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. }