]> Creatis software - crea.git/blob - appli/creaNewProject/creaNewProject.cpp
93cfd5c9d70f085434f9b5cefd39221331a6d58a
[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 char * install_Dir = getenv("bbtk_DIR");
39 std::string execGUICreateNewPackage(install_Dir);
40 execGUICreateNewPackage = "bbi " + execGUICreateNewPackage;
41
42 #if(_WIN32)
43         std::string command("creaNewProject.bat ");
44         std::string command1("creaSed.exe ");
45         std::string command2("del ");
46
47         command  += "\"" + crea::wx2std(dir) + "\" \"" + crea::wx2std(name) + "\"";
48         command1 += "\"" + crea::wx2std(dir)+"\\"+crea::wx2std(name)+"\\CMakeLists.txt.in\" " + "NameOfTheProject " + crea::wx2std(name) + "> \"" + crea::wx2std(dir)+"\\"+crea::wx2std(name)+"\\CMakeLists.txt\"";
49         command2 += "\"" + crea::wx2std(dir)+"\\"+crea::wx2std(name)+"\\CMakeLists.txt.in\"";
50         if ( ! system ( command.c_str() ) )
51         {
52                 system ( command1.c_str() );
53                 system ( command2.c_str() );
54                 wxMessageBox(_T("New Project created !"),_T("creaNewProject"),
55                                 wxOK | wxICON_INFORMATION);
56
57                 // Create a Package at the same time.   JPR
58                 
59                 /// \TODO rewrite, according to new trick
60                 execGUICreateNewPackage += "\..\..\..\share\bbtk\bbs\toolsbbtk\appli\GUICreatePackage.bbs";
61                 system(execGUICreateNewPackage.c_str());
62         }
63         else 
64         {
65                 wxString err(_T("An error occured while running '"));
66                 err +=  crea::std2wx(command) + _T("'");
67                 wxMessageBox(err,_T("creaNewProject"),wxOK | wxICON_ERROR);
68         }
69
70 // ------ LINUX / MacOS
71
72 #else
73         std::string command("creaNewProject.sh ");
74         command += "\"" + crea::wx2std(dir) + "\"" +" " + crea::wx2std(name);
75         
76         if ( ! system ( command.c_str() ) )
77         {
78                 wxMessageBox(_T("New Project created !"),_T("creaNewProject"),
79                                         wxOK | wxICON_INFORMATION);
80
81                 // Create a Package at the same time.   JPR
82                 
83                 //execGUICreateNewPackage += "/../../../share/bbtk/bbs/toolsbbtk/appli/GUICreatePackage.bbs";
84                 //system(execGUICreateNewPackage.c_str());
85                 
86                 // or, better, new trick :
87                 // bbCreatePackage nomDirectory nomPackage author Description
88    
89                 char *author = getenv("USER");
90                 std::string nomDirectory = crea::wx2std(dir) + "/" + crea::wx2std(name);
91                 std::string nomPackageDirectory = nomDirectory + "/" + "bbtk_" + crea::wx2std(name) + "_PKG";
92
93                 std::string bbCreatePackage("bbCreatePackage ");
94                 bbCreatePackage += nomDirectory + " " + crea::wx2std(name) + " " + author + " " + crea::wx2std(description);
95                 system (bbCreatePackage.c_str());
96                 
97                 std::string add;
98                 add = "echo 'ADD_SUBDIRECTORY(bbtk_" + crea::wx2std(name)  + "_PKG)' >> " + nomDirectory + "/CMakeLists.txt";
99                 std::cout << add << std::endl;
100                 system(add.c_str());
101                 
102         }
103         else
104         {
105                 wxString err(_T("An error occured while running '"));
106                 err +=  crea::std2wx(command) + _T("'");
107                 wxMessageBox(err,_T("creaNewProject"),wxOK | wxICON_ERROR);
108         }
109
110 #endif
111
112    return false;
113 }
114