VirtualBox

Changeset 23304 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
Sep 24, 2009 5:13:41 PM (15 years ago)
Author:
vboxsync
Message:

Main: make backups before overwriting old XML files; remove obsolete source file

Location:
trunk/src/VBox/Main
Files:
1 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/MachineImpl.cpp

    r23249 r23304  
    5353# include "USBProxyService.h"
    5454#endif
    55 
    56 #include "VirtualBoxXMLUtil.h"
    5755
    5856#include "Logging.h"
  • trunk/src/VBox/Main/VirtualBoxImpl.cpp

    r23235 r23304  
    6565#include "DHCPServerImpl.h"
    6666
    67 #include "VirtualBoxXMLUtil.h"
    68 
    6967#include "Logging.h"
    7068
     
    7270# include "win/svchlp.h"
    7371#endif
    74 
    75 // #include <stdio.h>
    76 // #include <stdlib.h>
    7772
    7873// defines
  • trunk/src/VBox/Main/xml/Settings.cpp

    r23289 r23304  
    2424#include <iprt/stream.h>
    2525#include <iprt/ctype.h>
    26 
    27 #include "VirtualBoxXMLUtil.h"
     26#include <iprt/file.h>
    2827
    2928// generated header
     
    3433using namespace com;
    3534using namespace settings;
     35
     36////////////////////////////////////////////////////////////////////////////////
     37//
     38// Defines
     39//
     40////////////////////////////////////////////////////////////////////////////////
     41
     42/** VirtualBox XML settings namespace */
     43#define VBOX_XML_NAMESPACE      "http://www.innotek.de/VirtualBox-settings"
     44
     45/** VirtualBox XML settings version number substring ("x.y")  */
     46#define VBOX_XML_VERSION        "1.9"
     47
     48/** VirtualBox XML settings version platform substring */
     49#if defined (RT_OS_DARWIN)
     50#   define VBOX_XML_PLATFORM     "macosx"
     51#elif defined (RT_OS_FREEBSD)
     52#   define VBOX_XML_PLATFORM     "freebsd"
     53#elif defined (RT_OS_LINUX)
     54#   define VBOX_XML_PLATFORM     "linux"
     55#elif defined (RT_OS_NETBSD)
     56#   define VBOX_XML_PLATFORM     "netbsd"
     57#elif defined (RT_OS_OPENBSD)
     58#   define VBOX_XML_PLATFORM     "openbsd"
     59#elif defined (RT_OS_OS2)
     60#   define VBOX_XML_PLATFORM     "os2"
     61#elif defined (RT_OS_SOLARIS)
     62#   define VBOX_XML_PLATFORM     "solaris"
     63#elif defined (RT_OS_WINDOWS)
     64#   define VBOX_XML_PLATFORM     "windows"
     65#else
     66#   error Unsupported platform!
     67#endif
     68
     69/** VirtualBox XML settings full version string ("x.y-platform") */
     70#define VBOX_XML_VERSION_FULL   VBOX_XML_VERSION "-" VBOX_XML_PLATFORM
     71
     72////////////////////////////////////////////////////////////////////////////////
     73//
     74// Internal data
     75//
     76////////////////////////////////////////////////////////////////////////////////
    3677
    3778/**
     
    4586        : pParser(NULL),
    4687          pDoc(NULL),
    47           pelmRoot(NULL)
     88          pelmRoot(NULL),
     89          sv(SettingsVersion_Null),
     90          svRead(SettingsVersion_Null)
    4891    {}
    4992
     
    59102    xml::Document           *pDoc;
    60103    xml::ElementNode        *pelmRoot;
     104
    61105    com::Utf8Str            strSettingsVersionFull;     // e.g. "1.7-linux"
    62     SettingsVersion_T       sv;                         // e.g. SETTINGS_VERSION_1_7
     106    SettingsVersion_T       sv;                         // e.g. SettingsVersion_v1_7
     107
     108    SettingsVersion_T       svRead;                     // settings version that the original file had when it was read,
     109                                                        // or SettingsVersion_Null if none
    63110
    64111    void cleanup()
     
    110157    }
    111158};
     159
     160////////////////////////////////////////////////////////////////////////////////
     161//
     162// ConfigFileBase
     163//
     164////////////////////////////////////////////////////////////////////////////////
    112165
    113166/**
     
    199252        if (m->sv == SettingsVersion_Null)
    200253            throw ConfigFileError(this, m->pelmRoot, N_("Cannot handle settings version '%s'"), m->strSettingsVersionFull.c_str());
     254
     255        // remember the settings version we read in case it gets upgraded later,
     256        // so we know when to make backups
     257        m->svRead = m->sv;
    201258    }
    202259    else
     
    425482 * Creates a new stub xml::Document in the m->pDoc member with the
    426483 * root "VirtualBox" element set up. This is used by both
    427  * MainConfigFile and MachineConfigFile when writing out their XML.
     484 * MainConfigFile and MachineConfigFile at the beginning of writing
     485 * out their XML.
    428486 *
    429487 * Before calling this, it is the responsibility of the caller to
     
    459517
    460518        default:
    461             // silently upgrade if necessary
     519            // silently upgrade if this is less than 1.7 because that's the oldest we can write
    462520            pcszVersion = "1.7";
    463521            m->sv = SettingsVersion_v1_7;
    464522        break;
    465523    }
     524
    466525    m->pelmRoot->setAttribute("version", Utf8StrFmt("%s-%s",
    467526                                                    pcszVersion,
    468527                                                    VBOX_XML_PLATFORM));       // e.g. "linux"
     528
     529    // since this gets called before the XML document is actually written out
     530    // do this, this is where we must check whether we're upgrading the settings
     531    // version and need to make a backup, so the user can go back to an earlier
     532    // VirtualBox version and recover his old settings files.
     533    if (    (m->svRead != SettingsVersion_Null)     // old file exists?
     534         && (m->svRead < m->sv)                     // we're upgrading?
     535       )
     536    {
     537        // compose new filename: strip off trailing ".xml"
     538        Utf8Str strFilenameNew = m->strFilename.substr(0, m->strFilename.length() - 4);
     539        // and append something likd "-1.3-linux.xml"
     540        strFilenameNew.append("-");
     541        strFilenameNew.append(m->strSettingsVersionFull);       // e.g. "1.3-linux"
     542        strFilenameNew.append(".xml");
     543
     544        RTFileMove(m->strFilename.c_str(),
     545                   strFilenameNew.c_str(),
     546                   0);      // no RTFILEMOVE_FLAGS_REPLACE
     547
     548        // do this only once
     549        m->svRead = SettingsVersion_Null;
     550    }
    469551}
    470552
     
    575657    return m->fFileExists;
    576658}
     659
     660
     661////////////////////////////////////////////////////////////////////////////////
     662//
     663// MainConfigFile
     664//
     665////////////////////////////////////////////////////////////////////////////////
    577666
    578667/**
     
    21352224}
    21362225
     2226////////////////////////////////////////////////////////////////////////////////
     2227//
     2228// MachineConfigFile
     2229//
     2230////////////////////////////////////////////////////////////////////////////////
     2231
    21372232/**
    21382233 * Constructor.
     
    21692264        }
    21702265
     2266        // clean up memory allocated by XML engine
    21712267        clearDocument();
    21722268    }
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