]> Creatis software - crea.git/blob - lib/creaDevManagerLib/ControlCreaDevManagerMain.cpp
eb3bdb06de5f23a8c37a9319089a029e5f0a5d87
[crea.git] / lib / creaDevManagerLib / ControlCreaDevManagerMain.cpp
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image 
5 #                        pour la Santé)
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 #
8 #  This software is governed by the CeCILL-B license under French law and 
9 #  abiding by the rules of distribution of free software. You can  use, 
10 #  modify and/ or redistribute the software under the terms of the CeCILL-B 
11 #  license as circulated by CEA, CNRS and INRIA at the following URL 
12 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
13 #  or in the file LICENSE.txt.
14 #
15 #  As a counterpart to the access to the source code and  rights to copy,
16 #  modify and redistribute granted by the license, users are provided only
17 #  with a limited warranty  and the software's author,  the holder of the
18 #  economic rights,  and the successive licensors  have only  limited
19 #  liability. 
20 #
21 #  The fact that you are presently reading this means that you have had
22 #  knowledge of the CeCILL-B license and that you accept its terms.
23 # ------------------------------------------------------------------------ */ 
24
25
26 /*
27  * ControlCreaDevManagerMain.cpp
28  *
29  *  Created on: 5/11/2012
30  *      Author: daniel
31  */
32
33 #include "ControlCreaDevManagerMain.h"
34
35 #include <cstdio>
36 #include <fstream>
37
38 ControlCreaDevManagerMain::ControlCreaDevManagerMain()
39 {
40 }
41
42 ControlCreaDevManagerMain::~ControlCreaDevManagerMain()
43 {
44 }
45
46 const modelCDMProjectsTree& ControlCreaDevManagerMain::GetActiveProjects() const
47 {
48   return projectsTree;
49 }
50
51 bool ControlCreaDevManagerMain::LoadActiveProjects()
52 {
53   // TODO LoadActiveProjects
54   std::cerr << "LoadActiveProjects unimplemented yet" << std::endl;
55   return true;
56 }
57
58 bool ControlCreaDevManagerMain::UpdateActiveProjects()
59 {
60   // TODO UpdateActiveProjects
61   std::cerr << "UpdateActiveProjects unimplemented yet" << std::endl;
62   return true;
63 }
64
65 const int ControlCreaDevManagerMain::OpenProject(const std::string& actualpath)
66 {
67   std::string path = actualpath;
68   std::cout << "selection path: "<< path << std::endl;
69   std::string path1 = path + "/Makefile";
70   FILE* pFile = fopen(path1.c_str(), "r");
71   if(pFile == NULL) // not the binary folder
72   {
73     std::cerr << path1 << ": file not found..." << std::endl;
74     path1 = path + "/CMakeLists.txt";
75     pFile = fopen(path1.c_str(), "r");
76     if(pFile == NULL) //not the source folder
77     {
78       std::cerr << path1 << ": file not found..." << std::endl;
79       return 1;
80     }else{//source folder
81       std::cout << "sources folder found..." << std::endl;
82       fclose(pFile);
83     }
84   }else{//binary folder
85     std::cout << "binary folder found..." << std::endl;
86     fclose(pFile);
87
88     std::ifstream readFile;
89     readFile.open(path1.c_str());
90     std::string word;
91     bool found = false;
92
93     while(!found && readFile >> word)
94     {
95       //cout << word << endl;
96       if(word == "CMAKE_SOURCE_DIR")
97       {
98         readFile >> word;
99         readFile.ignore();
100         getline(readFile, word, '\n');
101         path = word;
102         found = true;
103       }
104     }
105     readFile.close();
106
107     if(!found)
108     {
109         std::cerr << "sources not found..." << std::endl;
110
111         return 2;
112     }else{
113         pFile = fopen(path.c_str(), "r");
114         std::cout << "sources at " << path << " open = " << (pFile != NULL) << std::endl;
115         std::cout.flush();
116     }
117   }
118
119   projectsTree.SetRoot(path);
120   projectsTree.populateNode(path);
121   return 0;
122 }
123
124 bool ControlCreaDevManagerMain::CloseProject(const std::string& projectName)
125 {
126   // TODO CloseProject
127   std::cerr << "CloseProject unimplemented yet" << std::endl;
128   return true;
129 }