]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - common.c
***map loader generates portals for the map*** (can you tell this is a big deal? :)
[xonotic/darkplaces.git] / common.c
index 1430e057d6c651cca4470e3630b7ff75bea9e2df..717317266bc30d01a24820ecc312126c369539b7 100644 (file)
--- a/common.c
+++ b/common.c
@@ -1349,8 +1349,10 @@ typedef struct
 // LordHavoc: was 2048, increased to 16384 and changed info[MAX_PACK_FILES] to a temporary malloc to avoid stack overflows
 #define MAX_FILES_IN_PACK       16384
 
-char    com_cachedir[MAX_OSPATH];
-char    com_gamedir[MAX_OSPATH];
+#if CACHEENABLE
+char   com_cachedir[MAX_OSPATH];
+#endif
+char   com_gamedir[MAX_OSPATH];
 
 typedef struct searchpath_s
 {
@@ -1383,6 +1385,30 @@ void COM_Path_f (void)
        }
 }
 
+/*
+============
+COM_CreatePath
+
+LordHavoc: Previously only used for CopyFile, now also used for COM_WriteFile.
+============
+*/
+void    COM_CreatePath (char *path)
+{
+       char    *ofs, save;
+       
+       for (ofs = path+1 ; *ofs ; ofs++)
+       {
+               if (*ofs == '/' || *ofs == '\\' || *ofs == ':')
+               {       // create the directory
+                       save = *ofs;
+                       *ofs = 0;
+                       Sys_mkdir (path);
+                       *ofs = save;
+               }
+       }
+}
+
+
 /*
 ============
 COM_WriteFile
@@ -1397,6 +1423,9 @@ void COM_WriteFile (char *filename, void *data, int len)
        
        sprintf (name, "%s/%s", com_gamedir, filename);
 
+       // LordHavoc: added this
+       COM_CreatePath (name); // create directories up to the file
+
        handle = Sys_FileOpenWrite (name);
        if (handle == -1)
        {
@@ -1410,29 +1439,6 @@ void COM_WriteFile (char *filename, void *data, int len)
 }
 
 
-/*
-============
-COM_CreatePath
-
-Only used for CopyFile
-============
-*/
-void    COM_CreatePath (char *path)
-{
-       char    *ofs;
-       
-       for (ofs = path+1 ; *ofs ; ofs++)
-       {
-               if (*ofs == '/')
-               {       // create the directory
-                       *ofs = 0;
-                       Sys_mkdir (path);
-                       *ofs = '/';
-               }
-       }
-}
-
-
 /*
 ===========
 COM_CopyFile
@@ -1476,12 +1482,15 @@ Sets com_filesize and one of handle or file
 */
 int COM_FindFile (char *filename, int *handle, FILE **file, qboolean quiet)
 {
-       searchpath_t    *search;
-       char            netpath[MAX_OSPATH];
-       char            cachepath[MAX_OSPATH];
-       pack_t          *pak;
-       int                     i;
-       int                     findtime, cachetime;
+       searchpath_t    *search;
+       char                    netpath[MAX_OSPATH];
+#if CACHEENABLE
+       char                    cachepath[MAX_OSPATH];
+       int                             cachetime;
+#endif
+       pack_t                  *pak;
+       int                             i;
+       int                             findtime;
 
        if (file && handle)
                Sys_Error ("COM_FindFile: both handle and file set");
@@ -1540,10 +1549,9 @@ int COM_FindFile (char *filename, int *handle, FILE **file, qboolean quiet)
                        if (findtime == -1)
                                continue;
                                
-               // see if the file needs to be updated in the cache
-                       if (!com_cachedir[0])
-                               strcpy (cachepath, netpath);
-                       else
+#if CACHEENABLE
+                       // see if the file needs to be updated in the cache
+                       if (com_cachedir[0])
                        {       
 #if defined(_WIN32)
                                if ((strlen(netpath) < 2) || (netpath[1] != ':'))
@@ -1560,6 +1568,7 @@ int COM_FindFile (char *filename, int *handle, FILE **file, qboolean quiet)
                                        COM_CopyFile (netpath, cachepath);
                                strcpy (netpath, cachepath);
                        }       
+#endif
 
                        if (!quiet)
                                Sys_Printf ("FindFile: %s\n",netpath);
@@ -1639,7 +1648,7 @@ void COM_CloseFile (int h)
 COM_LoadFile
 
 Filename are reletive to the quake directory.
-Allways appends a 0 byte.
+Always appends a 0 byte.
 ============
 */
 cache_user_t *loadcache;
@@ -1866,6 +1875,7 @@ void COM_InitFilesystem (void)
                        basedir[j-1] = 0;
        }
 
+#if CACHEENABLE
 //
 // -cachedir <path>
 // Overrides the system supplied cache directory (NULL or /qcache)
@@ -1883,6 +1893,7 @@ void COM_InitFilesystem (void)
                strcpy (com_cachedir, host_parms.cachedir);
        else
                com_cachedir[0] = 0;
+#endif
 
 //
 // start up with GAMENAME by default (id1)