Subversion Repositories Kolibri OS

Rev

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