]> Creatis software - crea.git/blob - appli/creaNewProject/creaNewProject.cpp
265d432b4e031c707ffc49d1b63dd5ca5ce53595
[crea.git] / appli / creaNewProject / creaNewProject.cpp
1 #include <creaWx.h>
2 #include <wx/dirdlg.h>
3 #include <stdlib.h> // for getenv
4
5 class myApp : public wxApp
6 {
7 public:
8   bool OnInit( );
9   int  OnExit() { return true; }
10 };
11
12 IMPLEMENT_APP(myApp);
13 CREA_WXMAIN_WITH_CONSOLE
14
15 bool myApp::OnInit( )
16 {
17   wxApp::OnInit();
18 #ifdef __WXGTK__
19   //See http://www.wxwindows.org/faqgtk.htm#locale
20   setlocale(LC_NUMERIC, "C");
21 #endif
22    wxInitAllImageHandlers();
23
24    wxString dir = wxDirSelector(_T("Select directory in which to create the project"), _T(""), wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST );
25
26    if (dir.IsEmpty()) return false;
27
28    wxString name = wxGetTextFromUser(_T("Enter project name"),
29                                      _T("creaNewProject"),
30                                      _T("New"));
31    if (name.IsEmpty()) return false;
32    
33    wxString description = wxGetTextFromUser(_T("Enter Package Description (html format)"),
34                                      _T("create New Package"),
35                                      _T("NO_DESCRIPTION"));
36    if (description.IsEmpty()) return false;
37
38 #if(_WIN32)
39         // \TODO rewrite, according to new trick // JPR
40         
41         char * install_Dir = getenv("bbtk_DIR");
42         std::string execGUICreateNewPackage(install_Dir);
43         execGUICreateNewPackage = "bbi " + execGUICreateNewPackage;
44
45         std::string command("creaNewProject.bat ");
46         std::string command1("creaSed.exe ");
47         std::string command2("del ");
48
49         command  += "\"" + crea::wx2std(dir) + "\" \"" + crea::wx2std(name) + "\"";
50         command1 += "\"" + crea::wx2std(dir)+"\\"+crea::wx2std(name)+"\\CMakeLists.txt.in\" " + "NameOfTheProject " + crea::wx2std(name) + "> \"" + crea::wx2std(dir)+"\\"+crea::wx2std(name)+"\\CMakeLists.txt\"";
51         command2 += "\"" + crea::wx2std(dir)+"\\"+crea::wx2std(name)+"\\CMakeLists.txt.in\"";
52         if ( ! system ( command.c_str() ) )
53         {
54                 system ( command1.c_str() );
55                 system ( command2.c_str() );
56                 wxMessageBox(_T("New Project created !"),_T("creaNewProject"),
57                                 wxOK | wxICON_INFORMATION);
58
59                 // Create a Package at the same time.   JPR
60                 
61                 /// \TODO rewrite, according to new trick // JPR
62                 execGUICreateNewPackage += "\..\..\..\share\bbtk\bbs\toolsbbtk\appli\GUICreatePackage.bbs";
63                 system(execGUICreateNewPackage.c_str());
64         }
65         else 
66         {
67                 wxString err(_T("An error occured while running '"));
68                 err +=  crea::std2wx(command) + _T("'");
69                 wxMessageBox(err,_T("creaNewProject"),wxOK | wxICON_ERROR);
70         }
71
72 // ------ LINUX / MacOS
73
74 #else
75         std::string command("creaNewProject.sh ");
76         command += "\"" + crea::wx2std(dir) + "\"" +" " + crea::wx2std(name);
77         
78         if ( ! system ( command.c_str() ) )
79         {
80                 wxMessageBox(_T("New Project created !"),_T("creaNewProject"),
81                                         wxOK | wxICON_INFORMATION);
82
83                 // Create a Package at the same time.   JPR
84                 
85                 //execGUICreateNewPackage += "/../../../share/bbtk/bbs/toolsbbtk/appli/GUICreatePackage.bbs";
86                 //system(execGUICreateNewPackage.c_str());
87                 
88                 // or, better, new trick :
89                 // bbCreatePackage nomDirectory nomPackage author Description
90    
91                 char *author = getenv("USER");
92                 std::string nomDirectory = crea::wx2std(dir) + "/" + crea::wx2std(name);
93                 std::string nomPackageDirectory = nomDirectory + "/" + "bbtk_" + crea::wx2std(name) + "_PKG";
94
95                 std::string bbCreatePackage("bbCreatePackage ");
96                 bbCreatePackage += nomDirectory + " " + crea::wx2std(name) + " " + author + " " + crea::wx2std(description);
97                 system (bbCreatePackage.c_str());
98                 
99                 std::string add;
100                 add = "echo 'ADD_SUBDIRECTORY(bbtk_" + crea::wx2std(name)  + "_PKG)' >> " + nomDirectory + "/CMakeLists.txt";
101                 //std::cout << add << std::endl;
102                 system(add.c_str());
103                 
104         }
105         else
106         {       
107                 wxString err(_T("An error occured while running '"));
108                 err +=  crea::std2wx(command) + _T("'");
109                 wxMessageBox(err,_T("creaNewProject"),wxOK | wxICON_ERROR);
110         }
111
112 #endif
113
114    return false;
115 }
116