Advertisement
Guest User

Untitled

a guest
Dec 21st, 2014
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. #include <string.h>
  2. #include <fstream>
  3. #define BUFSIZE MAX_PATH
  4.  
  5. std::string replaceStrChar(std::string str, const std::string& replace, char ch){
  6. // set our locator equal to the first appearance of any character in replace
  7. size_t i = str.find_first_of(replace);
  8. unsigned found = str.find_first_of(replace);
  9. while (found != std::string::npos) { // While our position in the sting is in range.
  10. str[found] = ch; // Change the character at position.
  11. found = str.find_first_of(replace, found+1); // Relocate again.
  12. }
  13. return str; // return our new string.
  14. }
  15.  
  16. void loadResources(){
  17. Ogre::ConfigFile cf;
  18.  
  19. //Get Current Path
  20. char Buffer[BUFSIZE];
  21. DWORD dwRet;
  22. dwRet = GetCurrentDirectory(BUFSIZE, Buffer);
  23.  
  24. // Replace Backslashes with Forwardslashes
  25. std::string currentPath;
  26. currentPath.assign(Buffer);
  27. currentPath = replaceStrChar(currentPath, "\\", (char) 47);
  28.  
  29. std::string prefix = "FileSystem=";
  30. prefix.append(currentPath);
  31.  
  32. std::ofstream fout;
  33. fout.open("resources.cfg");
  34. fout << "[General]" << std::endl;
  35. fout << prefix + "/Resources/Materials" << std::endl;
  36. fout << prefix + "/Resources/Models"<< std::endl;
  37. fout << prefix + "/Resources/Textures" << std::endl;
  38. fout << prefix + "/Resources/Particles" << std::endl;
  39. fout << prefix + "/Resources/Fonts" << std::endl;
  40. // fout << prefix + "/Resources/Sounds" << std::endl;
  41.  
  42. fout.close();
  43.  
  44. #ifdef _DEBUG
  45. cf.load("resources.cfg"); // the same atm
  46. #else
  47. cf.load("resources.cfg");
  48. #endif
  49.  
  50. Ogre::ConfigFile::SectionIterator sectionIter = cf.getSectionIterator();
  51. Ogre::String sectionName, typeName, dataname;
  52. while (sectionIter.hasMoreElements()){
  53. sectionName = sectionIter.peekNextKey();
  54. Ogre::ConfigFile::SettingsMultiMap *settings = sectionIter.getNext();
  55. Ogre::ConfigFile::SettingsMultiMap::iterator i;
  56. for (i = settings->begin(); i != settings->end(); ++i){
  57. typeName = i->first;
  58. dataname = i->second;
  59.  
  60. Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
  61. dataname, typeName, sectionName);
  62. }
  63. }
  64.  
  65. Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement