Canon Camera Hackers Manual page 198

Camera hackers manual berthold daum
Table of Contents

Advertisement

function copy_file(from, to)
local new = to..".NEW"
local ffile, msg =
io.open (from, "rb")
if not ffile then error(msg) end
local tfile, msg =
io.open (new, "wb")
if not tfile then
ffile:close()
error(msg)
end
local ret = true
while ret do
local s = ffile:read (256)
if not s then break end
ret, msg = tfile:write(s)
end
tfile:close()
ffile:close()
if ret then
ret,msg =
_activate_file(new, to)
end
if not ret then error(msg) end
end
The next function, compare_files(), is used to compare the current con-
figuration file with its former origin in folder CONFIGS/. The function re-
turns true if the content of the file has changed since it was copied from its
origin. If this is the case, we need to save the current configuration before
we switch to a new configuration. The function compares both files by
reading their contents in chunks of 256 bytes and comparing these strings:
function compare_files(n1, n2)
local f1 = io.open (n1, "rb")
if not f1 then
return false
end
local f2 = io.open (n2, "rb")
if not f2 then
f1:close()
return true
end
5.7 Example scripts
189

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Powershot sx10 is

Table of Contents