property myGlobalPrefList, myPrefFile
on GetObjectPrefs (me, id, obj)
if voidP(myPrefFile) then me.Init()
pList = myGlobalPrefList.getAProp(id)
if voidP(pList) then
put "Prefs not set for " & id
return 0
else
repeat with i = 1 to pList.count
p = symbol(pList.getPropAt(i))
v = pList[i]
obj[p] = v
end repeat
return 1
end if
end
on SaveObjectPrefs (me, id, inList)
if voidP(myPrefFile) then me.Init()
pList = myGlobalPrefList.getAProp(id)
if voidP(pList) then
pList = [:]
end if
repeat with i = 1 to inList.count
p = inList.getPropAt(i)
v = inList[i]
pList[p] = v
end repeat
myGlobalPrefList.setAProp(id, pList)
end
on WritePrefsFile (me)
if voidP(myPrefFile) then me.Init()
ps = ""
repeat with i = 1 to myGlobalPrefList.count
ps = ps & "$"&myGlobalPrefList.getPropAt(i) & return
pList = myGlobalPrefList[i]
repeat with j = 1 to pList.count
p = pList.getPropAt(j)
v = pList[j]
if v.ilk = #Symbol then v = "#" & (v)
ps = ps & p & "=" & v & return
end repeat
end repeat
setPref (myPrefFile, ps)
end
on new (me)
return me.script
end
on PrefsExist (me, id)
if voidP(myPrefFile) then me.Init()
pList = myGlobalPrefList.getAProp(id)
return NOT(voidP(pList))
end
on Init (me, PrefFile)
if voidP(PrefFile) then me._SetDefaultPrefFile()
else myPrefFile = PrefFile
myGlobalPrefList = [:]
me._LoadPrefs()
end
on _LoadPrefs(me)
if voidP(myPrefFile) then me.Init()
ps = getPref(myPrefFile)
if (ps.ilk = #String) then
mx = ps.line.count
currentid = ""
currentCollection = [:]
repeat with i = 1 to mx
thisline = ps.line[i]
if thisline starts "$" then if currentid <> "" then myGlobalPrefList.addProp(currentid, currentCollection)
end if
currentid = thisline.char[2..thisline.length]
currentCollection = [:]
else if currentid <> "" then
slen = length(thisline)
p = offset("=", thisline)
if p > 1 AND p< slen then
toSet = symbol(thisline.char[1..p-1])
theVal = me._evalString(thisline.char[p+1..slen])
currentCollection[toSet] = theVal
end if
end if
end repeat
if currentid <> "" then
myGlobalPrefList.addProp(currentid, currentCollection)
end if
else
myGlobalPrefList = [:]
end if
end
on _SetDefaultPrefFile (me)
m = the movieName
the itemDelimiter = "."
mx = m.item.count
myPrefFile = (m.item[1..(mx-1)] & ".txt")
end
on _evalString(me, aStr)
if NOT(aStr starts QUOTE) then
test1 = value(aStr)
if not voidP(test1) then
if symbolP(test1) then
test2 = "#"&test1
if test2 = aStr then
return test1
end if
else
test2 = string(test1)
if test2 = test1 then
return test1
end if
end if
end if
end if
return aStr
end