ENGINE-579: Read Registry values pEp/UserFolder and pEp/SystemFolder and use the defined paths if available sequoia_windows
authorThomas
Mon, 17 Jun 2019 11:20:00 +0200
branchsequoia_windows
changeset 38425be8219250cb
parent 3835 65f3c7d59eb1
child 3843 cbdc7255c019
ENGINE-579: Read Registry values pEp/UserFolder and pEp/SystemFolder and use the defined paths if available
src/platform_windows.cpp
     1.1 --- a/src/platform_windows.cpp	Fri Jun 14 14:45:26 2019 +0200
     1.2 +++ b/src/platform_windows.cpp	Mon Jun 17 11:20:00 2019 +0200
     1.3 @@ -25,8 +25,13 @@
     1.4  #define WC_ERR_INVALID_CHARS      0x00000080  // error for invalid chars
     1.5  #endif
     1.6  
     1.7 -#define ENV_PEP_APPDATA "PEP_APPDATA"
     1.8 -#define ENV_PEP_APPDATA_VAL "1" 
     1.9 +#define SYSTEM_FOLDER_DEFAULT "%ALLUSERSPROFILE%\\pEp"
    1.10 +#define USER_FOLDER_DEFAULT "%LOCALAPPDATA%\\pEp"
    1.11 +#define KEYS_DB "keys.db"
    1.12 +#define MANAGEMENT_DB "management.db"
    1.13 +#define SYSTEM_DB "system.db"
    1.14 +#define USER_FOLDER_PATH pEpUserFolderPath().c_str()
    1.15 +#define SYSTEM_FOLDER_PATH pEpSystemFolderPath().c_str()
    1.16  
    1.17  using namespace std;
    1.18  
    1.19 @@ -135,6 +140,38 @@
    1.20  	return path;
    1.21  }
    1.22  
    1.23 +static inline string pEpSystemFolderPath(void)
    1.24 +{
    1.25 +	static TCHAR tPath[PATH_BUF_SIZE];
    1.26 +	string path = SYSTEM_FOLDER_DEFAULT;
    1.27 +
    1.28 +	// Get SystemFolder Registry value and use if available
    1.29 +	bool result = readRegistryString(HKEY_CURRENT_USER,
    1.30 +		TEXT("SOFTWARE\\pEp"), TEXT("SystemFolder"), tPath,
    1.31 +		PATH_BUF_SIZE, NULL);
    1.32 +
    1.33 +	if (result)
    1.34 +		path = utf8_string(tPath);
    1.35 +
    1.36 +	return path;
    1.37 +}
    1.38 +
    1.39 +static inline string pEpUserFolderPath(void)
    1.40 +{
    1.41 +	static TCHAR tPath[PATH_BUF_SIZE];
    1.42 +	string path = USER_FOLDER_DEFAULT;
    1.43 +
    1.44 +	// Get UserFolder Registry value and use if available
    1.45 +	bool result = readRegistryString(HKEY_CURRENT_USER,
    1.46 +		TEXT("SOFTWARE\\pEp"), TEXT("UserFolder"), tPath,
    1.47 +		PATH_BUF_SIZE, NULL);
    1.48 +
    1.49 +	if (result)
    1.50 +		path = utf8_string(tPath);
    1.51 +	
    1.52 +	return path;
    1.53 +}
    1.54 +
    1.55  extern "C" {
    1.56  
    1.57  void *dlopen(const char *filename, int flag) {
    1.58 @@ -199,35 +236,22 @@
    1.59  const char *windoze_keys_db(void) {
    1.60  	static string path;
    1.61  	if (path.length() == 0) {
    1.62 -
    1.63 -		const char * env = getenv(ENV_PEP_APPDATA);
    1.64 -
    1.65 -		if (env && (strcmp(env, ENV_PEP_APPDATA_VAL) == 0))
    1.66 -			path = managementPath("%APPDATA%\\pEp", "keys.db");
    1.67 -		else
    1.68 -			path = managementPath("%LOCALAPPDATA%\\pEp", "keys.db");
    1.69 +		path = managementPath(USER_FOLDER_PATH, KEYS_DB);
    1.70  	}
    1.71  	return path.c_str();
    1.72  }
    1.73  
    1.74  const char *windoze_local_db(void) {
    1.75  	static string path;
    1.76 -	if (path.length() == 0) {
    1.77 -
    1.78 -		const char * env = getenv(ENV_PEP_APPDATA);
    1.79 -
    1.80 -		if (env && (strcmp(env, ENV_PEP_APPDATA_VAL) == 0))
    1.81 -			path = managementPath("%APPDATA%\\pEp", "management.db");
    1.82 -		else
    1.83 -			path = managementPath("%LOCALAPPDATA%\\pEp", "management.db");
    1.84 -	}
    1.85 +	if (path.length() == 0)
    1.86 +		path = managementPath(USER_FOLDER_PATH, MANAGEMENT_DB);
    1.87      return path.c_str();
    1.88  }
    1.89  
    1.90  const char *windoze_system_db(void) {
    1.91  	static string path;
    1.92  	if (path.length() == 0)
    1.93 -		path = managementPath("%ALLUSERSPROFILE%\\pEp", "system.db");
    1.94 +		path = managementPath(SYSTEM_FOLDER_PATH, SYSTEM_DB);
    1.95      return path.c_str();
    1.96  }
    1.97