Rev 9597 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
8013 | leency | 1 | #define MEMSIZE 1024*50 |
7938 | leency | 2 | |
3 | #include "../lib/gui.h" |
||
4 | #include "../lib/copyf.h" |
||
5 | |||
6 | #include "../lib/obj/http.h" |
||
7 | #include "../lib/obj/network.h" |
||
8 | |||
9 | #include "../lib/patterns/restart_process.h" |
||
10 | |||
8013 | leency | 11 | bool install_complete = false; |
7938 | leency | 12 | _http http; |
9439 | leency | 13 | dword unimg_id; |
7938 | leency | 14 | |
7939 | leency | 15 | #define WINW 460 |
9439 | leency | 16 | #define WINH 330 |
7938 | leency | 17 | |
7939 | leency | 18 | //#define LANG_RUS 1 |
7938 | leency | 19 | |
20 | #ifdef LANG_RUS |
||
7939 | leency | 21 | #define T_WINDOW_TITLE "Онлайн обновление KolibriOS" |
9439 | leency | 22 | #define T_TITLE_H1 "Онлайн обновление" |
7939 | leency | 23 | #define T_INTRO "Данное приложение скачает последнюю версию KolibriOS и распакует ее на RAM-диск. При этом ядро не будет перезапущено, для этого необходимо сохранить образ и перезагрузится. Пожалуйста, закройте все открытые приложения перед началом обновления. |
24 | ВНИМАНИЕ: Все изменные файлы на RAM-диске будут перезаписаны!"; |
||
25 | #define T_INSTALL "Обновить" |
||
9439 | leency | 26 | #define T_DOWNLOADING "Скачиваю свежий образ kolibri.img..." |
27 | #define T_UNPACKING "Распаковываю и копирую файлы..." |
||
28 | #define T_COMPLETE "Обновление успешно завершено." |
||
7938 | leency | 29 | #define T_EXIT "Выход" |
30 | #define IMG_URL "http://builds.kolibrios.org/rus/data/data/kolibri.img" |
||
8013 | leency | 31 | #define KS "Сохранить настройки" |
7938 | leency | 32 | #else |
7939 | leency | 33 | #define T_WINDOW_TITLE "KolibriOS Online Updater" |
9439 | leency | 34 | #define T_TITLE_H1 "Online Updater" |
7939 | leency | 35 | #define T_INTRO "This app will download the latest KolibriOS dirsto and update your RAM-disk with it. Kernel won't be restarted. |
36 | Please close all opened apps before start. |
||
8013 | leency | 37 | Note that all changes on RAM-disk will be lost."; |
7938 | leency | 38 | #define T_INSTALL "Update" |
9439 | leency | 39 | #define T_DOWNLOADING "Downloading the latest kolibri.img..." |
40 | #define T_UNPACKING "Unpacking and copying files..." |
||
41 | #define T_COMPLETE "Update complete successfully." |
||
7938 | leency | 42 | #define T_EXIT "Exit" |
43 | #define IMG_URL "http://builds.kolibrios.org/eng/data/data/kolibri.img" |
||
8013 | leency | 44 | #define KS "Keep settings folder" |
7938 | leency | 45 | #endif |
7939 | leency | 46 | char accept_language[]="en"; //not used, necessary for http.get() |
8013 | leency | 47 | void Operation_Draw_Progress(dword f) {} //not used, necessary for copyf() |
7938 | leency | 48 | |
8013 | leency | 49 | checkbox keep_settings = { KS, true }; |
9439 | leency | 50 | sensor progress = { 40, WINH-70, WINW-80, 20 }; |
8013 | leency | 51 | |
7938 | leency | 52 | void main() |
53 | { |
||
8013 | leency | 54 | int btn; |
9536 | punk_joker | 55 | saved_state = FILE_REPLACE; |
8996 | leency | 56 | load_dll(libHTTP, #http_lib_init,1); |
9439 | leency | 57 | SetWindowLayerBehaviour(-1, ZPOS_ALWAYS_TOP); |
8013 | leency | 58 | @SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_STACK); |
59 | loop() switch(@WaitEventTimeout(300)) |
||
7938 | leency | 60 | { |
8013 | leency | 61 | case evButton: |
62 | btn = @GetButtonID(); |
||
63 | if (btn<=2) ExitProcess(); |
||
64 | if (btn==9) goto _INSTALL; |
||
65 | keep_settings.click(btn); |
||
7938 | leency | 66 | break; |
8013 | leency | 67 | |
7938 | leency | 68 | case evKey: |
8013 | leency | 69 | switch (@GetKeyScancode()) { |
70 | case SCAN_CODE_ESC: ExitProcess(); |
||
71 | case SCAN_CODE_ENTER: |
||
72 | if (install_complete) ExitProcess(); |
||
73 | else { |
||
74 | _INSTALL: |
||
75 | http.get(IMG_URL); |
||
76 | goto _DRAW_WINDOW; |
||
77 | } |
||
7938 | leency | 78 | } |
79 | break; |
||
8013 | leency | 80 | |
7938 | leency | 81 | case evReDraw: |
8013 | leency | 82 | _DRAW_WINDOW: |
9439 | leency | 83 | draw_window(); |
7938 | leency | 84 | |
85 | case evNetwork: |
||
86 | if (http.transfer <= 0) break; |
||
87 | http.receive(); |
||
7939 | leency | 88 | if (http.content_length) { |
8013 | leency | 89 | progress.draw_progress(http.content_length - http.content_received |
90 | * progress.w / http.content_length); |
||
7939 | leency | 91 | } |
8013 | leency | 92 | if (!http.receive_result) { |
93 | CreateFile(http.content_received, |
||
94 | http.content_pointer, "/tmp0/1/latest.img"); |
||
8339 | leency | 95 | http.stop(); |
8013 | leency | 96 | EventDownloadComplete(); |
97 | } |
||
7938 | leency | 98 | } |
99 | } |
||
100 | |||
9439 | leency | 101 | void draw_window() |
102 | { |
||
103 | sc.get(); |
||
9597 | leency | 104 | DefineAndDrawWindow(screen.w-WINW/2,screen.h-WINH/2, |
105 | WINW+9,WINH+skin_h,0x34,sc.work,T_WINDOW_TITLE,0); |
||
9439 | leency | 106 | WriteText(30, 20, 0x91, 0xEC008C, T_TITLE_H1); |
107 | if (!install_complete) { |
||
108 | if (GetProcessSlot(unimg_id)) { |
||
109 | //UNPACKING |
||
110 | draw_icon_32(WINW-32/2, 140, sc.work, 89); |
||
111 | WriteTextCenter(0, 185, WINW, sc.work_text, T_UNPACKING); |
||
112 | } else if (http.transfer<=0) { |
||
113 | //INTRO |
||
114 | DrawTextViewArea(30, 65, WINW-60, WINH-80, T_INTRO, -1, sc.work_text); |
||
115 | DrawCaptButton(WINW-160, WINH-70, 110, 28, 9, 0x0092D8, 0xFFFfff, T_INSTALL); |
||
116 | keep_settings.draw(30, WINH-65); |
||
117 | } else { |
||
118 | //DOWNLOADING |
||
119 | draw_icon_32(WINW-32/2, 140, sc.work, 51); |
||
120 | WriteTextCenter(0, 185, WINW, sc.work_text, T_DOWNLOADING); |
||
121 | progress.draw_wrapper(); |
||
122 | } |
||
123 | } else { |
||
124 | //COMPLETE |
||
125 | draw_icon_32(WINW-32/2, 140, sc.work, 49); |
||
126 | WriteTextCenter(0, 185, WINW, sc.work_text, T_COMPLETE); |
||
127 | DrawCaptButton(WINW-110/2, WINH-70, 110, 28, 2, |
||
128 | 0x0092D8, 0xFFFfff, T_EXIT); |
||
129 | } |
||
130 | } |
||
131 | |||
8013 | leency | 132 | dword GetFreeSpaceOfRamdisk() |
7938 | leency | 133 | { |
8013 | leency | 134 | dword rdempty = malloc(1440*1024); |
8839 | leency | 135 | CreateFile(0, 1440*1024, rdempty, "/sys/rdempty"); |
8013 | leency | 136 | free(rdempty); |
8839 | leency | 137 | rdempty = get_file_size("/sys/rdempty"); |
138 | DeleteFile("/sys/rdempty"); |
||
8013 | leency | 139 | return rdempty; |
7938 | leency | 140 | } |
141 | |||
8013 | leency | 142 | signed CheckFreeSpace(dword _latest, _combined) |
7938 | leency | 143 | { |
8013 | leency | 144 | dword cur_size, new_size, empty; |
145 | DIR_SIZE dir_size; |
||
7938 | leency | 146 | |
8013 | leency | 147 | dir_size.get("/sys"); |
9694 | leency | 148 | cur_size = dir_size.sizelo; |
7938 | leency | 149 | |
8013 | leency | 150 | copyf("/sys", _combined); |
151 | copyf(_latest, _combined); |
||
152 | dir_size.get(_combined); |
||
9694 | leency | 153 | new_size = dir_size.sizelo; |
8013 | leency | 154 | |
155 | empty = GetFreeSpaceOfRamdisk(); |
||
156 | |||
157 | return cur_size + empty - new_size / 1024; |
||
7938 | leency | 158 | } |
159 | |||
160 | void EventDownloadComplete() |
||
161 | { |
||
9439 | leency | 162 | dword slot_n; |
8013 | leency | 163 | signed space_delta; |
164 | int i=0; |
||
7938 | leency | 165 | |
8013 | leency | 166 | char osupdate[32]; |
167 | char latest[40]; |
||
168 | char backup[40]; |
||
169 | char combined[40]; |
||
170 | char exract_param[64]; |
||
171 | char backup_settings[64]; |
||
7938 | leency | 172 | |
9439 | leency | 173 | do { miniprintf(#osupdate, "/tmp0/1/osupdate%d", i); i++; |
8013 | leency | 174 | } while (dir_exists(#osupdate)); |
175 | CreateDir(#osupdate); |
||
176 | |||
9439 | leency | 177 | miniprintf(#latest, "%s/latest", #osupdate); |
178 | miniprintf(#backup, "%s/rdbackup", #osupdate); |
||
179 | miniprintf(#combined, "%s/combined", #osupdate); |
||
180 | miniprintf(#backup_settings, "%s/settings", #backup); |
||
181 | miniprintf(#exract_param, "/tmp0/1/latest.img %s -e", #latest); |
||
8013 | leency | 182 | |
9439 | leency | 183 | unimg_id = RunProgram("/sys/unimg", #exract_param); |
184 | draw_window(); |
||
8013 | leency | 185 | |
7938 | leency | 186 | do { |
187 | slot_n = GetProcessSlot(unimg_id); |
||
188 | pause(10); |
||
189 | } while (slot_n!=0); |
||
190 | |||
8013 | leency | 191 | space_delta = CheckFreeSpace(#latest, #combined); |
192 | if (space_delta<0) { |
||
9439 | leency | 193 | miniprintf(#param, "'Not enought free space! You need %d KB more.'E", -space_delta); |
8013 | leency | 194 | notify(#param); |
195 | } else { |
||
196 | copyf("/sys", #backup); |
||
197 | copyf(#latest, "/sys"); |
||
8839 | leency | 198 | if (keep_settings.checked) copyf(#backup_settings, "/sys/settings"); |
8013 | leency | 199 | install_complete = true; |
7938 | leency | 200 | } |
201 | }0)>=0)>=>=2)> |
||
202 |