stoneharry

Untitled

Dec 3rd, 2011
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.53 KB | None | 0 0
  1. void LuaEngine::ScriptLoadDir(char* Dirname, LUALoadScripts* pak)
  2. {
  3. #ifdef WIN32
  4.     Log.Notice("LuaEngine", "Scanning Directory %s", Dirname);
  5.     HANDLE hFile;
  6.     WIN32_FIND_DATA FindData;
  7.     memset(&FindData, 0, sizeof(FindData));
  8.  
  9.     char SearchName[MAX_PATH];
  10.  
  11.     strcpy(SearchName, Dirname);
  12.     strcat(SearchName, "\\*.*");
  13.  
  14.     hFile = FindFirstFile(SearchName, &FindData);
  15.     FindNextFile(hFile, &FindData);
  16.  
  17.     while(FindNextFile(hFile, &FindData))
  18.     {
  19.         // custom condition
  20.         if(FindData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
  21.                 continue;
  22.                     string fname = Dirname;
  23.                     fname += "\\";
  24.                     fname += FindData.cFileName;
  25.  
  26.                 size_t len = strlen(fname.c_str());
  27.         if(FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)   //Credits for this 'if' go to Cebernic from ArcScripts Team. Thanks, you saved me some work ;-)
  28.         {
  29.             strcpy(SearchName, Dirname);
  30.             // custom 1 lines
  31.             printf("------- \n Folder: %s \n -------- \n", Dirname);
  32.             strcat(SearchName, "\\");
  33.             strcat(SearchName, FindData.cFileName);
  34.             ScriptLoadDir(SearchName, pak);
  35.         }
  36.         else
  37.         {
  38.             string fname = Dirname;
  39.             fname += "\\";
  40.             fname += FindData.cFileName;
  41.  
  42.             size_t len = strlen(fname.c_str());
  43.             int i = 0;
  44.             char ext[MAX_PATH];
  45.  
  46.             while(len > 0)
  47.             {
  48.                 ext[i++] = fname[--len];
  49.                 if(fname[len] == '.')
  50.                     break;
  51.             }
  52.             ext[i++] = '\0';
  53.             if ( !_stricmp(ext,"aul.") )
  54.             {
  55.                 pak->luaFiles.insert(fname);
  56.                 //printf("Loaded %s", fname);
  57.                 printf("Loaded %s \n", FindData.cFileName);
  58.             }
  59.         }
  60.     }
  61.     FindClose(hFile);
  62. #else
  63.  
Advertisement
Add Comment
Please, Sign In to add comment