-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstallParser.cpp
More file actions
175 lines (158 loc) · 4.67 KB
/
InstallParser.cpp
File metadata and controls
175 lines (158 loc) · 4.67 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
171
172
173
174
175
#include "InstallParser.h"
#include <sdk.h> // Code::Blocks SDK
#include <logmanager.h>
#include <string>
InstallParser::InstallParser(std::string sInstallFile):install_file(sInstallFile) {
}
void InstallParser::setFile(std::string sInstallFile) {
install_file = sInstallFile;
}
std::string InstallParser::getOS() {
if (platform::macosx)
return "mac";
else if (platform::windows)
return "win32";
else if (platform::linux)
return "linux";
else
return "unknown";
/*
//if (PLATFORM == PLATFORM_MSW)
// return "win32";
else if (PLATFORM == PLATFORM_MAC)
return "mac";
else
return "unknown";
*/
}
bool InstallParser::parse() {
Manager::Get()->GetLogManager()->Log(_T("Start parsing install file"));
TiXmlDocument doc(install_file.c_str());
if (!doc.LoadFile()) {
Manager::Get()->GetLogManager()->Log(_T("Cannot load xml file."));
return false;
}
Manager::Get()->GetLogManager()->Log(_T("Successfully loaded the install file"));
TiXmlElement* root = doc.RootElement();
if (strcmp(root->Value(), "install") != 0) {
Manager::Get()->GetLogManager()->Log(_T("The install file is not formatted correctly"));
return false;
}
// Files to be added to the project
//-----------------------------------------------------------------
TiXmlHandle handle(&doc);
TiXmlElement* add = handle
.FirstChild("install")
.FirstChild("add")
.FirstChild("src")
.FirstChild("folder")
.ToElement();
if (add) {
project_files.clear();
while(add) {
wxString folder(add->Attribute("name"),wxConvUTF8);
Manager::Get()->GetLogManager()->Log(folder);
TiXmlElement* file_el = add->FirstChild()->ToElement();
while(file_el) {
if (file_el) {
wxString file(file_el->GetText(), wxConvUTF8);
struct FileInfo project_file = {file};
project_files.push_back(project_file);
// Manager::Get()->GetLogManager()->Log(file);
}
else {
Manager::Get()->GetLogManager()->Log(_T("no file found"));
}
file_el = file_el->NextSiblingElement();
}
add = add->NextSiblingElement();
}
}
// @todo keep track of the includes
// Include dirs to be added.
//-----------------------------------------------------------------
TiXmlElement* includes = handle
.FirstChild("install")
.FirstChild("add")
.FirstChild("include")
.FirstChild("path")
.ToElement();
if (includes) {
while(includes) {
wxString include_dir(includes->GetText(),wxConvUTF8);
Manager::Get()->GetLogManager()->Log(include_dir);
include_dirs.push_back(include_dir);
includes = includes->NextSiblingElement();
}
}
else {
Manager::Get()->GetLogManager()->Log(_T("No includes dir found."));
}
// @todo keep track of the linker files
// Linker values.
//-----------------------------------------------------------------
std::string os = getOS();
TiXmlElement* link = handle
.FirstChild("install")
.FirstChild("add")
.FirstChild("link")
.FirstChild("lib")
.ToElement();
Manager::Get()->GetLogManager()->Log(_T("our os is: ") );
Manager::Get()->GetLogManager()->Log(_T(os.c_str()) );
while(link) {
wxString link_file(link->GetText(),wxConvUTF8);
if(strcmp(link->Attribute("os"),os.c_str()) == 0
&& std::string(link->Attribute("compiler")).find("codeblocks") != std::string::npos)
{
link_libs.push_back(link_file);
Manager::Get()->GetLogManager()->Log(link_file);
}
else {
Manager::Get()->GetLogManager()->Log(_T("Not linking:") +link_file);
}
link = link->NextSiblingElement();
}
// Shared objects.
//-----------------------------------------------------------------
/*
Manager::Get()->GetLogManager()->Log(_T("Add linker files."));
std::string os = getOS();
TiXmlElement* link = handle
.FirstChild("install")
.FirstChild("add")
.FirstChild("link")
.FirstChild("lib")
.ToElement();
while(link) {
if(strcmp(link->Attribute("os"),os.c_str()) == 0
&& std::string(link->Attribute("compiler")).find("codeblocks") != std::string::npos)
{
wxString link_file(link->GetText(),wxConvUTF8);
Manager::Get()->GetLogManager()->Log(link_file);
}
link = link->NextSiblingElement();
}
*/
// Required addons
TiXmlElement* required = handle
.FirstChild("install")
.FirstChild("requires")
.ToElement();
if(required) {
wxString required_addon(required->GetText(),wxConvUTF8);
required_addons.push_back(required_addon);
}
}
std::vector<FileInfo> InstallParser::getProjectFiles() {
return project_files;
}
std::vector<wxString> InstallParser::getRequiredAddons() {
return required_addons;
}
std::vector<wxString> InstallParser::getIncludeDirs() {
return include_dirs;
}
std::vector<wxString> InstallParser::getLinkLibs() {
return link_libs;
}