5.7 Example scripts
187
and
cnt
with the current count of saved configurations. It writes two text
lines that should look like this:
cnt = 1
cur = CONF1.CFG
To be safe, the new file is first written to file
CONFSW.INI.NEW
. If this is suc-
cessful, the old
INI
file is renamed to
CONFSW.INI.BAK
(existing files of that
name are deleted first), and file
CONFSW.INI.NEW
is renamed to
CONFSW.INI
.
This is done in function
_activate_file()
. Working in this way, we always
have a valid
INI
file. Even a battery going flat when writing the
INI
file can-
not lead to a corrupt file:
function write_ini(name, cnt)
local new = ininame..".NEW"
local file,msg =
io.open (new, "w")
if not file then error(msg) end
local ret,msg = file:write(
"cnt="..cnt.."\n")
if ret then
ret,msg = file:write (
"cur="..name.."\n")
end
file:close()
if ret then
ret,msg =
_activate_file(new, ininame)
end
if not ret then error(msg) end
end
function _activate_file(new, to)
local bak = to..".BAK"
os.remove(bak)
os.rename(to,bak)
local ret,msg =
os.rename(new,to)
if not ret then
os.rename(bak,to)
end
return ret,msg
end
Содержание Camera
Страница 1: ......
Страница 2: ...The Canon Camera Hackers Manual ...
Страница 3: ......
Страница 4: ...Berthold Daum The Canon Camera Hackers Manual Teach Your Camera New Tricks ...
Страница 19: ...10 CH APTER 2 Cameras and Operating Systems ...
Страница 25: ...16 CH APTER 3 ...
Страница 85: ...76 CH APTER 4 Teach Your Camera New Tricks ...
Страница 213: ...204 CH APTER 6 ...
Страница 253: ...244 AP PENDIX ...