Skip to content

Commit

Permalink
Merge pull request FreeRDP#2670 from akallabeth/windows_config_paths
Browse files Browse the repository at this point in the history
Adjusted config paths
  • Loading branch information
bmiklautz committed Jun 9, 2015
2 parents 0278f7f + 6b4cc2f commit 0740792
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 15 deletions.
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ if(NOT DEFINED VENDOR)
set(VENDOR "FreeRDP" CACHE STRING "FreeRDP package vendor")
endif()

if(NOT DEFINED PRODUCT)
set(PRODUCT "FreeRDP" CACHE STRING "FreeRDP package name")
endif()

if(NOT DEFINED FREERDP_VENDOR)
set(FREERDP_VENDOR 1)
endif()
Expand Down Expand Up @@ -284,8 +288,8 @@ if(WIN32)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWIN32_LEAN_AND_MEAN")

# Set product and vendor for dll and exe version information.
set(RC_VERSION_VENDOR "FreeRDP")
set(RC_VERSION_PRODUCT "FreeRDP")
set(RC_VERSION_VENDOR ${VENDOR})
set(RC_VERSION_PRODUCT ${PRODUCT})
set(RC_VERSION_PATCH ${BUILD_NUMBER})
set(RC_VERSION_DESCRIPTION ${GIT_REVISION})

Expand Down
3 changes: 3 additions & 0 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
#define CMAKE_SHARED_LIBRARY_SUFFIX "${CMAKE_SHARED_LIBRARY_SUFFIX}"
#define CMAKE_SHARED_LIBRARY_PREFIX "${CMAKE_SHARED_LIBRARY_PREFIX}"

#define FREERDP_VENDOR_STRING "${VENDOR}"
#define FREERDP_PRODUCT_STRING "${PRODUCT}"

/* Include files */
#cmakedefine HAVE_FCNTL_H
#cmakedefine HAVE_UNISTD_H
Expand Down
39 changes: 35 additions & 4 deletions libfreerdp/core/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,14 @@ void settings_get_computer_name(rdpSettings* settings)

GetComputerNameExA(ComputerNameNetBIOS, NULL, &nSize);
settings->ComputerName = (char*) malloc(nSize);
if (!settings->ComputerName)
return;
if (!settings->ComputerName)
return;
GetComputerNameExA(ComputerNameNetBIOS, settings->ComputerName, &nSize);
}

rdpSettings* freerdp_settings_new(DWORD flags)
{
char* base;
rdpSettings* settings;

settings = (rdpSettings*) calloc(1, sizeof(rdpSettings));
Expand Down Expand Up @@ -471,7 +472,37 @@ rdpSettings* freerdp_settings_new(DWORD flags)
settings->HomePath = GetKnownPath(KNOWN_PATH_HOME);
if (!settings->HomePath)
goto out_fail;
settings->ConfigPath = GetKnownSubPath(KNOWN_PATH_XDG_CONFIG_HOME, "freerdp");

/* For default FreeRDP continue using same config directory
* as in old releases.
* Custom builds use <Vendor>/<Product> as config folder. */
if (_stricmp(FREERDP_VENDOR_STRING, FREERDP_PRODUCT_STRING))
{
base = GetKnownSubPath(KNOWN_PATH_XDG_CONFIG_HOME,
FREERDP_VENDOR_STRING);
if (base)
{
settings->ConfigPath = GetCombinedPath(
base,
FREERDP_PRODUCT_STRING);
if (!PathFileExistsA(base))
if (!CreateDirectoryA(base, NULL))
settings->ConfigPath = NULL;
}
free (base);
} else {
int i;
char product[sizeof(FREERDP_PRODUCT_STRING)];

memset(product, 0, sizeof(product));
for (i=0; i<sizeof(product); i++)
product[i] = tolower(FREERDP_PRODUCT_STRING[i]);

settings->ConfigPath = GetKnownSubPath(
KNOWN_PATH_XDG_CONFIG_HOME,
product);
}

if (!settings->ConfigPath)
goto out_fail;

Expand Down Expand Up @@ -778,7 +809,7 @@ rdpSettings* freerdp_settings_clone(rdpSettings* settings)
void freerdp_settings_free(rdpSettings* settings)
{
if (!settings)
return;
return;
free(settings->ServerHostname);
free(settings->Username);
free(settings->Password);
Expand Down
66 changes: 57 additions & 9 deletions winpr/libwinpr/path/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@

#include <winpr/path.h>

#if defined(WIN32)
#include <Shlobj.h>
#endif

static char* GetPath_XDG_CONFIG_HOME(void);
static char* GetPath_XDG_RUNTIME_DIR(void);

/**
* SHGetKnownFolderPath function:
* http://msdn.microsoft.com/en-us/library/windows/desktop/bb762188/
Expand All @@ -43,7 +50,7 @@
* http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
*/

char* GetEnvAlloc(LPCSTR lpName)
static char* GetEnvAlloc(LPCSTR lpName)
{
DWORD length;
char* env = NULL;
Expand All @@ -62,7 +69,7 @@ char* GetEnvAlloc(LPCSTR lpName)
return env;
}

char* GetPath_HOME()
static char* GetPath_HOME(void)
{
char* path = NULL;

Expand All @@ -80,7 +87,7 @@ char* GetPath_HOME()
return path;
}

char* GetPath_TEMP()
static char* GetPath_TEMP(void)
{
char* path = NULL;

Expand All @@ -96,11 +103,14 @@ char* GetPath_TEMP()
return path;
}

char* GetPath_XDG_DATA_HOME()
static char* GetPath_XDG_DATA_HOME(void)
{
char* path = NULL;
char* home = NULL;

#if defined(WIN32)
path = GetPath_XDG_CONFIG_HOME();
#else
char* home = NULL;
/**
* There is a single base directory relative to which user-specific data files should be written.
* This directory is defined by the environment variable $XDG_DATA_HOME.
Expand All @@ -127,15 +137,28 @@ char* GetPath_XDG_DATA_HOME()
sprintf(path, "%s%s", home, "/.local/share");

free(home);
#endif

return path;
}

char* GetPath_XDG_CONFIG_HOME()
static char* GetPath_XDG_CONFIG_HOME(void)
{
char* path = NULL;
char* home = NULL;

#if defined(WIN32)
path = calloc(MAX_PATH, sizeof(char));
if (!path)
return NULL;

if (SHGetFolderPathA(0, CSIDL_APPDATA, NULL,
SHGFP_TYPE_CURRENT, path) != S_OK)
{
free(path);
return NULL;
}
#else
char* home = NULL;
/**
* There is a single base directory relative to which user-specific configuration files should be written.
* This directory is defined by the environment variable $XDG_CONFIG_HOME.
Expand Down Expand Up @@ -166,15 +189,27 @@ char* GetPath_XDG_CONFIG_HOME()
sprintf(path, "%s%s", home, "/.config");

free(home);
#endif

return path;
}

char* GetPath_XDG_CACHE_HOME()
static char* GetPath_XDG_CACHE_HOME(void)
{
char* path = NULL;
char* home = NULL;

#if defined(WIN32)
home = GetPath_XDG_RUNTIME_DIR();
if (home)
{
path = GetCombinedPath(home, "cache");
if (!PathFileExistsA(path))
if (!CreateDirectoryA(path, NULL))
path = NULL;
}
free(home);
#else
/**
* There is a single base directory relative to which user-specific non-essential (cached) data should be written.
* This directory is defined by the environment variable $XDG_CACHE_HOME.
Expand All @@ -201,14 +236,26 @@ char* GetPath_XDG_CACHE_HOME()
sprintf(path, "%s%s", home, "/.cache");

free(home);
#endif

return path;
}

char* GetPath_XDG_RUNTIME_DIR()
char* GetPath_XDG_RUNTIME_DIR(void)
{
char* path = NULL;
#if defined(WIN32)
path = calloc(MAX_PATH, sizeof(char));
if (!path)
return NULL;

if (SHGetFolderPathA(0, CSIDL_LOCAL_APPDATA, NULL,
SHGFP_TYPE_CURRENT, path) != S_OK)
{
free(path);
return NULL;
}
#else
/**
* There is a single base directory relative to which user-specific runtime files and other file objects should be placed.
* This directory is defined by the environment variable $XDG_RUNTIME_DIR.
Expand Down Expand Up @@ -237,6 +284,7 @@ char* GetPath_XDG_RUNTIME_DIR()
*/

path = GetEnvAlloc("XDG_RUNTIME_DIR");
#endif

if (path)
return path;
Expand Down

0 comments on commit 0740792

Please sign in to comment.