Subversion Repositories Kolibri OS

Rev

Rev 7939 | Rev 8291 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7939 Rev 8013
Line 1... Line 1...
1
#define MEMSIZE 1024*460
1
#define MEMSIZE 1024*50
Line 2... Line 2...
2
 
2
 
3
#include "../lib/io.h"
3
#include "../lib/io.h"
4
#include "../lib/gui.h"
4
#include "../lib/gui.h"
Line 15... Line 15...
15
 
15
 
16
#ifndef AUTOBUILD
16
#ifndef AUTOBUILD
17
#include "lang.h--"
17
#include "lang.h--"
Line 18... Line -...
18
#endif
-
 
19
 
-
 
20
_http http;
18
#endif
21
proc_info Form;
19
 
Line 22... Line 20...
22
bool install_complete = false;
20
bool install_complete = false;
-
 
21
_http http;
Line 23... Line 22...
23
sensor progress;
22
 
Line 24... Line 23...
24
 
23
#define WINW 460
25
#define WINW 460
-
 
26
 
24
#define WINH 380
27
//#define LANG_RUS 1
25
 
28
 
26
//#define LANG_RUS 1
29
#ifdef LANG_RUS
-
 
30
#define WINH 345
27
 
31
#define T_WINDOW_TITLE "Ž­« ©­ ®¡­®¢«¥­¨¥ KolibriOS"
28
#ifdef LANG_RUS
32
#define T_TITLE_H1 "Ž‹€‰ ŽŽ‚‹…ˆ…"
29
#define T_WINDOW_TITLE "Ž­« ©­ ®¡­®¢«¥­¨¥ KolibriOS"
33
#define T_INTRO "„ ­­®¥ ¯à¨«®¦¥­¨¥ ᪠砥⠯®á«¥¤­îî ¢¥àá¨î KolibriOS ¨ à á¯ ªã¥â ¥¥ ­  RAM-¤¨áª. à¨ í⮬ ï¤à® ­¥ ¡ã¤¥â ¯¥à¥§ ¯ã饭®, ¤«ï í⮣® ­¥®¡å®¤¨¬® á®åà ­¨âì ®¡à § ¨ ¯¥à¥§ £à㧨âáï. ®¦ «ã©áâ , § ªà®©â¥ ¢á¥ ®âªàëâë¥ ¯à¨«®¦¥­¨ï ¯¥à¥¤ ­ ç «®¬ ®¡­®¢«¥­¨ï.
30
#define T_TITLE_H1 "Ž‹€‰ ŽŽ‚‹…ˆ…"
34
 
31
#define T_INTRO "„ ­­®¥ ¯à¨«®¦¥­¨¥ ᪠砥⠯®á«¥¤­îî ¢¥àá¨î KolibriOS ¨ à á¯ ªã¥â ¥¥ ­  RAM-¤¨áª. à¨ í⮬ ï¤à® ­¥ ¡ã¤¥â ¯¥à¥§ ¯ã饭®, ¤«ï í⮣® ­¥®¡å®¤¨¬® á®åà ­¨âì ®¡à § ¨ ¯¥à¥§ £à㧨âáï. ®¦ «ã©áâ , § ªà®©â¥ ¢á¥ ®âªàëâë¥ ¯à¨«®¦¥­¨ï ¯¥à¥¤ ­ ç «®¬ ®¡­®¢«¥­¨ï.
-
 
32
‚ˆŒ€ˆ…: ‚ᥠ¨§¬¥­­ë¥ ä ©«ë ­  RAM-¤¨áª¥ ¡ã¤ãâ ¯¥à¥§ ¯¨á ­ë!"; 
-
 
33
#define T_INSTALL "Ž¡­®¢¨âì"
35
‚ˆŒ€ˆ…: ‚ᥠ¨§¬¥­­ë¥ ä ©«ë ­  RAM-¤¨áª¥ ¡ã¤ãâ ¯¥à¥§ ¯¨á ­ë!"; 
34
#define T_COMPLETE "Ž¡­®¢«¥­¨¥ § ¢¥à襭®"
36
#define T_INSTALL "Ž¡­®¢¨âì"
-
 
37
#define T_COMPLETE "Ž¡­®¢«¥­¨¥ § ¢¥à襭®"
35
#define T_EXIT "‚ë室"
38
#define T_EXIT "‚ë室"
36
#define IMG_URL "http://builds.kolibrios.org/rus/data/data/kolibri.img"
39
#define IMG_URL "http://builds.kolibrios.org/rus/data/data/kolibri.img"
37
#define KS "‘®åà ­¨âì ­ áâனª¨"
40
#else
38
#define RA "¥à¥§ ¯ãáâ¨âì ¢á¥ ¯à®£à ¬¬ë"
41
#define WINH 305
-
 
42
#define T_WINDOW_TITLE "KolibriOS Online Updater"
39
#else
43
#define T_TITLE_H1 "ONLINE UPDATE"
40
#define T_WINDOW_TITLE "KolibriOS Online Updater"
44
#define T_INTRO "This app will download the latest KolibriOS dirsto and update your RAM-disk with it. Kernel won't be restarted. 
41
#define T_TITLE_H1 "ONLINE UPDATE"
45
Please close all opened apps before start.
42
#define T_INTRO "This app will download the latest KolibriOS dirsto and update your RAM-disk with it. Kernel won't be restarted. 
46
 
43
Please close all opened apps before start.
-
 
44
Note that all changes on RAM-disk will be lost."; 
-
 
45
#define T_INSTALL "Update"
47
ALERT: All chages on RAM-disk will be lost!"; 
46
#define T_COMPLETE "Update complete"
48
#define T_INSTALL "Update"
47
#define T_EXIT "Exit"
-
 
48
#define IMG_URL "http://builds.kolibrios.org/eng/data/data/kolibri.img"
-
 
49
#define KS "Keep settings folder"
-
 
50
#define RA "Restart all apps"
-
 
51
#endif
Line 49... Line 52...
49
#define T_COMPLETE "Update complete"
52
char accept_language[]="en"; //not used, necessary for http.get()
50
#define T_EXIT "Exit"
53
void Operation_Draw_Progress(dword f) {} //not used, necessary for copyf()
-
 
54
 
51
#define IMG_URL "http://builds.kolibrios.org/eng/data/data/kolibri.img"
55
checkbox keep_settings = { KS, true };
52
#endif
56
checkbox restart_apps = { RA, true };
53
char accept_language[]="en"; //not used, necessary for http.get()
57
 
54
 
58
void main()
55
void main()
59
{
56
{
60
	int btn;
57
	//load_dll(libini, #lib_init,1);
61
	sensor progress;
58
	load_dll(libio, #libio_init,1);
62
	load_dll(libio, #libio_init,1);
-
 
63
	load_dll(libimg, #libimg_init,1);
59
	load_dll(libimg, #libimg_init,1);
64
	load_dll(libHTTP,   #http_lib_init,1);
-
 
65
	@SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_STACK);
-
 
66
	loop() switch(@WaitEventTimeout(300))
-
 
67
	{
60
	load_dll(libHTTP,   #http_lib_init,1);
68
		case evButton: 
Line 61... Line 69...
61
	SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_STACK);
69
			btn = @GetButtonID();
62
	loop() switch(WaitEventTimeout(300) & 0xFF)
70
			if (btn<=2) ExitProcess();
63
	{
71
			if (btn==9) goto _INSTALL; 
64
		case evButton:
72
			keep_settings.click(btn);
65
			if (GetButtonID() == 1) ExitProcess(); else EventInstall();
73
			restart_apps.click(btn);
-
 
74
			break;
-
 
75
 
66
			break;
76
		case evKey:
-
 
77
			switch (@GetKeyScancode()) {
-
 
78
				case SCAN_CODE_ESC: ExitProcess();
67
	  
79
				case SCAN_CODE_ENTER: 
68
		case evKey:
80
					if (install_complete) ExitProcess();
Line 69... Line 81...
69
			GetKeys();
81
					else {
-
 
82
						_INSTALL: 
70
			if (key_scancode == SCAN_CODE_ESC) ExitProcess();
83
						http.get(IMG_URL); 
-
 
84
						goto _DRAW_WINDOW;
-
 
85
						}
-
 
86
			}
-
 
87
			break;
-
 
88
 
-
 
89
		case evReDraw:
-
 
90
			_DRAW_WINDOW:
-
 
91
			sc.get();
-
 
92
			DefineAndDrawWindow(screen.width-WINW/2,screen.height-WINH/2,
-
 
93
				WINW+9,WINH+skin_height,0x34,sc.work,T_WINDOW_TITLE,0);
-
 
94
			WriteText(30, 20, 0x81, 0xEC008C, T_TITLE_H1);
71
			if (key_scancode == SCAN_CODE_ENTER) {
95
			if (!install_complete) {
-
 
96
					DrawTextViewArea(30, 50, WINW-60, WINH-80, T_INTRO, -1, sc.work_text);
-
 
97
					progress.set_size(30, WINH-130, WINW-60, 20);
-
 
98
					if (http.transfer<=0) {
-
 
99
						DrawCaptButton(WINW-110/2, WINH-70, 110, 28, 9, 0x0092D8, 0xFFFfff, T_INSTALL);
-
 
100
						keep_settings.draw(30, WINH - 210);
Line 72... Line 101...
72
				if (install_complete) ExitProcess();
101
						restart_apps.draw(30, WINH - 185);
73
				else EventInstall();
102
					}
74
			}
103
			} else {
75
			break;
104
					DrawIcon32(WINW-32/2, 140, sc.work, 49);
76
		 
105
					WriteTextCenter(0,185, WINW, sc.work_text, T_COMPLETE);
-
 
106
					DrawCaptButton(WINW-110/2, WINH-70, 110, 28, 2, 
77
		case evReDraw:
107
						0x0092D8, 0xFFFfff, T_EXIT);
78
			draw_window();
108
			}
-
 
109
 
-
 
110
		case evNetwork:
-
 
111
			if (http.transfer <= 0) break;
-
 
112
			http.receive();
79
			break;
113
			if (http.content_length) {
80
 
114
				progress.draw_progress(http.content_length - http.content_received 
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);
115
					* progress.w / http.content_length);
Line 96... Line 116...
96
	GetProcessInfo(#Form, -1);
116
			}
97
	WriteText(30, 20, 0x81, 0xEC008C, T_TITLE_H1);
117
			if (!http.receive_result) {
98
	if (install_complete) {
118
				CreateFile(http.content_received, 
99
		DrawInstallComplete(); 
119
					http.content_pointer, "/tmp0/1/latest.img");
-
 
120
				http.free();
100
	} else {
121
				EventDownloadComplete();
-
 
122
			}
101
		DrawIntro();
123
	}
-
 
124
}
102
		progress.set_size(30, WINH-130, WINW-60, 20);
125
 
Line 103... Line 126...
103
	}
126
dword GetFreeSpaceOfRamdisk()
104
}
127
{
105
 
128
	dword rdempty = malloc(1440*1024);
106
void DrawIntro()
-
 
107
{
-
 
108
	DrawTextViewArea(30, 50, WINW-60, WINH-80, 
129
	CreateFile(0, 1440*1024, rdempty, "/rd/1/rdempty");
109
		T_INTRO, -1, sc.work_text);
-
 
Line 110... Line 130...
110
	DrawCaptButton(WINW-110/2, WINH-70, 110, 28, 9999, 
130
	free(rdempty);
-
 
131
	file_size stdcall ("/rd/1/rdempty");
111
		0x0092D8, 0xFFFfff, T_INSTALL);
132
	rdempty = EBX;
-
 
133
	DeleteFile("/rd/1/rdempty");
-
 
134
	return rdempty;
112
}
135
}
-
 
136
 
-
 
137
signed CheckFreeSpace(dword _latest, _combined)
-
 
138
{
-
 
139
	dword cur_size, new_size, empty;
-
 
140
	DIR_SIZE dir_size;
113
 
141
 
Line 114... Line 142...
114
void DrawInstallComplete()
142
	dir_size.get("/sys");
115
{
143
	cur_size = dir_size.bytes;
116
	DrawIcon32(WINW-32/2, 140, sc.work, 49);
144
 
-
 
145
	copyf("/sys", _combined);
-
 
146
	copyf(_latest, _combined);
-
 
147
	dir_size.get(_combined);
-
 
148
	new_size = dir_size.bytes;
-
 
149
 
-
 
150
	empty = GetFreeSpaceOfRamdisk();
-
 
151
 
-
 
152
	return cur_size + empty - new_size / 1024;
-
 
153
}
-
 
154
 
-
 
155
void EventDownloadComplete()
-
 
156
{
-
 
157
	dword unimg_id, slot_n;
-
 
158
	signed space_delta;
-
 
159
	int i=0;
-
 
160
 
-
 
161
	char osupdate[32];
-
 
162
	char latest[40];
-
 
163
	char backup[40];
Line 117... Line -...
117
	WriteTextCenter(0,185, WINW, sc.work_text, T_COMPLETE);
-
 
118
	DrawCaptButton(WINW-110/2, WINH-70, 110, 28, 1, 
-
 
Line 119... Line 164...
119
		0x0092D8, 0xFFFfff, T_EXIT);
164
	char combined[40];
120
}
165
	char exract_param[64];
121
 
166
	char backup_settings[64];
122
void EventInstall()
167
 
123
{
168
	do  { sprintf(#osupdate, "/tmp0/1/osupdate%d", i); i++;
Line -... Line 169...
-
 
169
	} while (dir_exists(#osupdate));
-
 
170
	CreateDir(#osupdate);
-
 
171
 
-
 
172
	sprintf(#latest, "%s/latest", #osupdate);
-
 
173
	sprintf(#backup, "%s/rdbackup", #osupdate);
124
	http.get(IMG_URL);
174
	sprintf(#combined, "%s/combined", #osupdate);
125
}
175
	sprintf(#backup_settings, "%s/settings", #backup);
126
 
176
	sprintf(#exract_param, "/tmp0/1/latest.img %s -e", #latest);
127
void EventDownloadComplete()
-
 
128
{
177
 
129
	dword unimg_id, slot_n;
178
 
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
 
179
	unimg_id = RunProgram("/sys/unimg", #exract_param);
144
	RestartAllProcess();
-
 
145
	install_complete = true;
180
	do {
Line 146... Line -...
146
	draw_window();
-
 
147
}
181
		slot_n = GetProcessSlot(unimg_id);
-
 
182
		pause(10);
-
 
183
	} while (slot_n!=0);