Page 1 of 1

SaveFileRequester and long names

Posted: Tue Feb 09, 2010 11:40 am
by UserOfPure
I just found out today that if you call SaveFileRequester with a long file name, the requester isn't shown, the program just skips past the command as though it wasn't even there. My request is, could a check be done to ensure the requester isn't ignored, or do we have to check the length of every filename passed to it? I know this issue is probably due to #MAX_LEN path sizes, but it's a problem:

Code: Select all

file$="C:\Test"+Space(300)+"File.txt"
SaveFileRequester("Save file",f$,"",0) ; Never shown!
What this command currently needs to be 100% safe in all situations (just an example):

Code: Select all

file$="C:\Test"+Space(300)+"File.txt"
f$=GetFilePart(file$) : If Len(f$)>100 : f$=Left(f$,100) : EndIf
SaveFileRequester("Save file",GetPathPart(file$)+f$,"",0)
It's bad that we need to do a Len() check and Left() crop before every use of SaveFileRequester(). BTW, the filenames were obtained by parsing a text file of a list, so yes, the checks and crops ARE needed.

Re: SaveFileRequester and long names

Posted: Tue Feb 09, 2010 11:56 am
by Kurzer
I guess windows itself have a problem with your pathlength.
Check #MAX_PATH on your system to find out the maximum possible path length you can use in windows:

Debug #MAX_PATH

Space(300) already exeeds this limit, so I dont think it it is a problem of PB.

Re: SaveFileRequester and long names

Posted: Tue Feb 09, 2010 12:01 pm
by UserOfPure
I know it's a Windows limit of #MAX_PATH, and that's my point. Should the requester just ignore an oversize file length and do nothing? Couldn't some sort of error be raised so we can trap it, and THEN do the cropping accordingly?

Re: SaveFileRequester and long names

Posted: Tue Feb 09, 2010 4:54 pm
by Trond
Strange, it's shown here even though I use Space(3000).

Re: SaveFileRequester and long names

Posted: Tue Feb 09, 2010 5:04 pm
by Demivec
Trond wrote:Strange, it's shown here even though I use Space(3000).
Same here. Win XP Home Sp3 32-bit.

In the meantime you can avoid an error check by simply cropping every filename, just use:

Code: Select all

File$="C:\Test"+Space(300)+"File.txt"
SaveFileRequester("Save file",GetPathPart(File$)+Left(GetFilePart(File$),100),"",0)

Re: SaveFileRequester and long names

Posted: Tue Feb 09, 2010 7:50 pm
by ABBKlaus
looks like you found a bug :wink: (i changed f$ in the example with file$)

Crashes here in ASCII mode.
[ERROR] Invalid memory access. (read error at adress 2581586)
Never finishes the call to SaveFileRequester when in UNICODE mode.

Code: Select all

file$="C:\Test"+Space(300)+"File.txt"
SaveFileRequester("Save file",file$,"",0) ; Never shown in UNICODE mode / crashes in ASCII mode
tested with PB4.41x86 on Windows 7 x64

Re: SaveFileRequester and long names

Posted: Tue Feb 09, 2010 9:00 pm
by Demivec
ABBKlaus wrote:looks like you found a bug :wink: (i changed f$ in the example with file$)

Crashes here in ASCII mode.
[ERROR] Invalid memory access. (read error at adress 2581586)
Never finishes the call to SaveFileRequester when in UNICODE mode.

Code: Select all

file$="C:\Test"+Space(300)+"File.txt"
SaveFileRequester("Save file",file$,"",0) ; Never shown in UNICODE mode / crashes in ASCII mode
tested with PB4.41x86
Should have double checked that variable. Good catch. :wink:

After making the same change the code sample does not show a requester nor does it error out in either Unicode nor Ascii mode using PB 4.41x86 with or without debugger.

Re: SaveFileRequester and long names

Posted: Tue Feb 09, 2010 9:31 pm
by ABBKlaus
@Demivec,

does my example above finishes executing ?
(At least here on Win7x64 its crashing)

[Update]Tested in VirtualBox and XPSP3 it is not crashing and it finishes executing, but the requester is not shown[/Update]

Re: SaveFileRequester and long names

Posted: Wed Feb 10, 2010 8:02 pm
by ABBKlaus
finally i made it crash on XP too :

Code: Select all

file$="C:\Test"+Space(99999)+"File.txt"
Res$=SaveFileRequester("Save file",file$,"",0)