Exemple #1
0
bool wxXmlDocument::Save(wxOutputStream& stream) const
{
    if ( !IsOk() )
        return false;

    wxString s;

    wxMBConv *convMem = NULL;

#if wxUSE_UNICODE
    wxMBConv *convFile = new wxCSConv(GetFileEncoding());
#else
    wxMBConv *convFile = NULL;
    if ( GetFileEncoding() != GetEncoding() )
    {
        convFile = new wxCSConv(GetFileEncoding());
        convMem = new wxCSConv(GetEncoding());
    }
#endif

    s.Printf(wxT("<?xml version=\"%s\" encoding=\"%s\"?>\n"),
             GetVersion().c_str(), GetFileEncoding().c_str());
    OutputString(stream, s, NULL, NULL);

    OutputNode(stream, GetRoot(), 0, convMem, convFile);
    OutputString(stream, wxT("\n"), NULL, NULL);

    if ( convFile )
        delete convFile;
    if ( convMem )
        delete convMem;

    return true;
}
Exemple #2
0
bool wxXmlDocument::Save(wxOutputStream& stream, int indentstep) const
{
    if ( !IsOk() )
        return false;

    wxString s;

    wxMBConv *convMem = NULL,
             *convFile;

#if wxUSE_UNICODE
    convFile = new wxCSConv(GetFileEncoding());
    convMem = NULL;
#else
    if ( GetFileEncoding().CmpNoCase(GetEncoding()) != 0 )
    {
        convFile = new wxCSConv(GetFileEncoding());
        convMem = new wxCSConv(GetEncoding());
    }
    else // file and in-memory encodings are the same, no conversion needed
    {
        convFile =
        convMem = NULL;
    }
#endif

    s.Printf(wxT("<?xml version=\"%s\" encoding=\"%s\"?>\n"),
             GetVersion().c_str(), GetFileEncoding().c_str());
    OutputString(stream, s);

    OutputNode(stream, GetRoot(), 0, convMem, convFile, indentstep);
    OutputString(stream, wxT("\n"));

    delete convFile;
    delete convMem;

    return true;
}
Exemple #3
0
bool wxXmlDocument::Save(wxOutputStream& stream, int indentstep) const
{
    if ( !IsOk() )
        return false;

    wxScopedPtr<wxMBConv> convMem, convFile;

#if wxUSE_UNICODE
    convFile.reset(new wxCSConv(GetFileEncoding()));
#else
    if ( GetFileEncoding().CmpNoCase(GetEncoding()) != 0 )
    {
        convFile.reset(new wxCSConv(GetFileEncoding()));
        convMem.reset(new wxCSConv(GetEncoding()));
    }
    //else: file and in-memory encodings are the same, no conversion needed
#endif

    wxString dec = wxString::Format(
                                    wxS("<?xml version=\"%s\" encoding=\"%s\"?>\n"),
                                    GetVersion(), GetFileEncoding()
                                   );
    bool rc = OutputString(stream, dec, convMem.get(), convFile.get());

    wxXmlNode *node = GetDocumentNode();
    if ( node )
        node = node->GetChildren();

    while( rc && node )
    {
        rc = OutputNode(stream, node, 0, convMem.get(),
                        convFile.get(), indentstep) &&
             OutputString(stream, wxS("\n"), convMem.get(), convFile.get());
        node = node->GetNext();
    }
    return rc;
}
Exemple #4
0
DWORD
ParserConfigFile(po::options_description& config, const std::string& configFile)
{
    DWORD dwError = ERROR_SUCCESS;
#ifdef WIN32
    std::ifstream ifs(string_to_w(configFile).c_str(), std::ifstream::binary);
#else
    std::ifstream ifs(configFile.c_str(), std::ifstream::binary);
#endif
    if(!ifs)
    {
        std::cout << "Failed to open config file: " << configFile << "\n"
                  << "Exiting ...";
#ifdef WIN32
        dwError = GetLastError();
#else
        dwError = VMCAGetWin32ErrorCode(errno);
#endif
    }
    else
    {
        VMCA_FILE_ENCODING encoding = GetFileEncoding(ifs, true);

        if (encoding != VMCA_FILE_ENCODING_UTF8)
        {
            std::cout << "Config file: " << configFile
                      << "uses UTF16 encoding, certool supports only UTF8 or ASCII encoding for config files" << std::endl
                      << "Exiting ...";
            return VMCA_ARGUMENT_ERROR;
        }

        std::cout << "Using config file : " << configFile << std::endl;
        store(parse_config_file(ifs, config), argsMap);
        notify(argsMap);
    }
    return dwError;
}