Mini Kabibi Habibi

Current Path : C:/Program Files/Smart Professional Surveillance System/PC-NVR/Common/Lua/
Upload File :
Current File : C:/Program Files/Smart Professional Surveillance System/PC-NVR/Common/Lua/LiveUpdate.lua

--   "$Id: LiveUpdate.lua 4957 2006-11-01 04:06:25Z yuan_shiyong $"
--   (c) Copyright 1992-2005, ZheJiang Dahua Information Technology Stock CO.LTD.
--                            All Rights Reserved
--
--	�� �� ��� Upgrade.lua
--	��    �:  ���ļ����ڿ����������
--	�޸ļ�¼�� 2005-12-29 ����� <wanghw@dhmail.com> ��ʼ���汾
--    

require"compat-5.1"

require('zip')

local LiveUpdate = {};

-- ���֧�Ż����İ汾��
LiveUpdate.Version = "1.0.0";


-- �ڲ�������̿���
-- params:
--        zfile: Zip�ļ��ľ�
--     callback: �ص����
-- return: 
--    �ɹ�����True, ʧ�ܷ���False�Լ�ʧ�ܵ�ԭ��
local function doInternalUpgrade(zfile, callback)
	-- ���Դ�LUA�ű�
	local f1, err = zfile:open('Install.lua')

	if( not f1) then
		return false, "invalid package";
	end
	
	local content = f1:read("*a");
	f1:close();	
	
	-- ���ؽű�������
	local Installer;
	local f ,err= loadstring(content, "Install.lua");
	if (f) then 
		err, Installer = pcall(f);
		if(not err) then
			return false, "pcall failed:" + err;
		end
	else 
		return false, err;
	end

	Installer.ZipArchive = zfile;
	Installer.callback   = callback;
	return Installer:execute();
end


-- �����ṩ��������ƺ��,����Zip�ļ����,���ϲ�Ӧ�õ���
-- params:
--     filename: Zip�ļ���ڵ�·��
--     callback: �ص����
-- return: 
--    �ɹ�����True, ʧ�ܷ���False�Լ�ʧ�ܵ�ԭ��
function LiveUpdate.doFileUpgrade(filename,callback)
	assert(type(filename) == 'string');
	
	local zfile, err = zip.open(filename);

	if(not zfile) then
		return false, err;
	end;

	return 	doInternalUpgrade(zfile, callback);
end


-- �����ṩ��������ƺ��,���ϲ�Ӧ�õ���
-- params:
--      bufAddr: Zip�ļ����ڴ��е���ʼ��ַ
--       bufLen: Zip�ļ��Ĵ�С
--     callback: �ص����
-- return: 
--    �ɹ�����True, ʧ�ܷ���False�Լ�ʧ�ܵ�ԭ��
function LiveUpdate.doUpgrade(bufAddr, bufLen, callback)
	assert(type(bufAddr) == 'number');
	assert(type(bufLen) == 'number');

	local zfile, err = zip.open(bufAddr, bufLen);

	if(not zfile) then
		return false, err;
	end;
	return 	doInternalUpgrade(zfile, callback);
end

return LiveUpdate;
--
-- "$Id: LiveUpdate.lua 4957 2006-11-01 04:06:25Z yuan_shiyong $"
--