-- PACKAGE SCRIPT -- by Matt Spencer -- This utility takes a script filename as input, and compiles all of the (fileIn) included scripts into a single script file. -- You can exclude individually-included scripts by name by adding them to the array -- Usage: -- packageScriptExcludeFiles = #("Custom.ms", "XMLExample.ms", "AnimationViewer.ms") -- packageScript "SpriteRender.ms" global packageScriptExcludeFiles = #() fn scriptAsString scriptName excludeFiles alreadyIncluded = ( local fs = openFile scriptName mode:"rt" if fs == undefined then return "NO DICE" format "embedding: %\n" fs to:listener local outss = stringstream "" local ss = "" local temp = "" local curline = "" while not (eof fs) do ( curline = (readline fs) temp = trimleft curline if temp.count != 0 then ( ss = temp as stringstream temp = trimleft (readtoken ss) if temp.count != 0 then ( if (stricmp temp "filein") == 0 then -- insert the entire file into the script ( temp = readtoken ss temp = filterstring temp "\"" -- its already been compiled into the file, or is in the exclude list if (findItem alreadyIncluded temp[1]) != 0 then continue if (findItem excludeFiles temp[1]) == 0 then ( format "%" (scriptAsString temp[1] excludeFiles alreadyIncluded) to:outss append alreadyIncluded temp[1] continue ) ) ) ) format "%\n" curline to:outss ) close fs return (outss as string) ) -- CreateStringFromFile() -- This will take any text file as input and create a new script of the same name with a single string variable at the top -- that represents the entire file as a variable. -- Usage: -- createStringFromFile "readme.html" fn createStringFromFile filename = ( local f = openFile ((getFilenameFile filename)+".ms") mode:"wt" local ssread = openFile filename mode:"rt" local line = "" local tokens = #() format "global file_% = \"" (getfilenamefile filename) to:f while not eof ssread do ( line = readline ssread if line.count > 0 then ( tokens = filterstring line "\"" line = tokens[1] if tokens.count > 1 then for t=2 to tokens.count do append line ("\\\"" + tokens[t]) append line "\n" ) format "%" line to:f ) format "\"" to:f close ssread close f ) fn packageScript inputScript outputScript encrypt:false = ( deleteFile outputScript local f = openFile outputScript mode:"wt" format "%" (scriptAsString inputScript packageScriptExcludeFiles #()) to:f close f -- encrypt if you like! But its nice to share :) if( encrypt ) then encryptScript outputScript ) -- this is how I packaged my Sprite Render script -- createStringFromFile "readme.html" --packageScriptExcludeFiles = #("Custom.ms", "XMLExample.ms", "AnimationViewer.ms") --packageScript "SpriteRender.ms" "Sprite Render v0.8.ms" encrypt:true