void CFileItem::SaveItem(pugi::xml_node& element) const { if (m_edit != CEditHandler::none || !element) { return; } auto file = element.append_child("File"); AddTextElement(file, "LocalFile", m_localPath.GetPath() + GetLocalFile()); AddTextElement(file, "RemoteFile", GetRemoteFile()); AddTextElement(file, "RemotePath", m_remotePath.GetSafePath()); AddTextElementUtf8(file, "Download", Download() ? "1" : "0"); if (m_size != -1) { AddTextElement(file, "Size", m_size); } if (m_errorCount) { AddTextElement(file, "ErrorCount", m_errorCount); } if (m_priority != QueuePriority::normal) { AddTextElement(file, "Priority", static_cast<int>(m_priority)); } AddTextElementUtf8(file, "DataType", Ascii() ? "0" : "1"); if (m_defaultFileExistsAction != CFileExistsNotification::unknown) { AddTextElement(file, "OverwriteAction", m_defaultFileExistsAction); } }
void CFolderItem::SaveItem(pugi::xml_node& element) const { auto file = element.append_child("Folder"); if (Download()) { AddTextElement(file, "LocalFile", GetLocalPath().GetPath() + GetLocalFile()); } else { AddTextElement(file, "RemoteFile", GetRemoteFile()); AddTextElement(file, "RemotePath", m_remotePath.GetSafePath()); } AddTextElementUtf8(file, "Download", Download() ? "1" : "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); } }
void AddTextElement(pugi::xml_node node, std::wstring const& value) { AddTextElementUtf8(node, fz::to_utf8(value)); }
pugi::xml_node AddTextElement(pugi::xml_node node, const char* name, std::wstring const& value, bool overwrite) { return AddTextElementUtf8(node, name, fz::to_utf8(value), overwrite); }