- *userdir = 0;
-
- // Add the personal game directory
-#ifdef WIN32
- if(qSHGetFolderPath && (qSHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, 0, mydocsdir) == S_OK))
- {
- dpsnprintf(userdir, sizeof(userdir), "%s/My Games/%s/", mydocsdir, gameuserdirname);
- Con_DPrintf("Obtained personal directory %s from SHGetFolderPath\n", userdir);
- }
- else
- {
- // use the environment
-#if _MSC_VER >= 1400
- _dupenv_s (&homedir, &homedirlen, "USERPROFILE");
-#else
- homedir = getenv("USERPROFILE");
-#endif
-
- if(homedir)
- {
- dpsnprintf(userdir, sizeof(userdir), "%s/My Documents/My Games/%s/", homedir, gameuserdirname);
-#if _MSC_VER >= 1400
- free(homedir);
-#endif
- Con_DPrintf("Obtained personal directory %s from environment\n", userdir);
- }
- else
- *userdir = 0; // just to make sure it hasn't been written to by SHGetFolderPath returning failure
- }
-
- if(!*userdir)
- Con_DPrintf("Could not obtain home directory; not supporting -mygames\n");
-#else
- homedir = getenv ("HOME");
- if(homedir)
- dpsnprintf(userdir, sizeof(userdir), "%s/.%s/", homedir, gameuserdirname);
-
- if(!*userdir)
- Con_DPrintf("Could not obtain home directory; assuming -nohome\n");
-#endif
-
-
-#ifdef WIN32
- if(!COM_CheckParm("-mygames"))
- {
-#if _MSC_VER >= 1400
- int fd;
- _sopen_s(&fd, va("%s%s/config.cfg", fs_basedir, dir), O_WRONLY | O_CREAT, _SH_DENYNO, _S_IREAD | _S_IWRITE); // note: no O_TRUNC here!
-#else
- int fd = open (va("%s%s/config.cfg", fs_basedir, dir), O_WRONLY | O_CREAT, 0666); // note: no O_TRUNC here!
-#endif
- if(fd >= 0)
- {
- close(fd);
- *userdir = 0; // we have write access to the game dir, so let's use it
- }
- }
-#endif
-
- if(COM_CheckParm("-nohome"))
- *userdir = 0;
-
- if((i = COM_CheckParm("-userdir")) && i < com_argc - 1)
- dpsnprintf(userdir, sizeof(userdir), "%s/", com_argv[i+1]);
-
- if (*userdir)
- FS_AddGameDirectory(va("%s%s/", userdir, dir));