Advertisement
Ember

buh

Aug 17th, 2015
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.58 KB | None | 0 0
  1. // ------------------------------------------------------------------------------------
  2. Void Resource::Manager::InitializeResourceLocation(const String& location)
  3. {
  4.     Bool result;
  5.  
  6.     Directory folder;
  7.     // Get all the files and folders in the location
  8.     result = folder.Read(location);
  9.  
  10.     // If recursive, be recursive
  11.     for(Int i = 0; i < folder.Folders.Count; ++i)
  12.     {
  13.         InitializeResourceLocation(location + folder.Folders[i] + "\\");
  14.     }
  15.  
  16.     // Iterate through every located file
  17.     for(Int i = 0; i < folder.Files.Count; ++i)
  18.     {
  19.         // Get the position of the extension separator
  20.         UInt pos = folder.Files[i].rfind('.');
  21.  
  22.         //
  23.         if(pos != std::string::npos)
  24.         {
  25.             // Get the extension
  26.             String extension = folder.Files[i].substr(pos + 1);
  27.  
  28.             if(extension.length() == 3)
  29.             {
  30.                 // Hash the extension for faster comparisons
  31.                 UInt hash = (extension[0] << 16) + (extension[1] << 8) + (extension[2]); //Hash::FNV32(extension.data(), extension.length());
  32.  
  33.                 // Match the extension to a supported resource type
  34.                 switch(hash)
  35.                 {
  36.                     // Input layout file
  37.                     case 'lay':
  38.                     {
  39.                         Layouts.Expand(1);
  40.                         UInt slot = Layouts.Append();
  41.                         Layouts[slot].CreateFromFile(location + folder.Files[i]);
  42.                         break;
  43.                     }
  44.                 }
  45.             }
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement