vivienneanthony

function_used_to_Generate_xmlcopy

Jan 5th, 2016
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.30 KB | None | 0 0
  1.  
  2. void GAFactory::BuildXMLFIles(void)
  3. {
  4.  
  5. // Get File Sysstem
  6.     FileSystem * currentFileSystem = g_pApp->GetFileSystem();
  7.  
  8.  
  9.     // Get filesystem directory
  10.     String currentPath = currentFileSystem->GetProgramDir()+"GameData/";
  11.     String fullPath = currentPath+String("Models/");
  12.     String fullPath2 = currentPath+String("GameAssets/");
  13.  
  14.     Vector<String> FilesList;
  15.  
  16.     // Get Files
  17.     currentFileSystem->ScanDir(FilesList, fullPath, "*.mdl", SCAN_FILES, false);
  18.  
  19.     // if siles appeared
  20.     if(FilesList.Size()==0)
  21.     {
  22.  
  23.         URHO3D_LOGINFO("No models in directory file");
  24.  
  25.         return ;
  26.     }
  27.  
  28.  
  29.  
  30.     /// Template
  31.     String TemplateFile = fullPath2+String("TemplateEngineObject.txt");
  32.  
  33.     /// Flag file for loading and load
  34.     File templateLoadFile(context_, TemplateFile, FILE_READ);
  35.  
  36.     String * TemplateContent = new String();
  37.  
  38.     /// Read  a template file
  39.     if (templateLoadFile.GetSize()!=0)
  40.     {
  41.  
  42.         char * stringmemory = new char(templateLoadFile.GetSize());
  43.  
  44.         templateLoadFile.Read(stringmemory,templateLoadFile.GetSize());
  45.  
  46.         TemplateContent->Append(String(stringmemory));
  47.     }
  48.     else
  49.     {
  50.         URHO3D_LOGINFO("No template file");
  51.  
  52.         return;
  53.     }
  54.  
  55.     // loop through each and replate a new templatefile with code
  56.     // loop through each file listing
  57.     for(unsigned int fileListing = 0; fileListing<FilesList.Size(); fileListing++)
  58.     {
  59.         String newFilename = FilesList.At(fileListing);
  60.         newFilename.Replace(".mdl",".xml", false);
  61.  
  62.         /// Template
  63.         String NewResourceFilePath = fullPath2+String("/")+newFilename;
  64.  
  65.         /// Flag file for loading and load
  66.         File NewResourceFile(context_, NewResourceFilePath, FILE_WRITE);
  67.  
  68.         // Copy template
  69.         String CopyTemplate;
  70.  
  71.         CopyTemplate.Append(TemplateContent->CString());
  72.  
  73.         // Replace
  74.         String StrippedName = FilesList.At(fileListing);
  75.         StrippedName.Replace(".mdl","",false);
  76.  
  77.         CopyTemplate.Replace("##1##", StrippedName, true);
  78.         CopyTemplate.Replace("##2##",FilesList.At(fileListing), true);
  79.  
  80.         // Replace Code
  81.         NewResourceFile.Write(CopyTemplate.CString(), CopyTemplate.Length());
  82.  
  83.         NewResourceFile.Close();
  84.  
  85.  
  86.     }
  87.  
  88.     return;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment