bool cxProjectInfo::Load(const wxFileName& rootPath, const wxString& path, bool onlyFilters) { wxFileName projectPath(path, wxEmptyString); this->path = path; this->isRoot = (projectPath == rootPath); projectPath.SetFullName(wxT(".eprj")); if (!projectPath.FileExists()) return false; // Load plist file TiXmlDocument doc; wxFFile docffile(projectPath.GetFullPath(), _T("rb")); wxCHECK(docffile.IsOpened() && doc.LoadFile(docffile.fp()), false); // Get top dict const TiXmlHandle docHandle(&doc); const TiXmlElement* topDict = docHandle.FirstChildElement("plist").FirstChildElement().Element(); if (!topDict || strcmp(topDict->Value(), "dict") != 0) return false; // empty plist // Parse entries const TiXmlElement* entry = topDict->FirstChildElement(); for(; entry; entry = entry->NextSiblingElement() ) { if (strcmp(entry->Value(), "key") != 0) return false; // invalid dict const TiXmlElement* const value = entry->NextSiblingElement(); if (strcmp(entry->GetText(), "filters") == 0) { // Load all filters const TiXmlElement* filter = value->FirstChildElement(); for(; filter; filter = filter->NextSiblingElement() ) { if (strcmp(filter->Value(), "key") != 0) return false; // invalid dict // Set target array wxArrayString* filterArray = NULL; const char* filterName = filter->GetText(); if (strcmp(filterName, "includeDirs") == 0) filterArray = &this->includeDirs; else if (strcmp(filterName, "excludeDirs") == 0) filterArray = &this->excludeDirs; else if (strcmp(filterName, "includeFiles") == 0) filterArray = &this->includeFiles; else if (strcmp(filterName, "excludeFiles") == 0) filterArray = &this->excludeFiles; else { wxASSERT(false); break; } const TiXmlElement* const array = filter->NextSiblingElement(); if (strcmp(array->Value(), "array") != 0) return false; // invalid dict const TiXmlElement* child = array->FirstChildElement(); for(; child; child = child->NextSiblingElement() ) { const char* valType = child->Value(); if (strcmp(valType, "string") == 0) { const char* pattern = child->GetText(); if (pattern) filterArray->Add(wxString(pattern, wxConvUTF8)); } else { wxASSERT(false); } } filter = array; // jump over value } this->hasFilters = true; if (onlyFilters) return true; } else if (strcmp(entry->GetText(), "environment") == 0) { // Load all env variables const TiXmlElement* env = value->FirstChildElement(); for(; env; env = env->NextSiblingElement() ) { // Get Key if (strcmp(env->Value(), "key") != 0) return false; // invalid dict const char* key = env->GetText(); const TiXmlElement* const val = env->NextSiblingElement(); if (strcmp(val->Value(), "string") != 0) return false; // invalid dict const char* value = val->GetText(); if (key) { this->env[wxString(key, wxConvUTF8)] = value ? wxString(value, wxConvUTF8) : *wxEmptyString; } env = val; // jump over value } } else if (strcmp(entry->GetText(), "fileTriggers") == 0) { // Load all env variables const TiXmlElement* trigger = value->FirstChildElement(); for(; trigger; trigger = trigger->NextSiblingElement() ) { // Get Key if (strcmp(trigger->Value(), "key") != 0) return false; // invalid dict const char* key = trigger->GetText(); const TiXmlElement* const val = trigger->NextSiblingElement(); if (strcmp(val->Value(), "string") != 0) return false; // invalid dict const char* value = val->GetText(); if (key && value) { wxFileName path(wxString(value, wxConvUTF8)); path.MakeAbsolute(rootPath.GetPath()); this->triggers[wxString(key, wxConvUTF8)] = path.GetFullPath(); } trigger = val; // jump over value } } entry = value; // jump over value } if (onlyFilters && !this->hasFilters) return false; return true; }