Skip to content
This repository has been archived by the owner on Sep 19, 2020. It is now read-only.

Commit

Permalink
Finished Auto-Updater, fixed ButtonDialouge issues
Browse files Browse the repository at this point in the history
  • Loading branch information
oeed committed Jan 13, 2014
1 parent b870d23 commit 4c941a4
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 15 deletions.
18 changes: 12 additions & 6 deletions System/API/ButtonDialogueWindow
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
end

self.OkButton:Draw()
self.CancelButton:Draw()
if self.CancelButton then
self.CancelButton:Draw()
end
end

Initialise = function(self, title, message, okText, cancelText, returnFunc)
Expand All @@ -40,10 +42,12 @@
returnFunc(true)
new:Close()
end, okText)
new.CancelButton = Button:Initialise(new.Width - #okText - 2 - 1 - #cancelText - 2, new.Height - 1, nil, 1, colours.lightGrey, colours.black, colours.blue, colours.white, new, function()
returnFunc(false)
new:Close()
end, cancelText)
if cancelText then
new.CancelButton = Button:Initialise(new.Width - #okText - 2 - 1 - #cancelText - 2, new.Height - 1, nil, 1, colours.lightGrey, colours.black, colours.blue, colours.white, new, function()
returnFunc(false)
new:Close()
end, cancelText)
end
return new
end

Expand Down Expand Up @@ -80,6 +84,8 @@

Click = function(self, side, x, y)
ButtonClick(self, self.OkButton, x, y)
ButtonClick(self, self.CancelButton, x, y)
if self.CancelButton then
ButtonClick(self, self.CancelButton, x, y)
end
return true
end
3 changes: 2 additions & 1 deletion System/API/Environment
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ This essentially allows the programs to run in sandbox. For example, os.shutdown
Helpers = Helpers,
Desktop = Desktop,
Settings = Settings,
Version = OneOSVersion
Version = OneOSVersion,
Reboot = os.reboot
}
end

Expand Down
4 changes: 3 additions & 1 deletion System/API/Overlay
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ function UpdateButtons()
},
{
Title = 'Update OneOS',
Click = error
Click = function()
CheckAutoUpdate(true)
end
},

{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function Initialise()
UpdaterRefresh()
if updaterEnvironment.Settings.TotalFiles == updaterEnvironment.Settings.DownloadedFiles then
sleep(3)
os.reboot()
OneOS.Reboot()
else
Current.StatusText = 'Download Failed!'
Current.SecondaryStatusText = updaterEnvironment.Settings.TotalFiles - updaterEnvironment.Settings.DownloadedFiles .. ' files were not downloaded. Try again.'
Expand Down
83 changes: 79 additions & 4 deletions System/main
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
OneOSVersion = '0.1 Private Beta'
OneOSVersion = '...'

local x = 1
local y = 1
Expand Down Expand Up @@ -51,6 +51,7 @@ function Initialise()
EventRegister('key', HandleKey)
EventRegister('char', HandleKey)
EventRegister('timer', Update)
EventRegister('http_success', AutoUpdateRespose)
ShowDesktop()
Draw()
--updateTimer = os.startTimer(0.05)
Expand All @@ -63,7 +64,7 @@ function Initialise()
--LaunchProgram('Programs/Files/startup', {'Programs/'}, 'Files')
--LaunchProgram('Programs/Shell', {}, 'Shell')
--LaunchProgram('Programs/npaintpro', {}, 'nPaintPro')
LaunchProgram('Programs/Update OneOS/startup', {}, 'Test')
--LaunchProgram('Programs/Update OneOS/startup', {}, 'Test')
--LaunchProgram('Programs/test', {}, 'Test')
--LaunchProgram('Programs/Pik/startup', {'/desktop/image.pik'}, 'Pik')
--LaunchProgram('Programs/Pik/startup', {}, 'Pik')
Expand All @@ -74,9 +75,80 @@ function Initialise()
--LaunchProgram('Programs/Settings/startup', {}, 'About OneOS')
--Settings:WriteDefaults()
--Helpers.OpenFile('/Desktop/')
local h = fs.open('.version', 'r')
OneOSVersion = h.readAll()
h.close()

CheckAutoUpdate()

EventHandler()
end

local checkAutoUpdateArg = nil

function CheckAutoUpdate(arg)
checkAutoUpdateArg = arg
if http then
http.request('https://api.github.com/repos/oeed/OneOS/releases')
elseif arg then
ButtonDialogueWindow:Initialise("HTTP Not Enabled!", "Turn on the HTTP API to update.", 'Ok', nil, function(success)end):Show()
end
end

function split(str, sep)
local sep, fields = sep or ":", {}
local pattern = string.format("([^%s]+)", sep)
str:gsub(pattern, function(c) fields[#fields+1] = c end)
return fields
end

function GetSematicVersion(tag)
tag = tag:sub(2)
return split(tag, '.')
end

--Returns true if the FIRST version is NEWER
function SematicVersionIsNewer(version, otherVersion)
if version[1] > otherVersion[1] then
return true
elseif version[2] > otherVersion[2] then
return true
elseif version[3] > otherVersion[3] then
return true
end
return false
end

function AutoUpdateRespose(event, url, data)
if Current.Program then
return false
end
os.loadAPI('/System/JSON')
if not data then
return
end
local releases = JSON.decode(data.readAll())
os.unloadAPI('JSON')
if not releases or not releases[1] or not releases[1].tag_name then
if checkAutoUpdateArg then
ButtonDialogueWindow:Initialise("Update Check Failed", "Check your connection and try again.", 'Ok', nil, function(success)end):Show()
end
return
end
local latestReleaseTag = releases[1].tag_name

if OneOSVersion == latestReleaseTag then
--using latest version
if checkAutoUpdateArg then
ButtonDialogueWindow:Initialise("Up to date!", "OneOS is up to date!", 'Ok', nil, function(success)end):Show()
end
return
elseif SematicVersionIsNewer(GetSematicVersion(latestReleaseTag), GetSematicVersion(OneOSVersion)) then
--using old version
LaunchProgram('/System/Programs/Update OneOS/startup', {}, 'Update OneOS')
end
end

function LaunchProgram(path, args, title)
Animation.RectangleSize(Drawing.Screen.Width/2, Drawing.Screen.Height/2, 1, 1, Drawing.Screen.Width, Drawing.Screen.Height, colours.grey, 0.3, function()
if Current.Menu then
Expand Down Expand Up @@ -339,8 +411,11 @@ function EventHandler()

if Events[event[1]] then
for i, e in ipairs(Events[event[1]]) do
e(event[1], event[2], event[3], event[4], event[5])
hasFound = true
if e(event[1], event[2], event[3], event[4], event[5]) == false then
hasFound = false
else
hasFound = true
end
end
end

Expand Down
3 changes: 2 additions & 1 deletion System/update
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ local blacklist = {
'/README.md',
'/TODO',
'/Desktop/.Desktop.settings',
'/System/.OneOS.settings'
'/System/.OneOS.settings',
'/.version'
}

function isBlacklisted(path)
Expand Down
5 changes: 4 additions & 1 deletion startup
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,11 @@ end

if LoadingScreen() then


if fs.exists('/.update/') and fs.isDir('/.update/') then
if not fs.exists('/.update/.version') then
fs.delete('/.update/')
end

function installFolder(path)
for i, v in ipairs(fs.list('/.update/'..path)) do
Drawing.DrawArea(1, math.floor(Drawing.Screen.Height / 2), Drawing.Screen.Width, 1, ' ', colours.lightGrey, colours.white)
Expand Down

0 comments on commit 4c941a4

Please sign in to comment.