Page 1 of 2

Wrong amount returned by FileSize()

Posted: Tue Oct 27, 2020 9:55 pm
by Psychophanta

Code: Select all

debug filesize("C:\Program Files (x86)\EAGLE\projects\myProjects\Amplificador de potencia\eagle.epf")
this one returns 274 bytes for all x86 PB versions I have tested, including PB5.73B2.
BUT the thing returns 12674 bytes (which is the real size) for all tested x64 PB versions like PB5.00, 5.31, etc.

If file is needed, I can send it; so you can test yourself.

// Moved from "Bugs - Windows" to "Coding Questions" (Kiffi)

Re: Wrong amount returned by FileSize()

Posted: Tue Oct 27, 2020 10:25 pm
by infratec
What returns:

Code: Select all

Debug FileSize("c:\Program Files (x86)\PureBasic\Examples\Sources - Advanced\Waponez II\Waponez II.pb")
In my case with PB x86 5.72 it reports the right size: 11569

Also

Code: Select all

Debug FileSize("c:\EAGLE-7.6.0\projects\examples\ti-launchpad\eagle.epf")
reports 4016 which is correct.

Re: Wrong amount returned by FileSize()

Posted: Wed Oct 28, 2020 12:43 am
by BarryG
Where can we download the Eagle file?

Re: Wrong amount returned by FileSize()

Posted: Wed Oct 28, 2020 3:13 am
by leonhardt
Or you can use API like GetFileSize_() to test again?

Re: Wrong amount returned by FileSize()

Posted: Wed Oct 28, 2020 9:04 am
by Psychophanta
BarryG wrote:Where can we download the Eagle file?
Actually, this issue is strange.
Looks like there is nothing to do with the file itself, because if i put it in other path, the result is correct. So the problem it is that path. :?

Re: Wrong amount returned by FileSize()

Posted: Wed Oct 28, 2020 9:43 am
by Psychophanta
leonhardt wrote:Or you can use API like GetFileSize_() to test again?

Code: Select all

debug filesize("C:\Program Files (x86)\EAGLE\projects\myProjects\Amplificador de potencia\eagle.epf"); <- 274  ; wrong result !
debug filesize("C:\Program Files (x86)\EAGLE\projects\myProjects\Amplificador de potencia\eagle - copia.epf"); <- 12674  ; just a copy => correct result: !!! O_O !!!
debug filesize("D:\AL\new\Amplificador de potencia\eagle.epf"); <- 12674. same file in other location ; correct result !

Openfile(0,"C:\Program Files (x86)\EAGLE\projects\myProjects\Amplificador de potencia\eagle.epf")
debug GetFileSize_(FileID(0),0); <- 274  ; wrong result !
closefile(0)
Command line MSDOS in a win 8.1 x64 in a shell window:
>dir "C:\Program Files (x86)\EAGLE\projects\myProjects\Amplificador de potencia\eagle.epf"
returns correct value.

Mystery :shock:

Re: Wrong amount returned by FileSize()

Posted: Wed Oct 28, 2020 9:56 am
by BarryG
Where can we download the Eagle file? And what size does Lof() return if you open it?

Re: Wrong amount returned by FileSize()

Posted: Wed Oct 28, 2020 10:11 am
by Marc56us
If this file is a parameter file of a program (EAGLE: Schematic ?), make sure that the program that uses it is not running (this may explain why its size may vary from time to time and why it doesn't move if you copy this file elsewhere)
To find out if it is not being used by another process, try moving it: if error, it's in use.
The fact that the size changes between the 32 and 64 bit versions of PB can be explained by the API used internally by PB which may not be the same ? (Current or cached file size. ?)

Re: Wrong amount returned by FileSize()

Posted: Wed Oct 28, 2020 10:43 am
by cas
My guess is that you probably edited that file in eagle running in user mode (not as admin) so when you saved it, it saved it to virtualstore folder because non-admins have read-only access to program files since vista. Go to compiler options and enable "Request User mode for Windows Vista and above (no virtualisation)".

Re: Wrong amount returned by FileSize()

Posted: Wed Oct 28, 2020 11:26 am
by leonhardt
if API calling result is also not correct,I think no bugs in the PB command.

Re: Wrong amount returned by FileSize()

Posted: Wed Oct 28, 2020 3:56 pm
by Psychophanta
BarryG wrote:Where can we download the Eagle file? And what size does Lof() return if you open it?
Here is that file:
https://www.dropbox.com/s/vqh85ed8ttrtc ... e.epf?dl=0
However I guess it is nonsense the file itself, but the path is making something wrong for x86 PB compilers, even with x64 ones it works correctly.
Lof(0) returns also the wrong amount !!

@leonhardt, maybe, but why that wierd behaviour?

@Marc56us, I have copied it, deleted it, created again as admin, etc. but the issue continued the same.
cas wrote:Go to compiler options and enable "Request User mode for Windows Vista and above (no virtualisation)
Waaaaw, that's it! :shock:
Activating that, the issue dissappeared !! :?
Still don't understand. Never happened this before.

Re: Wrong amount returned by FileSize()

Posted: Wed Oct 28, 2020 4:22 pm
by cas
Go to virtualstore (appdata\local\virtualstore) and you will find your 274byte file there.

Re: Wrong amount returned by FileSize()

Posted: Wed Oct 28, 2020 4:26 pm
by Marc56us
As cas has rightly pointed out, this is the normal behavior due to the VitrualStore
The 32-bit program was designed (wrongly) to save the data file in the program directory, which modern versions of Windows no longer (rightly) allow.
To allow these old programs to work, VirtualSore redirects the writings to a virtual folder.
So I think you have two versions of the eagle.epf file. One in ProgramFile and the other in the virtual folder.
The 32 bit compiler reads the original one (much smaller) while the 64 bit compiler follows the path to the VirtualStore and therefore reports the right size.

Just change:
C:\Program Files (x86) to %localappdata% + \virtualstore\

Code: Select all

debug FileSize(GetEnvironmentVariable("localappdata") + 
  "\virtualstore\Program Files (x86)\EAGLE\projects\myProjects\Amplificador de potencia\eagle.epf"

Re: Wrong amount returned by FileSize()

Posted: Wed Oct 28, 2020 6:37 pm
by cas
Marc56us wrote:The 32 bit compiler reads the original one (much smaller) while the 64 bit compiler follows the path to the VirtualStore and therefore reports the right size.
No, original one (larger) is in program files directory and modified one is smaller and is saved in virtualstore. 32bit exe without vista manifest first checks virtualstore and there it finds smaller file under the same path and reports its smaller size. When you add manifest, then it does not check virtualstore and only checks actual path (program files).

Re: Wrong amount returned by FileSize()

Posted: Thu Oct 29, 2020 8:38 am
by Psychophanta
Thanks @cas and everyone.
I hate all that "policies" in MS windows, and i am a complete ignorant of it.

An yes, cas, there in that folder in .... "\AppData\Local\VirtualStore\Program Files (x86)\EAGLE\projects\myProjects\Amplificador de potencia", is the mad of this film. :)