Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Setup Wizard
- -- By JPiolho
- -- Version 1.0
- -- Feel free to copy and edit as long you credit the original author
- -- More Info @ http://bit.ly/zoxn6V
- function explode(div,str) -- credit: http://richard.warburton.it
- if (div=='') then return false end
- local pos,arr = 0,{}
- -- for each divider found
- for st,sp in function() return string.find(str,div,pos,true) end do
- table.insert(arr,string.sub(str,pos,st-1)) -- Attach chars left of current divider
- pos = sp + 1 -- Jump past current divider
- end
- table.insert(arr,string.sub(str,pos)) -- Attach chars right of last divider
- return arr
- end
- local tArgs = { ... }
- if #tArgs == 0 then
- print( "Usage: setupwizard <folder path> [options]" )
- return
- end
- local sPath = shell.resolve( tArgs[1] )
- local bReadOnly = fs.isReadOnly( sPath )
- if fs.exists( sPath ) == false then
- print("The specified path doesn't exist")
- return
- end
- if fs.isDir( sPath ) == false then
- print("You must target a folder")
- return
- end
- local options = ""
- local i
- for i = 2,#tArgs do
- options = options .. tArgs[i] .. " "
- end
- print("Listing files...")
- local function ListFiles(path)
- if path == "rom" or path == "/rom" then return {} end
- local list = {}
- local f
- for _,f in pairs(fs.list(path)) do
- if fs.isDir(path .. "/" .. f) then
- local retList = ListFiles(path .. "/" .. f)
- local v
- for _,v in pairs(retList) do
- table.insert(list,v)
- end
- else
- if string.find(path,"setupwizard") == nil then
- table.insert(list,path .. "/" .. f)
- end
- end
- end
- return list
- end
- local finalLua = ""
- local fileList = ListFiles(sPath)
- io.write("Packaging " .. #fileList .. " file")
- if #fileList > 1 then io.write("s") end
- print("...")
- finalLua = "local data={"
- local firstFile = true
- local file
- for _,file in pairs(fileList) do
- if firstFile == false then finalLua = finalLua .. "," else firstFile = false end
- finalLua = finalLua .. "{\"" .. shell.resolve( file ) .. "\"," -- Start File entry
- local f = io.open(file,"r")
- local firstLine = true
- finalLua = finalLua .. "{" -- Start lines
- while true do
- local line = f:read()
- if line == nil then break end
- if firstLine == false then
- finalLua = finalLua .. ","
- else
- firstLine = false
- end
- line = string.gsub(line,"\\","\\\\")
- line = string.gsub(line,"\"","\\\"")
- line = string.gsub(line,"\'","\\\'")
- finalLua = finalLua .. "\"" .. line .. "\""
- end
- finalLua = finalLua .. "}" -- End Lines
- f:close()
- finalLua = finalLua .. "}" -- End File Entry
- end
- finalLua = finalLua .. "}\n" -- End Data Entry
- finalLua = finalLua .. "local tArgs = { ... };" ..
- "if #tArgs == 0 then " ..
- "print( \"Usage: \" .. shell.getRunningProgram() .. \" <install path>\" );" ..
- "return " ..
- "end " ..
- "local sPath = shell.resolve( tArgs[1] );" ..
- "local bReadOnly = fs.isReadOnly( sPath );" ..
- "if fs.exists( sPath ) == false then " ..
- "print(\"The specified path doesn't exist. Do you want to create? (y/n)\");" ..
- "local r = read();" ..
- "if r == \"y\" then " ..
- "fs.makeDir(sPath) " ..
- "else " ..
- "return " ..
- "end " ..
- "end " ..
- "if fs.isDir( sPath ) == false then " ..
- "print(\"You must specify a folder\") " ..
- "return " ..
- "end " ..
- "if sPath ~= \"\" and bReadOnly then " ..
- "print(\"The specified path is read-only\");" ..
- "return " ..
- "end " ..
- "print(\"Installing...\");" ..
- "local i;" ..
- "for i = 1,#data do " ..
- "local file = data[i];" ..
- "local filename = file[1];" ..
- "local folder = sPath;" ..
- "local _1,_2;" ..
- "for _1,_2 in string.gmatch(file[1],\"(.*)/(.*)\") do " ..
- "filename = _2;" ..
- "folder = sPath .. \"/\" .. _1 " ..
- "end " ..
- "if folder ~= \"\" and fs.exists(folder) == false then " ..
- "fs.makeDir(folder) " ..
- "end " ..
- "local f = io.open(folder .. \"/\" .. filename,\"w\");" ..
- "local lines = file[2];" ..
- "local v;" ..
- "for _,v in pairs(lines) do " ..
- "f:write(v .. \"\\n\") " ..
- "end " ..
- "f:close() " ..
- "end " ..
- "print(\"Installed!\")"
- if fs.exists("setup") then fs.delete("setup") end
- local f = io.open("setup","w")
- f:write(finalLua)
- f:close()
Advertisement
Add Comment
Please, Sign In to add comment