"use strict"
var edt, txt // global variables
function OnStart()
{
var lay = app.CreateLayout("linear", "VCenter,FillXY")
lay.SetChildMargins( 0.01, 0.01, 0.01, 0.03 )
var msg = storageIsScoped()+"\n"+
(app.IsPremium()?"":"Not ")+"Premium"+"\n"+
app.GetModel()+"\n"+
app.GetUser()+
builderInstalled()
txt = app.AddText( lay, msg, -1, -1, "Left,Multiline" )
edt = app.AddTextEdit(lay,
"
https://androidscript.org/apk/DroidScript_209/apkbuilder_209.ppk",
-1,-1,"autoSelect")
edt.SetOnChange( function (){
if(this.GetText()=="?")
this.SetText("
http://www.androidscript.org/Plugins/@.zip")
})
var btn = app.AddButton(lay, "Install")
btn.SetOnTouch(btn_OnTouch)
btn.SetMargins(0.01, 0.05, 0.01, 0.01)
app.AddLayout(lay)
}
function btn_OnTouch()
{
// url to retrieve plugin file from
var srcFileUrl = edt.GetText()
// intermediate file can be read/written by anyone
var targetDir = app.GetPrivateFolder("temp", "external")
var dld = app.CreateDownloader();
dld.SetOnError(dld_OnError);
dld.SetOnDownload(dld_OnDownload);
dld.Download(srcFileUrl, targetDir);
}
function dld_OnDownload(path)
{
// Plugins folder
var plugs = "/Storage/DroidScript/Plugins"
// plugs path + filename
var dest = plugs + "/" + (path.split("/")).pop()
// default status
var status = "Copy failed"
// ensure Plugins folder existd
app.MakeFolder(plugs)
// delete destination filevif it exists
if(app.FileExists(dest)) app.DeleteFile(dest)
app.CopyFile(path, dest)
if(app.FileExists(dest))
{
//edt.SetText( "" )
status = "Success:\nPlease restart DroidScript\n\nMake sure all DS windows are closed before restarting"
}
app.Alert(status, dest);
}
function dld_OnError(err)
{
app.Quit("Error:\n"+err)
}
// returns true=Scoped false=Traditional storage
function storageIsScoped() {
return (app.IsScoped()?"Scoped":"Traditional")+" Storage"
}
function builderInstalled() {
var msg = "Builder plugin not installed";
var path = app.GetPrivateFolder("Plugins") +
"/apkbuilder/ApkBuilder.inc"
if(app.FileExists(path)) {
app.LoadPlugin("ApkBuilder");
msg = "DroidScript Version "+app.GetDSVersion().toFixed(2)
+"\n"+
"Builder version " + (new ApkBuilder().GetVersion()).toFixed(2);
} else if(app.IsAPK()) {
msg = "Built with " + app.GetDSVersion().toFixed(2);
}
return "\n\n"+msg
}