Esempio n. 1
0
boolean GetPackTextureDirs(DIRLIST **dirlist)
{
	UInt16					i;
	char					buf[57];

	if (!pakopen)
		return 1;

  if (g_bPK3)
  {
    StrList *pl = g_PK3TexturePaths.Next();
    while (pl != NULL)
    {
      AddToDirListAlphabetized(dirlist, pl->Ref(), 0);
      pl = pl->Next();
    }
    return true;
  }

	for (i = 0; i < dirsize; i++)
	{
		if(!strnicmp(pakdirptr[i].name, "textures", 8))
		{
			strncpy(buf, &(pakdirptr[i].name[9]), 46);
			if(strchr(buf, '\\'))
	      	*strchr(buf, '\\') = '\0';
			else if(strchr(buf, '/'))
	      	*strchr(buf, '/') = '\0';
			else
	      	buf[56] = '\0';

			if(strchr(buf, '.'))
				continue;

			AddToDirListAlphabetized(dirlist, buf, 0);
		}
	}
	return true;
}
Esempio n. 2
0
// OpenPK3
// -------
// Opens a PK3 ( or zip ) file and creates a list of filenames
// and zip info structures
// 
boolean OpenPK3(const char *filename)
{
  char cFilename[WORK_LEN];
  char cName[WORK_LEN];
  char cWork[WORK_LEN];
  unz_file_info zInfo;
  unzFile *zFile = new unzFile(unzOpen(filename));
  g_zFiles.Add(zFile);
  if (zFile != NULL)
  {
    int nStatus = unzGoToFirstFile(*zFile);
    while (nStatus == UNZ_OK)
    {
      cFilename[0] = '\0';
      unzGetCurrentFileInfo(*zFile, &zInfo, cFilename, WORK_LEN, NULL, 0, NULL, 0);
      strlwr(cFilename);
    	__ConvertDOSToUnixName( cWork, cFilename);
      if (strstr(cWork, ".") != NULL)
      {
        PK3FileInfo *pInfo = new PK3FileInfo();
        pInfo->m_pName = __StrDup(cWork);
        memcpy(&pInfo->m_zInfo, (unz_s*)*zFile, sizeof(unz_s));
        pInfo->m_lSize = zInfo.uncompressed_size;
        pInfo->m_zFile = *zFile;
        g_PK3Files.Add(pInfo);
      }
      char *p = strstr(cFilename, TEXTURE_PATH);
      if (p != NULL)
      {
        // FIXME: path differences per os ?
        // catch solo directory entry
        if (strlen(p) > strlen(TEXTURE_PATH) + 1)
        {
          // skip textures + path seperator
          p += strlen(TEXTURE_PATH) + 1;
          int nEnd = strcspn(p, PATH_SEPERATORS);
          strncpy(cName, p, nEnd);
          cName[nEnd] = '\0';

          boolean bFound = false;
          StrList *pl = g_PK3TexturePaths.Next();
          while (pl != NULL)
          {
            if (strcmpi(pl->Ref(), cName) == 0)
            {
              // already have this, continue
              bFound = true;
              break;
            }
            pl = pl->Next();
          }
          if (!bFound)
          {
            g_PK3TexturePaths.Add(new Str(cName));
          }
        }
      }
      nStatus = unzGoToNextFile(*zFile);
    }
  }
  return (zFile != NULL);
}