]> Creatis software - crea.git/blobdiff - lib/creaDevManagerLib/modelCDMApplication.cpp
Feature #1711
[crea.git] / lib / creaDevManagerLib / modelCDMApplication.cpp
index c39b48d769677ca311727fe391180d14aa109244..57770444d31e13ad6df5c98617f5b83ab7a9cb1e 100644 (file)
@@ -45,25 +45,19 @@ modelCDMApplication::modelCDMApplication()
 {
 }
 
-modelCDMApplication::modelCDMApplication(const std::string& path, const int& level)
+modelCDMApplication::modelCDMApplication(const std::string& path, const std::string& name, const int& level)
 {
+  std::cout << "creating application: " + path + "\n";
   //folder name
-  std::vector<std::string> words;
-  std::string delimiters;
-  //TODO::fix for windows
-  delimiters = "/";
-  CDMUtilities::splitter::split(words, path, delimiters, CDMUtilities::splitter::no_empties);
-  this->name = words[words.size()-1];
-
+  this->name = name;
   //path
   this->path = CDMUtilities::fixPath(path);
   //type
   this->type = wxDIR_DIRS;
   //level
   this->level = level;
-
   //open CMakeList
-  std::string pathMakeLists = path + "/CMakeLists.txt";
+  std::string pathMakeLists = path + CDMUtilities::SLASH + "CMakeLists.txt";
 
   std::ifstream confFile;
   confFile.open((pathMakeLists).c_str());
@@ -89,7 +83,7 @@ modelCDMApplication::modelCDMApplication(const std::string& path, const int& lev
                   word += " " + wordBits[i];
                 }
 
-              this->nameApplication = this->executableName = word;
+              this->executableName = word;
             }
         }
     }
@@ -108,7 +102,7 @@ modelCDMApplication::modelCDMApplication(const std::string& path, const int& lev
         {
           std::string stdfileName = crea::wx2std(fileName);
 
-          modelCDMFolder* folder = new modelCDMFolder(this->path + "/" + stdfileName, this->level + 1);
+          modelCDMFolder* folder = new modelCDMFolder(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
           this->folders.push_back(folder);
           this->children.push_back(folder);
 
@@ -123,30 +117,26 @@ modelCDMApplication::modelCDMApplication(const std::string& path, const int& lev
           //if CMakeLists, create CMakeLists
           if(stdfileName == "CMakeLists.txt")
             {
-              this->CMakeLists = new modelCDMCMakeListsFile(this->path + "/" + stdfileName, this->level + 1);
+              this->CMakeLists = new modelCDMCMakeListsFile(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
               this->children.push_back(this->CMakeLists);
             }
           //if is an unknown file, create file
           else
             {
-              this->children.push_back(new modelCDMFile(this->path + "/" + stdfileName, this->level + 1));
+              this->children.push_back(new modelCDMFile(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1));
             }
 
           cont = dir.GetNext(&fileName);
         }
     }
   this->SortChildren();
+  std::sort(this->folders.begin(), this->folders.end(), CompareNodeItem);
 }
 
 modelCDMApplication::~modelCDMApplication()
 {
 }
 
-const std::string& modelCDMApplication::GetNameApplication() const
-{
-  return this->nameApplication;
-}
-
 const std::string& modelCDMApplication::GetExecutableName() const
 {
   return this->executableName;
@@ -164,14 +154,14 @@ bool modelCDMApplication::SetExecutableName(const std::string& fileName, std::st
 
   std::string line;
   //opening original cmakelists
-  std::ifstream in((this->path + "/CMakeLists.txt").c_str());
+  std::ifstream in((this->path + CDMUtilities::SLASH + "CMakeLists.txt").c_str());
   if( !in.is_open())
     {
       result = new std::string("CMakeLists.txt file failed to open.");
       return false;
     }
   //opening temporal cmakelists
-  std::ofstream out((this->path + "/CMakeLists.txt.tmp").c_str());
+  std::ofstream out((this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp").c_str());
   if( !out.is_open())
     {
       result = new std::string("CMakeLists.txt.tmp file failed to open.");
@@ -187,27 +177,27 @@ bool modelCDMApplication::SetExecutableName(const std::string& fileName, std::st
   in.close();
   out.close();
   //delete old file and rename new file
-  std::string renameCommand = "mv " + this->path + "/CMakeLists.txt.tmp " + this->path + "/CMakeLists.txt";
+  std::string renameCommand = "mv \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
   if(system(renameCommand.c_str()))
     {
       result = new std::string("An error occurred while running '" + renameCommand + "'.");
       return false;
     }
 
-  this->executableName = this->nameApplication = fileNameReal;
+  this->executableName = fileNameReal;
   return true;
 }
 
 modelCDMFolder* modelCDMApplication::CreateFolder(const std::string& name, std::string*& result)
 {
   //TODO:: mkdir depending on OS
-  std::string command = "mkdir " + path + "/" + name;
+  std::string command = "mkdir " + path + CDMUtilities::SLASH + name;
   if(system(command.c_str()))
     {
       result = new std::string("Error executing: " + command + ".");
       return NULL;
     }
-  modelCDMFolder* folder = new modelCDMFolder(path + "/" + name, level + 1);
+  modelCDMFolder* folder = new modelCDMFolder(path + CDMUtilities::SLASH + name, name, level + 1);
   this->folders.push_back(folder);
   this->children.push_back(folder);
 
@@ -216,11 +206,12 @@ modelCDMFolder* modelCDMApplication::CreateFolder(const std::string& name, std::
 
 const bool modelCDMApplication::Refresh(std::string*& result)
 {
+  std::cout << "refreshing application: " << this->executableName << std::endl;
   //set attributes
   this->type = wxDIR_DIRS;
 
   //open CMakeList
-  std::string pathMakeLists = path + "/CMakeLists.txt";
+  std::string pathMakeLists = path + CDMUtilities::SLASH + "CMakeLists.txt";
 
   std::ifstream confFile;
   confFile.open((pathMakeLists).c_str());
@@ -235,10 +226,10 @@ const bool modelCDMApplication::Refresh(std::string*& result)
 
       if(wordBits[wordBits.size()-1] == "SET")
         {
-          //get library name
+          //get app name
           std::getline(confFile,word,')');
           CDMUtilities::splitter::split(wordBits, word, " ", CDMUtilities::splitter::no_empties);
-          if(wordBits[0] == "LIBRARY_NAME")
+          if(wordBits[0] == "EXE_NAME")
             {
               word = wordBits[1];
               for (int i = 2; i < wordBits.size(); i++)
@@ -246,7 +237,7 @@ const bool modelCDMApplication::Refresh(std::string*& result)
                   word += " " + wordBits[i];
                 }
 
-              this->nameApplication = this->executableName = word;
+              this->executableName = word;
             }
         }
     }
@@ -269,7 +260,7 @@ const bool modelCDMApplication::Refresh(std::string*& result)
           std::string applicationName = stdfileName;
           //check if they already exist
           bool found = false;
-          for (int i = 0;!found && i < this->folders.size(); i++)
+          for (int i = 0; !found && i < this->folders.size(); i++)
             {
               if (this->folders[i]->GetName() == applicationName)
                 {
@@ -283,7 +274,7 @@ const bool modelCDMApplication::Refresh(std::string*& result)
             }
           if(!found)
             {
-              modelCDMFolder* folder = new modelCDMFolder(this->path + "/" + stdfileName, this->level + 1);
+              modelCDMFolder* folder = new modelCDMFolder(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
               this->folders.push_back(folder);
               this->children.push_back(folder);
             }
@@ -300,7 +291,7 @@ const bool modelCDMApplication::Refresh(std::string*& result)
             {
               if (this->CMakeLists == NULL)
                 {
-                  this->CMakeLists = new modelCDMCMakeListsFile(this->path + "/" + stdfileName, this->level + 1);
+                  this->CMakeLists = new modelCDMCMakeListsFile(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
                   this->children.push_back(this->CMakeLists);
                 }
               else
@@ -315,7 +306,7 @@ const bool modelCDMApplication::Refresh(std::string*& result)
           else
             {
               bool found = false;
-              for (int i = 0; i <!found && this->children.size(); i++)
+              for (int i = 0; !found && i < this->children.size(); i++)
                 {
                   if (this->children[i]->GetName() == stdfileName)
                     {
@@ -328,7 +319,7 @@ const bool modelCDMApplication::Refresh(std::string*& result)
 
               if(!found)
                 {
-                  modelCDMFile* file = new modelCDMFile(this->path + "/" + stdfileName, this->level + 1);
+                  modelCDMFile* file = new modelCDMFile(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
                   this->children.push_back(file);
                 }
             }