Virtual Bin for Resources

Advanced game related topics
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1286
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Post by Paul »

Actually after reading this post 2 weeks ago, I simply forgot about it since no one ever did email me (I'm quite busy on a number of other projects so a short email usually helps job my memory)

I happened to be browsing through the forum this evening and saw this thread was still alive so YES, I did fix the VBin library so the BIN extension can be changed.
The VBin Maker still saves it with the default .BIN extension but you can manually rename it. Then pass the whole filename including new extension to the vbin library functions. If you pass no extension then .BIN is used by default (this keeps backwards compatability)

Enjoy :)
Image Image
User avatar
J. Baker
Addict
Addict
Posts: 2196
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Post by J. Baker »

Hey Paul, thanks for the update! :D Also, will there be a catchfile option in the future? Thanks
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
PolyVector
Enthusiast
Enthusiast
Posts: 499
Joined: Wed Sep 17, 2003 9:17 pm
Location: Southern California
Contact:

Post by PolyVector »

Thanks for the update Paul... Good seeing my own extentions on my vbins... nice work :D
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1286
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Post by Paul »

J. Baker wrote:Hey Paul, thanks for the update! :D Also, will there be a catchfile option in the future? Thanks
Not sure what you mean by "catchfile" option?

I think VBin provides you with everything needed to pull data from a virtual bin.
Say you have a text file called test.txt which contains:
This is a test.
and this is put into a VBin.

the VBin() function returns a memory address of where this file is located in the VBin (which is what the various PB Catch commands use)...
MemAddress =VBin("Test.bin","test.txt","")
You can then use the VBinSize command to get the size of the data for this file...
size=VBinSize("Test.bin","test.txt","")

Then retrieve the text data using
A$=PeekS(MemAddress,size)

A$ will contain:
This is a test.

Does this example help at all?
Image Image
User avatar
J. Baker
Addict
Addict
Posts: 2196
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Post by J. Baker »

OH WOW! I thought you had to use the Catch commands to get anything from the VBin. Thanks very much for your explanation Paul, that helps alot. :D
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post by Shannara »

Code: Select all

Delete Resource from VBin.

Use:
Result =VBinDelete("MyBin.bin","Image.bmp")

Returns 1 if sucess.


Is there any way you could make it that it'll only delete password protected vbin resources if a password was passed to the command? As it stands now, anybody can delete resources from a vbin.

If there was a password required (only for those bins that are password protected), and people submit the wrong password, then the resource wont be deleted... you know, kinda helps with the protection :)
User avatar
griz
Enthusiast
Enthusiast
Posts: 167
Joined: Sun Jun 29, 2003 7:32 pm
Location: Canada

Post by griz »

Something like this Paul? :)

Code: Select all

; return file from VBIN as a string
Procedure.s VBinTextFile(BinName$, FileName$, Pass$)
  If VBin(BinName$, FileName$, Pass$)
    ProcedureReturn PeekS(VBin(BinName$, FileName$, Pass$),VBinSize(BinName$, FileName$, Pass$))
  EndIf
EndProcedure

debug VBinTextFile("MyBin", "test.txt", "")
BTW Thanks for VBIN.
User avatar
griz
Enthusiast
Enthusiast
Posts: 167
Joined: Sun Jun 29, 2003 7:32 pm
Location: Canada

Post by griz »

Here it is for Paul's newer VBIN 2 :

Code: Select all

; return specified file from VBIN as a string
Procedure.s VBinTextFile(BinName$, FileName$, Pass$)
  If VBin_(BinName$, FileName$, Pass$)
    ProcedureReturn PeekS(VBin_(BinName$, FileName$, Pass$),VBin_OriginalSize(BinName$, FileName$))
  EndIf
EndProcedure

debug VBinTextFile("MyBin", "test.txt", "")
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1286
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Post by Paul »

Nice procedure griz :)

I would suggest though, for the best speed only call VBin_() once:

Code: Select all

; return specified file from VBIN as a string
Procedure.s VBinTextFile(BinName$, FileName$, Pass$)
  mem=VBin_(BinName$, FileName$, Pass$)
  If mem
    ProcedureReturn PeekS(mem,VBin_OriginalSize(BinName$, FileName$))
  EndIf
EndProcedure

debug VBinTextFile("MyBin", "test.txt", "")
Every time you call VBin_() it must retrieve the required data from the internal file system.
Image Image
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

what would be good is if you could append the vbin file to the end of an exe and then vbin load from the exe...

as it stands i do this and have to copy the vbin to a temp area before accessing it.

-Anthony
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1286
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Post by Paul »

If you are going to attach the VBin to your exe then it kind of defeats the purpose of using a VBin. Might as well simply "IncludeBinary" your files. ;)
Image Image
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

Does windows load the whole EXE file into RAM though, or does it just load code and data segments to the correct areas of memory?

I think its the latter.

In the case of appending the data to the end of the file, it should not be actually loaded by windows.

In the case of includebinary it would be included in the load (for the data section).

This would be the difference, as the data would not take up valuable RAM until needed... :)

-Anthony
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
Fou-Lu
Enthusiast
Enthusiast
Posts: 201
Joined: Tue Jul 12, 2005 8:30 am
Location: I'm pretty sure this is all a nightmare
Contact:

Post by Fou-Lu »

I'm almost sure it loads the whole exe.
Shannara wrote:

Code: Select all

Delete Resource from VBin.

Use:
Result =VBinDelete("MyBin.bin","Image.bmp")

Returns 1 if sucess.
Is there any way you could make it that it'll only delete password protected vbin resources if a password was passed to the command? As it stands now, anybody can delete resources from a vbin.
I agree. It might not be that hard to do that. And thanks for the good work Anthony!! Now nobody will say DarkBASIC is better because of the "Create Final EXE" thing. ( Anyway I don't think anyone would ever say db is better than pb... )

~Fou-Lu (aka Lørd Cinneris (actually Elias Sant'Ana))

Image Image
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

And thanks for the good work Anthony!!
??? good work ???

-Anthony
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
Fou-Lu
Enthusiast
Enthusiast
Posts: 201
Joined: Tue Jul 12, 2005 8:30 am
Location: I'm pretty sure this is all a nightmare
Contact:

Post by Fou-Lu »

Hey did I say Anthony? I meant Paul!!! :oops: Oh my god that one was just horrible... Sorry Antho... *ahem* Paul.

~Fou-Lu (aka Lørd Cinneris (actually Elias Sant'Ana))

Image Image
Post Reply