Checking if the app is being run from a locked volume

Member
Posts: 86
Joined: 2005.01
Post: #1
Hi,

I recently released a game on write-protected DMG images; however, unless you move it out of the DMG and put it on your hard drive the game will just exit when a write-to-disk bit inside the game's C code fails. Obviously this is not a great way to go for future games, so I'm asking about this. Unfortunately, I don't know a whit of the OS X Cocoa API, and I'd prefer to implement the OS-specific code in the SDL OS X specific files so I don't have a big headache trying to port.

I'm using SDL and OpenGL -- the project file that comes with them, so I have an SDLmain.m (where I assume I'd put this code) and SDLmain.h file. Would anyone know where/how to check if the disk is write-protected and pop up an error message telling you to move the program to your hard drive?

Thanks.

Newest game: Glow, a sci-fi RPG with lots of zombie bashing. Get it: OS X
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
You should never write to your application's location. That's just plain badly behaved. ~/Library/Preferences, ~/Library/Application\ Support or /Users/Shared are the places to write, depending on the precise nature of the data you're dealing with.
Quote this message in a reply
Member
Posts: 86
Joined: 2005.01
Post: #3
OneSadCookie Wrote:You should never write to your application's location. That's just plain badly behaved. ~/Library/Preferences, ~/Library/Application\ Support or /Users/Shared are the places to write, depending on the precise nature of the data you're dealing with.

Most of my stuff that I'm writing is log files, config files and saved games.

Hrm. To keep this portable with a minimum of effort, I should probably write an OS-agnostic file writer wrapper that knows what paths to put things in (My Documents/My Games on XP, ~Shared on OS X) and how to make a new directory to cram files in for organization.

I'd still really like to know the answer to my original question, too. Wink OS X must be able to boot off a write protected volume (such as a DVD), can't it?

Newest game: Glow, a sci-fi RPG with lots of zombie bashing. Get it: OS X
Quote this message in a reply
Member
Posts: 161
Joined: 2005.07
Post: #4
ravuya Wrote:Most of my stuff that I'm writing is log files, config files and saved games.
Yes, put that stuff in the folders he already mentioned. It's not like those things get special treatment.
Quote this message in a reply
Member
Posts: 86
Joined: 2005.01
Post: #5
imikedaman Wrote:Yes, put that stuff in the folders he already mentioned. It's not like those things get special treatment.

Yes, of course. I'm not sure which one is best for saved games (probably ~Shared).

Newest game: Glow, a sci-fi RPG with lots of zombie bashing. Get it: OS X
Quote this message in a reply
Moderator
Posts: 508
Joined: 2002.09
Post: #6
ravuya Wrote:OS X must be able to boot off a write protected volume (such as a DVD), can't it?

Nope it can't, besides installing an OS on a write protected volume is a very bad idea.

"When you dream, there are no rules..."
Quote this message in a reply
Member
Posts: 86
Joined: 2005.01
Post: #7
Hmm. I'll definitely fix my code up to be more friendly, then. Anyone know offhand how to make a new directory from C++/Carbon?

Newest game: Glow, a sci-fi RPG with lots of zombie bashing. Get it: OS X
Quote this message in a reply
Member
Posts: 269
Joined: 2005.04
Post: #8
ravuya Wrote:Yes, of course. I'm not sure which one is best for saved games (probably ~Shared).

Some commercial games (like Sims 2, Sim City 4, and Halo) put saved games in ~/Documents/. Other games (like Doom 3 and Call of Duty, and my apps) put them in ~/Library/Application Support/. But don't do like Call of Duty 2 and put the saved games in the game app folder. Bad Call of Duty 2. No doughnut.

The only app I know of that uses /Users/Shared is Motion. I (and most other apps) use /Library/Application Support/ for any central data that needs to be shared with multiple users (like extra levels or what not). ~/Library/Application Support/ can be a backup if the user doesn't have write access, but everybody should have read access to there.
Quote this message in a reply
Member
Posts: 86
Joined: 2005.01
Post: #9
I think Application Support is probably a good idea; that way the user's precious Documents folder won't get all cluttered up with saved games in amongst their thousands of Word documents.

Apple's guidelines seem to agree:

Quote:Don’t Pollute User Space
It is important to remember that the user domain (/Users) is intended for files created by the user. With the exception of the ~/Library directory, your application should never install files into the user’s home directory. In particular, you should never install files into a user’s Documents directory or into the /Users/Shared directory. These directories should only be modified by the user.

Even if your application provides clip art or sample files that the user would normally manipulate, you should place those files in either the local or user’s Library/Application Support directory by default. The user can move or copy files from this directory as desired. If you are concerned about the user finding these files, you should include a way for the user to browse or access them directly from your application’s user interface.

Newest game: Glow, a sci-fi RPG with lots of zombie bashing. Get it: OS X
Quote this message in a reply
Member
Posts: 161
Joined: 2005.07
Post: #10
ravuya Wrote:I think Application Support is probably a good idea; that way the user's precious Documents folder won't get all cluttered up with saved games in amongst their thousands of Word documents.
Go for it. Glad to see you're committed to making things easier on the user.
Quote this message in a reply
Member
Posts: 86
Joined: 2005.01
Post: #11
Well, so far I've written my file-wrapper package for Windows -- it creates subfolders of the "My Documents\My Games" folder. Once I get back home to my Powerbook I'll whip up the OS X version, but I've put together what I think should work for Carbon so far.

Thing I don't like about this is that it's now harder for the user to remove the game fully once you're done with it; the save game files and persistent information (config) files are still kicking around your hard-drive even after you pitch the application

Newest game: Glow, a sci-fi RPG with lots of zombie bashing. Get it: OS X
Quote this message in a reply
Member
Posts: 204
Joined: 2002.09
Post: #12
In answers to some of your questions.

You can make a directory using mkdir:
int mkdir(const char *path, mode_t mode);



As for checking whether specific area is writable, one way to do it would be to try and open a file for writing... if it fails, then you can infer you can't write there.

Or, you can use one of the catalog information functions:

OSErr FSGetCatalogInfo (...);
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #13
There are more reasons why you wouldn't be able to write to a folder than that it's on a write-protected disk.

The usual reason to write to /Users/Shared even though it's not recommended is if you want to share high scores or a license across all users of the computer. /Library/Application\ Support/ would be the ideal location for such a thing, but it's not writable by ordinary users.
Quote this message in a reply
Member
Posts: 86
Joined: 2005.01
Post: #14
OneSadCookie Wrote:/Library/Application\ Support/ would be the ideal location for such a thing, but it's not writable by ordinary users.

I intended to use ~/Library/Application Support; it looks like I forgot to include that a couple times. Also, I don't think OS X really has the concept of "lock" anymore and is probably just using it as sugar to cover "read permission".

Newest game: Glow, a sci-fi RPG with lots of zombie bashing. Get it: OS X
Quote this message in a reply
Member
Posts: 86
Joined: 2005.01
Post: #15
I can't call FSPathMakeRef on "~/Library/Application Support"; it claims it doesn't exist. It's probably because ~ is interpreted by the shell and not the filesystem.

I wonder if there's a method to get the current user's home directory...

Edit: Got it. FS Find Folder. Works great. Smile

Hmph. Now when I use FSCreateDirectoryUnicode, it gets screwed up trying to convert my STL string::c_str() to a UniChar and ends up making a crazy Chinese directory. Anyone know an easier way to convert const char in UTF-8 to UniChar?

Newest game: Glow, a sci-fi RPG with lots of zombie bashing. Get it: OS X
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  porting weaker to stronger type checking C? WhatMeWorry 5 3,970 Jan 13, 2005 09:26 PM
Last Post: WhatMeWorry