+ // Add the personal game directory
+ if((i = COM_CheckParm("-userdir")) && i < com_argc - 1)
+ dpsnprintf(fs_userdir, sizeof(fs_userdir), "%s/", com_argv[i+1]);
+ else if (COM_CheckParm("-nohome"))
+ *fs_userdir = 0; // user wants roaming installation, no userdir
+ else
+ {
+#ifdef DP_FS_USERDIR
+ strlcpy(fs_userdir, DP_FS_USERDIR, sizeof(fs_userdir));
+#else
+ int dirmode;
+ int highestuserdirmode = USERDIRMODE_COUNT - 1;
+ int preferreduserdirmode = USERDIRMODE_COUNT - 1;
+ int userdirstatus[USERDIRMODE_COUNT];
+# ifdef WIN32
+ // historical behavior...
+ if (!strcmp(gamedirname1, "id1"))
+ preferreduserdirmode = USERDIRMODE_NOHOME;
+# endif
+ // check what limitations the user wants to impose
+ if (COM_CheckParm("-home")) preferreduserdirmode = USERDIRMODE_HOME;
+ if (COM_CheckParm("-mygames")) preferreduserdirmode = USERDIRMODE_MYGAMES;
+ if (COM_CheckParm("-savedgames")) preferreduserdirmode = USERDIRMODE_SAVEDGAMES;
+ // gather the status of the possible userdirs
+ for (dirmode = 0;dirmode < USERDIRMODE_COUNT;dirmode++)
+ {
+ userdirstatus[dirmode] = FS_ChooseUserDir((userdirmode_t)dirmode, fs_userdir, sizeof(fs_userdir));
+ if (userdirstatus[dirmode] == 1)
+ Con_DPrintf("userdir %i = %s (writable)\n", dirmode, fs_userdir);
+ else if (userdirstatus[dirmode] == 0)
+ Con_DPrintf("userdir %i = %s (not writable or does not exist)\n", dirmode, fs_userdir);
+ else
+ Con_DPrintf("userdir %i (not applicable)\n", dirmode);
+ }
+ // some games may prefer writing to basedir, but if write fails we
+ // have to search for a real userdir...
+ if (preferreduserdirmode == 0 && userdirstatus[0] < 1)
+ preferreduserdirmode = highestuserdirmode;
+ // check for an existing userdir and continue using it if possible...
+ for (dirmode = USERDIRMODE_COUNT - 1;dirmode > 0;dirmode--)
+ if (userdirstatus[dirmode] == 1)
+ break;
+ // if no existing userdir found, make a new one...
+ if (dirmode == 0 && preferreduserdirmode > 0)
+ for (dirmode = preferreduserdirmode;dirmode > 0;dirmode--)
+ if (userdirstatus[dirmode] >= 0)
+ break;
+ // and finally, we picked one...
+ FS_ChooseUserDir((userdirmode_t)dirmode, fs_userdir, sizeof(fs_userdir));
+ Con_DPrintf("userdir %i is the winner\n", dirmode);
+#endif
+ }
+
+ // if userdir equal to basedir, clear it to avoid confusion later
+ if (!strcmp(fs_basedir, fs_userdir))
+ fs_userdir[0] = 0;
+