aboutsummaryrefslogtreecommitdiffstats
path: root/common/os/os.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'common/os/os.cxx')
-rw-r--r--common/os/os.cxx54
1 files changed, 28 insertions, 26 deletions
diff --git a/common/os/os.cxx b/common/os/os.cxx
index 5c49ce12..35f87b03 100644
--- a/common/os/os.cxx
+++ b/common/os/os.cxx
@@ -24,6 +24,8 @@
#include <os/os.h>
#include <assert.h>
+#include <sys/types.h>
+#include <sys/stat.h>
#ifndef WIN32
#include <pwd.h>
@@ -31,18 +33,18 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
#include <unistd.h>
#else
#include <windows.h>
#include <wininet.h> /* MinGW needs it */
#include <shlobj.h>
+#define stat _stat
#endif
static const char* getvncdir(bool userDir, const char *xdg_env, const char *xdg_def)
{
- static char dir[PATH_MAX];
+ static char dir[PATH_MAX], legacy[PATH_MAX];
+ struct stat st;
#ifndef WIN32
char *homedir, *xdgdir;
@@ -67,23 +69,17 @@ static const char* getvncdir(bool userDir, const char *xdg_env, const char *xdg_
if (userDir)
return homedir;
- // check if (deprecated) legacy path exists and use that if so
- snprintf(dir, sizeof(dir), "%s/.vnc", homedir);
- struct stat st;
-
- if (stat(dir, &st) == 0)
- return dir;
-
- if (xdg_def != NULL) {
- xdgdir = getenv(xdg_env);
- if (xdgdir != NULL)
- snprintf(dir, sizeof(dir), "%s/tigervnc", xdgdir);
- else
- snprintf(dir, sizeof(dir), "%s/%s/tigervnc", homedir, xdg_def);
- }
+ xdgdir = getenv(xdg_env);
+ if (xdgdir != NULL && xdgdir[0] == '/')
+ snprintf(dir, sizeof(dir), "%s/tigervnc", xdgdir);
+ else
+ snprintf(dir, sizeof(dir), "%s/%s/tigervnc", homedir, xdg_def);
- return dir;
+ snprintf(legacy, sizeof(legacy), "%s/.vnc", homedir);
#else
+ (void) xdg_def;
+ (void) xdg_env;
+
if (userDir)
ret = SHGetSpecialFolderPath(NULL, dir, CSIDL_PROFILE, FALSE);
else
@@ -95,13 +91,20 @@ static const char* getvncdir(bool userDir, const char *xdg_env, const char *xdg_
if (userDir)
return dir;
- if (strlen(dir) + strlen("\\vnc") >= sizeof(dir))
+ ret = SHGetSpecialFolderPath(NULL, legacy, CSIDL_APPDATA, FALSE);
+
+ if (ret == FALSE)
return NULL;
- strcat(dir, "\\vnc");
+ if (strlen(dir) + strlen("\\TigerVNC") >= sizeof(dir))
+ return NULL;
+ if (strlen(legacy) + strlen("\\vnc") >= sizeof(legacy))
+ return NULL;
- return dir;
+ strcat(dir, "\\TigerVNC");
+ strcat(legacy, "\\vnc");
#endif
+ return (stat(dir, &st) != 0 && stat(legacy, &st) == 0) ? legacy : dir;
}
const char* os::getuserhomedir()
@@ -114,13 +117,12 @@ const char* os::getvncconfigdir()
return getvncdir(false, "XDG_CONFIG_HOME", ".config");
}
-const char* os::getvncstatedir()
+const char* os::getvncdatadir()
{
- return getvncdir(false, "XDG_STATE_HOME", ".local/state");
+ return getvncdir(false, "XDG_DATA_HOME", ".local/share");
}
-/* deprecated */
-const char* os::getvnchomedir()
+const char* os::getvncstatedir()
{
- return getvncdir(false, NULL, NULL);
+ return getvncdir(false, "XDG_STATE_HOME", ".local/state");
}