This shows you the differences between two versions of the page.
sample_code:backup_apps [2015/11/13 18:40] stevegarman [Backup your apps] |
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. | ||
- | |||
- | If you wish, you can save the mail as a draft, rather than sending it. | ||
- | |||
- | <code JavaScript archive.js> | ||
- | // | ||
- | var mygmail = app.GetUser(); | ||
- | |||
- | // | ||
- | function OnStart() | ||
- | { | ||
- | // | ||
- | lay = app.CreateLayout( " | ||
- | |||
- | |||
- | // | ||
- | txt = app.CreateText( " | ||
- | lay.AddChild( txt ); | ||
- | |||
- | // | ||
- | app.AddLayout( lay ); | ||
- | var fname = CreateArchive(); | ||
- | yesNo = app.CreateYesNoDialog( " | ||
- | yesNo.fname = fname; | ||
- | yesNo.SetOnTouch( yesNoMail_OnTouch ); | ||
- | } | ||
- | |||
- | // | ||
- | 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 yesNoMail_OnTouch( result ) | ||
- | { | ||
- | if( result==" | ||
- | { | ||
- | var fname = yesNo.fname; | ||
- | app.SendMail( mygmail, | ||
- | } | ||
- | } | ||
- | |||
- | </ | ||
- | ===== Warnings ===== | ||
- | ==== Personalise the code ==== | ||
- | You must change the email address in the first line | ||
- | ==== Version required ==== | ||
- | This code makes the assumption that you are using at least version 1.15 of DroidScript, | ||
- | ==== 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. |