std::string command = TEXT_EDITOR;
if(file != "")
- command += " \"" + file + "\" &";
+ command += " \"" + file + "\"";
+ command += " &";
return system(command.c_str());
}
std::string command = FILE_EXPLORER;
if(file != "")
- command += " \"" + file + "\" &";
+ command += " \"" + file + "\"";
+ command += " &";
return system(command.c_str());
}
{
std::string comm = command;
if(file != "")
- comm += " \"" + file + "\" &";
+ comm += " \"" + file + "\"";
+ comm += " &";
return system(comm.c_str());
}
int openCreaToolsTools()
{
+#ifdef _WIN32
+ std::string comm = "creaTools &";
+#else
std::string comm = "creaTools.sh &";
+#endif
+
return system(comm.c_str());
}
return true;
}
+ std::string stringify(const std::string& line)
+ {
+ std::string res;
+ for (int i = 0; i < line.size(); i++)
+ {
+ if(line[i] == '\\')
+ res.push_back('\\');
+ if(line[i] == '\"')
+ res.push_back('\\');
+ res.push_back(line[i]);
+ }
+ return res;
+ }
+
}
* @return True if the class was successfully created.
*/
bool createEmptyClass(const std::string& name, const std::string& path);
+ /**
+ * Creates a string replacing each \ by \\.
+ * @param line String to stringify.
+ * @return line stringified.
+ */
+ std::string stringify(const std::string& line);
};
#endif /* CDMUTILITIES_H_ */
}
modelCDMApplication* modelCDMAppli::CreateApplication(
- const std::string& name,
+ const std::string& namein,
std::string*& result
)
{
+ std::vector<std::string> words;
+ CDMUtilities::splitter::split(words,namein," '/\\*\"%",CDMUtilities::splitter::no_empties);
+ std::string name;
+ for (int i = 0; i < (int)(words.size()); i++)
+ {
+ name += words[i];
+ }
+ if (name == "")
+ {
+ result = new std::string("The given name is not valid: '/\\*\"% are forbidden.");
+ return NULL;
+ }
//copy template application folder with new name
+#ifdef _WIN32
+ std::string copyCommand = "xcopy \"" + this->path + CDMUtilities::SLASH + "template_appli\" \"" + this->path + CDMUtilities::SLASH + name + CDMUtilities::SLASH + "\" /Y";
+#else
std::string copyCommand = "cp -r \"" + this->path + CDMUtilities::SLASH + "template_appli\" \"" + this->path + CDMUtilities::SLASH + name + "\"";
+#endif
+
if(system(copyCommand.c_str()))
{
result = new std::string("An error occurred while running '" + copyCommand + "'.");
in.close();
out.close();
//delete old file and rename new file
+#ifdef _WIN32
+ std::string renameCommand = "move /Y \"" + this->path + CDMUtilities::SLASH + name + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + name + CDMUtilities::SLASH + "CMakeLists.txt\"";
+#else
std::string renameCommand = "mv \"" + this->path + CDMUtilities::SLASH + name + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + name + CDMUtilities::SLASH + "CMakeLists.txt\"";
+#endif
+
if(system(renameCommand.c_str()))
{
result = new std::string("An error occurred while running '" + renameCommand + "'.");
in.close();
out.close();
//delete old file and rename new file
+#ifdef _WIN32
+ std::string renameCommand = "move /Y \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
+#else
std::string renameCommand = "mv \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
+#endif
+
if(system(renameCommand.c_str()))
{
result = new std::string("An error occurred while running '" + renameCommand + "'.");
in.close();
out.close();
//delete old file and rename new file
+#ifdef _WIN32
+ std::string renameCommand = "move /Y \"" + pathHeader + ".tmp\" \"" + pathHeader + "\"";
+#else
std::string renameCommand = "mv \"" + pathHeader + ".tmp\" \"" + pathHeader + "\"";
+#endif
+
if(system(renameCommand.c_str()))
{
result = new std::string("An error occurred while running '" + renameCommand + "'.");
in.close();
out.close();
//delete old file and rename new file
+#ifdef _WIN32
+ std::string renameCommand = "move /Y \"" + pathHeader + ".tmp\" \"" + pathHeader + "\"";
+#else
std::string renameCommand = "mv \"" + pathHeader + ".tmp\" \"" + pathHeader + "\"";
+#endif
+
if(system(renameCommand.c_str()))
{
result = new std::string("An error occurred while running '" + renameCommand + "'.");
in.close();
out.close();
//delete old file and rename new file
+#ifdef _WIN32
+ std::string renameCommand = "move /Y \"" + pathHeader + ".tmp\" \"" + pathHeader + "\"";
+#else
std::string renameCommand = "mv \"" + pathHeader + ".tmp\" \"" + pathHeader + "\"";
+#endif
if(system(renameCommand.c_str()))
{
result = new std::string("An error occurred while running '" + renameCommand + "'.");
}
modelCDMLibrary* modelCDMLib::CreateLibrary(
- const std::string& name,
+ const std::string& namein,
std::string*& result
)
{
+ std::vector<std::string> words;
+ CDMUtilities::splitter::split(words,namein," '/\\*\"%",CDMUtilities::splitter::no_empties);
+ std::string name;
+ for (int i = 0; i < (int)(words.size()); i++)
+ {
+ name += words[i];
+ }
+ if (name == "")
+ {
+ result = new std::string("The given name is not valid: '/\\*\"% are forbidden.");
+ return NULL;
+ }
//copy template library folder with new name
+#ifdef _WIN32
+ std::string copyCommand = "xcopy \"" + this->path + CDMUtilities::SLASH + "template_lib\" \"" + this->path + CDMUtilities::SLASH + name + CDMUtilities::SLASH + "\" /Y";
+#else
std::string copyCommand = "cp -r \"" + this->path + CDMUtilities::SLASH + "template_lib\" \"" + this->path + CDMUtilities::SLASH + name + "\"";
+#endif
if(system(copyCommand.c_str()))
{
result = new std::string("An error occurred while running '" + copyCommand + "'.");
in.close();
out.close();
//delete old file and rename new file
+#ifdef _WIN32
+ std::string renameCommand = "move /Y \"" + this->path + CDMUtilities::SLASH + name + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + name + CDMUtilities::SLASH + "CMakeLists.txt\"";
+#else
std::string renameCommand = "mv \"" + this->path + CDMUtilities::SLASH + name + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + name + CDMUtilities::SLASH + "CMakeLists.txt\"";
+#endif
if(system(renameCommand.c_str()))
{
result = new std::string("An error occurred while running '" + renameCommand + "'.");
in.close();
out.close();
//delete old file and rename new file
+#ifdef _WIN32
+ std::string renameCommand = "move /Y \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
+#else
std::string renameCommand = "mv \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
+#endif
if(system(renameCommand.c_str()))
{
result = new std::string("An error occurred while running '" + renameCommand + "'.");
#include <cstdlib>
#include <iostream>
#include <string>
+#include <vector>
#include <cstdio>
#include <fstream>
std::string pathBuild = "";
//check if Makefile file exists
- std::string pathMakefile = pathFixed + CDMUtilities::SLASH + "Makefile";
- FILE* pFile;
#ifdef _WIN32
+ std::string pathMakefile = pathFixed + CDMUtilities::SLASH + "CMakeCache.txt";
+ FILE* pFile;
errno_t errorOpen = fopen_s(&pFile, pathMakefile.c_str(), "r");
#else
+ std::string pathMakefile = pathFixed + CDMUtilities::SLASH + "Makefile";
+ FILE* pFile;
pFile = fopen(pathMakefile.c_str(), "r");
bool errorOpen = (pFile == NULL);
#endif
readFile.open(pathMakefile.c_str());
std::string word;
+
+#ifdef _WIN32
+ while(!isBinary && !readFile.eof())
+ {
+ getline(readFile, word, '\n');
+ std::vector<std::string> words;
+ CDMUtilities::splitter::split(words,word,"=",CDMUtilities::splitter::no_empties);
+ if(words.size() && words[0] == "CMAKE_HOME_DIRECTORY:INTERNAL")
+ {
+ pathBuild = pathFixed;
+ pathFixed = CDMUtilities::fixPath(words[1]);
+ for (int i = 0; i < (int)(pathFixed.size()); i++)
+ {
+ if (pathFixed[i]=='/')
+ pathFixed[i]='\\';
+ }
+ isBinary = true;
+ }
+ }
+#else
while(!isBinary && readFile >> word)
{
- if(word == "CMAKE_SOURCE_DIR")
+ if(word == "CMAKE_SOURCE_DIR")
{
readFile >> word;
readFile.ignore();
pathFixed = CDMUtilities::fixPath(word);
isBinary = true;
}
- }
+ }
+#endif
readFile.close();
}
}
else
{
- result = new std::string("No source folder found. Please make sure to select either the project's build or source folder.");
+ result = new std::string("No source folder found. Please make sure to select either the project's build or source folder. " + pathBuild + pathFixed);
return false;
}
in.close();
out.close();
//delete old file and rename new file
+#ifdef _WIN32
+ std::string renameCommand = "move /Y \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
+#else
std::string renameCommand = "mv \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
+#endif
+
if(system(renameCommand.c_str()))
{
result = new std::string("An error occurred while running '" + renameCommand + "'.");
in.close();
out.close();
//delete old file and rename new file
+#ifdef _WIN32
+ std::string renameCommand = "move /Y \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
+#else
std::string renameCommand = "mv \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
+#endif
+
if(system(renameCommand.c_str()))
{
result = new std::string("An error occurred while running '" + renameCommand + "'.");
in.close();
out.close();
//delete old file and rename new file
+#ifdef _WIN32
+ std::string renameCommand = "move /Y \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
+#else
std::string renameCommand = "mv \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
+#endif
+
if(system(renameCommand.c_str()))
{
result = new std::string("An error occurred while running '" + renameCommand + "'.");
//create command
std::string command = "bbCreateBlackBox";
command += " \"" + this->path + "\"";
+#ifdef _WIN32
+ command += " " + package;
+ command += " " + bbName;
+ command += " " + type;
+ command += " " + format;
+#else
command += " \"" + package + "\"";
command += " \"" + bbName + "\"";
command += " \"" + type + "\"";
command += " \"" + format + "\"";
+#endif
command += " \"" + bbAuthors + "\"";
command += " \"" + bbDescription + "\"";
command += " \"" + bbCategories + "\"";
in.close();
out.close();
//delete old file and rename new file
+#ifdef _WIN32
+ std::string renameCommand = "move /Y \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
+#else
std::string renameCommand = "mv \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt.tmp\" \"" + this->path + CDMUtilities::SLASH + "CMakeLists.txt\"";
+#endif
if(system(renameCommand.c_str()))
{
result = new std::string("An error occurred while running '" + renameCommand + "'.");
//call project to create package : use bbCreatePackage <path> <name> [author] [description]
std::string creationCommand = "bbCreatePackage \"" + this->path + "\" \"" + nameFixed + "\" \"" + authorFixed + "\" \"" + descriptionFixed + "\"";
//TODO: bbCreatePackage script always returning 0. It should return 1 or greater if any error
- if(system(creationCommand.c_str()))
+ bool resultCommand = 0 != system(creationCommand.c_str());
+#ifdef _WIN32
+ resultCommand = false;
+#endif
+ if(resultCommand)
{
result = new std::string("An error occurred while running '" + creationCommand + "'.");
return NULL;
//TODO: adjust for windows and mac
#ifdef _WIN32
// ------ Windows
+ if(0 == system("cmake-gui"))
+ return true;
+ else
+ {
+ result = new std::string("There was an error opening cmake-gui. Please make sure it's installed and that cmake's bin folder is in the system path.");
+ return false;
+ }
#elif __APPLE__
// ------ Apple
#else
//TODO: adjust for windows and mac
#ifdef _WIN32
// ------ Windows
+ //\\..\\IDE\\VCExpress.exe \"" + this->buildPath + CDMUtilities::SLASH + this->nameProject + ".sln\"
+// std::string command = "\"" + std::string(getenv("VS90COMNTOOLS")) + "..\\IDE\\VCExpress.exe\" \"" + this->buildPath + CDMUtilities::SLASH + this->nameProject + ".sln\" &";
+ std::string command = "\"\"%VS90COMNTOOLS%..\\IDE\\VCExpress.exe\" \"" + this->buildPath + CDMUtilities::SLASH + this->nameProject + ".sln\" &\"";
+ command = "start cmd.exe /k " + command + " &";
+ if(0 == system(command.c_str()))
+ return true;
+ else
+ {
+ result = new std::string("An error has happened running: \"" + command + "\". Please make sure to have visual c++ express installed and to have the VS90COMNTOOLS environment variable set.");
+ return false;
+ }
#elif __APPLE__
// ------ Apple
#else
return true;
}
-bool modelCDMProject::Connect(std::string*& result)
+bool modelCDMProject::Connect(std::string*& result, const std::string& folder)
{
- //TODO: adjust for windows and mac
+ //TODO: adjust for mac
#ifdef _WIN32
// ------ Windows
+ //open binary folder
+ wxDir dir(crea::std2wx(folder));
+
+ //if binary folder can't be opened then return false
+ if (!dir.IsOpened())
+ {
+ result = new std::string("The path could not be opened. Make sure the folder exists and contains a bbtkPackage file.");
+ return false;
+ }
+ //create plug command
+ std::string plugComm = "bbPlugPackage \"" + folder + "\"";
+ std::cout << "executing '" << plugComm << "'" << std::endl;
+ //execute plug command
+ if(system(std::string("start cmd.exe /k \"" + plugComm + "\"").c_str()))
+ {
+ //if there was an error then report it
+ result = new std::string("There was an error plugging the packages of the project, please check the console to read more about the problem.");
+ return false;
+ }
#elif __APPLE__
// ------ Apple
#else
// ------ Linux
//open binary folder
- wxDir dir(crea::std2wx((this->buildPath).c_str()));
+ wxDir dir(crea::std2wx(folder));
//if binary folder can't be opened then return false
if (!dir.IsOpened())
{
- result = new std::string("The build path could not be opened. Make sure to configure the project before compiling it");
+ result = new std::string("The path could not be opened. Make sure the folder exists and contains a bbtkPackage file.");
return false;
}
//create plug command
if(system(plugComm.c_str()))
{
//if there was an error then report it
- result = new std::string("There was an error plugging the packages of the project, please check the console to read more about the problem.");
+ result = new std::string("There was an error plugging the packages of the project, please check the plugging.log in the build folder file to read more about the problem.");
return false;
}
#endif
* @param result Result message for connecting the project.
* @return if the command cannot be executed it return false.
*/
- bool Connect(std::string*& result);
+ bool Connect(std::string*& result, const std::string& folder);
/**
* Checks the CMakeLists files to see what's going to be compiled and what's not.
createClassbt->SetToolTip(wxT("Create a new Class (.h and .cxx files)."));
wxButton* createFolderbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_FOLDER, _T("Create Folder (Optional)"));
createFolderbt->SetToolTip(wxT("Create a new Folder inside the application folder."));
- wxButton* openMainbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_CXX, _T("A. Open Main File (Optional)"));
+ wxButton* openMainbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_CXX, _T("A. Open Main File"));
openMainbt->SetToolTip(wxT("Open the main file in the application folder with the default code editor."));
openMainbt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMApplicationDescriptionPanel::OnMainMouseEnter,NULL,this);
openMainbt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMApplicationDescriptionPanel::OnMainMouseExit,NULL,this);
//compile project
void wxCDMProjectActionsPanel::OnBtnBuildProject(wxCommandEvent& event)
{
+#ifdef _WIN32
+ std::string* result;
+ if(!this->project->Build(result, ""))
+ {
+ wxMessageBox(crea::std2wx(result->c_str()), wxT("Project Compilation - Error!"));
+ return;
+ }
+#else
//get author from user
wxTextEntryDialog* buildDlg = new wxTextEntryDialog(
this,
//wxMessageBox(crea::std2wx("The compilation was executed successfully. Please check the \"building.log\" file located in the build folder to check the compilation result."), wxT("Project Compilation"));
}
}
+#endif
}
//plug packages
void wxCDMProjectActionsPanel::OnBtnConnectProject(wxCommandEvent& event)
{
std::string* result;
- if(!this->project->Connect(result))
+ wxString file = wxDirSelector(
+ wxT("Please select the folder containing the bbtkPackage file you want to use. Usually it is where you built your project."),
+ crea::std2wx(this->project->GetBuildPath())
+ );
+
+ if(file.IsEmpty() || !this->project->Connect(result, crea::wx2std(file)))
{
wxMessageBox(crea::std2wx(result->c_str()), wxT("Plug Packages - Error!"));
return;
}
- wxMessageBox(crea::std2wx("The connection was executed successfully. Please check the \"plugging.log\" file located in the build folder to check the compilation result."), wxT("Plug Package"));
+#ifdef _WIN32
+ wxMessageBox(crea::std2wx("The connection was executed successfully. Please check the console to see the compilation result."), wxT("Plug Package"));
+#else
+ wxMessageBox(crea::std2wx("The connection was executed successfully. Please check the \"plugging.log\" file located in the build folder to see the compilation result."), wxT("Plug Package"));
+#endif
+
}