Reading a file from the installation directory.

Started by greg, Sat 23/04/2016 14:35:03

Previous topic - Next topic

greg

From the release notes, with 3.3.5, I understand that I can only write files to $SAVEGAMEDIR$ and $APPDATADIR$.  However, provided that I open the file in mode eFileRead, is it intended that I can still read files from the installation directory?

I have a call that looks like this...

File* st = File.Open("filename.txt", eFileRead);

...where filename.txt is located in the installation directory ("Compiled").  With 3.3.4, the call read the file successfully from that location.  With 3.3.5, it can't find the file -- I've verified that it's looking in $APPDATADIR$* instead.  I tried to force AGS to read from the Compiled directory with "./filename.txt", but it still can't find the file.

My question: is it possible to read files from the installation directory?  If so, how?

Thanks!
Greg

* - On my PC (Windows 10), $APPDATADIR$ is located at "C:\Users\All Users\Adventure Game Studio\Name of Save Game Directory".

Crimson Wizard

#1
Yes, it should be able to read from installation directory. I will test again to see why it may not work.

It first makes attempt to read from APPDATADIR though, but that is done for backwards-compatibility, because if game tries to write file into the installation directory, it is now being remapped to APPDATADIR instead. So, for example, if a game was writing something to game's dir, and then reading it back, now it will write to APPDATADIR, and should be able to read it back from APPDATADIR as well.

EDIT: I realized this may be a cause of your error, if your game wrote a file to APPDATADIR with same name first (whether it was by game logic, or just for a test).
This is a design flaw in the recent version, and I am currently thinking on how to correct this. I had plans to release a small patch to 3.3.5 in the end of the month; it should include a solution to this problem as well.

greg

> Yes, it should be able to read from installation directory. I will test again to see why it may not work.

Great, thanks!

> I realized this may be a cause of your error, if your game wrote a file to APPDATADIR with same name first (whether it was by game logic, or just for a test).

There was no file of the same name in APPDATADIR or SAVEGAMEDIR.  (In fact, APPDATADIR was empty.  After AGS was unable to read the file from the Compiled folder, I copied it to APPDATADIR to see if it could read there instead.)

To summarize, my testing revealed this logic:

* When filename.txt was in Compiled (but not APPDATADIR), "File.Open("filename.txt", eFileRead)" couldn't find/open the file.
* When filename.txt was in Compiled and APPDATADIR, "File.Open("filename.txt", eFileRead)" found/opened the file from APPDATADIR.
* When filename.txt was in Compiled and SAVEGAMEDIR, File.Open("filename.txt", eFileRead)" couldn't find/open the file.

Thanks!
Greg

Crimson Wizard

This is interesting; I wonder if it has anything to do with Compiler folder? I would test if the game can read file if it is in the project's root, or if the compiled game was copied to separate location (to emulate properly installed game).

greg

> I wonder if it has anything to do with Compiler folder? I would test if the game can read file if it is in the project's root.

Ah, yes, it could read the file when I moved it from $rootdir$/Compiled to $rootdir$.

To summarize:

* My project's root directory is C:\foo.  The game reads from filename.txt using "File.Open("filename.txt", eFileRead)"
* When I launch the game within the editor (i.e. Run (F5)):
- AGS 3.3.4 and earlier looked for the file in the build folder (C:\foo\Compiled\filename.txt).
- AGS 3.3.5 looks for the file in the project root (C:\foo\filename.txt).
* When I launch the game by building it and then launching the executable:
- AGS 3.3.4 and 3.3.5 both look for the file in the build folder (C:\foo\Compiled\filename.txt).

From your perspective, is this considered a bug?  It's not a big deal, but I would suggest reverting to the 3.3.4 behavior (where both launching-from-the-editor and launching-from-the-executable look in the build folder).  Otherwise, you need to keep two copies of the file you're trying to read and manually keep them in sync.

Thanks!
Greg

Crimson Wizard

Yes, it is a bug; there is a special case in AGS when it considers "Compiled" subfolder to be the place for reading/writing files when run from the Editor.


greg

Yes, that fixed it:

* When I launched the game from the editor, it found the file in the Compiled folder.
* When I launched the game from the built executable, it found the file in the same folder as the executable.

Thanks for addressing this so quickly!  (Also, thanks for working on 3.4.  Can't wait to try it out!)

Greg

SMF spam blocked by CleanTalk