Logo Search packages:      
Sourcecode: virtualbox-ose version File versions  Download package

void ConfigFileBase::createStubDocument (  )  [protected]

Creates a new stub xml::Document in the m->pDoc member with the root "VirtualBox" element set up. This is used by both MainConfigFile and MachineConfigFile at the beginning of writing out their XML.

Before calling this, it is the responsibility of the caller to set the "sv" member to the required settings version that is to be written. For newly created files, the settings version will be the latest (1.9); for files read in from disk earlier, it will be the settings version indicated in the file. However, this method will silently make sure that the settings version is always at least 1.7 and change it if necessary, since there is no write support for earlier settings versions.

Definition at line 534 of file Settings.cpp.

References iprt::MiniString::append(), Assert, iprt::MiniString::c_str(), iprt::MiniString::length(), NULL, settings::ConfigFileBase::Data::pDoc, settings::ConfigFileBase::Data::pelmRoot, settings::ConfigFileBase::Data::strFilename, settings::ConfigFileBase::Data::strSettingsVersionFull, iprt::MiniString::substr(), settings::ConfigFileBase::Data::sv, settings::ConfigFileBase::Data::svRead, and VBOX_XML_NAMESPACE.

    Assert(m->pDoc == NULL);
    m->pDoc = new xml::Document;

    m->pelmRoot = m->pDoc->createRootElement("VirtualBox");
    m->pelmRoot->setAttribute("xmlns", VBOX_XML_NAMESPACE);

    const char *pcszVersion = NULL;
    switch (m->sv)
        case SettingsVersion_v1_8:
            pcszVersion = "1.8";

        case SettingsVersion_v1_9:
        case SettingsVersion_Future:                // can be set if this code runs on XML files that were created by a future version of VBox;
                                                    // in that case, downgrade to current version when writing since we can't write future versions...
            pcszVersion = "1.9";
            m->sv = SettingsVersion_v1_9;

            // silently upgrade if this is less than 1.7 because that's the oldest we can write
            pcszVersion = "1.7";
            m->sv = SettingsVersion_v1_7;

    m->pelmRoot->setAttribute("version", Utf8StrFmt("%s-%s",
                                                    VBOX_XML_PLATFORM));       // e.g. "linux"

    // since this gets called before the XML document is actually written out
    // do this, this is where we must check whether we're upgrading the settings
    // version and need to make a backup, so the user can go back to an earlier
    // VirtualBox version and recover his old settings files.
    if (    (m->svRead != SettingsVersion_Null)     // old file exists?
         && (m->svRead < m->sv)                     // we're upgrading?
        // compose new filename: strip off trailing ".xml"
        Utf8Str strFilenameNew = m->strFilename.substr(0, m->strFilename.length() - 4);
        // and append something likd "-1.3-linux.xml"
        strFilenameNew.append(m->strSettingsVersionFull);       // e.g. "1.3-linux"

                   0);      // no RTFILEMOVE_FLAGS_REPLACE

        // do this only once
        m->svRead = SettingsVersion_Null;

Generated by  Doxygen 1.6.0   Back to index