Untabify platform_windows.cpp sync
authorThomas
Tue, 26 Nov 2019 14:51:42 +0100
branchsync
changeset 42277131be89c995
parent 4225 4aee2e82153d
child 4228 724d8085b47d
Untabify platform_windows.cpp
src/platform_windows.cpp
     1.1 --- a/src/platform_windows.cpp	Tue Nov 26 14:31:54 2019 +0100
     1.2 +++ b/src/platform_windows.cpp	Tue Nov 26 14:51:42 2019 +0100
     1.3 @@ -84,37 +84,37 @@
     1.4  {
     1.5      assert(lpResult);
     1.6  
     1.7 -	HKEY theKey;
     1.8 -	DWORD type;
     1.9 -	DWORD bytesCopied = dwSize;
    1.10 -	HRESULT result;
    1.11 +    HKEY theKey;
    1.12 +    DWORD type;
    1.13 +    DWORD bytesCopied = dwSize;
    1.14 +    HRESULT result;
    1.15  
    1.16 -	result = RegOpenKeyEx(hKey, lpSubKey, 0, KEY_READ, &theKey);
    1.17 -	if (result != ERROR_SUCCESS) {
    1.18 -		if (lpDefault) {
    1.19 -			wcsncpy_s(lpResult, dwSize, lpDefault, _TRUNCATE);
    1.20 -			return true;
    1.21 -		}
    1.22 -		else
    1.23 -			return false;
    1.24 -	}
    1.25 +    result = RegOpenKeyEx(hKey, lpSubKey, 0, KEY_READ, &theKey);
    1.26 +    if (result != ERROR_SUCCESS) {
    1.27 +        if (lpDefault) {
    1.28 +            wcsncpy_s(lpResult, dwSize, lpDefault, _TRUNCATE);
    1.29 +            return true;
    1.30 +        }
    1.31 +        else
    1.32 +            return false;
    1.33 +    }
    1.34  
    1.35 -	result = RegQueryValueEx(theKey, lpValueName, NULL, &type,
    1.36 +    result = RegQueryValueEx(theKey, lpValueName, NULL, &type,
    1.37              (LPBYTE) lpResult, &bytesCopied);
    1.38      if (result != ERROR_SUCCESS || (type != REG_EXPAND_SZ && type != REG_SZ)) {
    1.39 -		if (lpDefault) {
    1.40 -			wcsncpy_s(lpResult, dwSize, lpDefault, _TRUNCATE);
    1.41 -			RegCloseKey(theKey);
    1.42 -			return true;
    1.43 -		}
    1.44 -		else {
    1.45 -			RegCloseKey(theKey);
    1.46 -			return false;
    1.47 -		}
    1.48 -	}
    1.49 +        if (lpDefault) {
    1.50 +            wcsncpy_s(lpResult, dwSize, lpDefault, _TRUNCATE);
    1.51 +            RegCloseKey(theKey);
    1.52 +            return true;
    1.53 +        }
    1.54 +        else {
    1.55 +            RegCloseKey(theKey);
    1.56 +            return false;
    1.57 +        }
    1.58 +    }
    1.59  
    1.60 -	RegCloseKey(theKey);
    1.61 -	return true;
    1.62 +    RegCloseKey(theKey);
    1.63 +    return true;
    1.64  }
    1.65  
    1.66  static const DWORD PATH_BUF_SIZE = 32768;
    1.67 @@ -126,102 +126,102 @@
    1.68  
    1.69      DWORD length = ExpandEnvironmentStringsW(utf16_string(file_path).c_str(),
    1.70              tPath, PATH_BUF_SIZE);
    1.71 -	assert(length);
    1.72 +    assert(length);
    1.73      if (length == 0)
    1.74          throw bad_alloc(); // BUG: there are other errors possible beside out of memory
    1.75  
    1.76 -	CreateDirectory(tPath, NULL);
    1.77 -	DWORD error = GetLastError();
    1.78 +    CreateDirectory(tPath, NULL);
    1.79 +    DWORD error = GetLastError();
    1.80  
    1.81 -	path = utf8_string(tPath);
    1.82 -	path += "\\";
    1.83 -	path += file_name;
    1.84 +    path = utf8_string(tPath);
    1.85 +    path += "\\";
    1.86 +    path += file_name;
    1.87  
    1.88 -	return path;
    1.89 +    return path;
    1.90  }
    1.91  
    1.92  const char *_per_machine_directory(void)
    1.93  {
    1.94 -	static string path;
    1.95 -	if (path.length())
    1.96 -		return path.c_str();
    1.97 +    static string path;
    1.98 +    if (path.length())
    1.99 +        return path.c_str();
   1.100  
   1.101 -	TCHAR tPath[PATH_BUF_SIZE];
   1.102 +    TCHAR tPath[PATH_BUF_SIZE];
   1.103  
   1.104 -	// Get SystemFolder Registry value and use if available
   1.105 -	bool result = readRegistryString(HKEY_CURRENT_USER,
   1.106 -		TEXT("SOFTWARE\\pEp"), TEXT("SystemFolder"), tPath,
   1.107 -		PATH_BUF_SIZE, NULL);
   1.108 +    // Get SystemFolder Registry value and use if available
   1.109 +    bool result = readRegistryString(HKEY_CURRENT_USER,
   1.110 +        TEXT("SOFTWARE\\pEp"), TEXT("SystemFolder"), tPath,
   1.111 +        PATH_BUF_SIZE, NULL);
   1.112  
   1.113 -	// If not Registry value was found, use default
   1.114 -	if (!result) {
   1.115 -		DWORD length = ExpandEnvironmentStringsW(utf16_string(string(PER_MACHINE_DIRECTORY)).c_str(),
   1.116 -			tPath, PATH_BUF_SIZE);
   1.117 -		assert(length);
   1.118 -		if (length == 0)
   1.119 -			throw bad_alloc(); // BUG: there are other errors possible beside out of memory
   1.120 -	}
   1.121 +    // If not Registry value was found, use default
   1.122 +    if (!result) {
   1.123 +        DWORD length = ExpandEnvironmentStringsW(utf16_string(string(PER_MACHINE_DIRECTORY)).c_str(),
   1.124 +            tPath, PATH_BUF_SIZE);
   1.125 +        assert(length);
   1.126 +        if (length == 0)
   1.127 +            throw bad_alloc(); // BUG: there are other errors possible beside out of memory
   1.128 +    }
   1.129  
   1.130 -	path = utf8_string(wstring(tPath));
   1.131 -	return path.c_str();
   1.132 +    path = utf8_string(wstring(tPath));
   1.133 +    return path.c_str();
   1.134  }
   1.135  
   1.136  const char *_per_user_directory(void)
   1.137  {
   1.138 -	static string path;
   1.139 -	if (path.length())
   1.140 -		return path.c_str();
   1.141 +    static string path;
   1.142 +    if (path.length())
   1.143 +        return path.c_str();
   1.144  
   1.145 -	TCHAR tPath[PATH_BUF_SIZE];
   1.146 +    TCHAR tPath[PATH_BUF_SIZE];
   1.147  
   1.148 -	// Get UserFolder Registry value and use if available
   1.149 -	bool result = readRegistryString(HKEY_CURRENT_USER,
   1.150 -		TEXT("SOFTWARE\\pEp"), TEXT("UserFolder"), tPath,
   1.151 -		PATH_BUF_SIZE, NULL);
   1.152 +    // Get UserFolder Registry value and use if available
   1.153 +    bool result = readRegistryString(HKEY_CURRENT_USER,
   1.154 +        TEXT("SOFTWARE\\pEp"), TEXT("UserFolder"), tPath,
   1.155 +        PATH_BUF_SIZE, NULL);
   1.156  
   1.157 -	// If not Registry value was found, use default
   1.158 -	if (!result) {
   1.159 -		DWORD length = ExpandEnvironmentStringsW(utf16_string(string(PER_USER_DIRECTORY)).c_str(),
   1.160 -			tPath, PATH_BUF_SIZE);
   1.161 -		assert(length);
   1.162 -		if (length == 0)
   1.163 -			throw bad_alloc(); // BUG: there are other errors possible beside out of memory
   1.164 -	}
   1.165 +    // If not Registry value was found, use default
   1.166 +    if (!result) {
   1.167 +        DWORD length = ExpandEnvironmentStringsW(utf16_string(string(PER_USER_DIRECTORY)).c_str(),
   1.168 +            tPath, PATH_BUF_SIZE);
   1.169 +        assert(length);
   1.170 +        if (length == 0)
   1.171 +            throw bad_alloc(); // BUG: there are other errors possible beside out of memory
   1.172 +    }
   1.173  
   1.174 -	path = utf8_string(wstring(tPath));
   1.175 -	return path.c_str();
   1.176 +    path = utf8_string(wstring(tPath));
   1.177 +    return path.c_str();
   1.178  }
   1.179  
   1.180  extern "C" {
   1.181  
   1.182  DYNAMIC_API const char *per_user_directory(void)
   1.183  {
   1.184 -	return _per_user_directory();
   1.185 +    return _per_user_directory();
   1.186  }
   1.187  
   1.188  DYNAMIC_API const char *per_machine_directory(void)
   1.189  {
   1.190 -	return _per_machine_directory();
   1.191 +    return _per_machine_directory();
   1.192  }
   1.193  
   1.194  void *dlopen(const char *filename, int flag) {
   1.195 -	static TCHAR path[PATH_BUF_SIZE];
   1.196 +    static TCHAR path[PATH_BUF_SIZE];
   1.197  
   1.198      assert(filename);
   1.199 -	assert(flag == RTLD_LAZY); // only lazy binding is implemented
   1.200 +    assert(flag == RTLD_LAZY); // only lazy binding is implemented
   1.201  
   1.202 -	// Look up GnuPG installation in current user scope
   1.203 -	bool result = readRegistryString(HKEY_CURRENT_USER,
   1.204 -		TEXT("SOFTWARE\\GnuPG"), TEXT("Install Directory"), path,
   1.205 -		PATH_BUF_SIZE, NULL);
   1.206 -	// If not found in current user, look up in local machine
   1.207 -	if (!result)
   1.208 -		result = readRegistryString(HKEY_LOCAL_MACHINE,
   1.209 -			TEXT("SOFTWARE\\GnuPG"), TEXT("Install Directory"), path,
   1.210 -			PATH_BUF_SIZE, NULL);
   1.211 -	assert(result);
   1.212 -	if (!result)
   1.213 -		return NULL;
   1.214 +    // Look up GnuPG installation in current user scope
   1.215 +    bool result = readRegistryString(HKEY_CURRENT_USER,
   1.216 +        TEXT("SOFTWARE\\GnuPG"), TEXT("Install Directory"), path,
   1.217 +        PATH_BUF_SIZE, NULL);
   1.218 +    // If not found in current user, look up in local machine
   1.219 +    if (!result)
   1.220 +        result = readRegistryString(HKEY_LOCAL_MACHINE,
   1.221 +            TEXT("SOFTWARE\\GnuPG"), TEXT("Install Directory"), path,
   1.222 +            PATH_BUF_SIZE, NULL);
   1.223 +    assert(result);
   1.224 +    if (!result)
   1.225 +        return NULL;
   1.226  
   1.227      SetDllDirectory(TEXT(""));
   1.228      BOOL _result = SetDllDirectory(path);
   1.229 @@ -229,12 +229,12 @@
   1.230      if (_result == 0)
   1.231          return NULL;
   1.232  
   1.233 -	HMODULE module = LoadLibrary(utf16_string(filename).c_str());
   1.234 +    HMODULE module = LoadLibrary(utf16_string(filename).c_str());
   1.235  
   1.236      if (module == NULL) {
   1.237          SetDllDirectory(NULL);
   1.238                      
   1.239 -		_tcscat_s(path, TEXT("\\bin"));
   1.240 +        _tcscat_s(path, TEXT("\\bin"));
   1.241          
   1.242          SetDllDirectory(TEXT(""));
   1.243          _result = SetDllDirectory(path);
   1.244 @@ -242,46 +242,46 @@
   1.245          if (_result == 0)
   1.246              return NULL;
   1.247  
   1.248 -    	module = LoadLibrary(utf16_string(filename).c_str());
   1.249 +        module = LoadLibrary(utf16_string(filename).c_str());
   1.250      }
   1.251      
   1.252      SetDllDirectory(NULL);
   1.253 -	if (module == NULL)
   1.254 -		return NULL;
   1.255 -	else
   1.256 -		return (void *) module;
   1.257 +    if (module == NULL)
   1.258 +        return NULL;
   1.259 +    else
   1.260 +        return (void *) module;
   1.261  }
   1.262  
   1.263  int dlclose(void *handle) {
   1.264 -	if (FreeLibrary((HMODULE) handle))
   1.265 -		return 0;
   1.266 -	else
   1.267 -		return 1;
   1.268 +    if (FreeLibrary((HMODULE) handle))
   1.269 +        return 0;
   1.270 +    else
   1.271 +        return 1;
   1.272  }
   1.273  
   1.274  void *dlsym(void *handle, const char *symbol) {
   1.275 -	return (void *) (intptr_t) GetProcAddress((HMODULE) handle, symbol);
   1.276 +    return (void *) (intptr_t) GetProcAddress((HMODULE) handle, symbol);
   1.277  }
   1.278  
   1.279  const char *windoze_keys_db(void) {
   1.280 -	static string path;
   1.281 -	if (path.length() == 0) {
   1.282 -		path = managementPath(USER_FOLDER_PATH, KEYS_DB);
   1.283 -	}
   1.284 -	return path.c_str();
   1.285 +    static string path;
   1.286 +    if (path.length() == 0) {
   1.287 +        path = managementPath(USER_FOLDER_PATH, KEYS_DB);
   1.288 +    }
   1.289 +    return path.c_str();
   1.290  }
   1.291  
   1.292  const char *windoze_local_db(void) {
   1.293 -	static string path;
   1.294 -	if (path.length() == 0)
   1.295 +    static string path;
   1.296 +    if (path.length() == 0)
   1.297          path = managementPath(USER_FOLDER_PATH, LOCAL_DB_FILENAME);
   1.298      return path.c_str();
   1.299  }
   1.300  
   1.301  const char *windoze_system_db(void) {
   1.302 -	static string path;
   1.303 -	if (path.length() == 0)
   1.304 -		path = managementPath(PER_MACHINE_DIRECTORY, SYSTEM_DB_FILENAME);
   1.305 +    static string path;
   1.306 +    if (path.length() == 0)
   1.307 +        path = managementPath(PER_MACHINE_DIRECTORY, SYSTEM_DB_FILENAME);
   1.308      return path.c_str();
   1.309  }
   1.310  
   1.311 @@ -442,11 +442,11 @@
   1.312                         const char *description,
   1.313                         const char *comment)
   1.314  {
   1.315 -	const size_t size = 256;
   1.316 -	char str[size];
   1.317 -	
   1.318 -	snprintf(str, size, "*** %s %s %s %s\n", title, entity, description, comment);
   1.319 -	OutputDebugStringA(str);
   1.320 +    const size_t size = 256;
   1.321 +    char str[size];
   1.322 +    
   1.323 +    snprintf(str, size, "*** %s %s %s %s\n", title, entity, description, comment);
   1.324 +    OutputDebugStringA(str);
   1.325  }
   1.326  
   1.327  time_t timegm(struct tm* tm) {