QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: Unseen Machine on July 03, 2020, 04:11:58 am

Title: _FILEEXISTS error.
Post by: Unseen Machine on July 03, 2020, 04:11:58 am
Hi Folks,

It's not that the files dont exist cause i know they do, it's just if i call _FILEEXISTS my program just hangs up. Any ideas why?

Here's how i using it....

Code: QB64: [Select]
  1.       DIM Tmp_Texture AS BSP_Texture
  2.       NumTXRecs& = Entry(Index&).Size / LEN(Tmp_Texture)
  3.       DIM Texture(NumTXRecs& - 1) AS BSP_Texture
  4.       GET #InFile, BytePos&, Texture()
  5.       _MEMPUT Level.DataPntr, Level.DataPntr.OFFSET + MemOffset, Texture()
  6.  
  7.       '// Load all the texture files???
  8.       FOR i& = 0 TO NumTXRecs& - 1
  9.        PRINT Texture(i&).Name
  10.        IF _FILEEXISTS(RTRIM$(Texture(i&).Name) + ".tga") THEN PRINT "File Found"
  11.       NEXT
  12.  
  13.  

Thanks

Unseen
Title: Re: _FILEEXISTS error.
Post by: Petr on July 03, 2020, 04:37:47 am
Hi.

How is a dump of files from the disk to the field created? Is it including the full path to the file, or is the EXE in a different folder than the files and array contain just file names?

Filenames - do they contain unicode characters? If so, you need direntry.h to extract the files from disk (I've tried it and it works well) unlike the DIR command with file redirection, in DIR case are unicode characters replaced with spaces. (so for file name with unicode characters then DIR return invalid name)

Wait... in your code, you load texture to memory, you do not write texture data to harddrive to file?
Here miss something as

FF = FREEFILE
OPEN file FOR BINARY AS FF
PUT FF,, Texture()
CLOSE FF
Title: Re: _FILEEXISTS error.
Post by: Unseen Machine on July 03, 2020, 04:55:28 am
Quote
Filenames - do they contain unicode characters?

To be honest i don't know! They are read from a .bsp file, are specified as being 64 bytes in length and are not null terminated. These strings must contain something else though as RTRIM$ is not working on them!

Quote
in your code, you load texture to memory

Yep, i'm loading (well attempting to load) all the textures the level file uses. (I'd post the code and files but it's over 250mb....)

Unseen
Title: Re: _FILEEXISTS error.
Post by: Petr on July 03, 2020, 05:09:37 am
Good. Is there a field behind the file names indicating the size of the files in bytes? Is it written one after the other (binary data of the first file, then binary data of the next and so on)? Did you try the method A $ = SPACE $ (file size) then GET and then paste it into the file? Or is there something else between the file names and then comes the area where the binary data of the individual files is? I don't know if the TGA format has any identifiers at the beginning and end of the file, so I'd try to find out the location in the file and deduce how it's written in a row.

What ASC code do there have spaces in file names? The spaces may be changed to another code that _TRIM $ does not work with. Try converting these characters to spaces, then _TRIM $ will work for you and maybe it will help.

Code: QB64: [Select]
  1. a$ = "    HI   "
  2. b$ = STRING$(5, CHR$(255)) + "HI" + STRING$(5, CHR$(255))
  3.  

Title: Re: _FILEEXISTS error.
Post by: RhoSigma on July 03, 2020, 05:22:03 am
Just a guess, as I had a similar problem in GuiTools,
you take the filename from Texture().NAME, which is probably a fixed length string in your Texture UDT. Now assigning a value to a fixed length string in QB64 will properly fill the remaining bytes of a fixed length string (if any) with spaces, but you don't assign a value, but loading the contents out of a file via GET, hence you get into Texture().NAME whatever is in the file at that position, which may even be zeros. Using RTRIM in the _FILEEXIST call will only remove spaces, but not zeros. The zeros remain ant the end of the string and that makes _FILEEXIST failing.

I've made LStrip/RStrip functions in GuiTools (dev_framwork/GuiAppFrame.bm), which are much smarter than LTRIM/RTRIM and can handle the problem described above, just replace RTRIM with RStrip and use mode stripFIX.
Title: Re: _FILEEXISTS error.
Post by: Unseen Machine on July 03, 2020, 05:25:32 am
Quote
Is there a field behind the file names indicating the size of the files in bytes
Yes, the filenames are always 64 bytes long but not all of the bytes are always used.

I've just discovered that SOME of the entries are null terminated (chr$(0)), and for these i can now manipulate, now i've just gotta go through and find out how to sort out the ones which arent!

Quote
Try converting these characters to spaces, then _TRIM $ will work for you and maybe it will help.

No really the way i wanted to do it but i agree, it's a valid work around.

Quote
you take the filename from Texture().NAME, which is probably a fixed length string in your Texture UDT

Exactly that.

Quote
I've made LStrip/RStrip functions in GuiTools (dev_framwork/GuiAppFrame.bm), which are much smarter than LTRIM/RTRIM and can handle the problem described above, just replace RTRIM with RStrip and use mode stripFIX.

Thanks for the suggestion, i'll have a look into it.

Unseen
Title: Re: _FILEEXISTS error. - Resolved
Post by: Unseen Machine on July 03, 2020, 07:42:07 am
I made a work around thanks to the suggestions i received and now it works!

Code: QB64: [Select]
  1. FUNCTION BSP_File_Conform$ (File$) '// Changes file names so we can use them
  2.  
  3.  Allowed$ = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_\/"
  4.  
  5.  FOR i% = 1 TO LEN(File$)
  6.   Ltr$ = MID$(File$, i%, 1)
  7.   IF INSTR(Allowed$, Ltr$) OR INSTR(Allowed$, UCASE$(Ltr$)) THEN
  8.    IF Ltr$ = "/" THEN
  9.     FName$ = FName$ + "\"
  10.    ELSE
  11.     FName$ = FName$ + Ltr$
  12.    END IF
  13.   END IF
  14.  
  15.  BSP_File_Conform$ = FName$
  16.  

Thanks folks

Unseen