_AddPermissions("extsdcard");
_AddPermissions("Storage")
var txt1, txt2, txt3, txt4, l1, l2
var path, uri
var pathtxt, uritxt
function OnStart() {
path = app.LoadText("path","")
uri = app.LoadText("uri","")
lay = app.CreateLayout( "linear", "Top,Left,FillXY" )
lay.SetMargins( 0.02)
txt3 = app.AddText( lay,"Check Permission ExtSDCard " )
txt4 = app.AddText( lay,"Check Permission Storage" )
txt1 = app.AddText( lay,"List Permissions ExtSDCard (touch to remove)",-1,-1,"bold" )
l1 = app.AddList( lay,app.ListPermissions( "ExtSDcard" ) )
l1.SetOnTouch( function (t,b,ix) {alert(t);app.RemovePermission(t);display();})
txt2 = app.AddText( lay,"List Permissions Storage (touch to remove)" ,-1,-1,"bold")
l2 = app.AddList( lay,app.ListPermissions( "Storage" ) )
l2.SetOnTouch( function (t,b,ix) {alert(t);app.RemovePermission(t);display();})
permBtnx = app.AddButton(lay, "GetPermission ExtSDcard - pick folder without spaces", -1, -1);
permBtnx.SetOnTouch(function() {app.GetPermission("ExtSDcard",OnPermission)})
permBtni = app.AddButton(lay, "GetPermission Internal - pick internal folder without spaces", -1, -1);
permBtni.SetOnTouch(function() {app.GetPermission("Internal",OnPermission)})
permBtne = app.AddButton(lay, "GetPermission External - pick external folder without spaces", -1, -1);
permBtne.SetOnTouch(function() {app.GetPermission("External",OnPermission)})
permBtnu = app.AddButton(lay, "GetPermission USB - pick USB folder without spaces", -1, -1);
permBtnu.SetOnTouch(function() {app.GetPermission("usb",OnPermission)})
pathtxt = app.AddText(lay,path)
testBtn = app.AddButton(lay,"Test file functions with path",-1,-1)
testBtn.SetOnTouch(testfolder)
if (path == "") testBtn.Hide()
cf1 = app.AddButton( lay,"Choosefile with path",-1,-1 )
cf1.SetOnTouch( function() {
app.ChooseFile( "Choose File", "*/*", chosen, path)
} )
if (uri == "") cf1.Hide()
uritxt = app.AddText(lay,uri,-1,-1,"multiline,left")
testBtn2 = app.AddButton(lay,"Test file functions with uri",-1,-1)
testBtn2.SetOnTouch(testuri)
if (uri == "") testBtn2.Hide()
cf2 = app.AddButton( lay,"Choosefile with uri",-1,-1 )
cf2.SetOnTouch( function() {
app.ChooseFile( "Choose File", "*/*", chosen, uri)
} )
if (uri == "") cf2.Hide()
app.AddLayout( lay )
display()
}
function OnPermission (pathURI) {
uri = pathURI
var folderName = uri.split("%3A")[1].replace("%2F", "/")
// path = "/Internal/"+folderName
path = app.GetInternalFolder()+"/"+folderName
if (uri.search(/primary/i) ==-1) path = app.GetExternalFolder()+"/"+folderName
app.SaveText("path",path)
app.SaveText("uri",uri)
testBtn.Show()
testBtn2.Show()
display()
}
function display() {
check = app.ListPermissions( "ExtSDcard" )
l1.SetList( check.replaceAll(":","^c^" ))
check = app.ListPermissions( "Storage" )
l2.SetList( check.replaceAll(":","^c^" ))
check = app.CheckPermission( "ExtSDcard" )
txt3.SetText( "Check Permission ExtSDcard ungranted = " + check )
check = app.CheckPermission( "Storage" )
txt4.SetText("Check Permission Storage ungranted = " + check )
pathtxt.SetText(path)
uritxt.SetText(uri)
uritxt.sett
}
function chosen(file) {alert(file);}
function testfolder() {test(path);}
function testuri() {test(uri);}
function test(parm) {
x = parm + "/SAFtest"
// alert(x)
app.MakeFolder(x)
// alert("makefolder "+app.Folder(x))
alert("makefolder "+app.FolderExists(path+"/SAFtest")) // use path for check
alert("folderexists "+app.FolderExists(x))
alert("isfolder "+app.IsFolder(x))
file = x+"/text.txt"
app.WriteFile( file, "Works")
// alert("writefile "+app.FileExists(file))
alert("writefile "+app.ReadFile( file ))
// alert("readfiledata "+app.ReadFileData( file ,"asci")) // unexpected end of JSON for uri
alert("fileexists "+app.FileExists(file))
alert("getfiledata "+ app.GetFileDate( file ))
alert("getfilesize "+ app.GetFileSize( file ))
// alert("getfiledata "+ app.GetFileData( file ))
over = x+"/overwrite.txt"
app.WriteFile( over, "Fails")
app.ReplaceInFile( over,"Fails","Works")
alert("replaceinfile "+app.ReadFile( over ))
app.WriteFile( over,"XX" ) // write shorter file
alert("overwrite "+app.ReadFile( over ))
copy = x+"/copyfile.txt"
app.CopyFile( over,copy )
alert("copyfile "+ app.ReadFile( copy ))
alert("listfolder "+app.ListFolder( x ))
alert("walkfolder "+app.WalkFolder( x,null,null,null,"alphasort").toString())
app.DeleteFile( over )
app.DeleteFile( copy )
app.CopyFolder( x, parm+"/SAFcopy" )
alert("copyfolder "+ app.FolderExists( path+"/SAFcopy" )) // use path for test
app.DeleteFolder( path+"/SAFcopy" ) // use path fof tidy up
newfile = x+"/rename.txt"
app.RenameFile( file, newfile )
// alert("renamefile "+app.FileExists(newfile))
alert("renamefile "+app.ReadFile(newfile))
newfolder = parm + "/SAFRenamed"
app.RenameFolder( x, newfolder )
// alert("renamefolder "+app.FolderExists( newfolder ))
alert("renamefolder "+app.ReadFile(newfolder+"/rename.txt" ))
app.DeleteFile( newfolder + "/rename.txt")
alert("deletefile "+!app.FileExists(path+"/SAFRenamed/rename.txt")) //use path for check
app.DeleteFolder( newfolder )
alert("deletefolder "+!app.FolderExists(path+"/SAFRenamed")) // use path for check
app.DeleteFolder( path+"/SAFRenamed" ) // use path for tidy up
}
//
These all fail using a uri (from GetPermissions)
MakeFolder
FoldefExisis
IsFolder
FileExists
GetFileData
GetFileSize
CopyFile
CopyFolder
DeleteFolder (?)
WalkFolder (also problems using path)
Write File - writing short text over existing text