Subversion Repositories Kolibri OS

Rev

Rev 7938 | Rev 8013 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
7938 leency 1
#define MEMSIZE 1024*460
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
#include "../lib/patterns/http_downloader.h"
15
 
16
#ifndef AUTOBUILD
17
#include "lang.h--"
18
#endif
19
 
20
_http http;
21
proc_info Form;
7939 leency 22
bool install_complete = false;
23
sensor progress;
7938 leency 24
 
7939 leency 25
#define WINW 460
7938 leency 26
 
7939 leency 27
//#define LANG_RUS 1
7938 leency 28
 
29
#ifdef LANG_RUS
7939 leency 30
#define WINH 345
31
#define T_WINDOW_TITLE "Онлайн обновление KolibriOS"
32
#define T_TITLE_H1 "ОНЛАЙН ОБНОВЛЕНИЕ"
33
#define T_INTRO "Данное приложение скачает последнюю версию KolibriOS и распакует ее на RAM-диск. При этом ядро не будет перезапущено, для этого необходимо сохранить образ и перезагрузится. Пожалуйста, закройте все открытые приложения перед началом обновления.
34
 
35
ВНИМАНИЕ: Все изменные файлы на RAM-диске будут перезаписаны!";
36
#define T_INSTALL "Обновить"
37
#define T_COMPLETE "Обновление завершено"
7938 leency 38
#define T_EXIT "Выход"
39
#define IMG_URL "http://builds.kolibrios.org/rus/data/data/kolibri.img"
40
#else
7939 leency 41
#define WINH 305
42
#define T_WINDOW_TITLE "KolibriOS Online Updater"
43
#define T_TITLE_H1 "ONLINE UPDATE"
44
#define T_INTRO "This app will download the latest KolibriOS dirsto and update your RAM-disk with it. Kernel won't be restarted.
45
Please close all opened apps before start.
46
 
47
ALERT: All chages on RAM-disk will be lost!";
7938 leency 48
#define T_INSTALL "Update"
49
#define T_COMPLETE "Update complete"
50
#define T_EXIT "Exit"
51
#define IMG_URL "http://builds.kolibrios.org/eng/data/data/kolibri.img"
52
#endif
7939 leency 53
char accept_language[]="en"; //not used, necessary for http.get()
7938 leency 54
 
55
void main()
56
{
57
	//load_dll(libini, #lib_init,1);
58
	load_dll(libio, #libio_init,1);
59
	load_dll(libimg, #libimg_init,1);
60
	load_dll(libHTTP,   #http_lib_init,1);
61
	SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_STACK);
62
	loop() switch(WaitEventTimeout(300) & 0xFF)
63
	{
64
		case evButton:
7939 leency 65
			if (GetButtonID() == 1) ExitProcess(); else EventInstall();
7938 leency 66
			break;
67
 
68
		case evKey:
69
			GetKeys();
70
			if (key_scancode == SCAN_CODE_ESC) ExitProcess();
71
			if (key_scancode == SCAN_CODE_ENTER) {
72
				if (install_complete) ExitProcess();
73
				else EventInstall();
74
			}
75
			break;
76
 
77
		case evReDraw:
78
			draw_window();
79
			break;
80
 
81
		case evNetwork:
82
			if (http.transfer <= 0) break;
83
			http.receive();
7939 leency 84
			if (http.content_length) {
85
				progress.draw_progress(http.content_length - http.content_received * progress.w / http.content_length);
86
			}
7938 leency 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,
7939 leency 95
		WINW+9,WINH+skin_height,0x34,sc.work,T_WINDOW_TITLE,0);
7938 leency 96
	GetProcessInfo(#Form, -1);
7939 leency 97
	WriteText(30, 20, 0x81, 0xEC008C, T_TITLE_H1);
98
	if (install_complete) {
99
		DrawInstallComplete();
100
	} else {
101
		DrawIntro();
102
		progress.set_size(30, WINH-130, WINW-60, 20);
103
	}
7938 leency 104
}
105
 
106
void DrawIntro()
107
{
108
	DrawTextViewArea(30, 50, WINW-60, WINH-80,
109
		T_INTRO, -1, sc.work_text);
110
	DrawCaptButton(WINW-110/2, WINH-70, 110, 28, 9999,
111
		0x0092D8, 0xFFFfff, T_INSTALL);
112
}
113
 
114
void DrawInstallComplete()
115
{
116
	DrawIcon32(WINW-32/2, 140, sc.work, 49);
117
	WriteTextCenter(0,185, WINW, sc.work_text, T_COMPLETE);
118
	DrawCaptButton(WINW-110/2, WINH-70, 110, 28, 1,
119
		0x0092D8, 0xFFFfff, T_EXIT);
120
}
121
 
122
void EventInstall()
123
{
124
	http.get(IMG_URL);
125
}
126
 
127
void EventDownloadComplete()
128
{
129
	dword unimg_id, slot_n;
130
 
7939 leency 131
	CreateFile(http.content_received, http.content_pointer, "/tmp0/1/latest.img");
7938 leency 132
	http.free();
133
 
7939 leency 134
	unimg_id = RunProgram("/sys/unimg", "/tmp0/1/latest.img /tmp0/1/latest_img -e");
7938 leency 135
	do {
136
		slot_n = GetProcessSlot(unimg_id);
137
		pause(10);
138
	} while (slot_n!=0);
139
 
7939 leency 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");
7938 leency 143
 
144
	RestartAllProcess();
145
	install_complete = true;
146
	draw_window();
147
}
148
 
149
void RestartAllProcess() {
150
	int i;
151
	proc_info Process;
152
	for (i=0; i
153
	{
154
		GetProcessInfo(#Process, i);
155
		if (Process.name)
156
		&& (!streq(#Process.name, "OS"))
157
		&& (Process.ID != Form.ID)
158
			KillProcess(Process.ID);
159
	}
160
	RunProgram("/sys/launcher", NULL);
161
}
162
 
163
void Operation_Draw_Progress(dword filename) { debug("copying: "); debugln(filename); }