Register | Login
Views: 19364387
Main | Memberlist | Active users | ACS | Commons | Calendar | Online users
Ranks | FAQ | Color Chart | Photo album | IRC Chat
11-02-05 12:59 PM
0 user currently in Programming. | 3 guests
Acmlm's Board - I2 Archive - Programming - Saving User Prefernces Internally | |
Add to favorites | "RSS" Feed | Next newer thread | Next older thread
User Post
MathOnNapkins

Math n' Hacks
Level: 67

Posts: 2021/2189
EXP: 2495887
For next: 96985

Since: 03-18-04
From: Base Tourian

Since last post: 1 hour
Last activity: 32 min.
Posted on 06-29-05 01:16 AM Link | Quote
Generally what are the ways to save user preferences into an .exe file? If any. I know the conventional way would be to use an external file, but I can do that, I just want to know the answer to thie question.

So for example, I'm currently writing a program that has a toggle button associated with a boolean. But I when the program shuts down I want it to remember the state of that variable, i.e. store it somewhere internally. Also other things, like the position of the window, would be nice. Anyone got any ideas?
Ramsus

Octoballoon
Level: 19

Posts: 123/162
EXP: 34651
For next: 1126

Since: 01-24-05
From: United States

Since last post: 39 days
Last activity: 71 days
Posted on 06-29-05 03:55 AM Link | Quote
There's no real practical reason to not store user preferences into a separate file. Hacking the binary executable format that your program is in verges on downright stupid and requires you to understand things like the layout of the program, how the OS copies it into memory and initializes it, assembly language and how your language is translated into machine code, etc. It's not even really doable in any sort of portable or non-hackish way.

On Windows, you can store small values in the registry through a few API calls. If you simply want an invisible means of storing user preferences without messing with files, it's a good way to do it. Then Windows will just store the values in the registry file it keeps all of its registry information in.

Mac OS X and GNUstep also provides the OpenStep API methods for storing and loading preference options, which are then stored in the users Library/Preferences directory in a PLIST file.

GNOME and KDE provide their own services for storing and retrieving configuration files using gconfd (which stores XML files in a hidden folder in the users home directory) and whatever it is KDE uses.

If you're using Mac OS, BeOS, or some form of UNIX, your filesystem may support arbitrary meta data associated with files. You could then store small configuration values in the filesystem as meta-data associated with the program's binary file.

sloat

Level: 16

Posts: 68/85
EXP: 18044
For next: 2212

Since: 05-21-04
From: South Central Delaware

Since last post: 19 days
Last activity: 5 hours
Posted on 06-29-05 06:08 AM Link | Quote
You would have to have a set of global variables with values already in the code, then you would need to find them in the data segment of the binary and overwrite them. I would have doubts about that working on Windows however, since I'm not sure a running program can overwrite itself. It may also throw up a red flag to some virus scanners, but don't quote me on that.

Anyway, I agree with Ramsus. There's no reason to do it this way. Though I must implore you, if you're gonna have something write to the registry, please have something get rid of the keys you create (ie uninstaller).
HyperLamer
<||bass> and this was the soloution i thought of that was guarinteed to piss off the greatest amount of people

Sesshomaru
Tamaranian

Level: 118

Posts: 5326/8210
EXP: 18171887
For next: 211027

Since: 03-15-04
From: Canada, w00t!
LOL FAD

Since last post: 2 hours
Last activity: 2 hours
Posted on 06-29-05 07:28 AM Link | Quote
NTFS supports this metadata too.

I think you can just add to the end of the file but don't quote me on that. The best way would be to just do as sloat said; find the initial value and overwrite it.
MathOnNapkins

Math n' Hacks
Level: 67

Posts: 2024/2189
EXP: 2495887
For next: 96985

Since: 03-18-04
From: Base Tourian

Since last post: 1 hour
Last activity: 32 min.
Posted on 06-29-05 12:14 PM Link | Quote
Well I was hoping against hope there was a simple way to do it. Based on my own guesses and your responses it seems I'd have to come up with somethingverrry hackalicious.

"Anyway, I agree with Ramsus. There's no reason to do it this way."

I think it's stupid there isn't an easy way to do this. I find that the creation of files and messing with registry keys generates clutter. I think I'm just going to use a .dat file or something b/c I don't want to fuck up people's registries more then they already are. That and it tends to prevent you from running a program on a protected computer (such as a computer lab at a school/university)
creaothceann

Red Paragoomba
Level: 11

Posts: 26/50
EXP: 5903
For next: 82

Since: 01-27-05

Since last post: 21 hours
Last activity: 21 hours
Posted on 06-29-05 11:19 PM Link | Quote
In DOS it's possible. Maybe you can do it in Windows with these steps:

- the Application program stores its data in a global object (Link) or just in a file
- Application starts a Watcher program
- Watcher checks continually if Application is still running
- Application quits
- Watcher writes the data into Application's *.exe
- Watcher quits

Originally posted by MathOnNapkins
I find that the creation of files and messing with registry keys generates clutter.

IMO files don't clutter stuff - when they're in the application's directory. Many people just have to write into the Windows directory etc. I can't fathom their thinking.


(edited by creaothceann on 06-29-05 02:19 PM)
Add to favorites | "RSS" Feed | Next newer thread | Next older thread
Acmlm's Board - I2 Archive - Programming - Saving User Prefernces Internally | |


ABII


AcmlmBoard vl.ol (11-01-05)
© 2000-2005 Acmlm, Emuz, et al



Page rendered in 0.006 seconds.