Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 1,498 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19054 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Extracting text files bound to a resource file #230613
10/07/08 00:54
10/07/08 00:54
Joined: May 2008
Posts: 123
B
BES Offline OP
Member
BES  Offline OP
Member
B

Joined: May 2008
Posts: 123
I'd like to use file_open_read and similar functions, but I am unable to open the text file I've stored in the wrs. How can I extract it for manipulation?

Thanks as always!

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
V
Vadim647 Offline
Senior Member
Vadim647  Offline
Senior Member
V

Joined: Feb 2008
Posts: 337
Code:
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 Offline
Expert
EvilSOB  Offline
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
B
BES Offline OP
Member
BES  Offline OP
Member
B

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
B
BES Offline OP
Member
BES  Offline OP
Member
B

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 Offline
Expert
EvilSOB  Offline
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
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
Re: Extracting text files bound to a resource file [Re: EvilSOB] #230787
10/08/08 18:20
10/08/08 18:20
Joined: May 2008
Posts: 123
B
BES Offline OP
Member
BES  Offline OP
Member
B

Joined: May 2008
Posts: 123
Haven't gotten it yet, but just wanted to say thanks for taking time out of your day! You're a hero, for certain.

Back into the fray...


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1