0 registered members (),
1,498
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Extracting text files bound to a resource file
[Re: BES]
#230685
10/07/08 18:58
10/07/08 18:58
|
Joined: Feb 2008
Posts: 337
Vadim647
Senior Member
|
Senior Member
Joined: Feb 2008
Posts: 337
|
file_cpy("mytextfile.txt","mytextfile.pak");
Quoted from manual for file_cpy. ... Then you can use standart file_open_read and other functions with extracted file. The only con is that you can't pack files back into wrs.
I switched to other account since marth 2010. Guess which.
|
|
|
Re: Extracting text files bound to a resource file
[Re: Vadim647]
#230691
10/07/08 19:11
10/07/08 19:11
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Also take a look in the manual at combining file_load() and then add_buffer(). Ive never used it but it may help, if it works the way I think it does. File_Load() loads the file from WRS into memory space (not extract to the hard disk), and add_buffer() puts the memorised file into the 3DGS virtual file system, so any file_open type function can access. Theoretically...
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Extracting text files bound to a resource file
[Re: EvilSOB]
#230701
10/07/08 20:07
10/07/08 20:07
|
Joined: May 2008
Posts: 123
BES
OP
Member
|
OP
Member
Joined: May 2008
Posts: 123
|
Thanks, both very much.
Vadim, yeah I found the file_cpy func about an hour after I posted. I assume that your "Quoted from the manual..." was to encourage me to check the documentation more thoroughly, which is always good advice, but please don't assume that someone hasn't already been searching. I know how annoying it is when someone is a forum leech, so I search the documentation, wiki, and forums for at least a couple hours before posting. It hurts when someone thinks that you're being lazy. Of course, I probably should have immediately made the connection between unpacking a text file from a wrs and "file_cpy", heh =P In any case, I really appreciate everyone's help and time!
Sorry for the deviation, back to the subject- I try to use file_cpy, but it fails (returns 0). I renamed my text file .pak and added a BIND statement in the wdl file of the level I built. I published with the "starter" and "resource" boxes checked and the publish dialog indicated that myFile.pak was added to the wrs, so I'm fairly certain that it's in there. I tried using "add_resource()" to open the wdl in the loading project, but it doesn't actually seem to make any difference (it says myLevels.wrs is opened regardless of whether or not I have add_resource in there).
I haven't tried file_load() and add_buffer() yet; honestly I couldn't decipher what add_buffer did. I'll check it out.
Don't hesitate to chime in if you notice anything bogus about what I'm doing! Cheers!
|
|
|
Re: Extracting text files bound to a resource file
[Re: BES]
#230705
10/07/08 21:15
10/07/08 21:15
|
Joined: May 2008
Posts: 123
BES
OP
Member
|
OP
Member
Joined: May 2008
Posts: 123
|
alas, still stuck. Here's my code:
llist* golf_levels; char* wrsFile;
function main() { on_x = switchLevel; on_exit = cleanup;
golf_levels = new_llist(); TEXT* tDir = { strings = 10; flags = VISIBLE; } //search for all wrs files txt_for_dir( tDir, "*.wrs" );
STRING* rootName = "#40"; STRING* courseName = "#40"; STRING* levelName = "#40"; STRING* pakName = "#40"; STRING* wrsName = "#40";
//TODO: Do this for each string found! str_cpy(wrsName, _chr((tDir.pstring)[0]));
//Load the wrs file for inclusion later long fileSize; wrsFile = file_load( wrsName, NULL, &fileSize ); if( wrsFile == NULL ) { diag("\nUnable to open file: "); diag(wrsName); return; }
//remove the extension str_cpy( rootName, wrsName ); str_trunc( rootName, 4 );
//create the level name str_cpy(courseName, rootName ); str_cpy(levelName, rootName ); str_cpy(pakName, rootName );
//and add extensions str_cat(courseName, ".txt"); str_cat(levelName, ".wmb"); str_cat(pakName, ".pak");
STRING* str_name = "#40"; STRING* str_description = "#1024"; STRING* str_weather = "#40"; //make sure the names are what we expect diag("\n courseName: "); diag( courseName ); diag("\n pakName: "); diag( pakName ); diag("\n rootName: "); diag( rootName ); diag("\n wrsName: "); diag( wrsName );
//add the resource file and load it into a buffer add_resource( wrsFile ); add_buffer( wrsName, wrsFile, fileSize );
if( file_cpy(courseName,pakName) != 0 ) {
var filehandle_n = file_open_read( courseName ); file_find( filehandle_n, "Name:" ); file_str_read( filehandle_n, str_name ); file_find( filehandle_n, "Desc:" ); file_str_read( filehandle_n, str_description ); file_find( filehandle_n, "Wthr:" ); file_str_read( filehandle_n, str_weather ); diag("\n"); diag( str_name ); diag("\n"); diag( str_description ); diag("\n"); diag( str_weather ); } else { diag("\nCopy failed"); }
level_load(levelName); wait(2);
//Enumerate levels via special objects placed in an empty level int current_level_num = 0; ENTITY* currentEntity = ent_next(NULL); while( currentEntity != NULL ) { STRING* lvlString = str_create("#24"); str_cpy( lvlString, currentEntity.string1 ); llist_add( golf_levels, lvlString ); current_level_num++; currentEntity = ent_next(currentEntity); }
levelID = 0; if( golf_levels->numItems > 0 ) level_load( (STRING*)llist_get(golf_levels, levelID) ); else diag("\nNO LEVELS AVAILABLE!"); }
Any ideas?
|
|
|
Re: Extracting text files bound to a resource file
[Re: BES]
#230747
10/08/08 09:25
10/08/08 09:25
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Sorry, but I cant help any more than this, as I only own commercial and therefore dont have resource packing available so I cant test my theories. This is the best I can figure, insert this into your code ...
//add the resource file and load it into a buffer
add_resource( wrsFile );
add_buffer( wrsName, wrsFile, fileSize );
// vvvvvvvvv
// I am unclear if your coursename string needs to be *.txt, *.pak, or *.txt.pak
//but I think *.pak INSTEAD of *.txt is the most likely (actual filename stays txt)
long size; void* pCourse = file_load( coursename ,NULL,&size);
add_buffer( coursename ,pCourse,size);
// ^^^^^^^^^
if( file_cpy(courseName,pakName) != 0 )
...
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
|