The MASM Forum

General => The Workshop => Topic started by: sinsi on May 06, 2025, 05:45:40 PM

Title: Opinions on where to save options
Post by: sinsi on May 06, 2025, 05:45:40 PM
I have a clock program in progress which has a few options which I was going to save as a binary blob somewhere.
There are many ways to do this, each with their pros and cons.
 - registry   plenty of people dislike storing stuff in the registry
 - data file  what if we don't have write access (e.g. CD-ROM)?
 - resource   write access (as above), AV problems?
 - ADS        only for NTFS

Thoughts?
Title: Re: Opinions on where to save options
Post by: daydreamer on May 06, 2025, 07:35:40 PM
If its supposed to be on any cd or dvd rom,in readme.txt, tell user to install or move to a hd before use,to make it possible to write settings to a config file

Title: Re: Opinions on where to save options
Post by: Biterider on May 06, 2025, 07:49:11 PM
Hi sinsi
Just to complete the list, you can also use an environment variable, which is indirectly a registry entry.

Biterider
Title: Re: Opinions on where to save options
Post by: TimoVJL on May 06, 2025, 08:50:16 PM
Local user profile is a junkyard for many kind of files for user.
An AppData is similar folder for those files.

https://learn.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shgetfolderpatha (https://learn.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shgetfolderpatha)
Title: Re: Opinions on where to save options
Post by: Quin on May 06, 2025, 10:36:54 PM
I agree with Timo, probably the user's appdata folder  if you're worried about running off read-only media.
Title: Re: Opinions on where to save options
Post by: jj2007 on May 06, 2025, 11:53:40 PM
Quote from: sinsi on May 06, 2025, 05:45:40 PM- registry   plenty of people dislike storing stuff in the registry
 - data file  what if we don't have write access (e.g. CD-ROM)?

Just check if you can write to the executable's folder, and if not, use the registry.
Title: Re: Opinions on where to save options
Post by: zedd on May 07, 2025, 12:19:32 AM
Quote from: jj2007 on May 06, 2025, 11:53:40 PM
Quote from: sinsi on May 06, 2025, 05:45:40 PM- data file  what if we don't have write access (e.g. CD-ROM)?
Just check if you can write to the executable's folder, and if not, use the registry.
I would also check the "user" folders as well for write access. Even in scenarios where the user has limited privileges (a work computer for instance), the user folders are a possibility. In that scenario the registry may not be a viable option.
Title: Re: Opinions on where to save options
Post by: Quin on May 07, 2025, 01:30:32 AM
Quote from: zedd on May 07, 2025, 12:19:32 AM
Quote from: jj2007 on May 06, 2025, 11:53:40 PM
Quote from: sinsi on May 06, 2025, 05:45:40 PM- data file  what if we don't have write access (e.g. CD-ROM)?
Just check if you can write to the executable's folder, and if not, use the registry.
I would also check the "user" folders as well for write access. Even in scenarios where the user has limited privileges (a work computer for instance), the user folders are a possibility. In that scenario the registry may not be a viable option.
+1, I'd say current directory, user's appdata folder, and then registry, in that order.
Title: Re: Opinions on where to save options
Post by: NoCforMe on May 07, 2025, 03:56:55 AM
My preference, being a registry disliker, is a config file in the application's directory.

As you know, it's really easy to locate that folder by using GetModuleFileName(). That way you don't have config files spread out all over hell and gone.

Of course, if you want to have separate config files depending on what the user's current directory is, you can just write them to that folder.

Seems like a pretty good assumption that both of these schemes should have a writable folder available.
Title: Re: Opinions on where to save options
Post by: sinsi on May 08, 2025, 05:01:12 PM
OK, so my thoughts are
 - exe folder
 - user's appdata folder
 - registry
The data is going to be 4xDWORDs (x, y, font size, text colour) and a unicode font name.

Since it's going to start with Windows, maybe create a shortcut in Startup and use command-line parameters.


Quote from: jj2007 on May 06, 2025, 11:53:40 PMuse the registry.
jj, I had you pegged as vehemently anti-registry :badgrin:
Title: Re: Opinions on where to save options
Post by: NoCforMe on May 08, 2025, 06:18:49 PM
One thing I'm unclear about here:
What exactly is the "user's appdata folder"?
Is this their <username> folder under Users?
Title: Re: Opinions on where to save options
Post by: sinsi on May 08, 2025, 07:34:30 PM
Quote from: NoCforMe on May 08, 2025, 06:18:49 PMOne thing I'm unclear about here:
What exactly is the "user's appdata folder"?
Is this their <username> folder under Users?
I would use local appdata
LOCALAPPDATA=C:\Users\<user>\AppData\Local
APPDATA=C:\Users\<user>\AppData\Roaming
Title: Re: Opinions on where to save options
Post by: TimoVJL on May 09, 2025, 02:56:49 AM
Yes, APPDATA is just for AD environment and LOCALAPPDATA is right place for normal programs.
In many companies users can login from many PCs and can have roaming program settings.
Title: Re: Opinions on where to save options
Post by: sinsi on May 09, 2025, 03:17:32 AM
Quote from: TimoVJL on May 09, 2025, 02:56:49 AMYes, APPDATA is just for AD environment and LOCALAPPDATA is right place for normal programs.
In many companies users can login from many PCs and can have roaming program settings.

That's the exact reason I don't want it in the roaming profile. The whole point of it is for the clock to sit at the top right of my second monitor so I can see it properly.
A roaming profile suggests a variety of hardware, so in the worst case the clock shows at (3500,100) which is off-screen in a single-monitor configuration and, since there's no taskbar icon, makes it hard to move.
Plus, the company probably locks down startup items.
Title: Re: Opinions on where to save options
Post by: jj2007 on May 09, 2025, 05:56:37 PM
Quote from: sinsi on May 08, 2025, 05:01:12 PMjj, I had you pegged as vehemently anti-registry :badgrin:

I am, sinsi :biggrin:

But if you really can't write to the executable's folder, which should be a rare case IMO, the registry is a workaround. You may use SetRegVal (https://www.jj2007.eu/MasmBasicQuickReference.htm#Mb1214) to do that ;-)
Title: Re: Opinions on where to save options
Post by: sinsi on May 09, 2025, 06:11:19 PM
Quote from: jj2007 on May 09, 2025, 05:56:37 PMYou may use SetRegVal (https://www.jj2007.eu/MasmBasicQuickReference.htm#Mb1214) to do that ;-)
Never miss an opportunity for a plug, do you  :biggrin:

Anyway, I've decided that the registry is the way to go.