Reputation: 1738
I'm making a scored game, and want to save the high scores. I want to save the scores in a file that the program can access (of course), but the scores shouldn't be editable by the user (a read-only file, probably). The problem with a read-only file is that, obviously, it's read only, so I can't write the high scores to it. Is there any way to create a file that can be edited by the application but not by the user, or do I have to encrypt the file in some way?
Note: I prefer the C (stdio.h
) method of file writing.
Upvotes: 1
Views: 256
Reputation:
Even encryption won't stop editing of the file by something other than your application.
Can I suggest that one option is to simply store the data in binary format? You then save the complication of implementing an encryption, but still prevent any accidental editing of the file.
You could also make your application set the file to be read-only by all, and then make it writeable only while using it. Again, this won't prevent someone else changing those permissions, but it will prevent accidental editing.
Upvotes: 2
Reputation: 119229
There is an established means of accomplishing this on Unix-like systems, but I don't know how you'd do it on other platforms. The idea is to give the high scores files the group ID of a special group just for this purpose, usually simply called games
. The games themselves are then setgid games
, so that ordinary users can run games, and the games can edit the high scores files, but users cannot directly write to the high scores files.
More details over on Unix & Linux: https://unix.stackexchange.com/a/59059/14308
Upvotes: 1