]> Creatis software - crea.git/blob - lib/creaDevManagerLib/ControlCreaDevManagerMain.cpp
Feature #1711
[crea.git] / lib / creaDevManagerLib / ControlCreaDevManagerMain.cpp
1 /*
2  * ControlCreaDevManagerMain.cpp
3  *
4  *  Created on: 5/11/2012
5  *      Author: daniel
6  */
7
8 #include "ControlCreaDevManagerMain.h"
9
10 #include <cstdio>
11 #include <fstream>
12
13 ControlCreaDevManagerMain::ControlCreaDevManagerMain()
14 {
15 }
16
17 ControlCreaDevManagerMain::~ControlCreaDevManagerMain()
18 {
19 }
20
21 const modelCDMProjectsTree& ControlCreaDevManagerMain::GetActiveProjects() const
22 {
23   return projectsTree;
24 }
25
26 bool ControlCreaDevManagerMain::LoadActiveProjects()
27 {
28   // TODO LoadActiveProjects
29   std::cerr << "LoadActiveProjects unimplemented yet" << std::endl;
30   return true;
31 }
32
33 bool ControlCreaDevManagerMain::UpdateActiveProjects()
34 {
35   // TODO UpdateActiveProjects
36   std::cerr << "UpdateActiveProjects unimplemented yet" << std::endl;
37   return true;
38 }
39
40 const int ControlCreaDevManagerMain::OpenProject(const std::string& actualpath)
41 {
42   std::string path = actualpath;
43   std::cout << "selection path: "<< path << std::endl;
44   std::string path1 = path + "/Makefile";
45   FILE* pFile = fopen(path1.c_str(), "r");
46   if(pFile == NULL) // not the binary folder
47   {
48     std::cerr << path1 << ": file not found..." << std::endl;
49     path1 = path + "/CMakeLists.txt";
50     pFile = fopen(path1.c_str(), "r");
51     if(pFile == NULL) //not the source folder
52     {
53       std::cerr << path1 << ": file not found..." << std::endl;
54       return 1;
55     }else{//source folder
56       std::cout << "sources folder found..." << std::endl;
57       fclose(pFile);
58     }
59   }else{//binary folder
60     std::cout << "binary folder found..." << std::endl;
61     fclose(pFile);
62
63     std::ifstream readFile;
64     readFile.open(path1.c_str());
65     std::string word;
66     bool found = false;
67
68     while(!found && readFile >> word)
69     {
70       //cout << word << endl;
71       if(word == "CMAKE_SOURCE_DIR")
72       {
73         readFile >> word;
74         readFile.ignore();
75         getline(readFile, word, '\n');
76         path = word;
77         found = true;
78       }
79     }
80     readFile.close();
81
82     if(!found)
83     {
84         std::cerr << "sources not found..." << std::endl;
85
86         return 2;
87     }else{
88         pFile = fopen(path.c_str(), "r");
89         std::cout << "sources at " << path << " open = " << (pFile != NULL) << std::endl;
90         std::cout.flush();
91     }
92   }
93
94   projectsTree.SetRoot(path);
95   projectsTree.populateNode(path);
96   return 0;
97 }
98
99 bool ControlCreaDevManagerMain::CloseProject(const std::string& projectName)
100 {
101   // TODO CloseProject
102   std::cerr << "CloseProject unimplemented yet" << std::endl;
103   return true;
104 }