a little help please

Started by wadmixfm, June 07, 2021, 23:13:40

Previous topic - Next topic

wadmixfm

i am trying to save a file with the inbuilt file requester, is it possible ??

loading (or requesting) works great

i cant seem to make it work

lee

Midimaster

#1
The file request is not the part where you save a file. FileRequest is only responsible for defining the file name and the path.

So first question is: What do you want to save? Binary datas? Plain text? A Stream? Often we want to save the content of a variable or the RAM content of a bank. But there are different ways, depending on what you want to save.

The FileRequest only shows a windows to the user, where he can select a folder and define a file name. When the user clicks "SAVE" it looks like the saving is done, but in reality this is the moment where the saving starts.

Example for saving the content of a string:
Code (BlitzMax) Select
local Text$="hello world"
SaveText Text, "test.txt"

As you can see: There is no need for using the FileRequest for saving anything.

The FileRequest would only define the name of the file and is fininshes before the saving start. Here is the same example with FileRequest:

Code (BlitzMax) Select
Local text$="HelloWorld"

Local FileName$ = RequestFile("select a name", "Textfiles:txt", True)
Print "User wants this Filename: " + Filename
If FileName<>"" Then
SaveText Text, FileName
Else
Print "file note saved"
EndIf

Now the user is forced to select a existing file or defining a new name with the extension ".txt".
there are several possible scenarios:

- If the user clicks at "CANCEL" the variable FilenName$ will be empty. This means that not should not save the file.

- If the user defines a name or selects a existing file, the FileName$ will contain a whole path and not only the name.

- If the user only enters the name without using an extension, the FileName$ will automatically get the extension ".TXT"

- If the user enters a filename like "image.png" also the filename will have the extension ".PNG". So you have to check it this!

Code (BlitzMax) Select
Local text$="HelloWorld"

Local FileName$ = RequestFile("select a name", "Textfiles:txt", True)
Print "User wants this Filename: " + Filename
If FileName<>"" And ExtractExt(FileName)="txt" Then
SaveText Text, FileName
Else
Print "file note saved"
EndIf

...back from Egypt

wadmixfm

Top man Midimaster :)

also whilst your here i cant get your miniaudio wrapper to compile on ng 64bit

i downloaded the mod folder did everything i was supposed to and it fails

can you enlighten me :)

Lee

wadmixfm

on the file requester issue

i want the requester to default to a folder say

/Applications/bla/bla/

where do i type that everything i try it defaults to the last folder i opened

lee

Midimaster

#4
this needs to use the 4th parameter of the function:

Code (BlitzMax) Select
Local UserDir$=""
Local FileName$ = RequestFile("select a name", "Textfiles:txt", True, UserDir )
Print "User wants this Filename: " + Filename

'now set user dir for the next call:
UserDir= ExtractDir(FileName) + "/"

Print "new user dir =" + UserDir
....
' later:
FileName$ = RequestFile("SECOND TIME CALL !!!!", "Textfiles:txt", True, UserDir )


this is also often used together with Brucey new functions of the "Volumes"-Mod. Now part of "Others":
GetUserHomeDir()       Returns the user home directory.
GetUserDesktopDir()    Returns the user Desktop directory.
GetUserAppDir()        Returns the user directory for application data.
GetUserDocumentsDir()  Returns the user Documents directory.
GetCustomDir()         Returns the custom directory path.



Code (BlitzMax) Select
Local UserDir$=GetUserAppDir()
Local FileName$ = RequestFile("select a name", "Textfiles:txt", True, UserDir )
...back from Egypt

wadmixfm

Thank you so much for the help

Lee