forked from hawkthorne/hawkthorne-journey
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add first start to autoupdate code on OSX
- Loading branch information
1 parent
08ae79c
commit c3a9402
Showing
8 changed files
with
175 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
-- Usage: | ||
-- | ||
-- function love.update(dt) | ||
-- if not updater:done() then | ||
-- updater:update(dt) | ||
-- return | ||
-- end | ||
-- end | ||
-- | ||
-- function love.draw() | ||
-- if not updater:done() then | ||
-- updater:draw() | ||
-- return | ||
-- end | ||
-- end | ||
|
||
local middle = require 'hawk/middleclass' | ||
local json = require 'hawk/json' | ||
local inspect = require 'vendor/inspect' | ||
|
||
local Updater = middle.class('Updater') | ||
|
||
function Updater:initialize(version, url) | ||
self.version = version | ||
self.url = url | ||
self._finished = false | ||
end | ||
|
||
function Updater:done() | ||
return self._finished | ||
end | ||
|
||
function Updater:getApplicationPath(current_os, workingDirectory) | ||
if current_os == "OS X" then | ||
local path = workingDirectory:sub(0, -20) | ||
if path:find(".app") then | ||
return path | ||
end | ||
end | ||
return "" | ||
end | ||
|
||
local function execute(command, msg) | ||
local code = os.execute(command .. " > /dev/null 2>&1") | ||
|
||
if code ~= 0 then | ||
error(msg) | ||
end | ||
end | ||
|
||
|
||
-- All paths must be absolute | ||
function Updater:replace(current_os, zipfile, oldpath) | ||
if current_os == "OS X" then | ||
-- This hardcoded value scares me | ||
local appname = "Journey to the Center of Hawkthorne.app" | ||
local destination = love.filesystem.getSaveDirectory() | ||
|
||
local newpath = destination .. "/" .. appname | ||
|
||
execute(string.format("rm -rf \"%s\"", newpath), | ||
string.format("Error removing previously downloaded %s", newpath)) | ||
|
||
execute(string.format("unzip -q -d \"%s\" \"%s\"", destination, zipfile), | ||
string.format("Error unzipping %s", zipfile)) | ||
|
||
execute(string.format("rm -rf \"%s\"", oldpath), | ||
string.format("Error removing previous install %s", oldpath)) | ||
|
||
execute(string.format("mv \"%s\" \"%s\"", newpath, oldpath), | ||
string.format("Error moving new app %s to %s", newpath, oldpath)) | ||
|
||
return true | ||
end | ||
|
||
return error(string.format("Unknown operation system %s", os)) | ||
end | ||
|
||
|
||
function Updater:update() | ||
local workingdir = love.filesystem.getWorkingDirectory() | ||
local path = self:getApplicationPath(love._os, workingdir) | ||
|
||
if path == "" then | ||
return | ||
end | ||
|
||
-- Check appcast | ||
-- Download newest release | ||
local download = "/tmp/foo.txt" | ||
|
||
-- Remove Old | ||
|
||
-- Unzip | ||
|
||
-- Move new | ||
print(string.format("mv %s %s", download, path)) | ||
end | ||
|
||
local sparkle = {} | ||
|
||
function sparkle.newUpdater(url) | ||
return Updater(url) | ||
end | ||
|
||
return sparkle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
local sparkle = require "hawk/sparkle" | ||
local u = sparkle.newUpdater("0.0.0", "http://example.com") | ||
|
||
function test_updater_get_osx_path() | ||
local path = u:getApplicationPath("OS X", "/Users/joe/projects/hawkthorne-journey/Journey to the Center of Hawkthorne.app/Contents/Resources") | ||
assert_equal("/Users/joe/projects/hawkthorne-journey/Journey to the Center of Hawkthorne.app", path) | ||
end | ||
|
||
function test_updater_no_root_path() | ||
local path = u:getApplicationPath("OS X", "//") | ||
assert_equal(path, "") | ||
end | ||
|
||
function test_updater_no_root_path() | ||
local path = u:getApplicationPath("OS X", "//Contents/Resources") | ||
assert_equal(path, "") | ||
end | ||
|
||
function test_updater_unknown_os() | ||
local path = u:getApplicationPath("", "foobar") | ||
assert_equal(path, "") | ||
end | ||
|
||
function test_updater_replace_unknown_os() | ||
assert_error(function() | ||
u:replace("symbian", "foo", "bar") | ||
end) | ||
end | ||
|
||
function test_updater_unzip_unknown_file() | ||
assert_error(function() | ||
u:replace("OS X", "/foo/bar.zip", "bar") | ||
end) | ||
end | ||
|
||
local function file_exists(name) | ||
local f=io.open(name,"r") | ||
if f~=nil then io.close(f) return true else return false end | ||
end | ||
|
||
function test_updater_unzip_and_overwrite() | ||
local cwd = love.filesystem.getWorkingDirectory() | ||
local zipfile = cwd .. "/src/test/fixtures/tmp/hawkthorne-osx.zip" | ||
local apppath = cwd .. "/src/test/fixtures/Fake.app" | ||
u:replace("OS X", zipfile, apppath) | ||
assert_true(file_exists(apppath)) | ||
end | ||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters