mirror of
https://github.com/FreeRDP/FreeRDP.git
synced 2025-06-03 00:00:20 +00:00
[core,settings] unify configuration paths
* Add new function freerdp_settings_get_config_path to get current user configuration directory * Add CMake option WITH_FULL_CONFIG_PATH (default OFF): If defined, use <appdata>/Vendor/Product as config directory, otherwise use <appdata>/vendor (lowercase, only if vendor equal to product)
This commit is contained in:
parent
ad83ba2088
commit
7aa72a7507
@ -23,7 +23,7 @@ add_library(sdl-common-prefs STATIC
|
|||||||
sdl_prefs.hpp
|
sdl_prefs.hpp
|
||||||
sdl_prefs.cpp
|
sdl_prefs.cpp
|
||||||
)
|
)
|
||||||
target_link_libraries(sdl-common-prefs winpr)
|
target_link_libraries(sdl-common-prefs winpr freerdp)
|
||||||
|
|
||||||
if(BUILD_TESTING)
|
if(BUILD_TESTING)
|
||||||
add_subdirectory(test)
|
add_subdirectory(test)
|
||||||
|
@ -34,6 +34,7 @@ namespace fs = std::experimental::filesystem;
|
|||||||
#include <winpr/config.h>
|
#include <winpr/config.h>
|
||||||
#include <freerdp/version.h>
|
#include <freerdp/version.h>
|
||||||
#include <winpr/json.h>
|
#include <winpr/json.h>
|
||||||
|
#include <freerdp/settings.h>
|
||||||
|
|
||||||
SdlPref::WINPR_JSONPtr SdlPref::get()
|
SdlPref::WINPR_JSONPtr SdlPref::get()
|
||||||
{
|
{
|
||||||
@ -108,13 +109,11 @@ SdlPref::SdlPref(const std::string& file) : _name(file), _config(get())
|
|||||||
std::string SdlPref::get_pref_dir()
|
std::string SdlPref::get_pref_dir()
|
||||||
{
|
{
|
||||||
using CStringPtr = std::unique_ptr<char, decltype(&free)>;
|
using CStringPtr = std::unique_ptr<char, decltype(&free)>;
|
||||||
CStringPtr path(GetKnownPath(KNOWN_PATH_XDG_CONFIG_HOME), free);
|
CStringPtr path(freerdp_settings_get_config_path(), free);
|
||||||
if (!path)
|
if (!path)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
fs::path config{ path.get() };
|
fs::path config{ path.get() };
|
||||||
config /= FREERDP_VENDOR;
|
|
||||||
config /= FREERDP_PRODUCT;
|
|
||||||
return config.string();
|
return config.string();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,3 +237,5 @@ if (BUILD_FUZZERS)
|
|||||||
>
|
>
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
option(WITH_FULL_CONFIG_PATH "Use <appdata>/Vendor/Product instead of <appdata>/product (lowercase, only if vendor equals product) as config directory" OFF)
|
||||||
|
@ -713,6 +713,10 @@ typedef struct rdp_settings rdpSettings;
|
|||||||
FREERDP_API const char* freerdp_supported_color_depths_string(UINT16 mask, char* buffer,
|
FREERDP_API const char* freerdp_supported_color_depths_string(UINT16 mask, char* buffer,
|
||||||
size_t size);
|
size_t size);
|
||||||
|
|
||||||
|
/** \brief return the configuration directory for the library
|
||||||
|
*/
|
||||||
|
FREERDP_API char* freerdp_settings_get_config_path(void);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -398,6 +398,10 @@ AddTargetWithResourceFile(${MODULE_NAME} FALSE "${FREERDP_VERSION}" LIBFREERDP_S
|
|||||||
|
|
||||||
add_definitions(${LIBFREERDP_DEFINITIONS})
|
add_definitions(${LIBFREERDP_DEFINITIONS})
|
||||||
|
|
||||||
|
if (WITH_FULL_CONFIG_PATH)
|
||||||
|
add_definitions(-DWITH_FULL_CONFIG_PATH)
|
||||||
|
endif()
|
||||||
|
|
||||||
target_include_directories(${MODULE_NAME} INTERFACE $<INSTALL_INTERFACE:include>)
|
target_include_directories(${MODULE_NAME} INTERFACE $<INSTALL_INTERFACE:include>)
|
||||||
target_link_libraries(${MODULE_NAME} PRIVATE ${LIBFREERDP_LIBS})
|
target_link_libraries(${MODULE_NAME} PRIVATE ${LIBFREERDP_LIBS})
|
||||||
target_link_libraries(${MODULE_NAME} PUBLIC ${LIBFREERDP_PUB_LIBS})
|
target_link_libraries(${MODULE_NAME} PUBLIC ${LIBFREERDP_PUB_LIBS})
|
||||||
|
@ -350,9 +350,39 @@ BOOL freerdp_capability_buffer_allocate(rdpSettings* settings, UINT32 count)
|
|||||||
settings->ReceivedCapabilityDataSizes);
|
settings->ReceivedCapabilityDataSizes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !defined(WITH_FULL_CONFIG_PATH)
|
||||||
|
static char* freerdp_settings_get_legacy_config_path(void)
|
||||||
|
{
|
||||||
|
char product[sizeof(FREERDP_PRODUCT_STRING)] = { 0 };
|
||||||
|
|
||||||
|
for (size_t i = 0; i < sizeof(product); i++)
|
||||||
|
product[i] = tolower(FREERDP_PRODUCT_STRING[i]);
|
||||||
|
|
||||||
|
return GetKnownSubPath(KNOWN_PATH_XDG_CONFIG_HOME, product);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
char* freerdp_settings_get_config_path(void)
|
||||||
|
{
|
||||||
|
char* path = NULL;
|
||||||
|
/* For default FreeRDP continue using same config directory
|
||||||
|
* as in old releases.
|
||||||
|
* Custom builds use <Vendor>/<Product> as config folder. */
|
||||||
|
#if !defined(WITH_FULL_CONFIG_PATH)
|
||||||
|
if (_stricmp(FREERDP_VENDOR_STRING, FREERDP_PRODUCT_STRING) == 0)
|
||||||
|
return freerdp_settings_get_legacy_config_path();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
char* base = GetKnownSubPath(KNOWN_PATH_XDG_CONFIG_HOME, FREERDP_VENDOR_STRING);
|
||||||
|
if (base)
|
||||||
|
path = GetCombinedPath(base, FREERDP_PRODUCT_STRING);
|
||||||
|
free(base);
|
||||||
|
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
rdpSettings* freerdp_settings_new(DWORD flags)
|
rdpSettings* freerdp_settings_new(DWORD flags)
|
||||||
{
|
{
|
||||||
char* base = NULL;
|
|
||||||
char* issuers[] = { "FreeRDP", "FreeRDP-licenser" };
|
char* issuers[] = { "FreeRDP", "FreeRDP-licenser" };
|
||||||
const BOOL server = (flags & FREERDP_SETTINGS_SERVER_MODE) != 0 ? TRUE : FALSE;
|
const BOOL server = (flags & FREERDP_SETTINGS_SERVER_MODE) != 0 ? TRUE : FALSE;
|
||||||
const BOOL remote = (flags & FREERDP_SETTINGS_REMOTE_MODE) != 0 ? TRUE : FALSE;
|
const BOOL remote = (flags & FREERDP_SETTINGS_REMOTE_MODE) != 0 ? TRUE : FALSE;
|
||||||
@ -728,7 +758,7 @@ rdpSettings* freerdp_settings_new(DWORD flags)
|
|||||||
|
|
||||||
if (!freerdp_settings_get_bool(settings, FreeRDP_ServerMode))
|
if (!freerdp_settings_get_bool(settings, FreeRDP_ServerMode))
|
||||||
{
|
{
|
||||||
BOOL rc = 0;
|
BOOL rc = FALSE;
|
||||||
char* path = NULL;
|
char* path = NULL;
|
||||||
if (!freerdp_settings_set_bool(settings, FreeRDP_RedirectClipboard, TRUE))
|
if (!freerdp_settings_set_bool(settings, FreeRDP_RedirectClipboard, TRUE))
|
||||||
goto out_fail;
|
goto out_fail;
|
||||||
@ -740,42 +770,10 @@ rdpSettings* freerdp_settings_new(DWORD flags)
|
|||||||
if (!rc || !freerdp_settings_get_string(settings, FreeRDP_HomePath))
|
if (!rc || !freerdp_settings_get_string(settings, FreeRDP_HomePath))
|
||||||
goto out_fail;
|
goto out_fail;
|
||||||
|
|
||||||
/* For default FreeRDP continue using same config directory
|
char* config = freerdp_settings_get_config_path();
|
||||||
* as in old releases.
|
rc = freerdp_settings_set_string(settings, FreeRDP_ConfigPath, config);
|
||||||
* Custom builds use <Vendor>/<Product> as config folder. */
|
free(config);
|
||||||
if (_stricmp(FREERDP_VENDOR_STRING, FREERDP_PRODUCT_STRING))
|
if (!rc)
|
||||||
{
|
|
||||||
BOOL res = TRUE;
|
|
||||||
base = GetKnownSubPath(KNOWN_PATH_XDG_CONFIG_HOME, FREERDP_VENDOR_STRING);
|
|
||||||
|
|
||||||
if (base)
|
|
||||||
{
|
|
||||||
char* combined = GetCombinedPath(base, FREERDP_PRODUCT_STRING);
|
|
||||||
res = freerdp_settings_set_string(settings, FreeRDP_ConfigPath, combined);
|
|
||||||
free(combined);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(base);
|
|
||||||
if (!res)
|
|
||||||
goto out_fail;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
BOOL res = 0;
|
|
||||||
char* cpath = NULL;
|
|
||||||
char product[sizeof(FREERDP_PRODUCT_STRING)] = { 0 };
|
|
||||||
|
|
||||||
for (size_t i = 0; i < sizeof(product); i++)
|
|
||||||
product[i] = tolower(FREERDP_PRODUCT_STRING[i]);
|
|
||||||
|
|
||||||
cpath = GetKnownSubPath(KNOWN_PATH_XDG_CONFIG_HOME, product);
|
|
||||||
res = freerdp_settings_set_string(settings, FreeRDP_ConfigPath, cpath);
|
|
||||||
free(cpath);
|
|
||||||
if (!res)
|
|
||||||
goto out_fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!freerdp_settings_get_string(settings, FreeRDP_ConfigPath))
|
|
||||||
goto out_fail;
|
goto out_fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -734,58 +734,9 @@ int shadow_server_stop(rdpShadowServer* server)
|
|||||||
|
|
||||||
static int shadow_server_init_config_path(rdpShadowServer* server)
|
static int shadow_server_init_config_path(rdpShadowServer* server)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
|
||||||
|
|
||||||
if (!server->ConfigPath)
|
if (!server->ConfigPath)
|
||||||
{
|
{
|
||||||
server->ConfigPath = GetEnvironmentSubPath("LOCALAPPDATA", "freerdp");
|
char* configHome = freerdp_settings_get_config_path();
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
#ifdef __APPLE__
|
|
||||||
|
|
||||||
if (!server->ConfigPath)
|
|
||||||
{
|
|
||||||
char* userLibraryPath;
|
|
||||||
char* userApplicationSupportPath;
|
|
||||||
userLibraryPath = GetKnownSubPath(KNOWN_PATH_HOME, "Library");
|
|
||||||
|
|
||||||
if (userLibraryPath)
|
|
||||||
{
|
|
||||||
if (!winpr_PathFileExists(userLibraryPath) && !winpr_PathMakePath(userLibraryPath, 0))
|
|
||||||
{
|
|
||||||
WLog_ERR(TAG, "Failed to create directory '%s'", userLibraryPath);
|
|
||||||
free(userLibraryPath);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
userApplicationSupportPath = GetCombinedPath(userLibraryPath, "Application Support");
|
|
||||||
|
|
||||||
if (userApplicationSupportPath)
|
|
||||||
{
|
|
||||||
if (!winpr_PathFileExists(userApplicationSupportPath) &&
|
|
||||||
!winpr_PathMakePath(userApplicationSupportPath, 0))
|
|
||||||
{
|
|
||||||
WLog_ERR(TAG, "Failed to create directory '%s'", userApplicationSupportPath);
|
|
||||||
free(userLibraryPath);
|
|
||||||
free(userApplicationSupportPath);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
server->ConfigPath = GetCombinedPath(userApplicationSupportPath, "freerdp");
|
|
||||||
}
|
|
||||||
|
|
||||||
free(userLibraryPath);
|
|
||||||
free(userApplicationSupportPath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!server->ConfigPath)
|
|
||||||
{
|
|
||||||
char* configHome = NULL;
|
|
||||||
configHome = GetKnownPath(KNOWN_PATH_XDG_CONFIG_HOME);
|
|
||||||
|
|
||||||
if (configHome)
|
if (configHome)
|
||||||
{
|
{
|
||||||
@ -796,8 +747,7 @@ static int shadow_server_init_config_path(rdpShadowServer* server)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
server->ConfigPath = GetKnownSubPath(KNOWN_PATH_XDG_CONFIG_HOME, "freerdp");
|
server->ConfigPath = configHome;
|
||||||
free(configHome);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user