VirtualBox

Changeset 28195 in vbox


Ignore:
Timestamp:
Apr 12, 2010 10:38:51 AM (15 years ago)
Author:
vboxsync
Message:

Main/OVF: add vbox settings version to vbox:Machine element

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/settings.h

    r28189 r28195  
    104104                              USBDeviceFiltersList &ll);
    105105
     106    void setVersionAttribute(xml::ElementNode &elm);
    106107    void createStubDocument();
    107108
     
    862863
    863864    void write(const com::Utf8Str &strFilename);
    864     void buildMachineXML(xml::ElementNode &elmMachine, bool fIncludeSnapshots);
     865
     866    enum
     867    {
     868        BuildMachineXML_IncludeSnapshots = 0x01,
     869        BuildMachineXML_WriteVboxVersionAttribute = 0x02
     870    };
     871    void buildMachineXML(xml::ElementNode &elmMachine, uint32_t fl);
    865872
    866873private:
  • trunk/src/VBox/Main/ApplianceImplExport.cpp

    r28162 r28195  
    12301230        vsdescThis->m->pMachine->copyMachineDataToSettings(*pConfig);
    12311231        pConfig->buildMachineXML(*pelmVBoxMachine,
    1232                                  false /* fIncludeSnapshots */);
     1232                                 settings::MachineConfigFile::BuildMachineXML_WriteVboxVersionAttribute);
     1233                                        // but not BuildMachineXML_IncludeSnapshots
    12331234        delete pConfig;
    12341235    }
  • trunk/src/VBox/Main/xml/Settings.cpp

    r28165 r28195  
    526526}
    527527
     528void ConfigFileBase::setVersionAttribute(xml::ElementNode &elm)
     529{
     530    const char *pcszVersion = NULL;
     531    switch (m->sv)
     532    {
     533        case SettingsVersion_v1_8:
     534            pcszVersion = "1.8";
     535        break;
     536
     537        case SettingsVersion_v1_9:
     538            pcszVersion = "1.9";
     539        break;
     540
     541        case SettingsVersion_v1_10:
     542        case SettingsVersion_Future:                // can be set if this code runs on XML files that were created by a future version of VBox;
     543                                                    // in that case, downgrade to current version when writing since we can't write future versions...
     544            pcszVersion = "1.10";
     545            m->sv = SettingsVersion_v1_10;
     546        break;
     547
     548        default:
     549            // silently upgrade if this is less than 1.7 because that's the oldest we can write
     550            pcszVersion = "1.7";
     551            m->sv = SettingsVersion_v1_7;
     552        break;
     553    }
     554
     555    elm.setAttribute("version", Utf8StrFmt("%s-%s",
     556                                           pcszVersion,
     557                                           VBOX_XML_PLATFORM));       // e.g. "linux"
     558}
     559
    528560/**
    529561 * Creates a new stub xml::Document in the m->pDoc member with the
     
    549581    m->pelmRoot->setAttribute("xmlns", VBOX_XML_NAMESPACE);
    550582
    551     const char *pcszVersion = NULL;
    552     switch (m->sv)
    553     {
    554         case SettingsVersion_v1_8:
    555             pcszVersion = "1.8";
    556             break;
    557 
    558         case SettingsVersion_v1_9:
    559             pcszVersion = "1.9";
    560             break;
    561 
    562         case SettingsVersion_v1_10:
    563         case SettingsVersion_Future:                // can be set if this code runs on XML files that were created by a future version of VBox;
    564                                                     // in that case, downgrade to current version when writing since we can't write future versions...
    565             pcszVersion = "1.10";
    566             m->sv = SettingsVersion_v1_10;
    567             break;
    568 
    569         default:
    570             // silently upgrade if this is less than 1.7 because that's the oldest we can write
    571             pcszVersion = "1.7";
    572             m->sv = SettingsVersion_v1_7;
    573             break;
    574     }
    575 
    576     m->pelmRoot->setAttribute("version", Utf8StrFmt("%s-%s",
    577                                                     pcszVersion,
    578                                                     VBOX_XML_PLATFORM));       // e.g. "linux"
    579 
    580     // since this gets called before the XML document is actually written out
    581     // do this, this is where we must check whether we're upgrading the settings
    582     // version and need to make a backup, so the user can go back to an earlier
     583    // add settings version attribute to root element
     584    setVersionAttribute(*m->pelmRoot);
     585
     586    // since this gets called before the XML document is actually written out,
     587    // this is where we must check whether we're upgrading the settings version
     588    // and need to make a backup, so the user can go back to an earlier
    583589    // VirtualBox version and recover his old settings files.
    584590    if (    (m->svRead != SettingsVersion_Null)     // old file exists?
     
    37013707 *  --  Appliance::buildXMLForOneVirtualSystem()
    37023708 *
     3709 * In fl, the following flag bits are recognized:
     3710 *
     3711 *  --  BuildMachineXML_IncludeSnapshots: If set, descend into the snapshots tree
     3712 *      of the machine and write out <Snapshot> and possibly more snapshots under
     3713 *      that, if snapshots are present. Otherwise all snapshots are suppressed.
     3714 *
     3715 *  --  BuildMachineXML_WriteVboxVersionAttribute: If set, add a settingsVersion
     3716 *      attribute to the machine tag with the vbox settings version. This is for
     3717 *      the OVF export case in which we don't have the settings version set in
     3718 *      the root element.
     3719 *
    37033720 * @param elmMachine XML <Machine> element to add attributes and elements to.
    3704  * @param fWriteSnapshots If false, we omit snapshots entirely (we don't recurse then).
     3721 * @param fl Flags.
    37053722 */
    37063723void MachineConfigFile::buildMachineXML(xml::ElementNode &elmMachine,
    3707                                         bool fIncludeSnapshots)
    3708 {
     3724                                        uint32_t fl)
     3725{
     3726    if (fl & BuildMachineXML_WriteVboxVersionAttribute)
     3727        // add settings version attribute to machine element
     3728        setVersionAttribute(elmMachine);
     3729
    37093730    elmMachine.setAttribute("uuid", makeString(uuid));
    37103731    elmMachine.setAttribute("name", strName);
     
    37163737    if (strStateFile.length())
    37173738        elmMachine.setAttribute("stateFile", strStateFile);
    3718     if (fIncludeSnapshots && !uuidCurrentSnapshot.isEmpty())
     3739    if (    (fl & BuildMachineXML_IncludeSnapshots)
     3740         && !uuidCurrentSnapshot.isEmpty())
    37193741        elmMachine.setAttribute("currentSnapshot", makeString(uuidCurrentSnapshot));
    37203742    if (strSnapshotFolder.length())
     
    37423764    writeExtraData(elmMachine, mapExtraDataItems);
    37433765
    3744     if (fIncludeSnapshots && llFirstSnapshot.size())
     3766    if (    (fl & BuildMachineXML_IncludeSnapshots)
     3767         && llFirstSnapshot.size())
    37453768        buildSnapshotXML(elmMachine, llFirstSnapshot.front());
    37463769
     
    39193942        xml::ElementNode *pelmMachine = m->pelmRoot->createChild("Machine");
    39203943        buildMachineXML(*pelmMachine,
    3921                         true /* fIncludeSnapshots */);
     3944                        MachineConfigFile::BuildMachineXML_IncludeSnapshots);
     3945                            // but not BuildMachineXML_WriteVboxVersionAttribute
    39223946
    39233947        // now go write the XML
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette