Wrong amount returned by FileSize()

Just starting out? Need help? Post your questions and find answers here.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Wrong amount returned by FileSize()

Post 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)
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
infratec
Always Here
Always Here
Posts: 7576
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Wrong amount returned by FileSize()

Post 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.
BarryG
Addict
Addict
Posts: 4122
Joined: Thu Apr 18, 2019 8:17 am

Re: Wrong amount returned by FileSize()

Post by BarryG »

Where can we download the Eagle file?
User avatar
leonhardt
Enthusiast
Enthusiast
Posts: 220
Joined: Wed Dec 23, 2009 3:26 pm

Re: Wrong amount returned by FileSize()

Post by leonhardt »

Or you can use API like GetFileSize_() to test again?
poor English...

PureBasic & Delphi & VBA
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: Wrong amount returned by FileSize()

Post 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. :?
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: Wrong amount returned by FileSize()

Post 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:
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
BarryG
Addict
Addict
Posts: 4122
Joined: Thu Apr 18, 2019 8:17 am

Re: Wrong amount returned by FileSize()

Post by BarryG »

Where can we download the Eagle file? And what size does Lof() return if you open it?
Marc56us
Addict
Addict
Posts: 1600
Joined: Sat Feb 08, 2014 3:26 pm

Re: Wrong amount returned by FileSize()

Post 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. ?)
cas
Enthusiast
Enthusiast
Posts: 597
Joined: Mon Nov 03, 2008 9:56 pm

Re: Wrong amount returned by FileSize()

Post 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)".
User avatar
leonhardt
Enthusiast
Enthusiast
Posts: 220
Joined: Wed Dec 23, 2009 3:26 pm

Re: Wrong amount returned by FileSize()

Post by leonhardt »

if API calling result is also not correct,I think no bugs in the PB command.
poor English...

PureBasic & Delphi & VBA
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: Wrong amount returned by FileSize()

Post 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.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
cas
Enthusiast
Enthusiast
Posts: 597
Joined: Mon Nov 03, 2008 9:56 pm

Re: Wrong amount returned by FileSize()

Post by cas »

Go to virtualstore (appdata\local\virtualstore) and you will find your 274byte file there.
Marc56us
Addict
Addict
Posts: 1600
Joined: Sat Feb 08, 2014 3:26 pm

Re: Wrong amount returned by FileSize()

Post 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"
cas
Enthusiast
Enthusiast
Posts: 597
Joined: Mon Nov 03, 2008 9:56 pm

Re: Wrong amount returned by FileSize()

Post 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).
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: Wrong amount returned by FileSize()

Post 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. :)
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Post Reply