]> Creatis software - crea.git/blobdiff - lib/creaDevManagerLib/modelCDMLib.cpp
Feature #1711
[crea.git] / lib / creaDevManagerLib / modelCDMLib.cpp
index e09cf2d978b3a4bb693ce4d6fb6c2f7dd9ee07db..e3c29023fffc04797962496f86d7f948d1fb2a00 100644 (file)
@@ -121,12 +121,28 @@ const std::vector<modelCDMLibrary*>& modelCDMLib::GetLibraries() const
 }
 
 modelCDMLibrary* modelCDMLib::CreateLibrary(
-    const std::string& name,
+    const std::string& namein,
     std::string*& result
 )
 {
+  std::vector<std::string> words;
+  CDMUtilities::splitter::split(words,namein," '/\\*\"%",CDMUtilities::splitter::no_empties);
+  std::string name;
+  for (int i = 0; i < (int)(words.size()); i++)
+    {
+         name += words[i];
+    }
+  if (name == "")
+    {
+      result = new std::string("The given name is not valid:  '/\\*\"% are forbidden.");
+         return NULL;
+    }
   //copy template library folder with new name
+#ifdef _WIN32
+       std::string copyCommand = "xcopy \"" + this->path + CDMUtilities::SLASH + "template_lib\" \"" + this->path + CDMUtilities::SLASH + name + CDMUtilities::SLASH + "\" /Y";
+#else
   std::string copyCommand = "cp -r \"" + this->path + CDMUtilities::SLASH + "template_lib\" \"" + this->path + CDMUtilities::SLASH + name + "\"";
+#endif
   if(system(copyCommand.c_str()))
     {
       result = new std::string("An error occurred while running '" + copyCommand + "'.");
@@ -150,7 +166,11 @@ modelCDMLibrary* modelCDMLib::CreateLibrary(
   in.close();
   out.close();
   //delete old file and rename new file
+#ifdef _WIN32
+  std::string renameCommand = "move /Y \"" + this->path + CDMUtilities::SLASH + name + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + name + CDMUtilities::SLASH + "CMakeLists.txt\"";
+#else
   std::string renameCommand = "mv \"" + this->path + CDMUtilities::SLASH + name + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + name + CDMUtilities::SLASH + "CMakeLists.txt\"";
+#endif
   if(system(renameCommand.c_str()))
     {
       result = new std::string("An error occurred while running '" + renameCommand + "'.");
@@ -193,7 +213,7 @@ const bool modelCDMLib::Refresh(std::string*& result)
               std::string libraryName = stdfileName;
               //check if library already exist
               bool found = false;
-              for (int i = 0; !found && i < this->libraries.size(); i++)
+              for (int i = 0; !found && i < (int)(this->libraries.size()); i++)
                 {
                   if (this->libraries[i]->GetName() == libraryName)
                     {
@@ -216,7 +236,7 @@ const bool modelCDMLib::Refresh(std::string*& result)
             {
               //check if folder already exist
               bool found = false;
-              for (int i = 0; !found && i < this->children.size(); i++)
+              for (int i = 0; !found && i < (int)(this->children.size()); i++)
                 {
                   if (this->children[i]->GetName() == stdfileName)
                     {
@@ -260,7 +280,7 @@ const bool modelCDMLib::Refresh(std::string*& result)
           else
             {
               bool found = false;
-              for (int i = 0; !found && i < this->children.size(); i++)
+              for (int i = 0; !found && i < (int)(this->children.size()); i++)
                 {
                   if (this->children[i]->GetName() == stdfileName)
                     {
@@ -282,7 +302,7 @@ const bool modelCDMLib::Refresh(std::string*& result)
         }
     }
 
-  for (int i = 0; i < checkedLibraries.size(); i++)
+  for (int i = 0; i < (int)(checkedLibraries.size()); i++)
     {
       if(!checkedLibraries[i])
         {
@@ -291,7 +311,7 @@ const bool modelCDMLib::Refresh(std::string*& result)
           i--;
         }
     }
-  for (int i = 0; i < checked.size(); i++)
+  for (int i = 0; i < (int)(checked.size()); i++)
     {
       if(!checked[i])
         {
@@ -312,7 +332,7 @@ void modelCDMLib::CheckStructure(std::map<std::string, bool>& properties)
   if(this->CMakeLists != NULL)
     {
       //set properties parameters based on model
-      for (int i = 0; i < this->libraries.size(); i++)
+      for (int i = 0; i < (int)(this->libraries.size()); i++)
         properties["lib add " + libraries[i]->GetName()] = false;
 
       //open cmakelists
@@ -334,7 +354,7 @@ void modelCDMLib::CheckStructure(std::map<std::string, bool>& properties)
                 {
                   word = words[0];
                   CDMUtilities::splitter::split(words, word, " ", CDMUtilities::splitter::empties_ok);
-                  for (int i = 0; i < words.size(); i++)
+                  for (int i = 0; i < (int)(words.size()); i++)
                     {
                       if(words[i].substr(0,2) == "//")
                         break;
@@ -372,7 +392,7 @@ void modelCDMLib::CheckStructure(std::map<std::string, bool>& properties)
     }
 
   //check libraries' structure
-  for (int i = 0; i < this->libraries.size(); i++)
+  for (int i = 0; i < (int)(this->libraries.size()); i++)
     {
       properties["library " + this->libraries[i]->GetName()] = true;
       this->libraries[i]->CheckStructure(properties);