package.path = package.path .. ";"..app.dir.."/Lib/lua/?.lua" package.cpath = package.cpath .. ";"..app.dir.."/Lib/clibs/?.dll" Sandcat = extensionpack:new() Sandcat.filename = 'Resources.pak' Sandcat.aboutdisplayed = false Sandcat.cfg_expextension = 'scpref' Sandcat.cfg_expfilter = 'Sandcat Preferences files (*.scpref)|*.scpref' Sandcat:dofile('corelibs.lua') Sandcat.Preview = {} Sandcat.Preview.Handlers = {} Sandcat.Preview.Types = {} Sandcat.Preview.Extensions = {} Sandcat.Preview.About = scl.stringlist:new() function Sandcat:RegisterPreviewHandler(id,func,extlist,typelist) if id ~= '' then self.Preview.Handlers[id]=func self.Preview.About:add(''..id..''..extlist..'') self.Preview.About:sort() local slp = scl.listparser:new() -- associates extensions with handler local s = '' slp.commatext = extlist while slp:parsing() do s = stringop.trim(slp.current) if s ~= '' then self.Preview.Extensions[s]=id end end -- associates types with handler if typelist ~= nil then slp:load(typelist) while slp:parsing() do s = stringop.trim(slp.current) if s ~= '' then self.Preview.Types[s]=id end end end slp:release() end end function Sandcat:ClearPrivateData() local html = Sandcat:getfile('dialog_clear.html') app.showdialogx(html) end function Sandcat:EditPreferences() self:dofile('dialog_prefs.lua') Preferences:Edit() end function Sandcat:ImportPreferences() local file = app.openfile(self.cfg_expfilter,self.cfg_expextension) if file ~= '' then prefs.load(scop.file.getcontents(file)) prefs.update() end end function Sandcat:ExportPreferences() local destfile = app.savefile(self.cfg_expfilter,self.cfg_expextension) if destfile ~= '' then local sl = scl.stringlist:new() sl.text = prefs.getall() sl:savetofile(destfile) sl:release() end end function Sandcat:IsURLLoaded(warnuser) local valid = false if stringop.beginswith(tab.url,'http') then valid = true end if stringop.beginswith(tab.url,'file') then valid = true end if stringop.beginswith(tab.url,'chrome') then valid = true end if valid == false then if warnuser then app.showmessage('No URL loaded.') end end return valid end function Sandcat:SetConsoleMode(mode) if mode == nil then mode = 'sc' end if mode == 'sc' then if console.gethandler() ~= '' then console.reset() end end if mode == 'js' then if console.gethandler() ~= mode then console.sethandler(mode) console.clear() console.setcolor('#FFFFFF') console.setfontcolor('#0066bb') --#003366 tab:runjs([[ Sandcat.WriteLn(navigator.userAgent); ]]) end end if mode == 'lua' then if console.gethandler() ~= mode then console.sethandler(mode) console.clear() console.setcolor('#003366') console.setfontcolor('#FFFFFF') console.writeln(_VERSION) end end end function Sandcat:ShowAbout() if self.aboutdisplayed == false then -- first display self.aboutdisplayed = true self:dofile('credits.lua') end self:dofile('dialog_about.lua') end function Sandcat:ShowPreviewHandlers() local html = Sandcat:getfile('dialog_preview_handlers.html') html = stringop.replace(html,'%handlerlist%',Sandcat.Preview.About.text) app.showdialogx(html) end function Sandcat:ShowErrorLog() local html = Sandcat:getfile('dialog_error.html') html = stringop.replace(html,'%errorlist%',browser.info.errorlog) app.showdialogx(html) browser.statbar:eval('HideNotification()') end function Sandcat:ShowLicense(pak,file) self:ShowTextFile('License',pak,file) end function Sandcat:ShowTextFile(tabtitle,pak,file) local html = scl.stringlist:new() html:add('') html:add(browser.getpackfile(pak,file)) html:add('') local j = {} j.title = tabtitle j.tag = 'sandcattextfile' j.loadnew = true browser.newtabx(json.encode(j),html.text) html:release() end function Sandcat:Write(s) console.write(s) end function Sandcat:WriteLn(s) console.writeln(s) end function Sandcat:Start() browser.addlua('task.init',Sandcat:getfile('task.lua')) self:dofile('commands.lua') self:dofile('previewer.lua') self:dofile('addons.lua') SandCommands:AddCommands() Previewer:Register() end