EasyManua.ls Logo

Canon Camera - Page 196

Canon Camera
257 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
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

Table of Contents

Related product manuals