diff --git a/src/config/home.c b/src/config/home.c index 1a6831fe..2af61a63 100644 --- a/src/config/home.c +++ b/src/config/home.c @@ -111,8 +111,14 @@ get_home(void) { unsigned char *home_elinks; unsigned char *envhome = getenv("HOME"); - unsigned char *home = envhome ? stracpy(envhome) - : elinks_dirname(program.path); + unsigned char *home = NULL; + + if (!home && envhome) + home = stracpy(envhome); + if (!home) + home = user_appdata_directory(); + if (!home) + home = elinks_dirname(program.path); if (home) strip_trailing_dir_sep(home); diff --git a/src/osdep/osdep.h b/src/osdep/osdep.h index 36bc0bfc..721916fd 100644 --- a/src/osdep/osdep.h +++ b/src/osdep/osdep.h @@ -75,4 +75,8 @@ unsigned char *get_shell(void); * available at all. Face it, we are just cool. */ void elinks_cfmakeraw(struct termios *t); +#ifndef user_appdata_directory +#define user_appdata_directory() NULL +#endif + #endif diff --git a/src/osdep/win32/win32.c b/src/osdep/win32/win32.c index 15d2aa4c..66b21288 100644 --- a/src/osdep/win32/win32.c +++ b/src/osdep/win32/win32.c @@ -4,7 +4,11 @@ #include "config.h" #endif +/* Get SHGFP_TYPE_CURRENT from . */ +#define _WIN32_IE 0x500 + #include +#include #include "osdep/system.h" @@ -258,3 +262,21 @@ gettext__parse(void *arg) return 0; } #endif + +unsigned char * +user_appdata_directory(void) +{ +#if _WIN32_WINNT >= 0x0500 + HWND hwnd = GetConsoleWindow(); +#else + HWND hwnd = NULL; +#endif + char path[MAX_PATH]; + HRESULT hr; + + hr = SHGetFolderPath(hwnd, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, path); + if (hr == S_OK) /* Don't even allow S_FALSE. */ + return stracpy(path); + else + return NULL; +} diff --git a/src/osdep/win32/win32.h b/src/osdep/win32/win32.h index 2e09bc5f..a2f30101 100644 --- a/src/osdep/win32/win32.h +++ b/src/osdep/win32/win32.h @@ -13,6 +13,8 @@ struct terminal; void open_in_new_win32(struct terminal *term, unsigned char *exe_name, unsigned char *param); +unsigned char *user_appdata_directory(void); +#define user_appdata_directory user_appdata_directory /* Stub functions: */