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