]> Creatis software - crea.git/blobdiff - lib/creaDevManagerLib/modelCDMLib.cpp
Feature #1711
[crea.git] / lib / creaDevManagerLib / modelCDMLib.cpp
index 57411ec64f340fc70288a41e9d364eb33904831c..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 + "'.");