From a77279fb4cf93d600ade8be47220c01a6023c711 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marc-Andr=C3=A9=20Moreau?= Date: Thu, 18 Sep 2014 10:06:59 -0400 Subject: [PATCH] shadow: fix and improve config path detection --- server/shadow/shadow_server.c | 68 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 62 insertions(+), 6 deletions(-) diff --git a/server/shadow/shadow_server.c b/server/shadow/shadow_server.c index e44808f..2e8b694 100644 --- a/server/shadow/shadow_server.c +++ b/server/shadow/shadow_server.c @@ -449,6 +449,67 @@ int shadow_server_stop(rdpShadowServer* server) return 0; } +int shadow_server_init_config_path(rdpShadowServer* server) +{ +#ifdef _WIN32 + if (!server->ConfigPath) + { + server->ConfigPath = GetEnvironmentSubPath("LOCALAPPDATA", "freerdp"); + } +#endif + +#ifdef __APPLE__ + if (!server->ConfigPath) + { + char* userLibraryPath; + char* userApplicationSupportPath; + + userLibraryPath = GetKnownSubPath(KNOWN_PATH_HOME, "Library"); + + if (userLibraryPath) + { + if (!PathFileExistsA(userLibraryPath)) + CreateDirectoryA(userLibraryPath, 0); + + userApplicationSupportPath = GetCombinedPath(userLibraryPath, "Application Support"); + + if (userApplicationSupportPath) + { + if (!PathFileExistsA(userApplicationSupportPath)) + CreateDirectoryA(userApplicationSupportPath, 0); + + server->ConfigPath = GetCombinedPath(userApplicationSupportPath, "freerdp"); + } + + free(userLibraryPath); + free(userApplicationSupportPath); + } + } +#endif + + if (!server->ConfigPath) + { + char* configHome; + + configHome = GetKnownPath(KNOWN_PATH_XDG_CONFIG_HOME); + + if (configHome) + { + if (!PathFileExistsA(configHome)) + CreateDirectoryA(configHome, 0); + + server->ConfigPath = GetKnownSubPath(KNOWN_PATH_XDG_CONFIG_HOME, "freerdp"); + + free(configHome); + } + } + + if (!server->ConfigPath) + return -1; /* no usable config path */ + + return 1; +} + int shadow_server_init_certificate(rdpShadowServer* server) { char* filepath; @@ -606,12 +667,7 @@ rdpShadowServer* shadow_server_new() server->mayView = TRUE; server->mayInteract = TRUE; -#ifdef _WIN32 - server->ConfigPath = GetEnvironmentSubPath("LOCALAPPDATA", "freerdp"); -#endif - - if (!server->ConfigPath) - server->ConfigPath = GetKnownSubPath(KNOWN_PATH_XDG_CONFIG_HOME, "freerdp"); + shadow_server_init_config_path(server); InitializeCriticalSectionAndSpinCount(&(server->lock), 4000); -- 2.7.4