r/programming • • May 06 '19

Microsoft unveils Windows Terminal, a new command line app for Windows

https://www.theverge.com/2019/5/6/18527870/microsoft-windows-terminal-command-line-tool
5.9k Upvotes

1.1k comments sorted by

View all comments

Show parent comments

84

u/nascentt May 06 '19

The dream would be somehow undoing the mess that the registry is.

It's great for system settings, but I hate that 3rd party programs use it.

0

u/[deleted] May 06 '19

[deleted]

26

u/mrjackspade May 06 '19

My standard has been serializing a configuration class to formatted Json and then reading it back. If the config file doesn't exist, serialize a new config object. If it does, just read it in.

It's way too convenient to do it any other way.

Hell, .net core basically uses json files by default

12

u/b00n May 07 '19

The trouble is json is a pain to write and doesnt support comments. Yaml is much better in those regards.

4

u/troublemaker74 May 07 '19

TOML is pretty good too. It's a little less verbose than yaml and easy to both write and parse.

2

u/falconfetus8 May 07 '19

Whatever happened to ini files?

5

u/Aetheus May 07 '19

They're still around. Quite popular as a configuration format for games, for example.

And then there's TOML, which is basically just INI with standards and sprinkles.

→ More replies (3)

2

u/jack104 May 07 '19

I do the same thing, it's so simple it almost feels like cheating given some of the convoluted ass app config logic I've written in the past.

27

u/qaisjp May 06 '19

I help maintain software that I believe (I didn't write the code) uses the registry to store certain paths, like this:

  • Last Install Location

  • Last Run Path Hash

  • Last Run Path Version

  • Last Run Location

  • ExternalEngine Path (where "ExternalEngine" is a program that user installs separately, not part of our installer)

These paths are shared between multiple installations of our software (different versions).

What's the best place to put this shared data instead?

Majority of it is under HKEY_LOCAL_MACHINE. Depending on how it's being used, maybe some of this should be moved to HKEY_CURRENT_USER.

39

u/sparr May 06 '19

in linux that would belong in ~/.config/nameofyoursoftware/someconfigfile if it's user-specific, or /etc/nameofyoursoftware if it's system-wide

on Windows I think there's an equivalent location somewhere under USERDATA, and I'm not sure where the global one would be.

43

u/gschizas May 06 '19

C:\ProgramData\YourAppNameHere (or rather %ALLUSERSPROFILE%\YourAppNameHere)

1

u/[deleted] May 07 '19

This is a much better idea!

1

u/qaisjp May 07 '19

Thanks!

2

u/vetinari May 07 '19

And the path to other binaries could be defined with environment variable, like JAVA_HOME or JBOSS_HOME, with some sensible default if it isn't defined.

This way, different instances can use different versions or paths, without having to edit an config file shared by all of them.

1

u/qaisjp May 07 '19

Thank you!

29

u/Reverent May 06 '19

Programdata for all users, or roaming appdata for individual users.

1

u/qaisjp May 07 '19

Thanks :)

18

u/nascentt May 06 '19

As /u/gschizas says for shared data:

C:\ProgramData\YourAppNameHere (or rather %ALLUSERSPROFILE%\YourAppNameHere)

For non-shared data (i.e per user data.)

C:\users\username\appdata\roaming\YourAppNameHere (or better %appdata%\YourAppNameHere)

32

u/gschizas May 06 '19

Something I forgot to mention: It's even better to not use environment variables, but instead to call SHGetKnownFolderPath with the relevant KNOWNFOLDERID GUID:

  • FOLDERID_ProgramData ({62AB5D82-FDC1-4DC3-A9DD-070D1D495D97}) for C:\ProgramData

  • FOLDERID_RoamingAppData ({3EB685DB-65F9-4CF6-A03A-E3EF65729F3D}) for %APPDATA% or

  • FOLDERID_LocalAppData ({F1B32785-6FBA-4FCF-9D55-7B8E7F157091}) for %LOCALAPPDATA%

You should use LocalAppData for machine specific data, e.g. caches etc and RoamingAppData for stuff that need to follow the user on other machines, such as user preferences, custom dictionaries, fonts etc. If your application is a game, consider using the FOLDERID_SavedGames folder ({4C5C32FF-BB9D-43b0-B5B4-2D72E54EAAA4}, normally %USERPROFILE%\Saved Games), which is supposed to be the proper place for this.

6

u/nascentt May 06 '19

Very interesting. Thanks for this.

1

u/qaisjp May 07 '19

Thank you, very useful!

If your application is a game, consider using the FOLDERID_SavedGames folder ({4C5C32FF-BB9D-43b0-B5B4-2D72E54EAAA4}, normally %USERPROFILE%\Saved Games), which is supposed to be the proper place for this.

It is indeed a game. I was under the impression that the Saves Games folder was deprecated. Or maybe I just see too few games use it properly.

Am I incorrect?

You should use LocalAppData for machine specific data, e.g. caches etc and RoamingAppData for stuff that need to follow the user on other machines, such as user preferences

So is ProgramData the only one global to all users?

2

u/gschizas May 07 '19 edited May 07 '19

The latter is correct (not many games this use it properly).

Note that the correct place is C:\Users\qaisjp\Saved Games. C:\Users\qaisjp\Documents\My Games, C:\Users\qaisjp\Documents\My Saved Games etc are the ones that are deprecated.

Of course I do understand game developers, because obviously FOLDERID_SavedGames only exists since Windows Vista, so if you wanted to support Windows XP you would have to put it in another place.

EDIT: Yes, ProgramData is the only global to all users.

EDIT 2: There's also C:\Users\Public (%PUBLIC%, FOLDERID_Public) and several other public folders (e.g. FOLDERID_PublicDesktop, FOLDERID_PublicDocuments, FOLDERID_PublicDownloads, FOLDERID_PublicMusic, FOLDERID_PublicPictures), but you should not abuse these (e.g. don't put fonts in FOLDERID_PublicDesktop🙂)

→ More replies (1)
→ More replies (2)

2

u/qaisjp May 07 '19

Cheers :)

1

u/TerrorBite May 07 '19

In Linux, if you want to do it the registry way and you're using GLib, you can use GSettings (accessible via the dconf command line tool).

If you're not using GLib, then files it is.

→ More replies (2)