5.7 Example scripts
189
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
Summary of Contents for Camera
Page 1: ......
Page 2: ...The Canon Camera Hackers Manual ...
Page 3: ......
Page 4: ...Berthold Daum The Canon Camera Hackers Manual Teach Your Camera New Tricks ...
Page 19: ...10 CH APTER 2 Cameras and Operating Systems ...
Page 25: ...16 CH APTER 3 ...
Page 85: ...76 CH APTER 4 Teach Your Camera New Tricks ...
Page 213: ...204 CH APTER 6 ...
Page 253: ...244 AP PENDIX ...