Skip to content

Instantly share code, notes, and snippets.

Created April 14, 2011 16:38
Show Gist options
  • Select an option

  • Save anonymous/919877 to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/919877 to your computer and use it in GitHub Desktop.
/* updating functionality */
// 1. install all databases
var eventsDB = Ti.Database.install('dbEvents.sql','events');
eventsDB.close();
var imagesDB = Ti.Database.install('dbImages.sql','events_images');
imagesDB.close();
var venuesDB = Ti.Database.install('dbVenues.sql','venues');
venuesDB.close();
var videosDB = Ti.Database.install('dbVideos.sql','events_videos');
videosDB.close();
// 2. move lastUpdated.txt file to app directory
var savedFile = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory+Titanium.Filesystem.separator,'lastUpdated.txt');
if(savedFile.exists()){
} else {
var lastUpdatedFile = Titanium.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory, 'lastUpdated.txt');
savedFile.write(lastUpdatedFile);
}
// 3. if online, download newUpdates.txt from server
if (Titanium.Network.online) {
var xhr = Titanium.Network.createHTTPClient();
xhr.setTimeout(10000); // 10 secs
xhr.open('GET','URL/newUpdates.txt');
xhr.onload = function() {
newUpdatesFile = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory,'newUpdates.txt');
if(newUpdatesFile.exists()){
newUpdatesFile.deleteFile(true);
newUpdatesFile.write(this.responseData);
} else {
newUpdatesFile.write(this.responseData);
}
if(this.readyState == 4 && this.status == "200" )
{
tabGroup.open();
Titanium.App.Properties.setString('update', 'YES');
}
xhr.onerror = function()
{
tabGroup.open();
Titanium.App.Properties.setString('update', 'NO');
};
};
xhr.send();
} else {
tabGroup.open();
Titanium.App.Properties.setString('update', 'NO');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment