creating files problem in a standalone

Jan 21, 2008 at 6:01pm

creating files problem in a standalone

Hi,

I’m using the code below to save data in a file. This works well as long as I’m working with Max, but it doesn’t write in the file when I run the standalone program. I am able to read the file though.
In the code below, I’m posting a message if the system cannot open the file. I never get this message on the console, so I presume that the standalone can create or open the file, but maybe only in read mode? In fact, the data stored in these file can be read but cannot be changed in the standalone version of my program.

Thanks for your help.

Jean-Baptiste

function save(n)
{
var cpt = n%8;

var f = new File(“bkp”+cpt,”readwrite”);
var s = new Array(4);

if (f.isopen)
{
f.writefloat32(Math.PI);

f.close();

post(“nThe file “,f.foldername,f.filename,”has beed saved”);

} else {
post(“could not create file: “,f , “n”);
}

}

#35473
Jan 21, 2008 at 11:27pm

On 21 janv. 08, at 19:01, Jean-Baptiste Thiebaut wrote:

> Hi,
>
> I’m using the code below to save data in a file. This works well as
> long as I’m working with Max, but it doesn’t write in the file when
> I run the standalone program. I am able to read the file though.
> In the code below, I’m posting a message if the system cannot open
> the file. I never get this message on the console, so I presume that
> the standalone can create or open the file, but maybe only in read
> mode? In fact, the data stored in these file can be read but cannot
> be changed in the standalone version of my program.

Hi,

The save() method is called when you save the patch, which, AFAIK, is
something which is not possible in a standalone. You may have to use
other strategy to trigger the writing mechanism of your file.

HTH,
ej

#120964
Jan 21, 2008 at 11:46pm

Hey Emmanuel,

thanks for your answer.
Is there a save() method called when the program is closed? I just called this function “save” without guessing it could be a reserved word. I’ll try to change the name. I’ll let you know if it works.

JB

#120965
Jan 22, 2008 at 12:03am

On 22 janv. 08, at 00:46, Jean-Baptiste Thiebaut wrote:

> Hey Emmanuel,
>
> thanks for your answer.
> Is there a save() method called when the program is closed? I just
> called this function “save” without guessing it could be a reserved
> word. I’ll try to change the name. I’ll let you know if it works.

Nope, it’s called when the patch is saved (p11 in JavascriptInMax.pdf).

Cheers,
ej

#120966
Jan 22, 2008 at 7:55am

I changed the name of my function to “_save()” and the same problem occurs: the data can not be saved when the function is called from a standalone, while it works when it is called from Max.

I’m not too sure where the file would be created though. When the function is called from Max, the file is created in the same folder that contains the JS file. Within a standalone in Mac OS, where should the file be created anyway?

#120967
Jan 22, 2008 at 8:15am

On 22 janv. 08, at 08:55, Jean-Baptiste Thiebaut wrote:

> I changed the name of my function to “_save()” and the same problem
> occurs: the data can not be saved when the function is called from a
> standalone, while it works when it is called from Max.
>
> I’m not too sure where the file would be created though. When the
> function is called from Max, the file is created in the same folder
> that contains the JS file. Within a standalone in Mac OS, where
> should the file be created anyway?

Can you try to provide an absoulte path to your File object? You may
use the max.apppath property to find where the standalone is.

ej

#120968
Jan 22, 2008 at 12:42pm

Quote: Emmanuel Jourdan wrote on Tue, 22 January 2008 08:15
—————————————————-
> On 22 janv. 08, at 08:55, Jean-Baptiste Thiebaut wrote:
>
> > I changed the name of my function to “_save()” and the same problem
> > occurs: the data can not be saved when the function is called from a
> > standalone, while it works when it is called from Max.
> >
> > I’m not too sure where the file would be created though. When the
> > function is called from Max, the file is created in the same folder
> > that contains the JS file. Within a standalone in Mac OS, where
> > should the file be created anyway?
>
> Can you try to provide an absoulte path to your File object? You may
> use the max.apppath property to find where the standalone is.
>
> ej
>
>
—————————————————-

Trying this, I had another unexpected error:

function _save(n)
{

var f = new File(“bkp”,”readwrite”);
f.foldername = max.apppath; //this makes the both max and the standalone crash
}

#120969
Jan 22, 2008 at 12:47pm

> —————————————————-
>
> Trying this, I had another unexpected error:
>
> function _save(n)
> {
>
> var f = new File(“bkp”,”readwrite”);
> f.foldername = max.apppath; //this makes the both max and the standalone crash
> }

my mistake. f.foldername has no set method…

#120970
Jan 29, 2008 at 5:58pm

Hi,

I’m a bit desperate to get this working.

The function below save a file while I’m running Max but doesn’t when I’m running the standalone. But, more strange, while running the standalone, the file is opened (I have a message on the console) but the file is not written on the disk. I’ve checked everywhere and the file is not created, although the condition “f.isopen” is satisfied.

function _save(n)
{

var f = new File(“bkp”,”readwrite”);

if (f.isopen)
{
f.writefloat32(3.14159);
f.close();
post(“nthe file has been saved”);

}
else
post(“could not create file: “,f , “n”);

}

Any idea?

Thanks
JB

#120971
Jan 29, 2008 at 7:02pm

It seems that the problem is elsewhere. Please don’t waste your time on this, I’ll let you know what I’ve done wrong :)

#120972
Jan 30, 2008 at 8:42am

Hi,

I finally solved the problem. We apparently can’t modify a file that has been included in the standalone package.

To give you an example, I have been including a number of files, called “bkp0″, “bkp1″, and so on, in my standalone so the files could be used by the programs. My app allows to modify these files. When these are stored within the program package I can’t modify them, so I guess that it forces the file to be opened as “read” instead of “readwrite”, for instance.

The solution was to remove the files before creating the standalone so that they would not be included, then add them manually at the same level as the application. The files can then be modified.

Cool. For those who used my program Pompiloop and reported about this bug, this is now fixed and should be online sometime today at http://www.pompiloop.com/

Jean-Baptiste

#120973
Jan 30, 2008 at 10:15am

On 30 janv. 08, at 09:42, Jean-Baptiste Thiebaut wrote:

>
> Hi,
>
> I finally solved the problem. We apparently can’t modify a file that
> has been included in the standalone package.
>
> To give you an example, I have been including a number of files,
> called “bkp0″, “bkp1″, and so on, in my standalone so the files
> could be used by the programs. My app allows to modify these files.
> When these are stored within the program package I can’t modify
> them, so I guess that it forces the file to be opened as “read”
> instead of “readwrite”, for instance.
>
> The solution was to remove the files before creating the standalone
> so that they would not be included, then add them manually at the
> same level as the application. The files can then be modified.

I can confirm the behavior. Thanks for the report.

ej

#120974

You must be logged in to reply to this topic.