VirtualBox

Changeset 22188 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Aug 11, 2009 6:06:11 PM (15 years ago)
Author:
vboxsync
Message:

Main: fix crash if VirtualBox.xml is not present.

Location:
trunk/src/VBox/Main
Files:
2 edited

Legend:

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

    r22187 r22188  
    3131#include <iprt/env.h>
    3232#include <iprt/cpputils.h>
     33#include <iprt/xml_cpp.h>
    3334
    3435#include <VBox/com/com.h>
     
    164165                                                VBOX_GLOBAL_SETTINGS_FILE);
    165166    HRESULT rc = S_OK;
     167    bool fCreate = false;
    166168    try
    167169    {
    168170        // load and parse VirtualBox.xml; this will throw on XML or logic errors
    169171        m_pMainConfigFile = new settings::MainConfigFile(&m_strSettingsFilePath);
    170 
    171         // either a) valid XML file loaded or b) file not found and defaults loaded:
    172         // now construct our global objects from that data
     172    }
     173    catch (xml::EIPRTFailure &e)
     174    {
     175        // this is thrown by the XML backend if the RTOpen() call fails;
     176        // only if the main settings file does not exist, create it,
     177        // if there's something more serious, then do fail!
     178        if (e.rc() == VERR_FILE_NOT_FOUND)
     179            fCreate = true;
     180    }
     181    catch (HRESULT err)
     182    {
     183        /* we assume that error info is set by the thrower */
     184        rc = err;
     185    }
     186    catch (...)
     187    {
     188        rc = VirtualBox::handleUnexpectedExceptions(RT_SRC_POS);
     189    }
     190
     191    try
     192    {
     193        if (fCreate)
     194            m_pMainConfigFile = new settings::MainConfigFile(NULL);
    173195
    174196#ifdef VBOX_WITH_RESOURCE_USAGE_API
     
    29863008
    29873009        // now write out the XML
    2988         m_pMainConfigFile->write();
     3010        m_pMainConfigFile->write(m_strSettingsFilePath);
    29893011    }
    29903012    catch (HRESULT err)
  • trunk/src/VBox/Main/xml/Settings.cpp

    r22173 r22188  
    786786 * builds an XML DOM tree and writes it out to disk.
    787787 */
    788 void MainConfigFile::write()
    789 {
     788void MainConfigFile::write(const com::Utf8Str strFilename)
     789{
     790    m->strFilename = strFilename;
    790791    createStubDocument();
    791792
     
    19521953{
    19531954    m->strFilename = strFilename;
    1954 
    19551955    createStubDocument();
    19561956
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