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