Subversion Repositories Kolibri OS

Rev

Rev 7939 | Go to most recent revision | Details | 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;
22
 
23
#define WINW 400
24
#define WINH 300
25
 
26
char accept_language[]="en"; //not used, necessary for http.get()
27
 
28
#ifdef LANG_RUS
29
#define T_INTRO "Попробуйте новое визуальное оформление Колибри, которое раньше было доступно только в KolibriNext.";
30
#define T_INSTALL "Установить"
31
#define T_COMPLETE "Установка завершена"
32
#define T_EXIT "Выход"
33
#define IMG_URL "http://builds.kolibrios.org/rus/data/data/kolibri.img"
34
#else
35
#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.";
36
#define T_INSTALL "Update"
37
#define T_COMPLETE "Update complete"
38
#define T_EXIT "Exit"
39
#define IMG_URL "http://builds.kolibrios.org/eng/data/data/kolibri.img"
40
#endif
41
 
42
 
43
bool install_complete = false;
44
 
45
void main()
46
{
47
	word btn;
48
	//load_dll(libini, #lib_init,1);
49
	load_dll(libio, #libio_init,1);
50
	load_dll(libimg, #libimg_init,1);
51
	load_dll(libHTTP,   #http_lib_init,1);
52
	SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_STACK);
53
	loop() switch(WaitEventTimeout(300) & 0xFF)
54
	{
55
		case evButton:
56
			btn = GetButtonID();
57
			if (btn == 1) ExitProcess();
58
			else EventInstall();
59
			break;
60
 
61
		case evKey:
62
			GetKeys();
63
			if (key_scancode == SCAN_CODE_ESC) ExitProcess();
64
			if (key_scancode == SCAN_CODE_ENTER) {
65
				if (install_complete) ExitProcess();
66
				else EventInstall();
67
			}
68
			break;
69
 
70
		case evReDraw:
71
			draw_window();
72
			break;
73
 
74
		case evNetwork:
75
			if (http.transfer <= 0) break;
76
			http.receive();
77
			if (http.content_length) DrawProgressBar(30, WINH-140, WINW-60, 20, sc.work, 0xC3C3C3,
78
				0x54B1D6, sc.work_text, 100 * http.content_received / http.content_length);
79
			if (http.receive_result == 0) EventDownloadComplete();
80
	}
81
}
82
 
83
void draw_window()
84
{
85
	sc.get();
86
	DefineAndDrawWindow(screen.width-WINW/2,screen.height-WINH/2,
87
		WINW+9,WINH+skin_height,0x34,sc.work,"KolibriOS Online Updater",0);
88
	GetProcessInfo(#Form, -1);
89
	WriteText(30, 20, 0x81, 0xEC008C, "ONLINE UPDATE");
90
	if (install_complete) DrawInstallComplete(); else DrawIntro();
91
}
92
 
93
void DrawIntro()
94
{
95
	DrawTextViewArea(30, 50, WINW-60, WINH-80,
96
		T_INTRO, -1, sc.work_text);
97
	DrawCaptButton(WINW-110/2, WINH-70, 110, 28, 9999,
98
		0x0092D8, 0xFFFfff, T_INSTALL);
99
}
100
 
101
void DrawInstallComplete()
102
{
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, 1,
106
		0x0092D8, 0xFFFfff, T_EXIT);
107
}
108
 
109
void EventInstall()
110
{
111
	http.get(IMG_URL);
112
}
113
 
114
void EventDownloadComplete()
115
{
116
	dword unimg_id, slot_n;
117
 
118
	CreateFile(http.content_received, http.content_pointer, "/tmp0/1/last.img");
119
	http.free();
120
 
121
	unimg_id = RunProgram("/tmp0/1/unimg", "/tmp0/1/last.img -e");
122
	do {
123
		slot_n = GetProcessSlot(unimg_id);
124
		pause(10);
125
	} while (slot_n!=0);
126
 
127
	copyf("/tmp0/1/KOLIBRI.IMG", "/rd/1");
128
 
129
	RestartAllProcess();
130
	install_complete = true;
131
	draw_window();
132
}
133
 
134
void RestartAllProcess() {
135
	int i;
136
	proc_info Process;
137
	for (i=0; i
138
	{
139
		GetProcessInfo(#Process, i);
140
		if (Process.name)
141
		&& (!streq(#Process.name, "OS"))
142
		&& (Process.ID != Form.ID)
143
			KillProcess(Process.ID);
144
	}
145
	RunProgram("/sys/launcher", NULL);
146
}
147
 
148
void Operation_Draw_Progress(dword filename) { debug("copying: "); debugln(filename); }