Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Locate user's profile directory on windows #140

Closed
ola-importer opened this issue Dec 24, 2013 · 10 comments
Closed

Locate user's profile directory on windows #140

ola-importer opened this issue Dec 24, 2013 · 10 comments

Comments

@ola-importer
Copy link

From si...@nomis52.net on May 22, 2011 09:30:50

On *nix we use getpwuid_r() to locate the user's home dir. Under Windows we can read the %UserProfile% environment variable.

We should add a function

string GetEnvVariable(const string &variable)

to the common utils and use this to read the env var.

Original issue: http://code.google.com/p/open-lighting/issues/detail?id=139

@ola-importer
Copy link
Author

From sl1200mk2 on May 23, 2011 00:10:25

there are several way to retrieve environment variable on windows:
-GetEnvironmentStrings() wich can be used to get system and user variables
-ExpandEnvironmentStrings() with "%ProgramFiles%" as first argument to retrieve exe location path

it depends of wich varaiable we need.

++
nicolas

@ola-importer
Copy link
Author

From si...@nomis52.net on May 23, 2011 08:10:14

We only need to fetch a single variable at a time so ExpandEnvironmentStrings() is the most appropriate here.

@ola-importer
Copy link
Author

From sl1200mk2 on May 25, 2011 06:59:50

from all i saw, major issue with ExpandEnvironmentStrings() is this function needs WCHAR as parameter.
we can use MultiByteToWideChar() to convert const char* to LPCWSTR and WideCharToMultiByte() to reverse LPCWSTR to const char

@ola-importer
Copy link
Author

From si...@nomis52.net on May 25, 2011 08:32:21

Ok, after reading http://www.codeproject.com/Tips/76252/What-are-TCHAR-WCHAR-LPSTR-LPWSTR-LPCTSTR-etc.aspx and coming up to speed on win32 string handling, it looks like it'll only require a LPCWSTR is unicode is on. Is unicode on when we compile? How can we check and/or turn it off?

I think this should work if unicode is off

const string key = "foo" // this would be the argument to the function we're writing
ExpandEnvironmentStrings(key.c_str(), buffer, buffer_length );

@ola-importer
Copy link
Author

From sl1200mk2 on June 06, 2011 06:39:14

unicode is off unless you set to 1 _UNICODE and UNICODE macro

this is coming from curl and should work as we do not turn on unicode, variable should be "%ProgramFiles%"

char env[MAX_PATH]; /* MAX_PATH is from windef.h */
char *temp = getenv(variable);
env[0] = '\0';
if(temp != NULL)
ExpandEnvironmentStrings(temp, env, sizeof(env));
return (env[0] != '\0')?strdup(env):NULL;

but maybe this is too much c style...

@ola-importer
Copy link
Author

From si...@nomis52.net on June 06, 2011 08:13:37

Let's start with that and then I can provide comments on C++ style.

@ola-importer
Copy link
Author

From sl1200mk2 on June 06, 2011 08:28:27

maybe it will be an issue for the future if we don't use wchar_t on windows ?
we can write function to return std::string from TCHAR...

@ola-importer
Copy link
Author

From si...@nomis52.net on June 06, 2011 08:33:40

We'll ignore unicode for now and just go with what you have above.

@ola-importer
Copy link
Author

From sl1200mk2 on June 06, 2011 08:40:11

ok Simon

@lukase
Copy link
Contributor

lukase commented Aug 5, 2014

olad preferences are now stored in %LOCALAPPDATA%/.ola/. This is handled in OlaDaemon::DefaultConfigDir() by using SHGetFolderPath with CSIDL_LOCAL_APPDATA .

@nomis52 nomis52 closed this as completed Aug 5, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants