#include "modelCDMAppli.h"
+#include <iostream>
+#include <fstream>
+
#include "CDMUtilities.h"
#include "creaWx.h"
#include "wx/dir.h"
{
}
-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)