VirtualBox

Changeset 105546 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Jul 30, 2024 11:59:31 PM (6 months ago)
Author:
vboxsync
Message:

FE/Qt: Added --restore-snapshot[=:]<name> option to VirtualBoxVM to make it simpler to work with snapshots from the command line. bugref:10727

Location:
trunk/src/VBox/Frontends/VirtualBox/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UICommon.cpp

    r105152 r105546  
    163163    , m_fAgressiveCaching(true)
    164164#endif
     165    , m_fNoKeyboardGrabbing(false)
    165166    , m_fRestoreCurrentSnapshot(false)
    166     , m_fNoKeyboardGrabbing(false)
    167167    , m_fExecuteAllInIem(false)
    168168    , m_uWarpPct(100)
     
    430430            enmOptType = OptType_VMRunner;
    431431            m_fRestoreCurrentSnapshot = true;
     432            m_strSnapshotToRestore.clear();
     433        }
     434        else if (   !::strcmp(arg, "--restore-snapshot")
     435                 || !::strncmp(arg, RT_STR_TUPLE("--restore-snapshot="))
     436                 || !::strncmp(arg, RT_STR_TUPLE("--restore-snapshot:")))
     437        {
     438            enmOptType = OptType_VMRunner;
     439            const char * const pszSep = &arg[sizeof("--restore-snapshot") - 1];
     440            if (*pszSep != '\0')
     441                m_strSnapshotToRestore = &pszSep[1];
     442            else if (++i < argc)
     443                m_strSnapshotToRestore = arguments.at(i);
     444            else
     445                m_strSnapshotToRestore.clear();
     446            m_fRestoreCurrentSnapshot = false;
    432447        }
    433448        else if (!::strcmp(arg, "--no-keyboard-grabbing"))
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UICommon.h

    r105152 r105546  
    168168        /** Returns the --restore-current option value (whether we should restore current snapshot before VM started). */
    169169        bool shouldRestoreCurrentSnapshot() const { return m_fRestoreCurrentSnapshot; }
    170         /** Defines whether we should fRestore current snapshot before VM started. */
    171         void setShouldRestoreCurrentSnapshot(bool fRestore) { m_fRestoreCurrentSnapshot = fRestore; }
     170        /** Returns the --restore-snapshot option value (whether to restore named snapshot before starting VM). */
     171        QString const &getSnapshotToRestore() const { return m_strSnapshotToRestore; }
     172        /** Clears the --restore-current and --restore-snapshot option values. */
     173        void clearSnapshotRestoreOptions() { m_fRestoreCurrentSnapshot = false; m_strSnapshotToRestore.clear(); }
    172174
    173175        /** Returns the --no-keyboard-grabbing option value (whether we should restore
     
    403405        bool  m_fAgressiveCaching;
    404406
    405         /** Holds the --restore-current option value. */
    406         bool  m_fRestoreCurrentSnapshot;
    407 
    408407        /** Holds the --no-keyboard-grabbing option value. */
    409408        bool  m_fNoKeyboardGrabbing;
     409
     410        /** Holds the --restore-current option value. */
     411        bool    m_fRestoreCurrentSnapshot;
     412        /** Holds the --restore-snapshot option value. */
     413        QString m_strSnapshotToRestore;
    410414
    411415        /** Holds the --fda option value (floppy image). */
  • trunk/src/VBox/Frontends/VirtualBox/src/main.cpp

    r105103 r105546  
    281281        "  --no-startvm-errormsgbox   do not show a message box for VM start errors\n"
    282282        "  --restore-current          restore the current snapshot before starting\n"
     283        "  --restore-snapshot=<name>  restore the named snapshot before starting\n"
    283284        "  --no-aggressive-caching    delays caching media info in VM processes\n"
    284285        "  --fda <image|none>         Mount the specified floppy image\n"
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.cpp

    r105265 r105546  
    123123
    124124    /* Restore current snapshot if requested: */
    125     if (uiCommon().shouldRestoreCurrentSnapshot())
     125    if (   uiCommon().shouldRestoreCurrentSnapshot()
     126        || !uiCommon().getSnapshotToRestore().isEmpty())
    126127    {
    127128        /* Create temporary session: */
     
    132133        /* Which VM we operate on? */
    133134        CMachine comMachine = comSession.GetMachine();
    134         /* Which snapshot we are restoring? */
    135         CSnapshot comSnapshot = comMachine.GetCurrentSnapshot();
     135        /* Which snapshot are we restoring? */
     136        CSnapshot comSnapshot = uiCommon().shouldRestoreCurrentSnapshot()
     137                              ? comMachine.GetCurrentSnapshot()
     138                              : comMachine.FindSnapshot(uiCommon().getSnapshotToRestore());
    136139
    137140        /* Prepare restore-snapshot progress: */
    138141        CProgress comProgress = comMachine.RestoreSnapshot(comSnapshot);
    139142        if (!comMachine.isOk())
    140             return msgCenter().cannotRestoreSnapshot(comMachine, comSnapshot.GetName(), comMachine.GetName());
     143            return msgCenter().cannotRestoreSnapshot(comMachine,
     144                                                     comSnapshot.isOk() ? comSnapshot.GetName()
     145                                                     /** @todo deal better with snapshot-not found issues: */
     146                                                     : uiCommon().shouldRestoreCurrentSnapshot() ? "current"
     147                                                     : uiCommon().getSnapshotToRestore(),
     148                                                     comMachine.GetName());
    141149
    142150        /* Show the snapshot-discarding progress: */
     
    149157
    150158        /* Clear snapshot-restoring request: */
    151         uiCommon().setShouldRestoreCurrentSnapshot(false);
     159        uiCommon().clearSnapshotRestoreOptions();
    152160    }
    153161
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