2020-05-31 16:37:09 +02:00
|
|
|
|
#define MEMSIZE 1024*50
|
2020-05-17 17:52:41 +02:00
|
|
|
|
|
|
|
|
|
#include "../lib/gui.h"
|
|
|
|
|
#include "../lib/copyf.h"
|
|
|
|
|
|
|
|
|
|
#include "../lib/obj/http.h"
|
|
|
|
|
#include "../lib/obj/network.h"
|
|
|
|
|
|
|
|
|
|
#include "../lib/patterns/restart_process.h"
|
|
|
|
|
|
2020-05-17 20:05:05 +02:00
|
|
|
|
bool install_complete = false;
|
2020-05-31 16:37:09 +02:00
|
|
|
|
_http http;
|
2021-12-18 16:21:21 +01:00
|
|
|
|
dword unimg_id;
|
2020-05-17 17:52:41 +02:00
|
|
|
|
|
2020-05-17 20:05:05 +02:00
|
|
|
|
#define WINW 460
|
2021-12-18 16:21:21 +01:00
|
|
|
|
#define WINH 330
|
2020-05-17 17:52:41 +02:00
|
|
|
|
|
2020-05-17 20:05:05 +02:00
|
|
|
|
//#define LANG_RUS 1
|
2020-05-17 17:52:41 +02:00
|
|
|
|
|
|
|
|
|
#ifdef LANG_RUS
|
2020-05-17 20:05:05 +02:00
|
|
|
|
#define T_WINDOW_TITLE "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> KolibriOS"
|
2021-12-18 16:21:21 +01:00
|
|
|
|
#define T_TITLE_H1 "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"
|
2020-05-17 20:05:05 +02:00
|
|
|
|
#define T_INTRO "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ਫ<EFBFBD><E0A8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ᪠砥<E1AAA0> <20><><EFBFBD><E1ABA5><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> KolibriOS <20> <20><>ᯠ<EFBFBD><E1AFA0><EFBFBD><EFBFBD> <20><> <20><> RAM-<2D><><EFBFBD><EFBFBD>. <20><><EFBFBD> <20>⮬ <20><><EFBFBD><EFBFBD> <20><> <20>㤥<EFBFBD> <20><>१<EFBFBD><E0A5A7><EFBFBD>饭<EFBFBD>, <20><><EFBFBD> <20>⮣<EFBFBD> <20><><EFBFBD><EFBFBD>室<EFBFBD><E5AEA4><EFBFBD> <20><><EFBFBD>࠭<EFBFBD><E0A0AD><EFBFBD> <20><>ࠧ <20> <20><>१<EFBFBD><E0A5A7><EFBFBD>㧨<EFBFBD><E3A7A8><EFBFBD>. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD>ன<EFBFBD><E0AEA9> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ਫ<EFBFBD><E0A8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>। <20><>砫<EFBFBD><E7A0AB> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
|
|
|
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 䠩<EFBFBD><EFBFBD> <EFBFBD><EFBFBD> RAM-<EFBFBD><EFBFBD>᪥ <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>१<EFBFBD><EFBFBD><EFBFBD>ᠭ<EFBFBD>!";
|
|
|
|
|
#define T_INSTALL "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"
|
2021-12-18 16:21:21 +01:00
|
|
|
|
#define T_DOWNLOADING "<22><><EFBFBD>稢<EFBFBD><E7A8A2> ᢥ<><E1A2A5><EFBFBD> <20><>ࠧ kolibri.img..."
|
|
|
|
|
#define T_UNPACKING "<22><>ᯠ<EFBFBD><E1AFA0><EFBFBD>뢠<EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 䠩<><E4A0A9>..."
|
|
|
|
|
#define T_COMPLETE "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ᯥ譮 <20><><EFBFBD><EFBFBD><EFBFBD>襭<EFBFBD>."
|
2020-05-17 17:52:41 +02:00
|
|
|
|
#define T_EXIT "<22><>室"
|
|
|
|
|
#define IMG_URL "http://builds.kolibrios.org/rus/data/data/kolibri.img"
|
2020-05-31 16:37:09 +02:00
|
|
|
|
#define KS "<22><><EFBFBD>࠭<EFBFBD><E0A0AD><EFBFBD> <20><><EFBFBD><EFBFBD>ன<EFBFBD><E0AEA9>"
|
2020-05-17 17:52:41 +02:00
|
|
|
|
#else
|
2020-05-17 20:05:05 +02:00
|
|
|
|
#define T_WINDOW_TITLE "KolibriOS Online Updater"
|
2021-12-18 16:21:21 +01:00
|
|
|
|
#define T_TITLE_H1 "Online Updater"
|
2020-05-17 20:05:05 +02:00
|
|
|
|
#define T_INTRO "This app will download the latest KolibriOS dirsto and update your RAM-disk with it. Kernel won't be restarted.
|
|
|
|
|
Please close all opened apps before start.
|
2020-05-31 16:37:09 +02:00
|
|
|
|
Note that all changes on RAM-disk will be lost.";
|
2020-05-17 17:52:41 +02:00
|
|
|
|
#define T_INSTALL "Update"
|
2021-12-18 16:21:21 +01:00
|
|
|
|
#define T_DOWNLOADING "Downloading the latest kolibri.img..."
|
|
|
|
|
#define T_UNPACKING "Unpacking and copying files..."
|
|
|
|
|
#define T_COMPLETE "Update complete successfully."
|
2020-05-17 17:52:41 +02:00
|
|
|
|
#define T_EXIT "Exit"
|
|
|
|
|
#define IMG_URL "http://builds.kolibrios.org/eng/data/data/kolibri.img"
|
2020-05-31 16:37:09 +02:00
|
|
|
|
#define KS "Keep settings folder"
|
2020-05-17 17:52:41 +02:00
|
|
|
|
#endif
|
2020-05-17 20:05:05 +02:00
|
|
|
|
char accept_language[]="en"; //not used, necessary for http.get()
|
2020-05-31 16:37:09 +02:00
|
|
|
|
void Operation_Draw_Progress(dword f) {} //not used, necessary for copyf()
|
|
|
|
|
|
|
|
|
|
checkbox keep_settings = { KS, true };
|
2021-12-18 16:21:21 +01:00
|
|
|
|
sensor progress = { 40, WINH-70, WINW-80, 20 };
|
2020-05-17 17:52:41 +02:00
|
|
|
|
|
|
|
|
|
void main()
|
|
|
|
|
{
|
2020-05-31 16:37:09 +02:00
|
|
|
|
int btn;
|
2021-07-04 19:27:35 +02:00
|
|
|
|
load_dll(libHTTP, #http_lib_init,1);
|
2021-12-18 16:21:21 +01:00
|
|
|
|
SetWindowLayerBehaviour(-1, ZPOS_ALWAYS_TOP);
|
2020-05-31 16:37:09 +02:00
|
|
|
|
@SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_STACK);
|
|
|
|
|
loop() switch(@WaitEventTimeout(300))
|
2020-05-17 17:52:41 +02:00
|
|
|
|
{
|
2020-05-31 16:37:09 +02:00
|
|
|
|
case evButton:
|
|
|
|
|
btn = @GetButtonID();
|
|
|
|
|
if (btn<=2) ExitProcess();
|
|
|
|
|
if (btn==9) goto _INSTALL;
|
|
|
|
|
keep_settings.click(btn);
|
2020-05-17 17:52:41 +02:00
|
|
|
|
break;
|
2020-05-31 16:37:09 +02:00
|
|
|
|
|
2020-05-17 17:52:41 +02:00
|
|
|
|
case evKey:
|
2020-05-31 16:37:09 +02:00
|
|
|
|
switch (@GetKeyScancode()) {
|
|
|
|
|
case SCAN_CODE_ESC: ExitProcess();
|
|
|
|
|
case SCAN_CODE_ENTER:
|
|
|
|
|
if (install_complete) ExitProcess();
|
|
|
|
|
else {
|
|
|
|
|
_INSTALL:
|
|
|
|
|
http.get(IMG_URL);
|
|
|
|
|
goto _DRAW_WINDOW;
|
|
|
|
|
}
|
2020-05-17 17:52:41 +02:00
|
|
|
|
}
|
|
|
|
|
break;
|
2020-05-31 16:37:09 +02:00
|
|
|
|
|
2020-05-17 17:52:41 +02:00
|
|
|
|
case evReDraw:
|
2020-05-31 16:37:09 +02:00
|
|
|
|
_DRAW_WINDOW:
|
2021-12-18 16:21:21 +01:00
|
|
|
|
draw_window();
|
2020-05-17 17:52:41 +02:00
|
|
|
|
|
|
|
|
|
case evNetwork:
|
|
|
|
|
if (http.transfer <= 0) break;
|
|
|
|
|
http.receive();
|
2020-05-17 20:05:05 +02:00
|
|
|
|
if (http.content_length) {
|
2020-05-31 16:37:09 +02:00
|
|
|
|
progress.draw_progress(http.content_length - http.content_received
|
|
|
|
|
* progress.w / http.content_length);
|
|
|
|
|
}
|
|
|
|
|
if (!http.receive_result) {
|
|
|
|
|
CreateFile(http.content_received,
|
|
|
|
|
http.content_pointer, "/tmp0/1/latest.img");
|
2020-12-08 12:26:22 +01:00
|
|
|
|
http.stop();
|
2020-05-31 16:37:09 +02:00
|
|
|
|
EventDownloadComplete();
|
2020-05-17 20:05:05 +02:00
|
|
|
|
}
|
2020-05-17 17:52:41 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-18 16:21:21 +01:00
|
|
|
|
void draw_window()
|
|
|
|
|
{
|
|
|
|
|
sc.get();
|
|
|
|
|
DefineAndDrawWindow(screen.width-WINW/2,screen.height-WINH/2,
|
|
|
|
|
WINW+9,WINH+skin_height,0x34,sc.work,T_WINDOW_TITLE,0);
|
|
|
|
|
WriteText(30, 20, 0x91, 0xEC008C, T_TITLE_H1);
|
|
|
|
|
if (!install_complete) {
|
|
|
|
|
if (GetProcessSlot(unimg_id)) {
|
|
|
|
|
//UNPACKING
|
|
|
|
|
draw_icon_32(WINW-32/2, 140, sc.work, 89);
|
|
|
|
|
WriteTextCenter(0, 185, WINW, sc.work_text, T_UNPACKING);
|
|
|
|
|
} else if (http.transfer<=0) {
|
|
|
|
|
//INTRO
|
|
|
|
|
DrawTextViewArea(30, 65, WINW-60, WINH-80, T_INTRO, -1, sc.work_text);
|
|
|
|
|
DrawCaptButton(WINW-160, WINH-70, 110, 28, 9, 0x0092D8, 0xFFFfff, T_INSTALL);
|
|
|
|
|
keep_settings.draw(30, WINH-65);
|
|
|
|
|
} else {
|
|
|
|
|
//DOWNLOADING
|
|
|
|
|
draw_icon_32(WINW-32/2, 140, sc.work, 51);
|
|
|
|
|
WriteTextCenter(0, 185, WINW, sc.work_text, T_DOWNLOADING);
|
|
|
|
|
progress.draw_wrapper();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
//COMPLETE
|
|
|
|
|
draw_icon_32(WINW-32/2, 140, sc.work, 49);
|
|
|
|
|
WriteTextCenter(0, 185, WINW, sc.work_text, T_COMPLETE);
|
|
|
|
|
DrawCaptButton(WINW-110/2, WINH-70, 110, 28, 2,
|
|
|
|
|
0x0092D8, 0xFFFfff, T_EXIT);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-31 16:37:09 +02:00
|
|
|
|
dword GetFreeSpaceOfRamdisk()
|
2020-05-17 17:52:41 +02:00
|
|
|
|
{
|
2020-05-31 16:37:09 +02:00
|
|
|
|
dword rdempty = malloc(1440*1024);
|
2021-06-13 16:09:46 +02:00
|
|
|
|
CreateFile(0, 1440*1024, rdempty, "/sys/rdempty");
|
2020-05-31 16:37:09 +02:00
|
|
|
|
free(rdempty);
|
2021-06-13 16:09:46 +02:00
|
|
|
|
rdempty = get_file_size("/sys/rdempty");
|
|
|
|
|
DeleteFile("/sys/rdempty");
|
2020-05-31 16:37:09 +02:00
|
|
|
|
return rdempty;
|
2020-05-17 17:52:41 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-31 16:37:09 +02:00
|
|
|
|
signed CheckFreeSpace(dword _latest, _combined)
|
2020-05-17 17:52:41 +02:00
|
|
|
|
{
|
2020-05-31 16:37:09 +02:00
|
|
|
|
dword cur_size, new_size, empty;
|
|
|
|
|
DIR_SIZE dir_size;
|
2020-05-17 17:52:41 +02:00
|
|
|
|
|
2020-05-31 16:37:09 +02:00
|
|
|
|
dir_size.get("/sys");
|
|
|
|
|
cur_size = dir_size.bytes;
|
2020-05-17 17:52:41 +02:00
|
|
|
|
|
2020-05-31 16:37:09 +02:00
|
|
|
|
copyf("/sys", _combined);
|
|
|
|
|
copyf(_latest, _combined);
|
|
|
|
|
dir_size.get(_combined);
|
|
|
|
|
new_size = dir_size.bytes;
|
|
|
|
|
|
|
|
|
|
empty = GetFreeSpaceOfRamdisk();
|
|
|
|
|
|
|
|
|
|
return cur_size + empty - new_size / 1024;
|
2020-05-17 17:52:41 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EventDownloadComplete()
|
|
|
|
|
{
|
2021-12-18 16:21:21 +01:00
|
|
|
|
dword slot_n;
|
2020-05-31 16:37:09 +02:00
|
|
|
|
signed space_delta;
|
|
|
|
|
int i=0;
|
|
|
|
|
|
|
|
|
|
char osupdate[32];
|
|
|
|
|
char latest[40];
|
|
|
|
|
char backup[40];
|
|
|
|
|
char combined[40];
|
|
|
|
|
char exract_param[64];
|
|
|
|
|
char backup_settings[64];
|
|
|
|
|
|
2021-12-18 16:21:21 +01:00
|
|
|
|
do { miniprintf(#osupdate, "/tmp0/1/osupdate%d", i); i++;
|
2020-05-31 16:37:09 +02:00
|
|
|
|
} while (dir_exists(#osupdate));
|
|
|
|
|
CreateDir(#osupdate);
|
|
|
|
|
|
2021-12-18 16:21:21 +01:00
|
|
|
|
miniprintf(#latest, "%s/latest", #osupdate);
|
|
|
|
|
miniprintf(#backup, "%s/rdbackup", #osupdate);
|
|
|
|
|
miniprintf(#combined, "%s/combined", #osupdate);
|
|
|
|
|
miniprintf(#backup_settings, "%s/settings", #backup);
|
|
|
|
|
miniprintf(#exract_param, "/tmp0/1/latest.img %s -e", #latest);
|
2020-05-17 17:52:41 +02:00
|
|
|
|
|
2020-05-31 16:37:09 +02:00
|
|
|
|
unimg_id = RunProgram("/sys/unimg", #exract_param);
|
2021-12-18 16:21:21 +01:00
|
|
|
|
draw_window();
|
|
|
|
|
|
2020-05-17 17:52:41 +02:00
|
|
|
|
do {
|
|
|
|
|
slot_n = GetProcessSlot(unimg_id);
|
|
|
|
|
pause(10);
|
|
|
|
|
} while (slot_n!=0);
|
|
|
|
|
|
2020-05-31 16:37:09 +02:00
|
|
|
|
space_delta = CheckFreeSpace(#latest, #combined);
|
|
|
|
|
if (space_delta<0) {
|
2021-12-18 16:21:21 +01:00
|
|
|
|
miniprintf(#param, "'Not enought free space! You need %d KB more.'E", -space_delta);
|
2020-05-31 16:37:09 +02:00
|
|
|
|
notify(#param);
|
|
|
|
|
} else {
|
|
|
|
|
copyf("/sys", #backup);
|
|
|
|
|
copyf(#latest, "/sys");
|
2021-06-13 16:09:46 +02:00
|
|
|
|
if (keep_settings.checked) copyf(#backup_settings, "/sys/settings");
|
2020-05-31 16:37:09 +02:00
|
|
|
|
install_complete = true;
|
2020-05-17 17:52:41 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-31 16:37:09 +02:00
|
|
|
|
|
|
|
|
|
|