-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOpenFrameworks.cpp
More file actions
170 lines (144 loc) · 4.8 KB
/
OpenFrameworks.cpp
File metadata and controls
170 lines (144 loc) · 4.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include <sdk.h> // Code::Blocks SDK
#include <configurationpanel.h>
#include "OpenFrameworks.h"
#include <logmanager.h>
#include <string>
#include <wx/utils.h>
#include <wx/filename.h>
#include "cbproject.h"
#include "configmanager.h"
#include "projectmanager.h"
namespace {
PluginRegistrant<OpenFrameworks> reg(_T("OpenFrameworks"));
}
OpenFrameworks::OpenFrameworks() {
if (!Manager::LoadResource(_T("OpenFrameworks.zip"))) {
NotifyMissingFile(_T("OpenFrameworks.zip"));
}
}
OpenFrameworks::~OpenFrameworks() {
}
void OpenFrameworks::OnAttach() {
}
void OpenFrameworks::OnRelease(bool appShutDown) {
}
int OpenFrameworks::Execute() {
if (!IsAttached()) {
return -1;
}
Manager::Get()->GetLogManager()->Log(_T("openFrameworks Addon"));
// Add files to the project.
ProjectManager* project_mng = Manager::Get()->GetProjectManager();
cbProject* project = project_mng->GetActiveProject();
// Begin test: dialog
int dlg_id = wxNewId();
AddonDialog dlg(
Manager::Get()->GetAppWindow()
,dlg_id
,wxString(_T("openFrameworks Addon Plugin"))
);
PlaceWindow(&dlg);
if (dlg.ShowModal() == wxID_OK) {
std::vector<AddonFile> selected_addons = dlg.getNewSelectedAddons();
std::vector<AddonFile> deselected_addons = dlg.getDeselectedAddons();
std::vector<AddonFile> available_addons = dlg.getFoundAddons();
addAddons(selected_addons, available_addons);
removeAddons(deselected_addons);
project_mng->RebuildTree();
}
else {
Manager::Get()->GetLogManager()->Log(_T("No addons selected."));
}
return 0;
}
void OpenFrameworks::removeAddons(std::vector<AddonFile> oAddons) {
InstallParser* parser = new InstallParser("");
ProjectManager* project_mng = Manager::Get()->GetProjectManager();
cbProject* project = project_mng->GetActiveProject();
std::vector<int> ids;
// remove files.
for(int i = 0; i < oAddons.size(); ++i) {
std::string install_xml = std::string(oAddons.at(i).install_file.mb_str());
parser->setFile(install_xml);
parser->parse();
std::vector<FileInfo>addon_files = parser->getProjectFiles();
std::map<wxString, wxString> mapped_addon_files;
wxArrayInt targets;
// create a lookup table.
std::vector<FileInfo>::const_iterator it = addon_files.begin();
for(;it != addon_files.end();++it) {
wxFileName addon_file = it->file;
mapped_addon_files[addon_file.GetFullPath()] = addon_file.GetFullPath();
}
// now find the ids of the project files for the addon files.
for(int k = 0; k < project->GetFilesCount(); ++k) {
if (mapped_addon_files.find(project->GetFile(k)->relativeFilename) != mapped_addon_files.end()) {
ids.push_back(k);
}
}
// @todo remove linkers
// @todo remove includes
}
// And remove all found project files
project->BeginRemoveFiles();
for(std::vector<int>::iterator p = ids.begin(); p != ids.end(); p++) {
project->RemoveFile(*p);
}
project->EndRemoveFiles();
}
/**
*
*
* @param vector with addons to add.
* @param vector with all available addons (necessary for addon dependencies)
*/
void OpenFrameworks::addAddons(std::vector<AddonFile> oAddons, std::vector<AddonFile> oAvailableAddons) {
InstallParser* parser = new InstallParser("");
ProjectManager* project_mng = Manager::Get()->GetProjectManager();
cbProject* project = project_mng->GetActiveProject();
if(!project) {
return;
}
for(int i = 0; i < oAddons.size(); ++i) {
Manager::Get()->GetLogManager()->Log(_T("Add addon: ") +oAddons.at(i).name);
std::string install_xml = std::string(oAddons.at(i).install_file.mb_str());
parser->setFile(install_xml);
parser->parse();
// Add project files.
std::vector<FileInfo>project_files = parser->getProjectFiles();
wxArrayInt targets;
for(int i = 0; i <project_files.size(); ++i) {
project_mng->AddFileToProject(
project_files[i].file
,project
,targets
);
}
// add linkers. We add them at the "top" of the libs list. So
// in your install.xml file, you'll need to add the libs in a
// last-first order.
std::vector<wxString> libs = parser->getLinkLibs();
wxArrayString curr_link_opts =project->GetLinkerOptions();
for(int i = 0; i < libs.size(); ++i) {
curr_link_opts.Insert(libs.at(i),0);
}
project->SetLinkerOptions(curr_link_opts);
// add includes.
std::vector<wxString> includes = parser->getIncludeDirs();
for(int i = 0; i < includes.size(); ++i) {
project->AddIncludeDir(includes.at(i));
}
// Install required addons.
std::vector<wxString> required = parser->getRequiredAddons();
for(int k = 0; k < required.size(); k++) {
for(int l = 0; l < oAvailableAddons.size(); l++) {
if (oAvailableAddons.at(l).name == required.at(k)) {
std::vector<AddonFile> add_required;
add_required.push_back(oAvailableAddons.at(l));
addAddons(add_required, oAvailableAddons);
break;
}
}
}
}
}