Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Game cannot write to its installation folder

This thread is locked; no one can reply to it. rss feed Print
Game cannot write to its installation folder
Werwolf696
Member #15,203
June 2013
avatar

Hello,

I just recently finished up a game in A5, used the nullsoft installer to create a deployment package, went over to my wife's laptop (running Windows XP Professional), installed ok, ran ok up until the point it need to save data to a file (I'm using the Boost library for serialization):

Code like this:

#SelectExpand
1std::ofstream output_file("Data/db_joystickconfig.dat", std::ios::binary); 2boost::archive::binary_oarchive oa(output_file); 3oa << joystickMapping; 4output_file.close();

"Data" is a folder off the installation root (ie: c:\Program Files\My Game\).
"joystickMapping" is just a struct defined elsewhere.

Anyone have experience with this? It runs fine if I launch the shortcut as Administrator, so I know it's permission related, just not sure how to "force" it or give it permission to write.

Thanks,
Rich

Thomas Fjellstrom
Member #476
June 2000
avatar

That's modern OSs for you. you can't write to system directories. You need to use the user's or shared user's data directory. in A5, you can use the al_get_standard_path function for that. Otherwise you basically need operating specific apis to get that information.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Matthew Leverton
Supreme Loser
January 1999
avatar

Sounds like you should be saving to the ALLEGRO_USER_SETTINGS_PATH location.

  1. al_set_org_name()

  2. al_set_app_name()

  3. al_get_standard_path(ALLEGRO_USER_SETTINGS_PATH)

  4. al_make_directory() if does not exist (no guarantee that it does)

  5. Create a path based off of that directory + db_joystickconfig.dat via al_set_path_filename()

Thomas Fjellstrom
Member #476
June 2000
avatar

And if you want to write actual data (and not config), you use ALLEGRO_USER_DATA_PATH.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Werwolf696
Member #15,203
June 2013
avatar

Awesome, thanks guys. My first Windows game, not used to all this security stuff. I appreciate your help.

Rich

l j
Member #10,584
January 2009
avatar

There's a special folder for saved games on windows vista and newer versions of windows, the allegro API doesn't support anything to find this folder though. Might be useful to have a function that returns a special path to the saved games folder if one is available.

Anyway, some games do save to the program files folder directly. It can be done by requesting admin privileges.

Werwolf696
Member #15,203
June 2013
avatar

taron said:

Anyway, some games do save to the program files folder directly. It can be done by requesting admin privileges.

Taron, how does one request admin privileges within the game?

Thomas Fjellstrom
Member #476
June 2000
avatar

You don't want to. The user will get a big scary UAC popup.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Go to: