Jump to content
New account registrations are disabed. This website is now an archive. Read more here.
  • 0
HeathLocke

How can I use File.exist even with an encrypted game?

Question

Here I am making yet another thread :P. Thanks to everybody that has been helping me, it means a lot.

 

Anyway, I need to use File.exist in a script that I made, and it works unless the game is encrypted. Since when encrypted there is no "Graphics/Pictures" folder, the file can't be accessed.

How can I work around this? RPG::Cache.picture works well with the other images, but I guess it is only for bitmaps.

I've also thought about using File.load, but it would ruin the purpose of using File.exist.

So yeah, I've ran out of ideas now.

PS: Just to make it a little more clear, here is a sample of the code I'm trying to do:

if File.exist("Graphics/Pictures/picture.png")
   @picture.bitmap = RPG::Cache.pictures("picture")
else
   @picture.bitmap = RPG::Cache.pictures("otherpicture")
end

Share this post


Link to post
Share on other sites

6 answers to this question

Recommended Posts

  • 0

weird, it worked before, but now it doesn't work for me either.

sorry. I think both Bitmap.new(filename) and RPG::Cache.picture(filename)  will make RMXP crash if the file doesn't exist, and there's no way to do a 'try' block in RMXP. there's also no way to check how RMXP searches files inside the encrypted game.rgssad file, as that's inside a hidden class, as everything related to encryption.

if you say FileTest works for files in the main-folder, then moving the picture into that folder may be your best option.

Edited by Metaclaw

Share this post


Link to post
Share on other sites
  • 0

you can use FileTest.exist. it's what RMXP uses to search for save-files, and it works in encrypted games too.

if FileTest.exist?("picture.png")
  @picture.bitmap = RPG::Cache.pictures("picture")
else
  @picture.bitmap = RPG::Cache.pictures("otherpicture")
end
Edited by Metaclaw

Share this post


Link to post
Share on other sites
  • 0

Hey, thanks! Although you don't use the file path, just the file name (figured that out by trial and error).

Can you edit your answer and remove the path? It would be better for people finding this through google. In this case, it would be

if FileTest.exist?("picture.png")

 

Again, thanks a lot for your answer.

Share this post


Link to post
Share on other sites
  • 0

you're welcome :)

about the path, I'll fix my post.

I saw RMXP uses that code to search for save-files, which are in the game's main folder, so I asssumed you'll need a path for inner-folders.. I forgot encrypted games have no inner folders.

Edited by Metaclaw

Share this post


Link to post
Share on other sites
  • 0

Hey man, I'm sorry but I must've messed something up, neither using the picture path nor just the filename are working now. I think I might have encrypted an older version and thought it was working.

Since the save files are in the main folder, both File.exists and FileTest.exists can find them, because they're probably not encrypted. So yeah, the problem is still going on.

Edited by HeathLocke

Share this post


Link to post
Share on other sites
  • 0

Yeah. Fortunately my images don't change dynamically, so I don't really need FileTest. I was doing it just for a good scripting practice, so I can remove it and things will work just fine..

I'll mark your answer as 'solved' because it really seems the best solution if someone really needs to do a FileTest for their script to work. Thanks a lot for your support and input, man.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...