Subversion Repositories Kolibri OS

Rev

Rev 6656 | Rev 6746 | 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.         int id;
  85.         load_dll(libio,  #libio_init,1);
  86.         load_dll(libini, #lib_init,1);
  87.         load_dll(boxlib, #box_lib_init,0);
  88.         GetIniData();
  89.         SetEventMask(0x27);
  90.         loop() switch(WaitEvent())
  91.         {
  92.                 case evMouse:
  93.                         if (!CheckActiveProcess(Form.ID)) break;
  94.                         SelectList_ProcessMouse();
  95.                         break;
  96.  
  97.                 case evButton:
  98.                         id=GetButtonID();              
  99.                         if (id==1) ExitProcess();
  100.                         if (id==BUTTON_ID_ASSEPT_RISK) Event_AsseptRisk();
  101.                         if (id==BUTTON_ID_README) Event_ShowReadme();
  102.                         if (id==BUTTON_ID_INSTALL) Event_RunInstall();
  103.                         break;
  104.          
  105.                 case evKey:
  106.                         GetKeys();
  107.                         if (select_list.ProcessKey(key_scancode)) SelectList_LineChanged();
  108.                         break;
  109.                  
  110.                 case evReDraw:
  111.                         Event_DrawWindow();
  112.         }
  113. }
  114.  
  115.  
  116. void draw_intro_window()
  117. {
  118.         incn y;
  119.         y.n = Form.cheight/2 - 80;
  120.         WriteTextB(30+2,y.n+2,0x81,MixColors(system.color.work, 0xB92234,220),T_CAUTION_TITLE);
  121.         WriteTextB(30,y.n,0x81,0xB92234,T_CAUTION_TITLE);
  122.         y.n = DrawTextViewArea(30, y.inc(30), Form.cwidth-60, Form.cheight-140,
  123.                 T_CAUTION_PARAGRAPH, -1, system.color.work_text);
  124.         DrawStandartCaptButton(30, y.inc(10), BUTTON_ID_ASSEPT_RISK, T_ASSEPT_RISK);
  125. }
  126.  
  127.  
  128. void draw_driver_list_window()
  129. {
  130.         int PADDING = 12;
  131.         int right_frame_x = Form.cwidth*46/100;
  132.         int readme_w = 0;
  133.         //LEFT FRAME
  134.         SelectList_Init(PADDING,
  135.                 PADDING,
  136.                 right_frame_x - PADDING - PADDING - 8 - scroll1.size_x,
  137.                 Form.cheight - PADDING - PADDING,
  138.                 false);
  139.         SelectList_Draw();
  140.         SelectList_DrawBorder();
  141.         //RIGHT FRAME
  142.         GetCurrentSectionData();
  143.         DrawBar(right_frame_x, PADDING+3, Form.cwidth - right_frame_x - PADDING, 80, system.color.work);
  144.         WriteTextB(right_frame_x, PADDING+3, 0x81, system.color.work_text, ini_sections.get(select_list.cur_y));
  145.         WriteText(right_frame_x, PADDING+23, 0x80, system.color.work_text, #cur_version);
  146.         if(cur_readme_path[0]) readme_w = DrawStandartCaptButton(right_frame_x, PADDING+45, BUTTON_ID_README, T_README);
  147.         DrawStandartCaptButton(right_frame_x + readme_w, PADDING+45, BUTTON_ID_INSTALL, T_INSTALL);
  148.         DrawTextViewArea(right_frame_x-2, PADDING+83, Form.cwidth - right_frame_x - PADDING, Form.cheight-PADDING-PADDING,
  149.                 #cur_description, system.color.work, system.color.work_text);
  150. }
  151.  
  152. void SelectList_DrawLine(dword i)
  153. {
  154.         int yyy, list_last;
  155.  
  156.         yyy = i*select_list.item_h+select_list.y;
  157.        
  158.         if (select_list.cur_y-select_list.first==i)
  159.         {
  160.                 DrawBar(select_list.x, yyy, select_list.w, select_list.item_h, system.color.work_button);
  161.                 WriteText(select_list.x+12,yyy+select_list.text_y,select_list.font_type,system.color.work_button_text, ini_sections.get(i));
  162.         }
  163.         else
  164.         {
  165.                 DrawBar(select_list.x,yyy,select_list.w, select_list.item_h, 0xFFFfff);
  166.                 WriteText(select_list.x+12,yyy+select_list.text_y,select_list.font_type,0, ini_sections.get(i));
  167.         }
  168. }
  169.  
  170. void SelectList_LineChanged()
  171. {
  172.         draw_driver_list_window();
  173. }
  174.  
  175.  
  176. void GetCurrentSectionData()
  177. {
  178.         dword section_name = ini_sections.get(select_list.cur_y);
  179.         dword description_name;
  180.         if (GetSystemLanguage() == SYS_LANG_RUS) description_name = "description_ru"; else description_name = "description_en";
  181.         ini_get_str stdcall (#drvinf_path, section_name, "ver", #cur_version, sizeof(cur_version), 0);
  182.         ini_get_str stdcall (#drvinf_path, section_name, description_name, #cur_description, sizeof(cur_description), 0);
  183.         ini_get_str stdcall (#drvinf_path, section_name, "readme", #cur_readme_path, sizeof(cur_readme_path), 0);
  184.         ini_get_str stdcall (#drvinf_path, section_name, "install", #cur_install_path, sizeof(cur_install_path), 0);
  185. }
  186.  
  187. //===================================================//
  188. //                                                   //
  189. //                     EVENTS                        //
  190. //                                                   //
  191. //===================================================//
  192.  
  193. void Event_DrawWindow()
  194. {
  195.         system.color.get();
  196.         DefineAndDrawWindow(215, 100, 600, 400, 0x33, system.color.work, WINDOW_TITLE);
  197.         GetProcessInfo(#Form, SelfInfo);
  198.         if (Form.status_window>2) return;
  199.         if (Form.width  < 450) { MoveSize(OLD,OLD,450,OLD); return; }
  200.         if (Form.height < 250) { MoveSize(OLD,OLD,OLD,250); return; }
  201.         if (window_step == WINDOW_STEP_INTRO) draw_intro_window();
  202.         if (window_step == WINDOW_STEP_DRIVER_LIST) draw_driver_list_window();
  203.         return;
  204. }
  205.  
  206. void Event_AsseptRisk()
  207. {
  208.         window_step = WINDOW_STEP_DRIVER_LIST;
  209.         Event_DrawWindow();
  210. }
  211.  
  212. void Event_ShowReadme()
  213. {
  214.         io.run("/sys/textreader", #cur_readme_path);
  215. }
  216.  
  217. void Event_RunInstall()
  218. {
  219.         io.run(#cur_install_path, NULL);
  220. }