Win32 should use USERPROFILE and COMMONPROGRAMFILES

more standard locations for each of these, plus supports multi-user
Windows machines a bit better
This commit is contained in:
Derek S. Ray
2015-03-25 22:35:24 -04:00
parent 335c7fc003
commit 6fcfa55f36
2 changed files with 2343 additions and 2344 deletions
+9 -37
View File
@@ -1,4 +1,4 @@
/* NetHack 3.5 files.c $NHDT-Date: 1426969026 2015/03/21 20:17:06 $ $NHDT-Branch: master $:$NHDT-Revision: 1.137 $ */ /* NetHack 3.5 files.c $NHDT-Date: 1427337311 2015/03/26 02:35:11 $ $NHDT-Branch: derek-farming $:$NHDT-Revision: 1.141 $ */
/* NetHack 3.5 files.c $Date: 2012/03/10 02:49:08 $ $Revision: 1.124 $ */ /* NetHack 3.5 files.c $Date: 2012/03/10 02:49:08 $ $Revision: 1.124 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -1837,8 +1837,7 @@ const char *filename;
int src; int src;
{ {
FILE *fp; FILE *fp;
#if defined(UNIX) || defined(VMS) || defined(WIN32) || defined(MSDOS) #if defined(UNIX) || defined(VMS)
char tmp_config[BUFSZ];
char *envp; char *envp;
#endif #endif
@@ -1867,9 +1866,12 @@ int src;
fqname(filename, SYSCONFPREFIX, 0), BUFSZ-1); fqname(filename, SYSCONFPREFIX, 0), BUFSZ-1);
} else } else
#endif #endif
/* always honor sysconf first before anything else */
(void) strncpy(lastconfigfile, filename, BUFSZ-1); (void) strncpy(lastconfigfile, filename, BUFSZ-1);
lastconfigfile[BUFSZ-1] = '\0'; lastconfigfile[BUFSZ-1] = '\0';
if ((fp = fopenp(lastconfigfile, "r")) != (FILE *)0) { if ((fp = fopenp(lastconfigfile, "r")) != (FILE *)0)
return(fp);
if ((fp = fopenp(filename, "r")) != (FILE *)0) {
return(fp); return(fp);
#if defined(UNIX) || defined(VMS) #if defined(UNIX) || defined(VMS)
} else { } else {
@@ -1883,45 +1885,15 @@ int src;
} }
#if defined(MICRO) || defined(MAC) || defined(__BEOS__) || defined(WIN32) #if defined(MICRO) || defined(MAC) || defined(__BEOS__) || defined(WIN32)
# if defined(WIN32) || defined(MSDOS)
/* user's home directory should be where we look first here, too */
envp = nh_getenv("USERPROFILE");
# endif
/*
* TODO: uncomment this when you figure out where to put it
(void) strncpy(lastconfigfile,
fqname(configfile, CONFIGPREFIX, 0), BUFSZ-1);
lastconfigfile[BUFSZ-1] = '\0';
if ((fp = fopenp(lastconfigfile, "r")) != (FILE *)0) {
*/
# ifdef WIN32
if (!envp) {
Strcpy(tmp_config, configfile);
} else {
Sprintf(tmp_config, "%s\\%s", envp, configfile);
}
/* try the home directory first, then the output of fqname() will
* pick up the current dir */
if ((fp = fopenp(tmp_config, "r")) != (FILE *)0)
return(fp);
if ((fp = fopenp(fqname(configfile, CONFIGPREFIX, 0), "r")) != (FILE *)0) if ((fp = fopenp(fqname(configfile, CONFIGPREFIX, 0), "r")) != (FILE *)0)
return(fp); return(fp);
# else if ((fp = fopenp(configfile, "r")) != (FILE *)0)
if ((fp = fopenp(fqname(configfile, CONFIGPREFIX, 0), "r")) != (FILE *)0)
return(fp); return(fp);
# endif
# ifdef MSDOS # ifdef MSDOS
else { if ((fp = fopenp(fqname(backward_compat_configfile, CONFIGPREFIX, 0), "r")) != (FILE *)0)
if (!envp) {
Strcpy(tmp_config, backward_compat_configfile);
} else {
Sprintf(tmp_config, "%s\\%s", envp, backward_compat_configfile);
}
if ((fp = fopenp(tmp_config, "r")) != (FILE *)0)
return(fp); return(fp);
if ((fp = fopenp(fqname(configfile, CONFIGPREFIX, 0), "r")) != (FILE *)0) if ((fp = fopenp(backward_compat_configfile, "r")) != (FILE *)0)
return(fp); return(fp);
}
# endif # endif
#else #else
/* constructed full path names don't need fqname() */ /* constructed full path names don't need fqname() */
+28 -1
View File
@@ -1,4 +1,4 @@
/* NetHack 3.5 pcmain.c $NHDT-Date: 1426966701 2015/03/21 19:38:21 $ $NHDT-Branch: master $:$NHDT-Revision: 1.51 $ */ /* NetHack 3.5 pcmain.c $NHDT-Date: 1427337317 2015/03/26 02:35:17 $ $NHDT-Branch: derek-farming $:$NHDT-Revision: 1.52 $ */
/* NetHack 3.5 pcmain.c $Date: 2012/01/20 03:41:31 $ $Revision: 1.48 $ */ /* NetHack 3.5 pcmain.c $Date: 2012/01/20 03:41:31 $ $Revision: 1.48 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -109,6 +109,8 @@ char *argv[];
register int fd; register int fd;
register char *dir; register char *dir;
#if defined(WIN32) #if defined(WIN32)
char* envp = NULL;
char* sptr = NULL;
char fnamebuf[BUFSZ], encodedfnamebuf[BUFSZ]; char fnamebuf[BUFSZ], encodedfnamebuf[BUFSZ];
boolean save_getreturn_status = getreturn_enabled; boolean save_getreturn_status = getreturn_enabled;
#endif #endif
@@ -162,6 +164,31 @@ char *argv[];
append_slash(fqn_prefix[0]); append_slash(fqn_prefix[0]);
for (prefcnt = 1; prefcnt < PREFIX_COUNT; prefcnt++) for (prefcnt = 1; prefcnt < PREFIX_COUNT; prefcnt++)
fqn_prefix[prefcnt] = fqn_prefix[0]; fqn_prefix[prefcnt] = fqn_prefix[0];
# if defined(WIN32) || defined(MSDOS)
/* sysconf should be searched for in this location */
envp = nh_getenv("COMMONPROGRAMFILES");
if (envp) {
if ((sptr = index(envp, ';')) != 0) *sptr = '\0';
if (strlen(envp) > 0) {
fqn_prefix[SYSCONFPREFIX] = (char *)alloc(strlen(envp) + 10);
Strcpy(fqn_prefix[SYSCONFPREFIX], envp);
append_slash(fqn_prefix[SYSCONFPREFIX]);
Strcat(fqn_prefix[SYSCONFPREFIX], "NetHack\\");
}
}
/* user's home directory should default to this - unless overridden */
envp = nh_getenv("USERPROFILE");
if (envp) {
if ((sptr = index(envp, ';')) != 0) *sptr = '\0';
if (strlen(envp) > 0) {
fqn_prefix[CONFIGPREFIX] = (char *)alloc(strlen(envp)+2);
Strcpy(fqn_prefix[CONFIGPREFIX], envp);
append_slash(fqn_prefix[CONFIGPREFIX]);
}
}
# endif
} }
#endif #endif
#if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS) #if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)