Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cleanEnvironment = {} --enviroment gets sad without this ;-;
- for k, v in pairs(_G) do
- cleanEnvironment[k] = v
- end
- local Extension = function(path, addDot)
- if not path then
- return nil
- elseif not string.find(fs.getName(path), '%.') then
- if not addDot then
- return fs.getName(path)
- else
- return ''
- end
- else
- local _path = path
- if path:sub(#path) == '/' then
- _path = path:sub(1,#path-1)
- end
- local extension = _path:gmatch('%.[0-9a-z]+$')()
- if extension then
- extension = extension:sub(2)
- else
- --extension = nil
- return ''
- end
- if addDot then
- extension = '.'..extension
- end
- return extension:lower()
- end
- end
- local RemoveExtension = function(path)
- if path:sub(1,1) == '.' then
- return path
- end
- local extension = Extension(path)
- if extension == path then
- return fs.getName(path)
- end
- return string.gsub(path, extension, ''):sub(1, -2)
- end
- local tAPIsLoading = {}
- function LoadAPI(_sPath)
- local sName = RemoveExtension(fs.getName( _sPath ))
- if tAPIsLoading[sName] == true then
- return true
- end
- Chameleon.Log.l("INFO", 'Loading: '.._sPath)
- tAPIsLoading[sName] = true
- local tEnv = {isStartup = true }
- setmetatable( tEnv, { __index = getfenv()} )
- local fnAPI, err = loadfile( _sPath )
- if fnAPI then
- setfenv( fnAPI, tEnv )
- fnAPI()
- else
- printError( err )
- Chameleon.Log.l("ERROR", 'Error: '..err)
- tAPIsLoading[sName] = nil
- return false
- end
- local tAPI = {}
- for k,v in pairs( tEnv ) do
- tAPI[k] = v
- end
- if not tAPI then
- Chameleon.Log.l("ERROR", 'Could not find API: '..sName)
- error('Could not find API: '..sName)
- end
- getfenv()[sName] = tAPI
- return true
- end
- Chameleon.Log.l("INFO", "Starting OneOS. OneOS logged to /System/OneOS.log.")
- Chameleon.Log.l("INFO", "Boot progress will continue to be logged.")
- LoadAPI('System/API/Log.lua')
- Log.Initialise()
- Log.i('Starting OneOS (via Chameleon)')
- Log.i(os.version())
- Log.i('Free space: '..fs.getFreeSpace('/'))
- local h = fs.open('/System/.version', 'r')
- local version = '?'
- if h then
- version = h.readAll()
- h.close()
- else
- version = 'Not set'
- end
- Log.i('OneOS Version: '..version)
- LoadAPI('System/API/Settings.lua')
- local _side = Settings:GetValues()['Monitor']
- if not term.setTextScale and _side then
- if peripheral.isPresent(_side) and peripheral.getType(_side) == 'monitor' and peripheral.call(_side, 'isColour') == true then
- Chameleon.Log.l("WARN", "Not using monitor.")
- Log.w("Not using monitor.")
- else
- Settings:SetValue('Monitor', nil)
- end
- end
- if fs.getFreeSpace and fs.getFreeSpace('/') < 51200 then
- Chameleon.Log.l("WARN", "Less than 50KB of space left!")
- Chameleon.Status = "<50KB disk space left!"
- Log.w("Less than 50KB disk space available.")
- sleep(1)
- end
- local totalAPIs = #fs.list(root .. 'System/API/')-- + #fs.list(root .. 'System/Objects/')
- local apis = {}
- for _, file in pairs(fs.list(root .. 'System/API/')) do
- if string.sub(file,1,1) ~= "." then
- table.insert(apis, 'System/API/' .. file)
- end
- end
- for _, file in pairs(apis) do
- if not LoadAPI(root .. file) then
- return false
- end
- end
- Chameleon.Log.l("INFO", "Entering GUI...")
- Chameleon.Running = false
- function ChameleonDone()
- os.run(getfenv(), '/System/main.lua')
- local ok = nil
- if not fs.exists('/System/.version') or not fs.exists('/System/.OneOS.settings') then
- Log.i('No .version or .OneOS.settings! Running First Setup')
- if fs.exists('/System/.OneOS.settings') then
- fs.delete('/System/.OneOS.settings')
- end
- xpcall(FirstSetup, function(err)
- Log.e('[> First Setup] '..err)
- ok = {false, err}
- end)
- else
- xpcall(Initialise, function(err)
- ok = {false, err}
- end)
- end
- return ok
- end
Advertisement
Add Comment
Please, Sign In to add comment