Jump to content

Reading A Text File From A Package


gamecreator
 Share

Recommended Posts

I have a text file in a zip package I'm trying to read.  The zip loads successfully and the contents show the txt file is there.  However, when I tried to load it with FileSystem::OpenFile("text.txt"), the function fails.  But if I put the text file into the folder by itself, the function succeeds (loading it directly, not from the zip file).  Does this just mean that FileSystem does not work with Package?  I'd love to have zipped text files which provide data to my game (like NPC conversations).

I could try to use Package::ExtractFile to do this the long way but I'd really rather not extract files just so I can access them and have them be publicly available, defeating the purpose of password protecting them.

In researching a solution for this, I saw that this came up 3 years ago, without a solution.

Code, if it helps:

	Package *package=NULL;
	package=Leadwerks::Package::Load("text.zip","");

	if(package==NULL) printf("Package load failed\n");
	else
	{
		printf("Package loaded\n");
		printf("Number of files: %d\n",package->CountFiles());
		cout << package->GetFileName(0) << endl;
		cout << package->GetFileName(1) << endl;
	}

	Stream *stream = FileSystem::OpenFile("text.txt");
	if(stream==NULL) printf("open failed\n");
	else System::Print(stream->ReadLine());

 

  • Upvote 1
Link to comment
Share on other sites

Out of curiosity, I tried to publish the project as Standalone, added the txt extension to include and unchecked "Only include used files."  I removed the zip loading code, only looking to read from a txt file inside data.zip, using the last three lines of the above code.  The load failed.

Tried with a mat file and that failed as well.  So it seems FileSystem doesn't work at all with Package or even the Leadwerks data.zip file, which is too bad.

  • Upvote 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...