--@Name: "XLib.UpdateUtility" --@Version: 1.06 --@Author: Luke Wigley (luke@meccamedialight.com.au) --@LastUpdate: 24/2/06 -- History -- v1.06 -- Added void check for DMX2004 and SES of 9 -- v1.05 -- Added parameter to ApplyXlibUpdate so you can specify that it should only update installed scripts (new scripts not installed) -- v1.04 -- Updated script to name itself -- v1.03 -- Updated to check whether the script is Javascript and set the Javascript Syntax (24/1/06) -- v1.02 -- Added versions to the message window output (13/1/06) -- v1.01 -- Change the way the script checks for the existence of a named script (Previously, you -- could simply check whether member("foo").type = #script. However, with DMX2004, member(NonexistentMember) -- is void so checking .type property causes an error. property id on UpdateXlib -- There are two stages to updating the xlib: (1) getting a list of the scripts; and -- (2) importing those scripts; start the process by calling UpdateXlib in the message window. -- Wait a few moments, then call ApplyXlibUpdate clearCache() -- check this script is named correctly f = 1 if voidP(member("XLib.UpdateUtility")) or member("XLib.UpdateUtility").ilk = #empty or voidP(member("XLib.UpdateUtility").ilk) then f = 0 repeat with c = 1 to the number of castlibs repeat with m = 1 to the number of members of castlib c memRef = member(m, c) if memRef.type = #script then if memRef.name = "" then s = memRef.scriptText if s contains Return & "on UpdateXlib" & return then memRef.name = "XLib.UpdateUtility" f = 1 exit repeat end if end if end if end repeat end repeat end if if not (f) then alert "Please name the XLib.UpdateUtility script" exit end if -- (1) get updatelist script("XLib.UpdateUtility").id = getNetText("http://www.lingoworkshop.com/code/classes/scripts/getclasses.php?"&random(the milliseconds)) -- since this movie is probably 'stopped', meaning we can't use timeouts or frame events, to check whether -- the GETNetText is finished. Therefore, prompt for a manual check of the netoperation. put "-------------------------------------------------" put "UpdateXlib v.1.05" put "Run the handler 'ApplyXlibUpdate()' in the message window in a few moments to finish the update. To only update installed scripts, run 'ApplyXlibUpdate(1)' " end on ApplyXlibUpdate(updateOnly) -- completes the update initiated by the UpdateXlib function -- called previously if netDone(script("XLib.UpdateUtility").id) then res = NetTextResult() updateList = value(res) if updateList.ilk =#List then __UpdateUtil__runUpdateList(updateList, updateOnly) else put "Error getting update list (expecting a list, but got a " & updateList.ilk & ")" end if else put "net operation not finished yet... try 'ApplyXlibUpdate()' again in a few moments" end if end ------------- HELPERS ---------------------------------------------------- on __UpdateUtil__runUpdateList (updateList, updateOnly) baseURL = "http://www.lingoworkshop.com/code/classes/scripts/" tmp = new(#field) tmp.name = "TEMP - Safe to delete" JSAvailable = float((the environment).productVersion)>=10 -- suppress errors (importing a linked javascript will default -- to a Lingo syntax member, which may generate script errors. -- the scriptSytax is set to javascript after it is imported) tempScript = new(#Script) tempScript.name = "TEMP_XLib.UpdateUtility_AlertHooker" tempScript.scriptType = #Parent if JSAvailable then tempScript.scriptsyntax = #Lingo tempScript.scripttext = "on alertHook (me)"&return &"return 1" & return & "end" the alertHook = script("TEMP_XLib.UpdateUtility_AlertHooker") put "-------------------------------------------------" put "UPDATING XLIB " put "Checking " & count(updateList) & " scripts" put "-------------------------------------------------" repeat with aScript in updateList theURL = baseURL & aScript & ".ls" if __SCRIPT__EXISTS(aScript) then t = member(aScript).scriptType tmp.importFileInto(theURL) if tmp.scriptText <> member(aScript).scriptText then res = "Updated" member(aScript).scriptText = tmp.scriptText member(aScript).scriptType = t else res = "Skipped (already up to date)" end if else if updateOnly then put "Skipped " & aScript & " (only updating installed scripts)" next repeat end if if NOT(JSAvailable) AND aScript.char[1..2] = "JS" then put "Skipped " & aScript & " (it appears to be a Javascript-syntax script, and your version of Director is too old)" next repeat end if memRef = new(#Script) memRef.name = aScript memRef.importFileInto(theURL) -- try and guess whether the script is a movie script -- or parent script, Lingo or Javascript using convention -- scripts names that end in "Lib" are movie scripts -- script names that start with JS are Javascript the itemDelimiter = "." basename = aScript.item[1] isProbablyaMovieScript = 0 if basename.length > 3 then isProbablyaMovieScript = (basename.char[basename.length-2..basename.length]= "lib") end if if aScript.char[aScript.length-2..aScript.length] = "lib" OR isProbablyaMovieScript then memRef.scriptType = #movie if JSAvailable then memRef.scriptsyntax = #Lingo else if JSAvailable AND aScript.char[1..2] = "JS" then memRef.scriptType = #movie memRef.scriptsyntax = #javascript else memRef.scriptType = #Parent if JSAvailable then memRef.scriptsyntax = #Lingo end if end if res = "Created" && memRef end if -- get the version s = member(aScript).scriptText mx = s.line.count vStr = "" repeat with i = 1 to mx if s.line[i] starts "--" OR s.line[i] starts "//" then L = tmp.scriptText.line[i] delete L.char[1..2] if L starts "@Version" then chnk = L.char[9..L.length] repeat while chnk.length > 0 if " :-" contains chnk.char[1] then delete chnk.char[1] else exit repeat end repeat vStr = "(v. " & chnk & ")" exit repeat else if L starts "@ Version" then chnk = L.char[10..L.length] repeat while chnk.length > 0 if " :-" contains chnk.char[1] then delete chnk.char[1] else exit repeat end repeat vStr = "(v. " & chnk & ")" exit repeat end if end if end repeat -- show the result put aScript && vStr & " ... " & res end repeat -- clean up various hacks the alertHook = 0 erase tempScript erase tmp -- thats it put "DONE -------------------------------------------------" end on __SCRIPT__EXISTS (aScriptName) if member(aScriptName).ilk = #member then return (member(aScriptName).type = #Script) end if end