--############################################################
--# Created By NicolasG(10/12/2015)-(19/12/2015) #
--# http://www.amsspecialist.com #
--############################################################
--[[
puedo obtener la version antes de actualizar y si la applicacion se cierra con el from 1 vuelve la version a antes de que se iniciara la actualizacion.(creo que ya esta, no tengo la mas puta idea)
]]--
UpdaterNG = {};
function DelimitedToTable(s, d)
if not(d or #d < 1)then
return nil
end
local tbl = {};
local sa = s;
local sD = '';
local nP = string.find(sa, d, 1, true)
while nP do
sD = string.sub(sa, 1, nP-1)
table.insert(tbl, #tbl+1, sD)
sa = string.sub(sa, nP+1, -1)
nP = string.find(sa, d, 1, true)
end
if(sa ~= '')then
Table.Insert(tbl, #tbl+1, sa)
end
return tbl;
end
function UpdaterNG.Configure(SF, ATR, FT, FD, P, L, PD, PDS, F_URL, SN, VN)
Settings_File = (SF);
Section_Name = (SN);
Value_Name = (VN);
Version = INIFile.GetValue(Settings_File, Section_Name, Value_Name);
Application_To_Run = (ATR);
Folder_Temporal = (FT);
Folder_Destination = (FD);
Password = (P);
Set_Label = (L);
ProgressBar_Download = (PD);
ProgressBar_Dscompression = (PDS);
URL = (F_URL);
end
Starter_Version = Version;
from = (0);
function DownloadCallback (BytesSoFar, TotalBytes, TransferRate, SecondLeft, SecondsLeftFormat)
if(TotalBytes ~= 0)then
dload_pct = ((BytesSoFar/TotalBytes) * 100);
dec_mBytesSofar = BytesSoFar/1000000
dec_TotalmBytes = TotalBytes/1000000
mBytesSoFar = Math.Round(dec_mBytesSofar, 2);
TotalmBytes = Math.Round(dec_TotalmBytes, 2);
strProgressText = 'Downloading: '..mBytesSoFar..'/'..TotalmBytes..' KB';
Progress.SetRange('Progress_Download', 0, 100);
local strkbs = string.format('%.1f', TransferRate);
strKbsRate = 'Speed: '..strkbs..' KB/Sec';
else
strProgressText = '';
dload_pct = 0;
strKbsRate = '';
end
Progress.SetCurrentPos(''..ProgressBar_Download..'', ((BytesSoFar/TotalBytes) * 100));
Label.SetText(''..Set_Label..'', strProgressText..' '..strKbsRate..' Time remaining: '..SecondsLeftFormat..'');
end
function ZipCallback (strpath, percent, status)
Progress.SetCurrentPos(''..ProgressBar_Dscompression..'', percent);
end
function QueryAllowProjectClose()
if(from == 1)then
return true;
elseif(from == 0)then
INIFile.SetValue(''..Settings_File..'', ''..Section_Name..'', ''..Value_Name..'', ''..Starter_Version..'');
return true;
end
end
function UpdaterNG.CloseUpdater()
from = (1);
Application.Exit(0);
end
function UpdaterNG.ToUpdate()
for K,V in pairs(DelimitedToTable(HTTP.Submit(''..URL..'', {}, SUBMITWEB_GET, 20, 80, nil, nil), '>'))do
if(V ~= '0')then
if(tonumber(K-2) > tonumber(''..Version..''))then
if(tonumber(K-2) ~= tonumber(''..Version..''))then
HTTP.DownloadSecure(''..String.TrimRight(V, K-1)..'', Folder_Temporal..'\\'..String.SplitPath(''..String.TrimRight(V, K-1)..'').Filename..'.zip', MODE_BINARY, 20, 443, nil, nil, DownloadCallback);
if(''..Password..'' == 'false')then
Zip.Extract(Folder_Temporal..'\\'..String.SplitPath(''..String.TrimRight(V, K-1)..'').Filename..'.zip', {'*.*'}, Folder_Temporal..'\\unzip\\', true, true, '', ZIP_OVERWRITE_ALWAYS, ZipCallback);
else
Zip.Extract(Folder_Temporal..'\\'..String.SplitPath(''..String.TrimRight(V, K-1)..'').Filename..'.zip', {'*.*'}, Folder_Temporal..'\\unzip\\', true, true, ''..Password..'', ZIP_OVERWRITE_ALWAYS, ZipCallback);
end
INIFile.SetValue(''..Settings_File..'', ''..Section_Name..'', ''..Value_Name..'', K-2);
Progress.SetCurrentPos(''..ProgressBar_Dscompression..'', 0);
elseif(K-2 == Version)then
Dialog.Message('Notice', 'No more recent version');
UpdaterNG.CloseUpdater()
end
end
end
end
Progress.SetRange(''..ProgressBar_Download..'', 0, 100);
Progress.SetRange(''..ProgressBar_Dscompression..'', 0, 100);
Label.SetText(''..Set_Label..'', 'Updating Complete');
if(''..Application_To_Run..'' ~= 'false')then
TextFile.WriteFromString(Folder_Temporal..'\\MoveUpdate.bat', [[
@ECHO OFF
timeout /t 5
move %temp%\Patches\unzip\*]]..' "'..Folder_Destination..'"\r\n'..[[
timeout /t 5
start]]..' "" "'..Application_To_Run..'"\r\n'..[[
DEL "%~f0"
]], false);
File.Run(Folder_Temporal..'\\MoveUpdate.bat', '', '', SW_HIDE, false);
UpdaterNG.CloseUpdater()
else
TextFile.WriteFromString(Folder_Temporal..'\\MoveUpdate.bat', [[
@ECHO OFF
timeout /t 5
move %temp%\Patches\unzip\*]]..' "'..Folder_Destination..'"\r\n'..[[
DEL "%~f0"
]], false);
File.Run(Folder_Temporal..'\\MoveUpdate.bat', '', '', SW_HIDE, false);
UpdaterNG.CloseUpdater()
end
end
--#Mode 0 return a string.
--#Mode 1 return a dialog of quiestion.
function UpdaterNG.CheckUpdates(mode)
local Status = (false);
for K,V in pairs(DelimitedToTable(HTTP.Submit(''..URL..'', {}, SUBMITWEB_GET, 20, 80, nil, nil), '>'))do
if(V ~= '0')then
if(tonumber(K-2) == tonumber(''..Version..''))then
Status = true;
else
Status = false;
end
end
end
if(Status == false)then
if(mode == 0)then
return 'Not updated application';
elseif(mode == 1)then
if(Dialog.Message('Updater', 'Updates are available, you want to upgrade?', MB_YESNO, MB_ICONINFORMATION, MB_DEFBUTTON1) == 6)then
UpdaterNG.ToUpdate()
end
end
else
if(mode == 0)then
return 'Updated application';
elseif(mode == 1)then
Dialog.TimedMessage('Updater', 'Updated application', 2000, MB_ICONINFORMATION);
end
end
end
move %temp%\Patches\unzip\*]]..' "'..Folder_Destination..'"\r\n'..[[
move %temp%\]]..'"'..Folder_Temporal..'"'..[[\unzip\*]]..' "'..Folder_Destination..'"\r\n'..[[
move "]]..''..Folder_Temporal..''..[[\unzip\*"]]..' "'..Folder_Destination..'"\r\n'..[[