From d139640755ec76a9dc260bb0ce0ca4fbde3cb996 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Wed, 23 Jan 2013 11:10:19 +0900 Subject: [PATCH] Make fs_userpath default to ~/quakeforge on windows. The ~ gets expanded to CSIDL_LOCAL_APPDATA, $HOME, $USERPROFILE or just ".", whichever succeeds first. The usual location will be: "C:\windows\profiles\\Local Settings\Application Data". "." is now the fallback for *nix systems too. --- config.d/paths.m4 | 2 +- libs/util/sys.c | 27 ++++++++++++++++----------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/config.d/paths.m4 b/config.d/paths.m4 index 3a9e5de11..f340eda78 100644 --- a/config.d/paths.m4 +++ b/config.d/paths.m4 @@ -20,7 +20,7 @@ if test "x$SYSTYPE" = "xWIN32"; then default_globalconf="~/${PACKAGE}.conf" default_userconf="~/${PACKAGE}rc" default_sharepath="." - default_userpath="." + default_userpath="~/${PACKAGE}" else default_globalconf="/etc/${PACKAGE}.conf" eval foo="$datarootdir" diff --git a/libs/util/sys.c b/libs/util/sys.c index 35d739e29..f9339b898 100644 --- a/libs/util/sys.c +++ b/libs/util/sys.c @@ -48,6 +48,7 @@ #endif #ifdef HAVE_WINDOWS_H # include "winquake.h" +# include "shlobj.h" #endif #ifdef HAVE_SYS_MMAN_H # include @@ -861,9 +862,10 @@ Sys_CreatePath (const char *path) char * Sys_ExpandSquiggle (const char *path) { - const char *home; - -#ifndef _WIN32 + const char *home = 0; +#ifdef _WIN32 + char userpath[MAX_PATH]; // sigh, why can't windows give the size? +#else # ifdef HAVE_GETUID struct passwd *pwd_ent; # endif @@ -874,24 +876,27 @@ Sys_ExpandSquiggle (const char *path) } #ifdef _WIN32 + if (SHGetFolderPathA (0, CSIDL_LOCAL_APPDATA, 0, 0, userpath) == S_OK) { + home = userpath; + } // LordHavoc: first check HOME to duplicate previous version behavior // (also handy if someone wants it elsewhere than their windows directory) - home = getenv ("HOME"); + if (!home) + home = getenv ("HOME"); if (!home || !home[0]) - home = getenv ("WINDIR"); + home = getenv ("USERPROFILE"); + if (!home || !home[0]) + home = 0; #else # ifdef HAVE_GETUID if ((pwd_ent = getpwuid (getuid ()))) { home = pwd_ent->pw_dir; } else home = getenv ("HOME"); -# else - home = ""; //FIXME configurable? # endif #endif - if (home) - return nva ("%s%s", home, path + 1); // skip leading ~ - - return strdup (path); + if (!home) + home = "."; + return nva ("%s%s", home, path + 1); // skip leading ~ }