Extracting data from file?

Blitz3D Forums/Blitz3D Programming/Extracting data from file?

David819(Posted 2006) [#1]
Hi, i'm reading a game format, it consists of two files one stores the file names, sizes and offsets of there location in the other file, the other holds the data. My problem is that i'm set at the offset where the data is but i dont know how to get it out into a seperate file. i think i need to use the file size in this but now sure. anyone got any ideas?


octothorpe(Posted 2006) [#2]
dest = WriteFile(chunk_name)
For i = 1 To chunk_size
	WriteByte(dest, ReadByte(src))
Next



David819(Posted 2006) [#3]
Ok i'll try that, thanks.


David819(Posted 2006) [#4]
Ok tryed it but it failed, not because of the code, it's because i've missed something along the line. I have an email with basic info that helped me, and also got some vb code of exporting the file but i dont understand it. would it be alright to post the code to see if anyone can understand it?
Thanks


octothorpe(Posted 2006) [#5]
[codebox][/codebox]


David819(Posted 2006) [#6]
I've got some c++ code here that is meant to read and write the data by i dont understand it as i dont program in c++. Can anyone understand this:



Thanks


David819(Posted 2006) [#7]
Update to post.


big10p(Posted 2006) [#8]
That code snippet seems to simply open a file, seek to a specific position, read a specific number of bytes from that position into a buffer(bank), and finally write the buffer contents out to a second file.

The file position to read from and the number of bytes to be read are specified via TxmpOffset and TxmpSize, respectively. As these variables aren't defined in the code, I can't tell you what they are. :)


David819(Posted 2006) [#9]
Ok, well i have the offset and the size of the txmp file already from some of my earlier coding for reading the dat file, Ok you said that it is store into a bank, does that mean that i have to do the same to get the correct data i want from the file i am reading?
Thanks


big10p(Posted 2006) [#10]
If you want to do the same as the above code (i.e. read data in from one file and write it out to another) then it'd be best to use a bank. Luckily, blitz makes it easy to read/write data between files and banks: take a look at the ReadBytes and WriteBytes commands (note the plural of 'Bytes' - these commands are different from the Read/WriteByte commands).


David819(Posted 2006) [#11]
Ok well i've done what i think is right but i'm still not getting equaly compared data between the two files, it just looks completely different from the actual file that it is meant to be (When opened in a text editor) Don't know if anyone can follow my coding but i put it below for you to see, it now uses banks and the read and writebytes commands:



I would have included in two files my exported file and the correctly exported file but thay are to big to even fit in a code box.
Thanks


big10p(Posted 2006) [#12]
Kain, I'll take a look at this tomorrow, when I get time. It's Friday night and I'm not 'in the right frame of mind'? ;)


big10p(Posted 2006) [#13]
Hmm, well, because I'm not familiar with the file formats you're working with, I'm not in a position help much. Sorry.


Stevie G(Posted 2006) [#14]
	librecsdata(datasearch,1) = Chr$(ReadByte(onifile)) + Chr$(ReadByte(onifile)) + Chr$(ReadByte(onifile)) + Chr$(ReadByte(onifile)) ;Lib type


You can't be sure that each of these bytes will be read from the file in that order. If you do something like ..

a$ = chr$( readbyte (onfile))
b$ = chr$( readbyte( onfile ) )
etc ....
liberectdata( datasearch, 1 ) = a$+b$

It may work.

Stevie


David819(Posted 2006) [#15]
big10p, would it help if i sent you the dat file as that is only about 2Mb, The file i am working with the from the game oni which it would probably be quite easy to get hold of a demo of it. The site that i got the specs of the dat file was http://mirex.mypage.sk in documents and Unmass archives descriptions. If you can help any further with this information it would be most appreciated.
Thanks


big10p(Posted 2006) [#16]
Did you try implementing the changes Stevie G suggested?


David819(Posted 2006) [#17]
Stevie G i applied your changes and still get the same result but from doing so and trying some things out i noticed that some of the data i have read in not correct to a program that can export these files, and it is to do with the typesfor example the sound files in the game should have the type DDNS but have some other one instead, i chaged some of the other code aswell to make it better but still not found out what causes the incorrect data.