Пример #1
0
void AddTextElement(pugi::xml_node node, const char* name, int64_t value, bool overwrite)
{
	if (overwrite) {
		node.remove_child(name);
	}
	auto child = node.append_child(name);
	child.text().set(static_cast<long long>(value));
}
Пример #2
0
pugi::xml_node AddTextElementUtf8(pugi::xml_node node, const char* name, std::string const& value, bool overwrite)
{
	assert(node);

	if (overwrite) {
		node.remove_child(name);
	}

	auto element = node.append_child(name);
	if (!value.empty()) {
		element.text().set(value.c_str());
	}

	return element;
}
Пример #3
0
pugi::xml_node AddTextElementRaw(pugi::xml_node node, const char* name, const char* value, bool overwrite)
{
	wxASSERT(node);
	wxASSERT(value);

	if (overwrite) {
		node.remove_child(name);
	}

	auto element = node.append_child(name);
	if (*value)
		element.text().set(value);

	return element;
}
Пример #4
0
void addFileDataNode(pugi::xml_node& parent, const FileData* file, const char* tag, SystemData* system)
{
	//create game and add to parent node
	pugi::xml_node newNode = parent.append_child(tag);

	//write metadata
	file->metadata.appendToXML(newNode, true, system->getStartPath());
	
	if(newNode.children().begin() == newNode.child("name") //first element is name
		&& ++newNode.children().begin() == newNode.children().end() //theres only one element
		&& newNode.child("name").text().get() == file->getDisplayName()) //the name is the default
	{
		//if the only info is the default name, don't bother with this node
		//delete it and ultimately do nothing
		parent.remove_child(newNode);
	}else{
		//there's something useful in there so we'll keep the node, add the path

		// try and make the path relative if we can so things still work if we change the rom folder location in the future
		newNode.prepend_child("path").text().set(makeRelativePath(file->getPath(), system->getStartPath(), false).generic_string().c_str());
	}
}
Пример #5
0
bool preprocess(pugi::xml_node node)
{
    for (pugi::xml_node child = node.first_child(); child; )
    {
        if (child.type() == pugi::node_pi && strcmp(child.name(), "include") == 0)
        {
            pugi::xml_node include = child;

            // load new preprocessed document (note: ideally this should handle relative paths)
            const char* path = include.value();

            pugi::xml_document doc;
            if (!load_preprocess(doc, path)) return false;

            // insert the comment marker above include directive
            node.insert_child_before(pugi::node_comment, include).set_value(path);

            // copy the document above the include directive (this retains the original order!)
            for (pugi::xml_node ic = doc.first_child(); ic; ic = ic.next_sibling())
            {
                node.insert_copy_before(ic, include);
            }

            // remove the include node and move to the next child
            child = child.next_sibling();

            node.remove_child(include);
        }
        else
        {
            if (!preprocess(child)) return false;

            child = child.next_sibling();
        }
    }

    return true;
}
Пример #6
0
void SetServer(pugi::xml_node node, const CServer& server)
{
	if (!node) {
		return;
	}

	bool kiosk_mode = COptions::Get()->GetOptionVal(OPTION_DEFAULT_KIOSKMODE) != 0;

	for (auto child = node.first_child(); child; child = node.first_child()) {
		node.remove_child(child);
	}

	AddTextElement(node, "Host", server.GetHost());
	AddTextElement(node, "Port", server.GetPort());
	AddTextElement(node, "Protocol", server.GetProtocol());
	AddTextElement(node, "Type", server.GetType());

	LogonType logonType = server.GetLogonType();

	if (server.GetLogonType() != ANONYMOUS) {
		AddTextElement(node, "User", server.GetUser());

		if (server.GetLogonType() == NORMAL || server.GetLogonType() == ACCOUNT) {
			if (kiosk_mode) {
				logonType = ASK;
			}
			else {
				std::string pass = fz::to_utf8(server.GetPass());
				
				pugi::xml_node passElement = AddTextElementUtf8(node, "Pass", fz::base64_encode(pass));
				if (passElement) {
					SetTextAttribute(passElement, "encoding", _T("base64"));
				}

				if (server.GetLogonType() == ACCOUNT) {
					AddTextElement(node, "Account", server.GetAccount());
				}
			}
		}
		else if (server.GetLogonType() == KEY) {
			AddTextElement(node, "Keyfile", server.GetKeyFile());
		}
	}
	AddTextElement(node, "Logontype", logonType);

	AddTextElement(node, "TimezoneOffset", server.GetTimezoneOffset());
	switch (server.GetPasvMode())
	{
	case MODE_PASSIVE:
		AddTextElementUtf8(node, "PasvMode", "MODE_PASSIVE");
		break;
	case MODE_ACTIVE:
		AddTextElementUtf8(node, "PasvMode", "MODE_ACTIVE");
		break;
	default:
		AddTextElementUtf8(node, "PasvMode", "MODE_DEFAULT");
		break;
	}
	AddTextElement(node, "MaximumMultipleConnections", server.MaximumMultipleConnections());

	switch (server.GetEncodingType())
	{
	case ENCODING_AUTO:
		AddTextElementUtf8(node, "EncodingType", "Auto");
		break;
	case ENCODING_UTF8:
		AddTextElementUtf8(node, "EncodingType", "UTF-8");
		break;
	case ENCODING_CUSTOM:
		AddTextElementUtf8(node, "EncodingType", "Custom");
		AddTextElement(node, "CustomEncoding", server.GetCustomEncoding());
		break;
	}

	if (CServer::SupportsPostLoginCommands(server.GetProtocol())) {
		std::vector<std::wstring> const& postLoginCommands = server.GetPostLoginCommands();
		if (!postLoginCommands.empty()) {
			auto element = node.append_child("PostLoginCommands");
			for (auto const& command : postLoginCommands) {
				AddTextElement(element, "Command", command);
			}				
		}
	}

	AddTextElementUtf8(node, "BypassProxy", server.GetBypassProxy() ? "1" : "0");
	std::wstring const& name = server.GetName();
	if (!name.empty()) {
		AddTextElement(node, "Name", name);
	}
}
Пример #7
0
int VR_DataAccessorNaviCN::getAddressMappingResult(pugi::xml_node &firstItem, pugi::xml_node &itemsNode, std::string &mappingType)
{
    int count = 0;
    VR_MappingTypeCN firstResultType = VR_MappingTypeCN::EMPTY;
    pugi::xml_node itemNodeTemplate = itemsNode.first_child();
    for (pugi::xml_node itemNode = firstItem; !itemNode.empty(); itemNode = itemNode.next_sibling()) {
        pugi::xml_node itemAddressNode = itemNode.first_child();
        std::string zone = itemAddressNode.child(VR_MSG_NAVI_ZONE).text().as_string();
        std::string city = itemAddressNode.child(VR_MSG_NAVI_CITY).text().as_string();
        std::string district = itemAddressNode.child(VR_MSG_NAVI_DISTRICT).text().as_string();
        std::string street = itemAddressNode.child(VR_MSG_NAVI_STREET).text().as_string();
        std::string streetBody = itemAddressNode.child(VR_MSG_NAVI_STREET_BODY).text().as_string();
        std::string houseNumber = itemAddressNode.child(VR_MSG_NAVI_HOUSE_NUMBER).text().as_string();

        VR_MappingTypeCN currentType = VR_MappingTypeCN::EMPTY;
        if (!zone.empty()) {
            currentType = VR_MappingTypeCN::TILL_STATE;
            if (!street.empty()) {
                currentType = VR_MappingTypeCN::TILL_STREET;
                if (!houseNumber.empty()) {
                    currentType = VR_MappingTypeCN::FULL;
                }
            }
            else {
                if (!district.empty()) {
                    currentType = VR_MappingTypeCN::TILL_DISTRICT;
                }
                else {
                    if (!city.empty()) {
                        currentType = VR_MappingTypeCN::TILL_CITY;
                    }
                }
            }
        }

        if (VR_MappingTypeCN::EMPTY == firstResultType) {
            if (VR_MappingTypeCN::EMPTY == currentType) {
                return count;
            }
            firstResultType = currentType;
        }

        if (firstResultType != currentType) {
            continue;
        }
        pugi::xml_node addressNode = itemsNode.append_copy(itemNodeTemplate).child(VR_MSG_NAVI_ADDRESS_ID);
        switch (firstResultType) {
        case VR_MappingTypeCN::FULL:
            addressNode.child(VR_MSG_NAVI_HOUSE_NUMBER).text().set(houseNumber.c_str());
        // need add stret info to addressNode
        case VR_MappingTypeCN::TILL_STREET:
            addressNode.child(VR_MSG_NAVI_STREET).text().set(street.c_str());
            addressNode.child(VR_MSG_NAVI_STREET_BODY).text().set(streetBody.c_str());
        // need add district info to addressNode
        case VR_MappingTypeCN::TILL_DISTRICT:
            addressNode.child(VR_MSG_NAVI_DISTRICT).text().set(district.c_str());
        // need add city info to addressNode
        case VR_MappingTypeCN::TILL_CITY:
            addressNode.child(VR_MSG_NAVI_CITY).text().set(city.c_str());
        // need add state info to addressNode
        case VR_MappingTypeCN::TILL_STATE:
            addressNode.child(VR_MSG_NAVI_ZONE).text().set(zone.c_str());
            break;
        default:
            break;
        }
        ++count;
    }

    // remove the itemNodeTemplate node
    itemsNode.remove_child(itemsNode.first_child());

    // get mappingType
    switch (firstResultType) {
    case VR_MappingTypeCN::FULL:
        mappingType = VR_MSG_RESPONSE_ADDRESS_MAPPING_TYPE_FULL;
        break;
    case VR_MappingTypeCN::TILL_STREET:
        mappingType = VR_MSG_RESPONSE_ADDRESS_MAPPING_TYPE_TILL_STREET;
        break;
    case VR_MappingTypeCN::TILL_DISTRICT:
        mappingType = VR_MSG_RESPONSE_ADDRESS_MAPPING_TYPE_TILL_DISTRICT;
        break;
    case VR_MappingTypeCN::TILL_CITY:
        mappingType = VR_MSG_RESPONSE_ADDRESS_MAPPING_TYPE_TILL_CITY;
        break;
    case VR_MappingTypeCN::TILL_STATE:
        mappingType = VR_MSG_RESPONSE_ADDRESS_MAPPING_TYPE_TILL_STATE;
        break;
    default:
        break;
    }

    return count;
}
Пример #8
0
void SetServer(pugi::xml_node node, const CServer& server)
{
	if (!node)
		return;

	bool kiosk_mode = COptions::Get()->GetOptionVal(OPTION_DEFAULT_KIOSKMODE) != 0;

	for (auto child = node.first_child(); child; child = node.first_child()) {
		node.remove_child(child);
	}

	AddTextElement(node, "Host", server.GetHost());
	AddTextElement(node, "Port", server.GetPort());
	AddTextElement(node, "Protocol", server.GetProtocol());
	AddTextElement(node, "Type", server.GetType());

	enum LogonType logonType = server.GetLogonType();

	if (server.GetLogonType() != ANONYMOUS) {
		AddTextElement(node, "User", server.GetUser());

		if (server.GetLogonType() == NORMAL || server.GetLogonType() == ACCOUNT) {
			if (kiosk_mode)
				logonType = ASK;
			else {
				wxString pass = server.GetPass();
				auto const& buf = pass.utf8_str(); // wxWidgets has such an ugly string API....
				std::string utf8(buf.data(), buf.length());

				wxString base64 = wxBase64Encode(utf8.c_str(), utf8.size());
				pugi::xml_node passElement = AddTextElement(node, "Pass", base64);
				if (passElement) {
					SetTextAttribute(passElement, "encoding", _T("base64"));
				}

				if (server.GetLogonType() == ACCOUNT)
					AddTextElement(node, "Account", server.GetAccount());
			}
		}
		else if (server.GetLogonType() == KEY)
		{
			AddTextElement(node, "Keyfile", server.GetKeyFile());
		}
	}
	AddTextElement(node, "Logontype", logonType);

	AddTextElement(node, "TimezoneOffset", server.GetTimezoneOffset());
	switch (server.GetPasvMode())
	{
	case MODE_PASSIVE:
		AddTextElementRaw(node, "PasvMode", "MODE_PASSIVE");
		break;
	case MODE_ACTIVE:
		AddTextElementRaw(node, "PasvMode", "MODE_ACTIVE");
		break;
	default:
		AddTextElementRaw(node, "PasvMode", "MODE_DEFAULT");
		break;
	}
	AddTextElement(node, "MaximumMultipleConnections", server.MaximumMultipleConnections());

	switch (server.GetEncodingType())
	{
	case ENCODING_AUTO:
		AddTextElementRaw(node, "EncodingType", "Auto");
		break;
	case ENCODING_UTF8:
		AddTextElementRaw(node, "EncodingType", "UTF-8");
		break;
	case ENCODING_CUSTOM:
		AddTextElementRaw(node, "EncodingType", "Custom");
		AddTextElement(node, "CustomEncoding", server.GetCustomEncoding());
		break;
	}

	if (CServer::SupportsPostLoginCommands(server.GetProtocol())) {
		std::vector<wxString> const& postLoginCommands = server.GetPostLoginCommands();
		if (!postLoginCommands.empty()) {
			auto element = node.append_child("PostLoginCommands");
			for (std::vector<wxString>::const_iterator iter = postLoginCommands.begin(); iter != postLoginCommands.end(); ++iter) {
				AddTextElement(element, "Command", *iter);
			}				
		}
	}

	AddTextElementRaw(node, "BypassProxy", server.GetBypassProxy() ? "1" : "0");
	const wxString& name = server.GetName();
	if (!name.empty())
		AddTextElement(node, "Name", name);
}