MBS Xojo Developer Conference and Training
Join us from 3rd to 6th May 2017 in Berlin, Germany.

MBS Real Studio Plugin Tutorial Videos

Sparkle Cocoa Source

1. Patch application

Class App
Inherits Application
// Constants
Const kFileQuitShortcut = Ctrl+Q
Const kFileQuit = E&xit
Const kEditClear = &Delete

// Event implementations
Sub Open()
if not FixInfoPlist("http://www.monkeybreadsoftware.de/test/appcast.xml") then
MsgBox "Failed to change the info.plist file."
Return
end if

dim PubKeyFile as FolderItem = GetFolderItem("dsa_pub.pem")

if PubKeyFile=nil or not PubKeyFile.Exists then
MsgBox "You need a dsa_pub.pem file with your public key."
Return
end if

dim SparkleTest as FolderItem = GetFolderItem("Sparkle Test.app")
dim contents as FolderItem = SparkleTest.Child("Contents")
dim Resources as FolderItem = contents.Child("Resources")

PubKeyFile.CopyFileTo Resources

dim Framework as FolderItem = GetFolderItem("Sparkle.framework")
dim MacOS as FolderItem = Contents.Child("MacOS")

Framework.CopyFileTo MacOS

MsgBox "OK"

End Sub

// Methods
Function FixInfoPlist(feedURL as string) As Boolean
// this method will fail if application is write protected

dim Application as FolderItem=GetFolderItem("Sparkle Test.app")

dim Contents as FolderItem = Application.Child("Contents")
dim plist as FolderItem = contents.Child("Info.plist")
dim Stream as BinaryStream = plist.OpenAsBinaryFile(true)

dim s as string = stream.Read(stream.Length)

dim b as CFBinaryDataMBS = NewCFBinaryDataMBSStr(s)
dim o as CFObjectMBS = NewCFObjectMBSFromXML(b)

if o isa CFDictionaryMBS then
dim d as CFDictionaryMBS = CFDictionaryMBS(o)
dim e as CFMutableDictionaryMBS = d.Edit

dim value, key as CFStringMBS

key=NewCFStringMBS("SUFeedURL")
value=NewCFStringMBS(feedURL)

e.Add key,value

key=NewCFStringMBS("SUPublicDSAKeyFile")
value=NewCFStringMBS("dsa_pub.pem")

e.add key,value

b=e.xml

s=B.str

Stream.Position=0
Stream.Write s
stream.Length=stream.Position // cut away rest of file

Return true

end if

Exception
Return false

End Function
End Class

Class Window1
Inherits Window
End Class


2. Test application

Class App
Inherits Application
// Constants
Const kFileQuitShortcut = Ctrl+Q
Const kFileQuit = E&xit
Const kEditClear = &Delete
End Class

Class Window1
Inherits Window
// Controls
ControlInstance
End ControlInstance

// Properties
Dim u As MySUUpdater



// Event implementations
Sub Open()
dim f as FolderItem

f=app.ExecutableFile.Parent.Child("Sparkle.framework")

if not SUUpdaterMBS.LoadFramework(f) then
MsgBox "Failed to load Sparkle framework."
quit
end if

u=new MySUUpdater

dim d as date
dim lines(-1) as string

lines.Append "Sparkle Status: "
lines.Append ""

f=u.hostBundle
if f=nil then
lines.Append "HostBundle: ?"
else
lines.Append "HostBundle: "+f.AbsolutePath
end if

lines.Append "FeedURL: "+u.feedURL

d=u.lastUpdateCheckDate
if d=nil then
lines.Append "LastUpdateCheckDate: ?"
else
lines.Append "LastUpdateCheckDate: "+d.LongDate+" "+d.LongTime
end if

// show information
MsgBox Join(lines,EndOfLine)

u.checkForUpdates

Exception e as NSExceptionMBS
MsgBox e.message


End Sub
End Class

Class MySUUpdater
Inherits SUUpdaterMBS
// Event implementations
Sub didFindValidUpdate(update as SUAppcastItemMBS)
log "did find valid update"
log "title: "+update.title
log "version: "+update.versionString
log "Signature: "+update.DSASignature

End Sub
Sub didFinishLoadingAppcast(update as SUAppcastMBS)
log "did finish loading appcast"

End Sub
Sub updaterDidNotFindUpdate()
log "updater did not find update"

End Sub
Sub willInstallUpdate(update as SUAppcastItemMBS)
log "will install update"

End Sub

// Methods
Sub log(s as string)
System.DebugLog s
window1.list.addrow s

End Sub
End Class


All movies




Links
MBS FileMaker blog