Bug: app.WriteFile() doesn't truncate SAF files
1) Steps to reproduce:
Select a text file with app.ChooseFile().
2) Write a long string:
Hello how are you?
3) Write a shorter string:
I'm good.
4) Read the file using app.ReadFile().
Expected: The file should contain only:
I'm good.
Actual: The file is not truncated correctly. Writing longer content works, but writing shorter content leaves the previous content instead.
Example:
//Called when application is started.
function OnStart()
{
//Create a layout with objects vertically centered.
lay = app.CreateLayout( "Linear", "VCenter,FillXY" )
app.ChooseFile( "Choose a file", "*/*", test )
txt = app.CreateText( "" )
lay.AddChild( txt )
//Create a text label and add it to layout.
btnshort = app.CreateButton( "Long" )
btnshort.SetOnTouch( btnshort_OnTouch )
lay.AddChild( btnshort )
btnlong = app.CreateButton( "Short" )
btnlong.SetOnTouch( btnlong_OnTouch )
lay.AddChild( btnlong )
//Add layout to app.
app.AddLayout( lay )
}
function test( file )
{
fileuri = file;
txt.SetText( app.ReadFile( file ) )
}
function btnshort_OnTouch()
{
app.WriteFile( fileuri, "Hello how are you?" )
txt.SetText( app.ReadFile( fileuri ) )
}
function btnlong_OnTouch()
{
app.WriteFile( fileuri, "I'm good." )
txt.SetText( app.ReadFile( fileuri ) )
}