Subversion Repositories Kolibri OS

Rev

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

  1. #define MEMSIZE 1024*460
  2.  
  3. #include "../lib/io.h"
  4. #include "../lib/gui.h"
  5. #include "../lib/copyf.h"
  6.  
  7. #include "../lib/obj/libini.h"
  8. #include "../lib/obj/libio.h"
  9. #include "../lib/obj/libimg.h"
  10. #include "../lib/obj/http.h"
  11. #include "../lib/obj/network.h"
  12.  
  13. #include "../lib/patterns/restart_process.h"
  14. #include "../lib/patterns/http_downloader.h"
  15.  
  16. #ifndef AUTOBUILD
  17. #include "lang.h--"
  18. #endif
  19.  
  20. _http http;
  21. proc_info Form;
  22. bool install_complete = false;
  23. sensor progress;
  24.  
  25. #define WINW 460
  26.  
  27. //#define LANG_RUS 1
  28.  
  29. #ifdef LANG_RUS
  30. #define WINH 345
  31. #define T_WINDOW_TITLE "Ž­« ©­ ®¡­®¢«¥­¨¥ KolibriOS"
  32. #define T_TITLE_H1 "Ž‹€‰ ŽŽ‚‹…ˆ…"
  33. #define T_INTRO "„ ­­®¥ ¯à¨«®¦¥­¨¥ ᪠砥⠯®á«¥¤­îî ¢¥àá¨î KolibriOS ¨ à á¯ ªã¥â ¥¥ ­  RAM-¤¨áª. à¨ í⮬ ï¤à® ­¥ ¡ã¤¥â ¯¥à¥§ ¯ã饭®, ¤«ï í⮣® ­¥®¡å®¤¨¬® á®åà ­¨âì ®¡à § ¨ ¯¥à¥§ £à㧨âáï. ®¦ «ã©áâ , § ªà®©â¥ ¢á¥ ®âªàëâë¥ ¯à¨«®¦¥­¨ï ¯¥à¥¤ ­ ç «®¬ ®¡­®¢«¥­¨ï.
  34.  
  35. ‚ˆŒ€ˆ…: ‚ᥠ¨§¬¥­­ë¥ ä ©«ë ­  RAM-¤¨áª¥ ¡ã¤ãâ ¯¥à¥§ ¯¨á ­ë!";
  36. #define T_INSTALL "Ž¡­®¢¨âì"
  37. #define T_COMPLETE "Ž¡­®¢«¥­¨¥ § ¢¥à襭®"
  38. #define T_EXIT "‚ë室"
  39. #define IMG_URL "http://builds.kolibrios.org/rus/data/data/kolibri.img"
  40. #else
  41. #define WINH 305
  42. #define T_WINDOW_TITLE "KolibriOS Online Updater"
  43. #define T_TITLE_H1 "ONLINE UPDATE"
  44. #define T_INTRO "This app will download the latest KolibriOS dirsto and update your RAM-disk with it. Kernel won't be restarted.
  45. Please close all opened apps before start.
  46.  
  47. ALERT: All chages on RAM-disk will be lost!";
  48. #define T_INSTALL "Update"
  49. #define T_COMPLETE "Update complete"
  50. #define T_EXIT "Exit"
  51. #define IMG_URL "http://builds.kolibrios.org/eng/data/data/kolibri.img"
  52. #endif
  53. char accept_language[]="en"; //not used, necessary for http.get()
  54.  
  55. void main()
  56. {
  57.         //load_dll(libini, #lib_init,1);
  58.         load_dll(libio, #libio_init,1);
  59.         load_dll(libimg, #libimg_init,1);
  60.         load_dll(libHTTP,   #http_lib_init,1);
  61.         SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_STACK);
  62.         loop() switch(WaitEventTimeout(300) & 0xFF)
  63.         {
  64.                 case evButton:
  65.                         if (GetButtonID() == 1) ExitProcess(); else EventInstall();
  66.                         break;
  67.          
  68.                 case evKey:
  69.                         GetKeys();
  70.                         if (key_scancode == SCAN_CODE_ESC) ExitProcess();
  71.                         if (key_scancode == SCAN_CODE_ENTER) {
  72.                                 if (install_complete) ExitProcess();
  73.                                 else EventInstall();
  74.                         }
  75.                         break;
  76.                  
  77.                 case evReDraw:
  78.                         draw_window();
  79.                         break;
  80.  
  81.                 case evNetwork:
  82.                         if (http.transfer <= 0) break;
  83.                         http.receive();
  84.                         if (http.content_length) {
  85.                                 progress.draw_progress(http.content_length - http.content_received * progress.w / http.content_length);
  86.                         }
  87.                         if (http.receive_result == 0) EventDownloadComplete();
  88.         }
  89. }
  90.  
  91. void draw_window()
  92. {
  93.         sc.get();
  94.         DefineAndDrawWindow(screen.width-WINW/2,screen.height-WINH/2,
  95.                 WINW+9,WINH+skin_height,0x34,sc.work,T_WINDOW_TITLE,0);
  96.         GetProcessInfo(#Form, -1);
  97.         WriteText(30, 20, 0x81, 0xEC008C, T_TITLE_H1);
  98.         if (install_complete) {
  99.                 DrawInstallComplete();
  100.         } else {
  101.                 DrawIntro();
  102.                 progress.set_size(30, WINH-130, WINW-60, 20);
  103.         }
  104. }
  105.  
  106. void DrawIntro()
  107. {
  108.         DrawTextViewArea(30, 50, WINW-60, WINH-80,
  109.                 T_INTRO, -1, sc.work_text);
  110.         DrawCaptButton(WINW-110/2, WINH-70, 110, 28, 9999,
  111.                 0x0092D8, 0xFFFfff, T_INSTALL);
  112. }
  113.  
  114. void DrawInstallComplete()
  115. {
  116.         DrawIcon32(WINW-32/2, 140, sc.work, 49);
  117.         WriteTextCenter(0,185, WINW, sc.work_text, T_COMPLETE);
  118.         DrawCaptButton(WINW-110/2, WINH-70, 110, 28, 1,
  119.                 0x0092D8, 0xFFFfff, T_EXIT);
  120. }
  121.  
  122. void EventInstall()
  123. {
  124.         http.get(IMG_URL);
  125. }
  126.  
  127. void EventDownloadComplete()
  128. {
  129.         dword unimg_id, slot_n;
  130.  
  131.         CreateFile(http.content_received, http.content_pointer, "/tmp0/1/latest.img");
  132.         http.free();
  133.  
  134.         unimg_id = RunProgram("/sys/unimg", "/tmp0/1/latest.img /tmp0/1/latest_img -e");
  135.         do {
  136.                 slot_n = GetProcessSlot(unimg_id);
  137.                 pause(10);
  138.         } while (slot_n!=0);
  139.  
  140.         copyf("/rd/1/settings", "/tmp0/1/settings_backup");
  141.         copyf("/tmp0/1/latest_img", "/rd/1");
  142.         copyf("/tmp0/1/settings_backup", "/rd/1/settings");
  143.  
  144.         RestartAllProcess();
  145.         install_complete = true;
  146.         draw_window();
  147. }
  148.  
  149. void RestartAllProcess() {
  150.         int i;
  151.         proc_info Process;
  152.         for (i=0; i<MAX_PROCESS_COUNT; i++;)
  153.         {
  154.                 GetProcessInfo(#Process, i);
  155.                 if (Process.name)
  156.                 && (!streq(#Process.name, "OS"))
  157.                 && (Process.ID != Form.ID)
  158.                         KillProcess(Process.ID);
  159.         }
  160.         RunProgram("/sys/launcher", NULL);
  161. }
  162.  
  163. void Operation_Draw_Progress(dword filename) { debug("copying: "); debugln(filename); }