SaveFileRequester and long names

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
UserOfPure
Enthusiast
Enthusiast
Posts: 469
Joined: Sun Mar 16, 2008 9:18 am

SaveFileRequester and long names

Post 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.
User avatar
Kurzer
Enthusiast
Enthusiast
Posts: 670
Joined: Sun Jun 11, 2006 12:07 am
Location: Near Hamburg

Re: SaveFileRequester and long names

Post 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.
PB 6.02 x64, OS: Win 7 Pro x64 & Win 11 x64, Desktopscaling: 125%, CPU: I7 6500, RAM: 16 GB, GPU: Intel Graphics HD 520, User age in 2024: 56y
"Happiness is a pet." | "Never run a changing system!"
UserOfPure
Enthusiast
Enthusiast
Posts: 469
Joined: Sun Mar 16, 2008 9:18 am

Re: SaveFileRequester and long names

Post 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?
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: SaveFileRequester and long names

Post by Trond »

Strange, it's shown here even though I use Space(3000).
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: SaveFileRequester and long names

Post 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)
ABBKlaus
Addict
Addict
Posts: 1143
Joined: Sat Apr 10, 2004 1:20 pm
Location: Germany

Re: SaveFileRequester and long names

Post 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
Last edited by ABBKlaus on Tue Feb 09, 2010 9:31 pm, edited 1 time in total.
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: SaveFileRequester and long names

Post 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.
ABBKlaus
Addict
Addict
Posts: 1143
Joined: Sat Apr 10, 2004 1:20 pm
Location: Germany

Re: SaveFileRequester and long names

Post 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]
ABBKlaus
Addict
Addict
Posts: 1143
Joined: Sat Apr 10, 2004 1:20 pm
Location: Germany

Re: SaveFileRequester and long names

Post 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)
Post Reply