]> Creatis software - crea.git/blobdiff - lib/creaDevManagerLib/modelCDMAppli.cpp
Feature #1711
[crea.git] / lib / creaDevManagerLib / modelCDMAppli.cpp
index 2bba913c0f7b98255fe3b77ff0a3a29915d22937..1f08f3b9b8dc5b4a2b2e429c85add024185193fb 100644 (file)
@@ -34,6 +34,9 @@
 
 #include "modelCDMAppli.h"
 
+#include <iostream>
+#include <fstream>
+
 #include "CDMUtilities.h"
 #include "creaWx.h"
 #include "wx/dir.h"
@@ -80,14 +83,55 @@ modelCDMAppli::~modelCDMAppli()
 {
 }
 
-bool modelCDMAppli::CreateApplication(
+modelCDMApplication* modelCDMAppli::CreateApplication(
     const std::string& name,
     std::string*& result,
     const std::string& path
 )
 {
-  //TODO: implement method
-  return true;
+  //copy template library folder with new name
+  //TODO: fix for windows
+  std::string copyCommand = "cp -r " + this->path + "/template_appli " + this->path + "/" + name;
+  if(system(copyCommand.c_str()))
+    {
+      result = new std::string("An error occurred while running '" + copyCommand + "'.");
+      return NULL;
+    }
+  //set name of library in CMakeLists inside copied folder
+  std::string line;
+  std::ifstream in((this->path + "/" + name + "/CMakeLists.txt").c_str());
+  if( !in.is_open())
+    {
+      result = new std::string("CMakeLists.txt file failed to open.");
+      return NULL;
+    }
+  std::ofstream out((this->path + "/" + name + "/CMakeLists.txt.tmp").c_str());
+  while (getline(in, line))
+    {
+      if(line == "SET ( EXE_NAME   MyExe  )")
+        line = "SET ( EXE_NAME   " + name + "  )";
+      out << line << std::endl;
+    }
+  in.close();
+  out.close();
+  //delete old file and rename new file
+  std::string renameCommand = "mv " + this->path + "/" + name + "/CMakeLists.txt.tmp " + this->path + "/" + name + "/CMakeLists.txt";
+  if(system(renameCommand.c_str()))
+    {
+      result = new std::string("An error occurred while running '" + renameCommand + "'.");
+      return NULL;
+    }
+
+  //add application to model
+  //TODO: fix for windows
+  modelCDMApplication* application = new modelCDMApplication(this->path + "/" + name, this->level + 1);
+  this->applications.push_back(application);
+  this->children.push_back(application);
+
+  this->SortChildren();
+
+  result = new std::string(this->path + "/" + name);
+  return application;
 }
 
 bool modelCDMAppli::OpenCMakeListsFile(std::string*& result)