Subversion Repositories Kolibri OS

Rev

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

  1. #define MEMSIZE 4096*20
  2.  
  3. //===================================================//
  4. //                                                   //
  5. //                       LIB                         //
  6. //                                                   //
  7. //===================================================//
  8.  
  9. #include "../lib/gui.h"
  10. #include "../lib/list_box.h"
  11. #include "../lib/obj/box_lib.h"
  12. #include "../lib/obj/libio_lib.h"
  13. #include "../lib/obj/libini.h"
  14. #include "../lib/collection.h"
  15. #include "../lib/io.h"
  16. #include "../lib/patterns/select_list.h"
  17.  
  18. //===================================================//
  19. //                                                   //
  20. //                       DATA                        //
  21. //                                                   //
  22. //===================================================//
  23.  
  24. proc_info Form;
  25.  
  26. #define WINDOW_TITLE "Driver Installer"
  27. #define T_CAUTION_TITLE "CAUTION"
  28. #define T_CAUTION_PARAGRAPH "Installing additional drivers can be harmful to the stability of the operation system and potentionally can harm hardware."
  29. #define T_ASSEPT_RISK "I assept the risk"
  30. #define T_README "Readme"
  31. #define T_INSTALL "Install"
  32.  
  33. #define BUTTON_ID_ASSEPT_RISK 10
  34. #define BUTTON_ID_README 11
  35. #define BUTTON_ID_INSTALL 12
  36.  
  37. //WINDOW STEPS
  38. #define WINDOW_STEP_INTRO 1;
  39. #define WINDOW_STEP_DRIVER_LIST 2;
  40. char window_step = WINDOW_STEP_INTRO;
  41.  
  42. collection ini_sections;
  43.  
  44. char drvinf_path[4096] = "/sys/drvinf.ini";
  45. char cur_version[64];
  46. char cur_description[1024];
  47. char cur_readme_path[4096];
  48. char cur_install_path[4096];
  49.  
  50. //===================================================//
  51. //                                                   //
  52. //                       CODE                        //
  53. //                                                   //
  54. //===================================================//
  55.  
  56. void GetIniData()
  57. {
  58.         select_list.count = 0;
  59.         ini_enum_sections stdcall (#drvinf_path, #process_sections);
  60. }
  61.  
  62. byte process_sections(dword sec_name, f_name)
  63. {
  64.         select_list.count++;
  65.         ini_sections.add(sec_name);
  66.         return true;
  67. }
  68.  
  69. void main()
  70. {
  71.         int id;
  72.         load_dll(libio,  #libio_init,1);
  73.         load_dll(libini, #lib_init,1);
  74.         load_dll(boxlib, #box_lib_init,0);
  75.         GetIniData();
  76.         SetEventMask(0x27);
  77.         loop() switch(WaitEvent())
  78.         {
  79.                 case evMouse:
  80.                         if (!CheckActiveProcess(Form.ID)) break;
  81.                         SelectList_ProcessMouse();
  82.                         break;
  83.  
  84.                 case evButton:
  85.                         id=GetButtonID();              
  86.                         if (id==1) ExitProcess();
  87.                         if (id==BUTTON_ID_ASSEPT_RISK) Event_AsseptRisk();
  88.                         if (id==BUTTON_ID_README) Event_ShowReadme();
  89.                         if (id==BUTTON_ID_INSTALL) Event_RunInstall();
  90.                         break;
  91.          
  92.                 case evKey:
  93.                         GetKeys();
  94.                         if (select_list.ProcessKey(key_scancode)) SelectList_LineChanged();
  95.                         break;
  96.                  
  97.                 case evReDraw:
  98.                         Event_DrawWindow();
  99.         }
  100. }
  101.  
  102.  
  103. void draw_intro_window()
  104. {
  105.         incn y;
  106.         y.n = Form.cheight/2 - 80;
  107.         WriteTextB(30+2,y.n+2,0x81,MixColors(system.color.work, 0xB92234,220),T_CAUTION_TITLE);
  108.         WriteTextB(30,y.n,0x81,0xB92234,T_CAUTION_TITLE);
  109.         y.n = DrawTextViewArea(30, y.inc(30), Form.cwidth-60, Form.cheight-140,
  110.                 T_CAUTION_PARAGRAPH, -1, system.color.work_text);
  111.         DrawStandartCaptButton(30, y.inc(10), BUTTON_ID_ASSEPT_RISK, T_ASSEPT_RISK);
  112. }
  113.  
  114.  
  115. void draw_driver_list_window()
  116. {
  117.         int PADDING = 12;
  118.         int right_frame_x = Form.cwidth*46/100;
  119.         int readme_w = 0;
  120.         //LEFT FRAME
  121.         SelectList_Init(PADDING,
  122.                 PADDING,
  123.                 right_frame_x - PADDING - PADDING - 8 - scroll1.size_x,
  124.                 Form.cheight - PADDING - PADDING,
  125.                 false);
  126.         SelectList_Draw();
  127.         //RIGHT FRAME
  128.         GetCurrentSectionData();
  129.         DrawBar(right_frame_x, PADDING+3, Form.cwidth - right_frame_x - PADDING, 80, system.color.work);
  130.         WriteTextB(right_frame_x, PADDING+3, 0x81, system.color.work_text, ini_sections.get(select_list.cur_y));
  131.         WriteText(right_frame_x, PADDING+23, 0x80, system.color.work_text, #cur_version);
  132.         if(cur_readme_path[0]) readme_w = DrawStandartCaptButton(right_frame_x, PADDING+45, BUTTON_ID_README, T_README);
  133.         DrawStandartCaptButton(right_frame_x + readme_w, PADDING+45, BUTTON_ID_INSTALL, T_INSTALL);
  134.         DrawTextViewArea(right_frame_x-2, PADDING+83, Form.cwidth - right_frame_x - PADDING, Form.cheight-PADDING-PADDING,
  135.                 #cur_description, system.color.work, system.color.work_text);
  136. }
  137.  
  138. void SelectList_DrawLine(dword i)
  139. {
  140.         int yyy, list_last;
  141.  
  142.         yyy = i*select_list.item_h+select_list.y;
  143.        
  144.         if (select_list.cur_y-select_list.first==i)
  145.         {
  146.                 DrawBar(select_list.x, yyy, select_list.w, select_list.item_h, system.color.work_button);
  147.                 WriteText(select_list.x+12,yyy+select_list.text_y,select_list.font_type,system.color.work_button_text, ini_sections.get(i));
  148.         }
  149.         else
  150.         {
  151.                 DrawBar(select_list.x,yyy,select_list.w, select_list.item_h, 0xFFFfff);
  152.                 WriteText(select_list.x+12,yyy+select_list.text_y,select_list.font_type,0, ini_sections.get(i));
  153.         }
  154. }
  155.  
  156. void SelectList_LineChanged()
  157. {
  158.         draw_driver_list_window();
  159. }
  160.  
  161. void GetCurrentSectionData()
  162. {
  163.         dword cur_section_name = ini_sections.get(select_list.cur_y);
  164.         ini_get_str stdcall (#drvinf_path, cur_section_name, "ver", #cur_version, sizeof(cur_version), 0);
  165.         ini_get_str stdcall (#drvinf_path, cur_section_name, "description", #cur_description, sizeof(cur_description), 0);
  166.         ini_get_str stdcall (#drvinf_path, cur_section_name, "readme", #cur_readme_path, sizeof(cur_readme_path), 0);
  167.         ini_get_str stdcall (#drvinf_path, cur_section_name, "install", #cur_install_path, sizeof(cur_install_path), 0);
  168. }
  169.  
  170. //===================================================//
  171. //                                                   //
  172. //                     EVENTS                        //
  173. //                                                   //
  174. //===================================================//
  175.  
  176. void Event_DrawWindow()
  177. {
  178.         system.color.get();
  179.         DefineAndDrawWindow(215, 100, 600, 400, 0x33, system.color.work, WINDOW_TITLE);
  180.         GetProcessInfo(#Form, SelfInfo);
  181.         if (Form.status_window>2) return;
  182.         if (Form.width  < 450) { MoveSize(OLD,OLD,450,OLD); return; }
  183.         if (Form.height < 250) { MoveSize(OLD,OLD,OLD,250); return; }
  184.         if (window_step == WINDOW_STEP_INTRO) draw_intro_window();
  185.         if (window_step == WINDOW_STEP_DRIVER_LIST) draw_driver_list_window();
  186.         return;
  187. }
  188.  
  189. void Event_AsseptRisk()
  190. {
  191.         window_step = WINDOW_STEP_DRIVER_LIST;
  192.         Event_DrawWindow();
  193. }
  194.  
  195. void Event_ShowReadme()
  196. {
  197.         io.run("/sys/textreader", #cur_readme_path);
  198. }
  199.  
  200. void Event_RunInstall()
  201. {
  202.         io.run(#cur_install_path, NULL);
  203. }