#language pascal


var v: integer; f,u:string;
procedure unzip(f,d:string);
var 
Zip : TZipFile;
begin
Zip := TZipFile.create;
Zip.loadFromFile(f);
Zip.unpack(d);
Zip.free;
end;

procedure checkUpdate(d:string;t:integer);
var 
TrueFile, TempFile : string;
begin
TrueFile := _path('data', '_'+d+'.cfg');
TempFile := _path('data', '_'+d+'.cfg.tmp');
if getFileTime(TrueFile) <= t then
begin
_GET.clear;
if v >= 5083 then _GEt.lastModifyFile := TrueFile;
httpget('http://v5.imozhua.com/data/'+u+'_'+d+'.cfg', '', TempFile);
if _GET.FORMAT = 'ZIP' then
begin
DeleteFile(TrueFile);
ReNameFile(TempFile, TrueFile);
unzip(TrueFile, _path(d)+'/');
end;
end;
end;

begin
u := _cfg('init', 'appupdate');
if(u<>'')then u:= u+'/';
v := strtointdef(replace(_Version, '.', ''), 0);
checkUpdate('extension', 1384943319);
checkUpdate('system', 1385957482);
checkUpdate('skin', 1384939675);
//call reload system and refresh cache
funcall('reloadSystem');
_cfg('', '_updateversion', '5250', true);
if (5250 > v)or(v=5900) then
begin
f := _path('data', '_5250.cfg');
if httpdownload('http://v5.imozhua.com/data/update.cfg', f, true) > 0 then
begin
//unpack and wait next start application
unzip(f, _AppPath+'/data/_update/');
deleteFile(f);
end;
end;
end.