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