Ooops
July 26, 2021, 14:39:21

Author Topic: Is it possible to tell from inside a file where it is located?  (Read 246 times)

Offline Hardcoal

  • Hero Member
  • *****
  • Posts: 703
  • nothing is personal
HI.. is their a command that tells you from the .bmx file itself where it is located in the hard drive?
I guess not , but I had to ask..

...

Offline col

  • Hero Member
  • *****
  • Posts: 586
Re: Is it possible to tell from inside a file where it is located?
« Reply #1 on: June 19, 2021, 17:38:06 »
Hiya,

I think some context of what you are attempting may help us be more helpful.

Offline Hardcoal

  • Hero Member
  • *****
  • Posts: 703
  • nothing is personal
Re: Is it possible to tell from inside a file where it is located?
« Reply #2 on: June 19, 2021, 18:59:27 »
ok.. I got a library of my commands.. that i call with include "mylib.bmx"
and i want Mylib.bmx file to know where its located.
because i have load image commands in this file and it has to be relative to the file location.
but when you run ann app.. it only knows its own location.

anyway ill think of something. I think its impossible in a simple way.
not too crucial thing atm
...

Offline peteswansen

  • Jr. Member
  • **
  • Posts: 68
Re: Is it possible to tell from inside a file where it is located?
« Reply #3 on: June 19, 2021, 20:05:03 »
Hardcoal...can you use the Windows Search to locate it??  I understand because I have backup files in a lot of areas also, as well as multiple hard drives and ssd's.....

Offline wadmixfm

  • Full Member
  • ***
  • Posts: 129
Re: Is it possible to tell from inside a file where it is located?
« Reply #4 on: June 19, 2021, 20:41:03 »
do your paths change for the file during the app ??

why not set a variable for your path

and then call it with a file requester or read as a sequential file

or am i misunderstanding you :)

Lee

Offline GW

  • Full Member
  • ***
  • Posts: 222
Re: Is it possible to tell from inside a file where it is located?
« Reply #5 on: June 19, 2021, 21:17:37 »
Once an exe is compiled the bmx file locations are irrelevant.  If you want use a resource at compile-time, use IncBin, if you want use a resource at run-time, use CurrentDir() or Appargs[0]

Offline Hardcoal

  • Hero Member
  • *****
  • Posts: 703
  • nothing is personal
Re: Is it possible to tell from inside a file where it is located?
« Reply #6 on: June 19, 2021, 21:42:48 »
ok thanks..
...

Offline GW

  • Full Member
  • ***
  • Posts: 222
Re: Is it possible to tell from inside a file where it is located?
« Reply #7 on: June 19, 2021, 22:27:53 »
I should clarify my statement. If you care where a file location is at compile time, then use IncBin. If you only care at runtime where it is then start with CurrentDir() 

Offline Hardcoal

  • Hero Member
  • *****
  • Posts: 703
  • nothing is personal
Re: Is it possible to tell from inside a file where it is located?
« Reply #8 on: June 20, 2021, 04:45:20 »
I tried to use Incbin.. but i didnt understand what exactly it does..

it showed something about loadImage in the example ..
LoadImage("Incbin::imagename.png")
what does got to do with directory?

sorry I never understood this command
...

Offline Midimaster

  • Sr. Member
  • ****
  • Posts: 329
    • Midimaster Music Education Software
Re: Is it possible to tell from inside a file where it is located?
« Reply #9 on: June 20, 2021, 06:50:17 »
it is not related with directories and does not help you in your question this time.

Incbin enables to add files into the EXE. Instead of having a lot of files next to the exe in the final version you could also have one EXE which contains the code and the resources too.

For example, if your app need 2 files: an image "BackGround.png" and a resource "Data.Txt" you have 3 possibilities of sending this to the users:


1. You can build a ZIP with all three files
MyApp.Exe
Background.png
Data.Txt

and send this to the user. The use needs to unpack it to a new folder.


2.Or you can pack all three with an Installer to a Setup.Exe.

At the User's computer the Installer will copy all 3 files into a new directory, where your MyApp.Exe again will find the Background.Png and Data.png and can load it.


3. With IncBin you will have one file MyApp.Exe.

This will stay only one File on the users computer. The Background.png has become a part of the exe and has increased the size of the Exe. The use can not see the Background.Png and the Data.Txt, because they keep parts (inc-binaries) of the MyApp.Exe. The App can load them from "inside":

Code: BlitzMax
  1. SuperStrict
  2. Incbin "Background.Png"
  3. Incbin "Data.txt"
  4. Global Image:TImage=LoadImage("incbin::Background.png")
  5. Global Ini$=LoadText("incbin::Data.Txt")
  6. DrawImage Image,100,100
  7. Print Ini
  8. ....
  9.  


Incbin is very useful, if you want to hide files from the user.

To shrink the size of the Exe INCBIN is often used with the module KORIOLIS ZIPSTREAM, which enables to read single files of a ZIP, which is attached to the EXE via Incbin:

Code: BlitzMax
  1. SuperStrict
  2. Import koriolis.zipstream
  3.  
  4. Incbin "AllFiles.Zip"
  5. global Path$="ZIP::Incbin::AllFiles.Zip//"
  6. Global Image:TImage=LoadImage(Path + "Background.png")
  7. Global Ini$=LoadText(Path + "Data.Txt")
  8. DrawImage Image,100,100
  9. Print Ini
  10. ....
  11.  



Disadvantage of IncBin is: You cannot "write" to the files included with IncBin. Therefore you have to copy them from IncBin to a "real" directory.


 
« Last Edit: June 20, 2021, 06:59:23 by Midimaster »
See my current project on PlayStore: 20Tracks-Audio-Player https://play.google.com/store/apps/details?id=midimaster.twentytrackd

Offline Hardcoal

  • Hero Member
  • *****
  • Posts: 703
  • nothing is personal
Re: Is it possible to tell from inside a file where it is located?
« Reply #10 on: June 20, 2021, 18:02:56 »
Wow thanks again midimaster.. I think I got it..
I will experiment.. this was very useful

...

Offline Derron

  • Hero Member
  • *****
  • Posts: 3613
Re: Is it possible to tell from inside a file where it is located?
« Reply #11 on: June 20, 2021, 18:31:35 »
Just to clarify:

myapp.bmx import "mylib.dll" (which is compiled)
mylib.dll needs to know its own location so on startup it can call "LoadMyFile(localpath)" ?
-> DLLs might be "executed" and you can use CurrentDir()
-> myapp could call "mylib_setpath()" and inform about the myapp's CurrentDir() and potential subfolders in which mylib.dll resides


myapp.bmx imports "mylib.bmx"
mylib.bmx needs to know its own location so on startup (does something in the "main part" of the file) so it can call "LoadMyFile(localpath)" ?
-> wrap the loading in a "initLib(baseDir:string)" function which you call from myapp.bmx (in the moment in which it is approbriate)
-> pass whatever basedir is needed (so you can even import it from "sources/what/ever/mylib.bmx"

No need to incbin


bye
Ron

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal