This shows you the differences between two versions of the page.
sample_code:backup_apps [2015/01/11 19:43] stevegarman created |
sample_code:backup_apps [2015/11/15 00:00] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Backup your apps ====== | ||
- | Following a reminder from Dave on the discussion group that we should be backing up our apps regularly, I thought I would post a simple way of sending yourself an email archive of your DroidScript folder. | ||
- | The following code is intended as a guide to one way you can keep a snapshot of your code at any given time. | ||
- | |||
- | You may well find the archiving code more useful than the email code. | ||
- | |||
- | <code JavaScript archive.js> | ||
- | var mygmail = " | ||
- | var mypass = " | ||
- | |||
- | // | ||
- | function OnStart() | ||
- | { | ||
- | // | ||
- | lay = app.CreateLayout( " | ||
- | |||
- | |||
- | // | ||
- | txt = app.CreateText( " | ||
- | lay.AddChild( txt ); | ||
- | |||
- | // | ||
- | app.AddLayout( lay ); | ||
- | var fname = CreateArchive(); | ||
- | sendGmail( mygmail, | ||
- | } | ||
- | |||
- | // | ||
- | |||
- | function CreateArchive( ) | ||
- | { | ||
- | var archfolder = "/ | ||
- | app.MakeFolder(archfolder); | ||
- | // | ||
- | var zip = app.CreateZipUtil(); | ||
- | var fldr = "/ | ||
- | var archname = (new Date).toISOString().slice(0, | ||
- | archname = " | ||
- | archname = archname.replace(/ | ||
- | var file = archfolder+archname+" | ||
- | zip.Create( file ); | ||
- | |||
- | app.ShowProgress( " | ||
- | AddFolder( zip, | ||
- | app.HideProgress(); | ||
- | zip.Close(); | ||
- | |||
- | return file; | ||
- | } | ||
- | |||
- | |||
- | // | ||
- | |||
- | function AddFolder( zip, | ||
- | |||
- | { | ||
- | txt.SetText(name); | ||
- | var list = app.ListFolder( fldr,"", | ||
- | for( var i=0; | ||
- | { | ||
- | var title = list[i]; | ||
- | if( !app.IsFolder( fldr+"/" | ||
- | zip.AddFile( name+"/" | ||
- | else | ||
- | AddFolder( zip, | ||
- | } | ||
- | } | ||
- | |||
- | function sendGmail(addr, | ||
- | { | ||
- | // | ||
- | var email = app.CreateEmail( addr, | ||
- | email.SetSMTP( " | ||
- | email.SetOnStatus( email_OnStatus ); | ||
- | |||
- | // | ||
- | app.ShowProgress( " | ||
- | email.Send( attach, | ||
- | addr, | ||
- | } | ||
- | |||
- | // | ||
- | function email_OnStatus( status ) | ||
- | { | ||
- | app.HideProgress(); | ||
- | app.Alert( status ); | ||
- | } | ||
- | |||
- | </ | ||
- | ===== Warnings ===== | ||
- | ==== Personalise the code ==== | ||
- | You must change the email address and password in the first two lines | ||
- | ==== Version required ==== | ||
- | This code makes the assumption that you are using at least version 1.15 of DroidScript, | ||
- | ==== Possible Gmail Problem ==== | ||
- | The code used for emailing is pretty simplistic and you may get an authentication error if your gmail account is set to high security. | ||
- | ==== Filling your sdcard ==== | ||
- | There is no code included to delete the zip files. | ||
- | |||
- | Over time, / | ||
- | |||
- | You should probably delete those files manually from time to time, probably after emailing them or placing them in your cloud storage. |