예제 #1
0
// init level-info subsystem
void LoadLevelsList(void)
{
  CPrintF(TRANSV("Reading levels directory...\n"));

  // list the levels directory with subdirs
  CDynamicStackArray<CTFileName> afnmDir;
  MakeDirList(afnmDir, CTString("Levels\\"), CTString("*.wld"), DLI_RECURSIVE|DLI_SEARCHCD);

  // for each file in the directory
  for (INDEX i=0; i<afnmDir.Count(); i++) {
    CTFileName fnm = afnmDir[i];

    CPrintF(TRANSV("  file '%s' : "), (const char *)fnm);
    // try to load its info, and if valid
    CLevelInfo li;
    if (GetLevelInfo(li, fnm)) {
      CPrintF(TRANSV("'%s' spawn=0x%08x\n"), (const char *) li.li_strName, li.li_ulSpawnFlags);

      // create new info for that file
      CLevelInfo *pliNew = new CLevelInfo;
      *pliNew = li;
      // add it to list of all levels
      _lhAllLevels.AddTail(pliNew->li_lnNode);
    } else {
      CPrintF(TRANSV("invalid level\n"));
    }
  }

  // sort the list
  _lhAllLevels.Sort(qsort_CompareLevels, _offsetof(CLevelInfo, li_lnNode));
}
예제 #2
0
void FillDirList_internal(const CTFileName &fnmBasePath,
  CDynamicStackArray<CTFileName> &afnm, const CTFileName &fnmDir, const CTString &strPattern, BOOL bRecursive,
  CDynamicStackArray<CTFileName> *pafnmInclude, CDynamicStackArray<CTFileName> *pafnmExclude)
{
  // add the directory to list of directories to search
  CListHead lhDirs;
  CDirToRead *pdrFirst = new CDirToRead;
  pdrFirst->dr_strDir = fnmDir;
  lhDirs.AddTail(pdrFirst->dr_lnNode);

  // while the list of directories is not empty
  while (!lhDirs.IsEmpty()) {
    // take the first one
    CDirToRead *pdr = LIST_HEAD(lhDirs, CDirToRead, dr_lnNode);
    CTFileName fnmDir = pdr->dr_strDir;
    delete pdr;

    // if the dir is not allowed
    if (pafnmInclude!=NULL &&
      (!FileMatchesList(*pafnmInclude, fnmDir) || FileMatchesList(*pafnmExclude, fnmDir)) ) {
      // skip it
      continue;
    }
    
    // start listing the directory
    struct _finddata_t c_file; long hFile;
    hFile = _findfirst( (const char *)(fnmBasePath+fnmDir+"*"), &c_file );
    
    // for each file in the directory
    for (
      BOOL bFileExists = hFile!=-1; 
      bFileExists; 
      bFileExists = _findnext( hFile, &c_file )==0) {

      // if dummy dir (this dir, parent dir, or any dir starting with '.')
      if (c_file.name[0]=='.') {
        // skip it
        continue;
      }

      // get the file's filepath
      CTFileName fnm = fnmDir+c_file.name;

      // if it is a directory
      if (c_file.attrib&_A_SUBDIR) {
        // if recursive reading
        if (bRecursive) {
          // add it to the list of directories to search
          CDirToRead *pdrNew = new CDirToRead;
          pdrNew->dr_strDir = fnm+"\\";
          lhDirs.AddTail(pdrNew->dr_lnNode);
        }
      // if it matches the pattern
      } else if (strPattern=="" || fnm.Matches(strPattern)) {
        // add that file
        afnm.Push() = fnm;
      }
    }
  }
}
예제 #3
0
void CDlgClient::OnShowWindow(BOOL bShow, UINT nStatus) 
{
  CComboBox *cbShader = ((CComboBox*)GetDlgItem(IDC_CB_SHADER));
  if((bShow==TRUE) && (cbShader!=NULL))
  {
    // read all shaders files
    CDynamicStackArray<CTFileName> afnShaders;
    MakeDirList( afnShaders, CTString("Shaders\\"), "*.sha", 0);
    cbShader->ResetContent();
    for(INDEX ifn=0; ifn<afnShaders.Count(); ifn++)
    {
      CTFileName fnShader = afnShaders[ifn];
      cbShader->AddString(CString(fnShader.FileName()));
    }
  }
	CDialog::OnShowWindow(bShow, nStatus);
}
예제 #4
0
extern BOOL FileMatchesList(CDynamicStackArray<CTFileName> &afnm, const CTFileName &fnm)
{
  for(INDEX i=0; i<afnm.Count(); i++) {
    if (fnm.Matches(afnm[i]) || fnm.HasPrefix(afnm[i])) {
      return TRUE;
    }
  }
  return FALSE;
}
예제 #5
0
static INDEX GetNumberOfActiveEntries(void)
{
  INDEX ctActive = 0;
  for(INDEX ice=0; ice<_aceEntries.Count(); ice++) {
    if (_aceEntries[ice].ce_bActive) {
      ctActive++;
    }
  }
  return ctActive;
}
// start pasring fnParseFile file (may include mesh,skeleton,animset,...)
BOOL StartParser(CTString fnParseFile)
{
  CTFileName fnFull;
  fnFull = _fnmApplicationPath + fnParseFile;

  yyin = NULL;
  astrText.PopAll();
  astrText.Clear();
  // initialize pre-parsing variables
  yyin = fopen(fnFull, "r");
  // reset include depth ptr
  include_stack_ptr = 0;
  strCurentFileName = fnFull;

  _yy_iIndex = 0;
  _yy_jIndex = 0;
  _yy_iLine = 1;

  // load data
  try
  {
    if (yyin==NULL) {
      ThrowF_t("Cannot open file '%s'!", (const char*)fnParseFile );
    }

    yyrestart(yyin);
    yyparse();
 
    fclose(yyin);
  }
  // if an error in parsing occured
  catch(char *strError)
  {
    WarningMessage(strError);
    // AfxMessageBox(strError);
    theApp.ErrorMessage(strError);
    if(yyin!=NULL) fclose(yyin);
    return FALSE;
  }
return TRUE;
}
예제 #7
0
// load a filelist
static BOOL LoadFileList(CDynamicStackArray<CTFileName> &afnm, const CTFileName &fnmList)
{
  afnm.PopAll();
  try {
    CTFileStream strm;
    strm.Open_t(fnmList);
    while(!strm.AtEOF()) {
      CTString strLine;
      strm.GetLine_t(strLine);
      strLine.TrimSpacesLeft();
      strLine.TrimSpacesRight();
      if (strLine!="") {
        afnm.Push() = strLine;
      }
    }
    return TRUE;
  } catch(char *strError) {
    CPrintF("%s\n", strError);
    return FALSE;
  }
}
예제 #8
0
// dump list of all active files to the stream
void CRCT_MakeFileList_t(CTStream &strmFiles)  // throw char *
{
  // save number of active entries
  INDEX ctActive = GetNumberOfActiveEntries();
  strmFiles<<ctActive;
  // for each active entry
  for(INDEX ice=0; ice<_aceEntries.Count(); ice++) {
    CCRCEntry &ce = _aceEntries[ice];
    if (!ce.ce_bActive) {
      continue;
    }
    // save name to stream
    strmFiles<<(CTString&)ce.ce_fnmFile;
  }
}
예제 #9
0
// add one file to active list and get its crc
void CRCT_AddFile_t(const CTFileName &fnm, ULONG ulCRC/*=0*/) // throw char *
{
  // if not gathering CRCs now
  if (!CRCT_bGatherCRCs) {
    // do nothing
    return;
  }

  // try to find it in table
  CCRCEntry *pce = _ntEntries.Find(fnm);

  BOOL bNew = FALSE;
  // if found
  if (pce!=NULL) {
    // just activate it
    bNew = !pce->ce_bActive;
    pce->ce_bActive = TRUE;
    // if crc is given
    if (ulCRC!=0) {
      // force it
      pce->ce_ulCRC = ulCRC;
    }
  // if not found
  } else {
    // calculate checksum
    if (ulCRC==0) {
      
      if (FileMatchesList(_afnmNoCRC, fnm)) {
        ulCRC = 0x12345678;
      } else {
        ulCRC = GetFileCRC32_t(fnm);
      }
    }
    // add to the table
    pce = &_aceEntries.Push();
    pce->ce_fnmFile = fnm;
    pce->ce_ulCRC = ulCRC;
    pce->ce_bActive = TRUE;
    _ntEntries.Add(pce);
    bNew = TRUE;
  }
  if (bNew && net_bReportCRC) {
    CPrintF("CRC %08x: '%s'\n", pce->ce_ulCRC, (const char*)pce->ce_fnmFile);
  }
}
예제 #10
0
// reset all files to not active
void CRCT_ResetActiveList(void)
{
  for(INDEX ice=0; ice<_aceEntries.Count(); ice++) {
    _aceEntries[ice].ce_bActive = FALSE;
  }
}
예제 #11
0
// free all memory used by the crc cache
void CRCT_Clear(void)
{
  _ntEntries.Clear();
  _aceEntries.Clear();
}
예제 #12
0
// make a list of all files in a directory
ENGINE_API void MakeDirList(
  CDynamicStackArray<CTFileName> &afnmDir, const CTFileName &fnmDir, const CTString &strPattern, ULONG ulFlags)
{
  afnmDir.PopAll();
  BOOL bRecursive = ulFlags&DLI_RECURSIVE;
  BOOL bSearchCD  = ulFlags&DLI_SEARCHCD;

  // make one temporary array
  CDynamicStackArray<CTFileName> afnm;

  if (_fnmMod!="") {
    FillDirList_internal(_fnmApplicationPath, afnm, fnmDir, strPattern, bRecursive,
      &_afnmBaseBrowseInc, &_afnmBaseBrowseExc);
    if (bSearchCD) {
      FillDirList_internal(_fnmCDPath, afnm, fnmDir, strPattern, bRecursive,
      &_afnmBaseBrowseInc, &_afnmBaseBrowseExc);
    }
    FillDirList_internal(_fnmApplicationPath+_fnmMod, afnm, fnmDir, strPattern, bRecursive, NULL, NULL);
  } else {
    FillDirList_internal(_fnmApplicationPath, afnm, fnmDir, strPattern, bRecursive, NULL, NULL);
    if (bSearchCD) {
      FillDirList_internal(_fnmCDPath, afnm, fnmDir, strPattern, bRecursive, NULL, NULL);
    }
  }

  // for each file in zip archives
  CTString strDirPattern = fnmDir;
  INDEX ctFilesInZips = UNZIPGetFileCount();
  for(INDEX iFileInZip=0; iFileInZip<ctFilesInZips; iFileInZip++) {
    const CTFileName &fnm = UNZIPGetFileAtIndex(iFileInZip);

    // if not in this dir, skip it
    if (bRecursive) {
      if (!fnm.HasPrefix(strDirPattern)) {
        continue;
      }
    } else {
      if (fnm.FileDir()!=fnmDir) {
        continue;
      }
    }

    // if doesn't match pattern
    if (strPattern!="" && !fnm.Matches(strPattern)) {
      // skip it
      continue;
    }

    // if mod is active, and the file is not in mod
    if (_fnmMod!="" && !UNZIPIsFileAtIndexMod(iFileInZip)) {
      // if it doesn't match base browse path
      if ( !FileMatchesList(_afnmBaseBrowseInc, fnm) || FileMatchesList(_afnmBaseBrowseExc, fnm) ) {
        // skip it
        continue;
      }
    }

    // add that file
    afnm.Push() = fnm;
  }

  // if no files
  if (afnm.Count()==0) {
    // don't check for duplicates
    return;
  }

  // resort the array
  qsort(afnm.da_Pointers, afnm.Count(), sizeof(void*), qsort_CompareCTFileName);

  // for each file
  INDEX ctFiles = afnm.Count();
  for (INDEX iFile=0; iFile<ctFiles; iFile++) {
    // if not same as last one
    if (iFile==0 || afnm[iFile]!=afnm[iFile-1]) {
      // copy over to final array
      afnmDir.Push() = afnm[iFile];
    }
  }
}