File paths : APPDATADIR

Started by Monsieur OUXX, Thu 28/03/2019 17:59:42

Previous topic - Next topic

Monsieur OUXX

(AGS 3.4.1-P4)

OK so this will sound dumb but...

Simple code :

Code: ags

  String fileName = "$APPDATADIR$/FILE.png"; 
  File* f = File.Open(fileName, eFileRead);
  if (f==null)
    AbortGame(String.Format("Can't find file '%s'", fileName));


I've tried to put FILE.png in the following places :
( where "/" is the game's project folder)
Code: ags

/_Debug/FILE.png
/_Debug/Data/FILE.png
/Compiled/FILE.png
/Compiled/Data/FILE.png



The file is not found.
I've also built the EXE to be sure.

I am confusion ??????????????????????????
 

morganw

I think you would need to use $INSTALLDIR$ instead of $APPDATADIR$.

Monsieur OUXX

Quote from: morganw on Thu 28/03/2019 18:27:04
I think you would need to use $INSTALLDIR$ instead of $APPDATADIR$.
Are you saying that it doesn't work yet, or that it doesn't work as expected?
 

morganw

I'm not sure what you mean, these are different locations. $INSTALLDIR$ is where your game files are.
https://www.adventuregamestudio.co.uk/manual/ags53.htm#File.Open

Crimson Wizard

#4
Quote from: Monsieur OUXX on Thu 28/03/2019 17:59:42
I've tried to put FILE.png in the following places :
( where "/" is the game's project folder)
Code: ags

/_Debug/FILE.png
/_Debug/Data/FILE.png
/Compiled/FILE.png
/Compiled/Data/FILE.png




Too much confusion in above!
In addition to the information in the article morganw linked, - none of the above folders are correct ones for $INSTALLDIR$ either.

1) Subfolders in _Debug are ignored, they simply don't work. If you tell the game to open file from e.g. "$INSTALLDIR$/Subfolder" when game is run in test mode it looks either in <root>/<Subfolder> or Compiled/Windows/<Subfolder>.
2) Since 3.4.0 anything in just "Compiled" is ignored also. In 3.4.1 Windows build gathers necessary files in "Compiled/Data", and then copies to "Compiled/Windows".

Cassiebsg

Personally I just use the $SAVEGAMEDIR$ folder, since I "know" where it is and that folder is write able. (this is for if I need to write a file, like an ini file that I'll use to keep track of configurable game settings)
But I guess it depends what you want to do exactly, of course.
There are those who believe that life here began out there...

Monsieur OUXX

#6
EDIT
Spoiler

I still don't get what's the correct way of opening a file from APPDATADIR for reading when I'm debugging.

Is this supposed to work when FILE.png is in "game project folder/Compiled/Data/" ? Because it doesn't.

Code: ags

  String fileName = "$APPDATADIR$/FILE.png"; 
  File* f = File.Open(fileName, eFileRead);
  if (f==null)
    AbortGame(String.Format("Can't find file '%s'", fileName));


[close]

99% of the confusion comes from the fact that I always believe that this "App data" folder targetted by APPDATADIR is the "Data" subfolder inside "compiled". Not C:/ProgramData/Whatnot.

I'm also bummed out by the fact that I want to read and write to a SUBfolder. But that's not possible, I'm now accepting it.
Reason: If I put it in APPDATADIR, then File.Open won't work for writing (because it's a SUBfolder, as per AGS documentation). If I put it in INSTALLDIR then writing will be blocked because safety reasons. And if I want to write to SAVEGAMEDIR then I cannot guarantee that the folder is created there beforehand, and I cannot create it through the script language. Oh well.
 

Cassiebsg

Wait, what do you mean it's not there beforehand?
Where exactly do you think restart point is saved to?  8-0
There are those who believe that life here began out there...

Crimson Wizard

#8
Quote from: Monsieur OUXX on Fri 29/03/2019 19:20:15
Reason: If I put it in APPDATADIR, then File.Open won't work for writing (because it's a SUBfolder, as per AGS documentation).
If I put it in INSTALLDIR then writing will be blocked because safety reasons. And if I want to write to SAVEGAMEDIR then I cannot guarantee that the folder is created there beforehand, and I cannot create it through the script language. Oh well.

Alright, not being able to create a subdirectory in APPDATADIR and SAVEGAMEDIR is definitely a defect of the engine, and must be fixed. I will open a ticket in repository.
Reading should be possible 100%. What subfolder do you have in mind?
I have a proof: my own racing game is reading from subfolder: https://github.com/ivan-mogilko/ags-lastfurious/blob/master/Last'n'Furious/Race.asc#L119

Although I am still not sure what do you mean by "subfolder". Is it APPDATADIR itself, or APPDATADIR/Subfolder?



But anyways, could you tell what are you trying to do? Read or write, for which purpose (is it data for single user, all users, overall game data), and where the file should be located relative to installed game?
Maybe then we could give you a proper solution or at least a workaround.

Monsieur OUXX

#9
Quote from: Crimson Wizard on Fri 29/03/2019 20:40:03
Reading should be possible 100%. What subfolder do you have in mind?

I wasn't clear enough because Cassiebsg sounded puzzled too.
What I want is generate some custom data from the game, and store it in a subfolder so that it doesn't become messy --that's just an OCD thing because there wil be hundreds of files. (if you want to know everything I'm writing a virtual filesystem module, to go around the absence of File.MakeDir, and therefore be able to manage a complete cache from the game). Everything is written and read from this single, flat subfolder.

If this custom subfolder of mine is already present in either of savegame/data/installdir folders, then I can read from it. No problem.

The question is : How does this subfolder arrive there in the first place?
It's for dynamic data, so ideally it would be created by the game. But since it's not an option, then I need to create it myself, beforehand. As a developer, it's easy for me to create manually my Custom subfolder in the Compiled folder and then forget about it. But then that will be the install dir. No good for writing dynamic files there.
Then, remain the game's data and savegame folders, but I don't think I can create a folder there manually before the game is actually "installed" (or at least has run at least once on the system). Creating a subfolder into the /Compiled/Data folder has no effect, apparently. A backup solution would be to deploy my subfolder to appadatadir with a custom installer but I don't want to go there.
 

Crimson Wizard

#10
Alright I think I understand now.

Denial to write inside game folder (or its subfolders for what's worth) was introduced for safety, because game may be installed in the location where writing requires additional permissions or technically difficult. Example: it may be installed to C:/Program Files/ , where player would have to "run as administrator" every time to let the game write anything to its folder.

In the past I've opened a discussion asking for opinions on this. My main concern was "editor-like" games, which may create data for themselves, even if only at design time (I had this problem myself when working on my game). For that it could be beneficial to be able to write to game's dir and create game data (which is normally only read from during normal gameplay).
Here's that discussion:
https://www.adventuregamestudio.co.uk/forums/index.php?topic=55806.0
This situation still frustrates me a lot, because it seems that my previous solution was either wrong or incomplete.
AGS is still partially a legacy engine that was meant run from one folder without external dependencies, and does not provides default means to install and uninstall its data.


So, what solution did I use for my game? AGS allows to remap special path tags to paths provided in config. This is how it's done:
Quote
[misc]
user_data_dir = [string] - custom path to $SAVEGAMEDIR$
shared_data_dir = [string] - custom path to $APPDATADIR$
NOTE: since AGS 3.4.1 you may set these up in Default Setup pane in the editor.
NOTE: "user_data_dir" (path to saves) may be also edited in winsetup by player if they'd like to store saves in different place.
These settings are commonly used for Steam version of the game that expects saves and other dynamic data inside game folder (to be able to sync with Steam's cloud storage, I think).

Basically what I did, I set shared_data_dir to relative path and that made $APPDATADIR$ to point inside game subfolder. That allowed me to create files from AGS there at design time.
But since I did not intent to keep this, I removed this setting for release version.

In your case, I am still not sure if you are planning to keep writing into that folder when the game is run normally. If yes, then you may keep the setting after release.
Just keep in mind what I said about game may be installed into special location.

Quote from: Monsieur OUXX on Mon 01/04/2019 08:12:33A backup solution would be to deploy my subfolder to appadatadir with a custom installer but I don't want to go there.

You could also write a script that does that and ask players to run it before the game; or make a script that first checks if the folder exists and run game only after; but these are options to consider.


Quote from: Monsieur OUXX on Mon 01/04/2019 08:12:33Creating a subfolder into the /Compiled/Data folder has no effect, apparently.

Hmm, I don't remember if Editor copies subfolders from Compiled/Data too, it probably should be made do that.

Monsieur OUXX

Quote from: Crimson Wizard on Mon 01/04/2019 12:00:54
Hmm, I don't remember if Editor copies subfolders from Compiled/Data too, it probably should be made do that.

Well yes it makes sense, but if /Data remains just a subfolder of the execution folder, then it's just a refinement, not a big change.
 

Crimson Wizard

Quote from: Monsieur OUXX on Mon 01/04/2019 16:03:14
Quote from: Crimson Wizard on Mon 01/04/2019 12:00:54
Hmm, I don't remember if Editor copies subfolders from Compiled/Data too, it probably should be made do that.

Well yes it makes sense, but if /Data remains just a subfolder of the execution folder, then it's just a refinement, not a big change.

I was still wondering if there's misunderstanding remaining here, so I will clarify just in case:

Since 3.4.1 "Compiled" folder is a group folder for number of other locations. Any files inside "Compiled" itself are ignored now.
Compiled/Data - is an intermediate place for game files before they are got packed for various platforms.
Compiled/Windows - is the final output for Windows version of the game.
Compiled/Linux - is for Linux, and so on.

In other words "Compiled/Data" is a root for generic game data, "Compiled/Windows" is a root for game deployed for Windows.

If we mean a "Data" subfolder inside game, then it will be "Compiled/Data/Data" and "Compiled/Windows/Data".

What I meant by earlier post is that Editor copies any files found in Compiled/Data to each of the platform-specific folders. But I don't remember if it copies subfolders found inside Compiled/Data.

SMF spam blocked by CleanTalk