#ifdef WIN32
# include <direct.h>
# include <io.h>
+# include <shlobj.h>
#else
# include <pwd.h>
# include <sys/stat.h>
*/
void FS_AddGameHierarchy (const char *dir)
{
-#ifndef WIN32
+ int i;
+ char userdir[MAX_QPATH];
+#ifdef WIN32
+ TCHAR mydocsdir[MAX_PATH + 1];
+#else
const char *homedir;
#endif
// Add the common game directory
FS_AddGameDirectory (va("%s%s/", fs_basedir, dir));
-#ifndef WIN32
+ *userdir = 0;
+
// Add the personal game directory
+#ifdef WIN32
+ if(SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, 0, mydocsdir) == S_OK)
+ dpsnprintf(userdir, sizeof(userdir), "%s/My Games/%s/", mydocsdir, gameuserdirname);
+ fprintf(stderr, "userdir = %s\n", userdir);
+#else
homedir = getenv ("HOME");
- if (homedir != NULL && homedir[0] != '\0')
- FS_AddGameDirectory (va("%s/.%s/%s/", homedir, gameuserdirname, dir));
+ if(homedir)
+ dpsnprintf(userdir, sizeof(userdir), "%s/.%s/", homedir, gameuserdirname);
#endif
+
+#ifdef WIN32
+ if(!COM_CheckParm("-mygames"))
+ {
+ int fd = open (va("%s%s/config.cfg", fs_basedir, dir), O_WRONLY | O_CREAT, 0666); // note: no O_TRUNC here!
+ 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));
}
FS_ChangeGameDirs
================
*/
-extern void Host_SaveConfig_f (void);
+extern void Host_SaveConfig (void);
extern void Host_LoadConfig_f (void);
qboolean FS_ChangeGameDirs(int numgamedirs, char gamedirs[][MAX_QPATH], qboolean complain, qboolean failmissing)
{
// halt demo playback to close the file
CL_Disconnect();
- Host_SaveConfig_f();
+ Host_SaveConfig();
fs_numgamedirs = numgamedirs;
for (i = 0;i < fs_numgamedirs;i++)
default:
return -1;
}
- if (offset < 0 || offset > (long) file->real_length)
+ if (offset < 0 || offset > file->real_length)
return -1;
// If we have the data in our read buffer, we don't need to actually seek
}
+/*
+==================
+FS_FileType
+
+Look for a file in the packages and in the filesystem
+==================
+*/
+int FS_FileType (const char *filename)
+{
+ searchpath_t *search;
+ char fullpath[MAX_QPATH];
+
+ search = FS_FindFile (filename, NULL, true);
+ if(!search)
+ return FS_FILETYPE_NONE;
+
+ if(search->pack)
+ return FS_FILETYPE_FILE; // TODO can't check directories in paks yet, maybe later
+
+ dpsnprintf(fullpath, sizeof(fullpath), "%s%s", search->filename, filename);
+ return FS_SysFileType(fullpath);
+}
+
+
/*
==================
FS_FileExists
Look for a file in the filesystem only
==================
*/
-qboolean FS_SysFileExists (const char *path)
+int FS_SysFileType (const char *path)
{
#if WIN32
- int desc;
+ DWORD result = GetFileAttributes(path);
- // TODO: use another function instead, to avoid opening the file
- desc = open (path, O_RDONLY | O_BINARY);
- if (desc < 0)
- return false;
+ if(result == INVALID_FILE_ATTRIBUTES)
+ return FS_FILETYPE_NONE;
- close (desc);
- return true;
+ if(result & FILE_ATTRIBUTE_DIRECTORY)
+ return FS_FILETYPE_DIRECTORY;
+
+ return FS_FILETYPE_FILE;
#else
struct stat buf;
if (stat (path,&buf) == -1)
- return false;
+ return FS_FILETYPE_NONE;
- return true;
+ if(S_ISDIR(buf.st_mode))
+ return FS_FILETYPE_DIRECTORY;
+
+ return FS_FILETYPE_FILE;
#endif
}
+qboolean FS_SysFileExists (const char *path)
+{
+ return FS_SysFileType (path) != FS_FILETYPE_NONE;
+}
+
void FS_mkdir (const char *path)
{
#if WIN32